parallelize widget shadow generation 2x faster

This commit is contained in:
Stewart Allen 2026-01-03 19:43:51 -05:00
commit f81e002766
5 changed files with 74 additions and 16 deletions

View file

@ -8,10 +8,10 @@ export class OpIndex extends CamOp {
}
weight() {
return 0.1;
return 3;
}
async slice() {
async slice(progress) {
let { op, state } = this;
if (!state.isIndexed) {
@ -37,7 +37,7 @@ export class OpIndex extends CamOp {
updateSlicer();
// recompute shadow from new widget geometry
await computeShadows();
await computeShadows(progress);
}
prepare(ops, progress) {

View file

@ -22,7 +22,7 @@ class OpShadow extends CamOp {
}
weight() {
return 0.1;
return 3;
}
async slice(progress) {
@ -50,6 +50,9 @@ class OpShadow extends CamOp {
tzindex = [ ];
}
// distributed pre-fill shadow layer cache
await widget.computeShadowStack(tzindex, prog => progress(prog / 2, 'shadow'));
// terrain is the "shadow stack" where index 0 = top of part
// thus array.length -1 = bottom of part
for (let i=0; i<tzindex.length; i++) {
@ -65,7 +68,7 @@ class OpShadow extends CamOp {
.setLayer("shadow", {line: 0x888800, thin: true })
.addPolys(shadow, { thin: true });
}
progress(i / tzindex.length);
progress(0.5 + i / tzindex.length, 'shadow');
}
if (devel && slices.length) {

View file

@ -261,12 +261,10 @@ export async function cam_slice(settings, widget, onupdate, ondone) {
return slicer = state.slicer = new cam_slicer(widget, opts);
}
async function computeShadows() {
console.time('computeShadows');
await new OPS.shadow(state, { type: "shadow", silent: true }).slice(progress => {
// console.log('reshadowing', progress.round(3));
});
console.timeEnd('computeShadows');
async function computeShadows(progress) {
console.time('compute shadow');
await new OPS.shadow(state, { type: "shadow", xsilent: true }).slice(progress);
console.timeEnd('compute shadow');
}
function setToolDiam(toolDiam) {