add optional device images

This commit is contained in:
Stewart Allen 2020-11-28 12:44:41 -05:00
commit a4cbaa9d0d
5 changed files with 53 additions and 11 deletions

View file

@ -46,7 +46,8 @@
platform = API.platform,
selection = API.selection;
let deviceLock = false,
let deviceImage = null,
deviceLock = false,
selectedTool = null,
editTools = null,
maxTool = 0,
@ -733,6 +734,36 @@
}
API.conf.save();
if (deviceImage) {
SPACE.world.remove(deviceImage);
deviceImage = null;
}
if (dev.imageURL) {
new THREE.TextureLoader().load(dev.imageURL, texture => {
if (deviceImage) {
SPACE.world.remove(deviceImage);
deviceImage = null;
}
if (!texture) {
return;
}
let { width, height } = texture.image;
let scale = dev.imageScale || 0.75;
let dev_ratio = dev.bedWidth / dev.bedDepth;
let img_ratio = width / height;
if (dev_ratio > img_ratio) {
scale *= dev.bedDepth / height;
} else {
scale *= dev.bedWidth / width;
}
let geometry = new THREE.PlaneBufferGeometry(width * scale, height * scale, 1),
material = new THREE.MeshBasicMaterial({ map: texture, transparent: true }),
mesh = new THREE.Mesh(geometry, material);
mesh.position.z = -dev.bedHeight;
SPACE.world.add(deviceImage = mesh);
});
}
} catch (e) {
console.log({error:e, device:code, devicename});
API.show.alert(`invalid or deprecated device: "${devicename}"`, 10);