checkpoint trace work
This commit is contained in:
parent
9945a08dbb
commit
ea4f5de034
4 changed files with 59 additions and 7 deletions
|
|
@ -1389,7 +1389,7 @@
|
||||||
* @param {Polygon} poly clipping mask
|
* @param {Polygon} poly clipping mask
|
||||||
* @returns {?Polygon[]}
|
* @returns {?Polygon[]}
|
||||||
*/
|
*/
|
||||||
PRO.mask = function(poly) {
|
PRO.mask = function(poly, nullOnEquiv) {
|
||||||
let fillang = this.fillang && this.area() > poly.area() ? this.fillang : poly.fillang,
|
let fillang = this.fillang && this.area() > poly.area() ? this.fillang : poly.fillang,
|
||||||
clib = self.ClipperLib,
|
clib = self.ClipperLib,
|
||||||
ctyp = clib.ClipType,
|
ctyp = clib.ClipType,
|
||||||
|
|
@ -1408,6 +1408,9 @@
|
||||||
poly.forEach(function(p) {
|
poly.forEach(function(p) {
|
||||||
p.fillang = fillang;
|
p.fillang = fillang;
|
||||||
})
|
})
|
||||||
|
if (nullOnEquiv && poly.length === 1 && poly[0].isEquivalent(this)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return poly;
|
return poly;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -1454,7 +1457,7 @@
|
||||||
});
|
});
|
||||||
return cuts;
|
return cuts;
|
||||||
} else {
|
} else {
|
||||||
return this;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,12 @@
|
||||||
layers.setLayer("trace", {line: 0x88aa55}, false).addPoly(poly);
|
layers.setLayer("trace", {line: 0x88aa55}, false).addPoly(poly);
|
||||||
stack.addLayers(layers);
|
stack.addLayers(layers);
|
||||||
});
|
});
|
||||||
|
// for (let [key, val] of Object.entries(widget.sindex)) {
|
||||||
|
// console.log('sindex', {key, val});
|
||||||
|
// let layers = new KIRI.Layers();
|
||||||
|
// layers.setLayer("sindex", {line: 0x55aa88}, false).addPolys(val);
|
||||||
|
// stack.addLayers(layers);
|
||||||
|
// }
|
||||||
widget.adds.appendAll(stack.meshes);
|
widget.adds.appendAll(stack.meshes);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
send("traces", { settings }, output => {
|
send("traces", { settings }, output => {
|
||||||
KIRI.codec.decode(output).forEach(rec => {
|
KIRI.codec.decode(output).forEach(rec => {
|
||||||
widgets[rec.id].traces = rec.traces;
|
widgets[rec.id].traces = rec.traces;
|
||||||
|
widgets[rec.id].sindex = rec.sindex;
|
||||||
});
|
});
|
||||||
ondone(true);
|
ondone(true);
|
||||||
});
|
});
|
||||||
|
|
@ -44,7 +45,8 @@
|
||||||
widgets.forEach(widget => CAM.traces(settings, widget));
|
widgets.forEach(widget => CAM.traces(settings, widget));
|
||||||
send.done(KIRI.codec.encode(widgets.map(widget => {return {
|
send.done(KIRI.codec.encode(widgets.map(widget => {return {
|
||||||
id: widget.id,
|
id: widget.id,
|
||||||
traces: widget.traces
|
traces: widget.traces,
|
||||||
|
sindex: widget.sindex
|
||||||
}})));
|
}})));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@
|
||||||
tzindex = [ tzindex.pop() ];
|
tzindex = [ tzindex.pop() ];
|
||||||
}
|
}
|
||||||
let terrain = slicer.slice(tzindex, { each: (data, index, total) => {
|
let terrain = slicer.slice(tzindex, { each: (data, index, total) => {
|
||||||
tshadow = POLY.union(tshadow.appendAll(data.tops), 0.01, true);
|
tshadow = POLY.union(tshadow.slice().appendAll(data.tops), 0.01, true);
|
||||||
tslices.push(data.slice);
|
tslices.push(data.slice);
|
||||||
if (false) {
|
if (false) {
|
||||||
const slice = data.slice;
|
const slice = data.slice;
|
||||||
|
|
@ -242,7 +242,7 @@
|
||||||
|
|
||||||
// console.log('indices', ...indices, {zBottom});
|
// console.log('indices', ...indices, {zBottom});
|
||||||
slicer.slice(indices, { each: (data, index, total) => {
|
slicer.slice(indices, { each: (data, index, total) => {
|
||||||
shadow = POLY.union(shadow.appendAll(data.tops), 0.01, true);
|
shadow = POLY.union(shadow.slice().appendAll(data.tops), 0.01, true);
|
||||||
if (flats.indexOf(data.z) >= 0) {
|
if (flats.indexOf(data.z) >= 0) {
|
||||||
// exclude flats injected to complete shadow
|
// exclude flats injected to complete shadow
|
||||||
return;
|
return;
|
||||||
|
|
@ -373,7 +373,7 @@
|
||||||
indices = indices.appendAll(flats).sort((a,b) => b-a);
|
indices = indices.appendAll(flats).sort((a,b) => b-a);
|
||||||
// console.log('indices', ...indices, {zBottom, slicer});
|
// console.log('indices', ...indices, {zBottom, slicer});
|
||||||
slicer.slice(indices, { each: (data, index, total) => {
|
slicer.slice(indices, { each: (data, index, total) => {
|
||||||
shadow = POLY.union(shadow.appendAll(data.tops), 0.01, true);
|
shadow = POLY.union(shadow.slice().appendAll(data.tops), 0.01, true);
|
||||||
if (flats.indexOf(data.z) >= 0) {
|
if (flats.indexOf(data.z) >= 0) {
|
||||||
// exclude flats injected to complete shadow
|
// exclude flats injected to complete shadow
|
||||||
return;
|
return;
|
||||||
|
|
@ -535,9 +535,19 @@
|
||||||
})
|
})
|
||||||
.filter(v => v !== null)))]
|
.filter(v => v !== null)))]
|
||||||
.sort((a,b) => b - a);
|
.sort((a,b) => b - a);
|
||||||
|
|
||||||
|
// create shadow
|
||||||
|
let sindex = {};
|
||||||
|
let shadow = [];
|
||||||
|
let sindices = indices.map((v,i) => v > 0 ? v : v + 0.005 );
|
||||||
|
slicer.slice(sindices, { each: (data, index, total) => {
|
||||||
|
shadow = POLY.union(shadow.slice().appendAll(data.tops), 0, true);
|
||||||
|
POLY.setZ(shadow, data.z);
|
||||||
|
sindex[index] = shadow;
|
||||||
|
}, flatoff: 0 });
|
||||||
let traces = [];
|
let traces = [];
|
||||||
|
// find and trim polys (including open) to shadow
|
||||||
let oneach = (data, index, total) => {
|
let oneach = (data, index, total) => {
|
||||||
// create separate slice for each poly (and inner)
|
|
||||||
BASE.polygons.flatten(data.tops,null,true).forEach(poly => {
|
BASE.polygons.flatten(data.tops,null,true).forEach(poly => {
|
||||||
for (let i=0, il=traces.length; i<il; i++) {
|
for (let i=0, il=traces.length; i<il; i++) {
|
||||||
// do not add duplicates
|
// do not add duplicates
|
||||||
|
|
@ -546,6 +556,36 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
traces.push(poly);
|
traces.push(poly);
|
||||||
|
return;
|
||||||
|
// do trimming
|
||||||
|
let trimto = sindex[index];
|
||||||
|
if (!trimto) {
|
||||||
|
traces.push(poly);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
trimto = trimto.clone(true);
|
||||||
|
if (poly.open) {
|
||||||
|
let cuts = poly.cut(trimto);
|
||||||
|
if (cuts.length) {
|
||||||
|
traces.appendAll(cuts);
|
||||||
|
} else {
|
||||||
|
traces.push(poly);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let limit = 1000;
|
||||||
|
while (trimto.length && limit-- > 0) {
|
||||||
|
let trim = trimto.shift();
|
||||||
|
let mask = poly.mask(trim, true);
|
||||||
|
if (mask) {
|
||||||
|
trimto.appendAll(mask);
|
||||||
|
} else {
|
||||||
|
traces.push(poly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (limit === 1000) {
|
||||||
|
traces.push(poly);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
let opts = { each: oneach, over: false, flatoff: 0, edges: true, openok: true };
|
let opts = { each: oneach, over: false, flatoff: 0, edges: true, openok: true };
|
||||||
|
|
@ -553,6 +593,7 @@
|
||||||
opts.over = true;
|
opts.over = true;
|
||||||
slicer.slice(indices, opts);
|
slicer.slice(indices, opts);
|
||||||
widget.traces = traces;
|
widget.traces = traces;
|
||||||
|
widget.sindex = sindex;
|
||||||
};
|
};
|
||||||
|
|
||||||
// drilling op
|
// drilling op
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue