diff --git a/src/kiri/init.js b/src/kiri/init.js index edd885d3..49471d94 100644 --- a/src/kiri/init.js +++ b/src/kiri/init.js @@ -46,7 +46,8 @@ platform = API.platform, selection = API.selection; - let deviceImage = null, + let deviceURL = null, + deviceImage = null, deviceLock = false, selectedTool = null, editTools = null, @@ -735,34 +736,15 @@ API.conf.save(); - if (deviceImage) { + if (dev.imageURL) { + if (dev.imageURL !== deviceURL) { + deviceURL = dev.imageURL; + loadDeviceImage(dev); + } + } else 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); - }); + deviceURL = null; } } catch (e) { console.log({error:e, device:code, devicename}); @@ -775,6 +757,32 @@ API.event.settings(); } + function loadDeviceImage(dev) { + 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); + }); + } + function updateDeviceName() { let newname = UI.deviceName.value, selected = API.device.get(), diff --git a/web/kiri/gridbot.png b/web/kiri/gridbot.png index 0df6ccc8..6bb59793 100644 Binary files a/web/kiri/gridbot.png and b/web/kiri/gridbot.png differ