checkpoint support work

This commit is contained in:
Stewart Allen 2020-11-22 14:53:17 -05:00
commit 373f133464
3 changed files with 52 additions and 20 deletions

View file

@ -9,6 +9,8 @@
UTIL = BASE.util,
FDM = KIRI.driver.FDM,
SPACE,
p1, p2, iw,
alert = [],
func = {};
FDM.init = function(kiri, api) {
@ -35,27 +37,44 @@
}
});
api.event.on("fdm.supports.add", func.sadd = () => {
api.show.alert("<esc> key when done editing supports");
alert = api.show.alert("<esc> key when done editing supports");
api.feature.hover = true;
});
api.event.on("fdm.supports.done", func.sdone = () => {
delbox('intZ');
delbox('intW');
api.hide.alert(alert);
api.feature.hover = false;
});
api.event.on("fdm.supports.clear", func.sclear = () => {
func.sdone();
});
api.event.on("key.esc", func.sdone);
api.event.on("key.esc", () => {
func.sdone()
});
// api.event.on("mouse.hover.down", data => {
// console.log({hover_down: data.point});
// });
api.event.on("mouse.hover.up", int => {
// console.log({hover_up: int});
console.log({hover_up: int, p1, p2, iw});
delbox('supp');
let hy = (p1.y + p2.y) / 2;
let dy = Math.abs(p1.y - p2.y);
let dw = api.conf.get().process.sliceSupportSize / 2;
addbox({x:p1.x, z:hy, y:-p1.z}, 0x0000dd, 'supp', {
x:dw, y:dw, z:dy
}, iw.mesh);
});
api.event.on("mouse.hover", data => {
const { int, type, point } = data;
if (SPACE._int1) {
SPACE.scene.remove(SPACE._int1);
if (int) {
iw = int.object.widget || iw;
}
addbox(point, 0xff0000, 'intZ');
// delbox('intZ');
// delbox('intW');
delbox('supp');
// addbox(point, 0xff0000, 'intZ');
p1 = point;
let dir = new THREE.Vector3(0,1,0)
let ray = new THREE.Raycaster(point, dir);
// when on object, project down on downward faces
@ -69,31 +88,42 @@
i2 = i2.filter(i => i.distance > 0.01);
// prevent single point base to top matches
if (i2.length > 1) {
i2 = i2[0].point;
addbox(i2, 0x00ff00, 'intW');
p2 = i2[0].point;
iw = i2[0].object.widget || iw;
let hy = (p1.y + p2.y) / 2;
let dy = Math.abs(p1.y - p2.y);
let dw = api.conf.get().process.sliceSupportSize / 2;
// addbox(p2, 0x00ff00, 'intW');
addbox({x:p1.x, y:hy, z:p1.z}, 0x0000dd, 'supp', {
x:dw, y:dw, z:dy
});
}
}
});
}
function delbox(name) {
function delbox(name, group) {
const old = SPACE[`__${name}`];
if (old) {
SPACE.scene.remove(old);
(group || SPACE.scene).remove(old);
}
}
function addbox(point, color, name) {
function addbox(point, color, name, dim = {x:1,y:1,z:1}, group) {
delbox(name);
name = `__${name}`;
const box = SPACE[name] = new THREE.Mesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshBasicMaterial({color})
new THREE.BoxGeometry(dim.x, dim.y, dim.z),
new THREE.MeshPhongMaterial({
transparent: true,
opacity: 0.5,
color
})
);
box.position.x = point.x;
box.position.y = point.y;
box.position.z = point.z;
SPACE.scene.add(box);
(group || SPACE.scene).add(box);
}
})();