checkpoint auto support work
This commit is contained in:
parent
c191e8bc04
commit
4bd21e4e10
5 changed files with 74 additions and 10 deletions
|
|
@ -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 = () => {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
} } )));
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue