2020-11-05 18:29:04 -05:00
|
|
|
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
|
|
let KIRI = self.kiri,
|
|
|
|
|
BASE = self.base,
|
|
|
|
|
UTIL = BASE.util,
|
2020-11-22 12:12:23 -05:00
|
|
|
FDM = KIRI.driver.FDM,
|
2020-11-22 12:57:25 -05:00
|
|
|
SPACE,
|
|
|
|
|
func = {};
|
2020-11-05 18:29:04 -05:00
|
|
|
|
|
|
|
|
FDM.init = function(kiri, api) {
|
2020-11-22 12:12:23 -05:00
|
|
|
SPACE = api.const.SPACE;
|
2020-11-05 18:29:04 -05:00
|
|
|
api.event.on("settings.load", (settings) => {
|
|
|
|
|
if (settings.mode !== 'FDM') return;
|
|
|
|
|
settings.process.outputOriginCenter = (settings.device.originCenter || false);
|
|
|
|
|
});
|
|
|
|
|
api.event.on("settings.saved", (settings) => {
|
|
|
|
|
let proc = settings.process;
|
|
|
|
|
api.ui.fdmSupport.marker.style.display = proc.sliceSupportEnable ? 'flex' : 'none';
|
|
|
|
|
});
|
2020-11-22 12:57:25 -05:00
|
|
|
api.event.on("button.click", target => {
|
|
|
|
|
switch (target) {
|
2020-11-22 13:15:27 -05:00
|
|
|
case api.ui.ssmAdd:
|
|
|
|
|
return func.sadd();
|
2020-11-22 13:35:01 -05:00
|
|
|
case api.ui.ssmDun:
|
|
|
|
|
return func.sdone();
|
2020-11-22 13:15:27 -05:00
|
|
|
case api.ui.ssmClr:
|
|
|
|
|
api.uc.confirm("clear supports?").then(ok => {
|
|
|
|
|
if (ok) func.sclear();
|
|
|
|
|
});
|
|
|
|
|
break;
|
2020-11-22 12:57:25 -05:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
api.event.on("fdm.supports.add", func.sadd = () => {
|
|
|
|
|
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.feature.hover = false;
|
|
|
|
|
});
|
|
|
|
|
api.event.on("fdm.supports.clear", func.sclear = () => {
|
2020-11-22 13:15:27 -05:00
|
|
|
func.sdone();
|
2020-11-22 12:57:25 -05:00
|
|
|
});
|
|
|
|
|
api.event.on("key.esc", func.sdone);
|
2020-11-22 13:15:27 -05:00
|
|
|
api.event.on("mouse.hover.up", int => {
|
|
|
|
|
// console.log({hover_up: int});
|
|
|
|
|
});
|
|
|
|
|
api.event.on("mouse.hover", data => {
|
2020-11-22 12:12:23 -05:00
|
|
|
const { int, type, point } = data;
|
|
|
|
|
if (SPACE._int1) {
|
|
|
|
|
SPACE.scene.remove(SPACE._int1);
|
|
|
|
|
}
|
|
|
|
|
addbox(point, 0xff0000, 'intZ');
|
|
|
|
|
let dir = new THREE.Vector3(0,1,0)
|
|
|
|
|
let ray = new THREE.Raycaster(point, dir);
|
|
|
|
|
// when on object, project down on downward faces
|
|
|
|
|
if (int && int.face && int.face.normal.z < -0.1) {
|
|
|
|
|
dir.y = -1;
|
|
|
|
|
}
|
2020-11-22 13:15:27 -05:00
|
|
|
let targets = api.widgets.meshes().append(SPACE.internals().platform);
|
|
|
|
|
let i2 = ray.intersectObjects(targets, false);
|
2020-11-22 12:12:23 -05:00
|
|
|
if (i2 && i2.length > 0) {
|
|
|
|
|
// prevent false matches close to origin of ray
|
|
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delbox(name) {
|
|
|
|
|
const old = SPACE[`__${name}`];
|
|
|
|
|
if (old) {
|
|
|
|
|
SPACE.scene.remove(old);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addbox(point, color, name) {
|
|
|
|
|
delbox(name);
|
|
|
|
|
name = `__${name}`;
|
|
|
|
|
const box = SPACE[name] = new THREE.Mesh(
|
|
|
|
|
new THREE.BoxGeometry(1, 1, 1),
|
|
|
|
|
new THREE.MeshBasicMaterial({color})
|
|
|
|
|
);
|
|
|
|
|
box.position.x = point.x;
|
|
|
|
|
box.position.y = point.y;
|
|
|
|
|
box.position.z = point.z;
|
|
|
|
|
SPACE.scene.add(box);
|
2020-11-05 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})();
|