add image anchor and more scaling control
This commit is contained in:
parent
80c87511bd
commit
69e4db9ee6
3 changed files with 33 additions and 8 deletions
|
|
@ -33,7 +33,8 @@
|
|||
},
|
||||
"settings":{
|
||||
"image_url": "gridbot.png",
|
||||
"image_scale": 0.7,
|
||||
"image_anchor": 0,
|
||||
"image_scale": 1,
|
||||
"origin_center": false,
|
||||
"bed_width": 300,
|
||||
"bed_depth": 300,
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@
|
|||
internal: 0,
|
||||
imageURL: valueOf(set.image_url, ""),
|
||||
imageScale: valueOf(set.image_scale, 0.75),
|
||||
imageAnchor: valueOf(set.image_anchor, 0),
|
||||
bedHeight: valueOf(set.bed_height, 2.5),
|
||||
bedWidth: valueOf(set.bed_width, 300),
|
||||
bedDepth: valueOf(set.bed_depth, 175),
|
||||
|
|
|
|||
|
|
@ -767,18 +767,41 @@
|
|||
return;
|
||||
}
|
||||
let { width, height } = texture.image;
|
||||
let { bedWidth, bedDepth, bedHeight } = dev;
|
||||
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;
|
||||
if (scale <= 1) {
|
||||
let dev_ratio = bedWidth / bedDepth;
|
||||
if (dev_ratio > img_ratio) {
|
||||
scale *= bedDepth / height;
|
||||
} else {
|
||||
scale *= bedWidth / width;
|
||||
}
|
||||
} else if (scale > 1) {
|
||||
scale = (scale / Math.max(width, height));
|
||||
}
|
||||
let geometry = new THREE.PlaneBufferGeometry(width * scale, height * scale, 1),
|
||||
width *= scale;
|
||||
height *= scale;
|
||||
let pos = null;
|
||||
if (true) switch (dev.imageAnchor) {
|
||||
case 1: pos = { x: -(bedWidth - width)/2, y: (bedDepth - height)/2 }; break;
|
||||
case 2: pos = { x: 0, y: (bedDepth - height)/2 }; break;
|
||||
case 3: pos = { x: (bedWidth - width)/2, y: (bedDepth - height)/2 }; break;
|
||||
case 4: pos = { x: -(bedWidth - width)/2, y: 0 }; break;
|
||||
case 5: pos = { x: (bedWidth - width)/2, y: 0 }; break;
|
||||
case 6: pos = { x: -(bedWidth - width)/2, y: -(bedDepth - height)/2 }; break;
|
||||
case 7: pos = { x: 0, y: -(bedDepth - height)/2 }; break;
|
||||
case 8: pos = { x: (bedWidth - width)/2, y: -(bedDepth - height)/2 }; break;
|
||||
}
|
||||
let geometry = new THREE.PlaneBufferGeometry(width, height, 1),
|
||||
material = new THREE.MeshBasicMaterial({ map: texture, transparent: true }),
|
||||
mesh = new THREE.Mesh(geometry, material);
|
||||
mesh.position.z = -dev.bedHeight;
|
||||
mesh.position.z = -bedHeight;
|
||||
mesh.renderOrder = -1;
|
||||
if (pos) {
|
||||
mesh.position.x = pos.x;
|
||||
mesh.position.y = pos.y;
|
||||
}
|
||||
SPACE.world.add(deviceImage = mesh);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue