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

@ -32,6 +32,8 @@
"progress": "M117 {progress}% layer {layer} / {layers}"
},
"settings":{
"image_url": "gridbot.png",
"image_scale": 0.7,
"origin_center": false,
"bed_width": 300,
"bed_depth": 300,

View file

@ -101,6 +101,8 @@
noclone: valueOf(code.no_clone, false),
mode: mode || code.mode || '',
internal: 0,
imageURL: valueOf(set.image_url, ""),
imageScale: valueOf(set.image_scale, 0.75),
bedHeight: valueOf(set.bed_height, 2.5),
bedWidth: valueOf(set.bed_width, 300),
bedDepth: valueOf(set.bed_depth, 175),
@ -247,6 +249,8 @@
d:{
new: true,
mode: "",
deviceName: "",
imageURL: "",
internal: 0,
bedWidth: 300,
bedDepth: 175,
@ -337,9 +341,10 @@
// device defaults SLA:Device
d:{
new: true,
deviceName: "",
noclone: false,
mode: "",
deviceName: "",
imageURL: "",
noclone: false,
internal: 0,
bedWidth: 150,
bedDepth: 150,
@ -380,6 +385,8 @@
d:{
new: true,
mode: "",
deviceName: "",
imageURL: "",
internal: 0,
bedWidth: 300,
bedDepth: 175,
@ -468,6 +475,8 @@
d:{
new: true,
mode: "",
deviceName: "",
imageURL: "",
internal: 0,
bedWidth: 300,
bedDepth: 175,

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);