diff --git a/src/kiri/init.js b/src/kiri/init.js
index f989f780..535602bf 100644
--- a/src/kiri/init.js
+++ b/src/kiri/init.js
@@ -1619,11 +1619,11 @@
fdmSep: UC.newBlank({class:"pop-sep", modes:FDM}),
sliceSupportSpan: UC.newInput(LANG.sp_span_s, {title:LANG.sp_span_l, bound:UC.bound(0.0,200.0), convert:UC.toFloat, modes:FDM, show: () => UI.sliceSupportEnable.checked}),
sliceSupportEnable: UC.newBoolean(LANG.sp_auto_s, onBooleanClick, {title: LANG.sp_auto_l, modes:FDM, trigger:true}),
- // sliceSupportGen: UC.newRow([
- // UI.ssaGen = UC.newButton('detect', onButtonClick)
- // ], { modes: FDM }),
fdmSep: UC.newBlank({class:"pop-sep", modes:FDM}),
+ sliceSupportGen: LOCAL ? UC.newRow([
+ UI.ssaGen = UC.newButton('detect', onButtonClick, {class: "f-col grow a-center"})
+ ], { modes: FDM, class: "ext-buttons f-row grow" }) : null,
sliceSupportManual: UC.newRow([
(UI.ssmAdd = UC.newButton(undefined, onButtonClick, {icon:''})),
(UI.ssmDun = UC.newButton(undefined, onButtonClick, {icon:''})),
diff --git a/src/mode/cam/driver.js b/src/mode/cam/driver.js
index 8903f6f1..e0058c11 100644
--- a/src/mode/cam/driver.js
+++ b/src/mode/cam/driver.js
@@ -34,7 +34,6 @@
KIRI.codec.decode(output).forEach(rec => {
ids.push(rec.id);
widgets[rec.id].traces = rec.traces;
- // widgets[rec.id].sindex = rec.sindex;
});
ondone(ids);
});
@@ -45,11 +44,10 @@
const { settings } = data;
const widgets = Object.values(cache);
const fresh = widgets.filter(widget => CAM.traces(settings, widget));
- send.done(KIRI.codec.encode(fresh.map(widget => {return {
+ send.done(KIRI.codec.encode(fresh.map(widget => { return {
id: widget.id,
traces: widget.traces,
- // sindex: widget.sindex
- }})));
+ } } )));
};
});
diff --git a/src/mode/fdm/client.js b/src/mode/fdm/client.js
index 491202f3..48ac5b1e 100644
--- a/src/mode/fdm/client.js
+++ b/src/mode/fdm/client.js
@@ -50,8 +50,30 @@
});
api.event.on("fdm.supports.gen", func.sgen = () => {
alert = api.show.alert("analyzing part...", 1000);
- FDM.support_generate(done => {
+ FDM.support_generate(array => {
+ console.log({generated_supports: array});
api.hide.alert(alert);
+ for (let rec of array) {
+ let { widget, supports } = rec;
+ let wa = API.widgets.annotate(widget.id);
+ let ws = wa.support || [];
+ for (let support of supports) {
+ let { from, to, mid } = support;
+ let dw = api.conf.get().process.sliceSupportSize / 2;
+ let dh = from.z - to.z;
+ let rec = {
+ x: mid.x,
+ y: mid.y,
+ z: mid.z,
+ dw,
+ dh,
+ id: Math.random() * 0xffffffffff
+ };
+ addWidgetSupport(widget, rec);
+ ws.push(Object.clone(rec));
+ }
+ wa.support = ws;
+ }
});
});
api.event.on("fdm.supports.add", func.sadd = () => {
diff --git a/src/mode/fdm/driver.js b/src/mode/fdm/driver.js
index 6a2005a4..eccdea0e 100644
--- a/src/mode/fdm/driver.js
+++ b/src/mode/fdm/driver.js
@@ -39,12 +39,24 @@
if (KIRI.client)
// FDM.support_generate = KIRI.client.fdm_support_generate = function(ondone) {
FDM.support_generate = function(ondone) {
- send('fdm_support_generate', {}, ondone);
+ KIRI.client.sync();
+ let settings = API.conf.get();
+ let widgets = API.widgets.map();
+ send('fdm_support_generate', {}, (gen) => {
+ for (let g of gen) g.widget = widgets[g.id];
+ ondone(gen);
+ });
};
if (KIRI.worker)
KIRI.worker.fdm_support_generate = function(data, send) {
- send.done();
+ const { settings } = data;
+ const widgets = Object.values(cache);
+ const fresh = widgets.filter(widget => FDM.supports(settings, widget));
+ send.done(KIRI.codec.encode(fresh.map(widget => { return {
+ id: widget.id,
+ supports: widget.supports,
+ } } )));
};
});
diff --git a/src/mode/fdm/slice.js b/src/mode/fdm/slice.js
index ea6b5474..0d6e4aab 100644
--- a/src/mode/fdm/slice.js
+++ b/src/mode/fdm/slice.js
@@ -1074,4 +1074,36 @@
return good.length > 2 ? good : [];
}
+ FDM.supports = function(settings, widget) {
+ let buf = new THREE.BufferGeometry();
+ buf.setAttribute('position', new THREE.BufferAttribute(widget.vertices, 3));
+ let geo = new THREE.Geometry().fromBufferGeometry(buf);
+ // console.log('geo',
+ // geo,
+ // {
+ // "<": geo.faces.filter(f => f.normal.z < 0),
+ // ">": geo.faces.filter(f => f.normal.z > 0),
+ // "=": geo.faces.filter(f => f.normal.z == 0)
+ // }
+ // );
+ let mesh = new THREE.Mesh(geo, new THREE.MeshBasicMaterial());
+ let dir = new THREE.Vector3(0,0,-1)
+ let add = [];
+ geo.faces.filter(f => f.normal.z < 0).forEach(face => {
+ let a = geo.vertices[face.a];
+ let b = geo.vertices[face.b];
+ let c = geo.vertices[face.c];
+ let point = a.add(b).add(c).divideScalar(3);
+ let ray = new THREE.Raycaster(point, dir);
+ let int = ray.intersectObjects([ mesh ], false);
+ if (int && int.length) {
+ console.log(int);
+ let mid = new THREE.Vector3().add(point).add(int[0].point).divideScalar(2);
+ add.push({from: point, to: int[0].point, mid});
+ }
+ });
+ widget.supports = add;
+ return add.length > 0;
+ };
+
})();