From 3b3d3e5a0891d3c312da6d5546ea1229051b01d4 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sat, 12 Nov 2022 12:08:43 -0500 Subject: [PATCH] use stock/tool bounding boxes to optimize animation. stock slices dynamic based on preference --- src/geo/csg.js | 7 +++++++ src/kiri-mode/cam/animate2.js | 19 ++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/geo/csg.js b/src/geo/csg.js index f80138db..89dad830 100644 --- a/src/geo/csg.js +++ b/src/geo/csg.js @@ -67,6 +67,13 @@ const CSG = { triVerts: index.toUint32() }); return mesh; + }, + + toBox3(mesh) { + const { min, max } = mesh._boundingBox(); + const vmin = new THREE.Vector3(min.x, min.y, min.z); + const vmax = new THREE.Vector3(max.x, max.y, max.z); + return new THREE.Box3(vmin, vmax); } }; diff --git a/src/kiri-mode/cam/animate2.js b/src/kiri-mode/cam/animate2.js index bdaf8068..07dcd3bf 100644 --- a/src/kiri-mode/cam/animate2.js +++ b/src/kiri-mode/cam/animate2.js @@ -268,6 +268,7 @@ class Stock { // console.log({ translate: this.id, x, y, z }); const oldmesh = this.mesh; this.mesh = this.mesh.translate(x, y, z); + this.bounds = CSG.toBox3(this.mesh); oldmesh.delete(); return this; } @@ -385,12 +386,11 @@ kiri.load(() => { stockSlices = []; const { x, y, z } = stock; - const sliceCount = 200; + const sliceCount = parseInt(settings.controller.animesh || 2000) / 100; const sliceWidth = stock.x / sliceCount; for (let i=0; i { } toolMove(pos); // console.log('renderMoves', {id, moves, seed}); - let tMinX = pos.x - toolRadius; - let tMaxX = pos.x + toolRadius; + let subs = 0; for (let slice of stockSlices) { - let { xmin, xmax } = slice.dim; - if ( - (tMinX >= xmin && tMinX < xmax) || - (tMaxX >= xmin && tMaxX < xmax) || - (tMinX < xmin && tMaxX > xmax) - ) { + if (slice.bounds.intersectsBox(toolMesh.bounds)) { slice.subtractTool(toolMesh); + subs++; } } + // console.log({ index, subs }); renderDist += pos.md; // pause renderer at specified offsets if (renderSpeed && renderDist >= renderSpeed) { @@ -582,6 +578,7 @@ kiri.load(() => { stockIndex = pos.a; } } + toolMesh.bounds = CSG.toBox3(toolMesh.mesh); } // delete old tool mesh, generate tool mesh, send to client @@ -610,7 +607,7 @@ kiri.load(() => { const raw = mesh.getMesh(); const vertex = raw.vertPos; const index = raw.triVerts; - toolMesh = { root: mesh, index, vertex }; + toolMesh = { root: mesh, index, vertex, bounds: CSG.toBox3(mesh) }; send.data({ mesh_add: { id:--toolID, ind: index, pos: vertex }}); }