clear supports on auto-generate. also produce more dense supports for large faces

This commit is contained in:
Stewart Allen 2021-01-03 18:10:10 -05:00
commit 1c9be01acd
2 changed files with 39 additions and 6 deletions

View file

@ -51,6 +51,7 @@
api.event.on("fdm.supports.detect", func.sgen = () => { api.event.on("fdm.supports.detect", func.sgen = () => {
alert = api.show.alert("analyzing part(s)...", 1000); alert = api.show.alert("analyzing part(s)...", 1000);
FDM.support_generate(array => { FDM.support_generate(array => {
func.sclear();
api.hide.alert(alert); api.hide.alert(alert);
for (let rec of array) { for (let rec of array) {
let { widget, supports } = rec; let { widget, supports } = rec;

View file

@ -1080,29 +1080,61 @@
} }
FDM.supports = function(settings, widget) { FDM.supports = function(settings, widget) {
let size = settings.process.sliceSupportSize;
let buf = new THREE.BufferGeometry(); let buf = new THREE.BufferGeometry();
buf.setAttribute('position', new THREE.BufferAttribute(widget.vertices, 3)); buf.setAttribute('position', new THREE.BufferAttribute(widget.vertices, 3));
let mat = new THREE.MeshBasicMaterial(); let mat = new THREE.MeshBasicMaterial();
let geo = new THREE.Geometry().fromBufferGeometry(buf); let geo = new THREE.Geometry().fromBufferGeometry(buf);
let angle = (Math.PI / 180) * settings.process.sliceSupportAngle; let angle = (Math.PI / 180) * settings.process.sliceSupportAngle;
let thresh = -Math.sin(angle); let thresh = -Math.sin(angle);
let mesh = new THREE.Mesh(geo, mat);
let dir = new THREE.Vector3(0,0,-1) let dir = new THREE.Vector3(0,0,-1)
let add = []; let add = [];
let mesh = new THREE.Mesh(geo, mat);
let platform = new THREE.Mesh( let platform = new THREE.Mesh(
new THREE.PlaneGeometry(1000,1000,1), mat new THREE.PlaneGeometry(1000,1000,1), mat
); );
geo.faces.filter(f => f.normal.z < thresh).forEach(face => { function tl(p1, p2) {
let a = geo.vertices[face.a]; let dist = p1.distanceTo(p2);
let b = geo.vertices[face.b]; let mp = new THREE.Vector3().add(p1).add(p2).divideScalar(2);
let c = geo.vertices[face.c]; if (dist >= size * 3) {
let point = a.add(b).add(c).divideScalar(3); tp(p1);
tp(p2);
let itr = Math.floor(dist / size);
let seg = p2.clone().sub(p1).divideScalar(itr);
let pnt = p1.clone();
while (itr-- > 0) {
pnt.add(seg);
tp(pnt.clone());
}
} else if (dist >= size * 2) {
tp(p1);
tp(p2);
tp(mp);
} else if (dist >= size) {
tp(p1);
tp(p2);
}
}
function tp(point) {
if (point.added) {
return;
}
let ray = new THREE.Raycaster(point, dir); let ray = new THREE.Raycaster(point, dir);
let int = ray.intersectObjects([ mesh, platform ], false); let int = ray.intersectObjects([ mesh, platform ], false);
if (int && int.length && int[0].distance > 0.01) { if (int && int.length && int[0].distance > 0.01) {
let mid = new THREE.Vector3().add(point).add(int[0].point).divideScalar(2); let mid = new THREE.Vector3().add(point).add(int[0].point).divideScalar(2);
add.push({from: point, to: int[0].point, mid}); add.push({from: point, to: int[0].point, mid});
point.added = true;
} }
}
geo.faces.filter(f => f.normal.z < thresh).forEach(face => {
let a = geo.vertices[face.a];
let b = geo.vertices[face.b];
let c = geo.vertices[face.c];
tp(new THREE.Vector3().add(a).add(b).add(c).divideScalar(3));
tl(a,b);
tl(b,c);
tl(a,c);
}); });
widget.supports = add; widget.supports = add;
return add.length > 0; return add.length > 0;