From 56c78ff002e93f7ae9dae95ef3eec41b01a77b03 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 27 Oct 2022 18:39:10 -0400 Subject: [PATCH] batch mesh updates to ui --- src/kiri-mode/cam/animate2.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/kiri-mode/cam/animate2.js b/src/kiri-mode/cam/animate2.js index 713d4d8d..e57af9d8 100644 --- a/src/kiri-mode/cam/animate2.js +++ b/src/kiri-mode/cam/animate2.js @@ -269,7 +269,7 @@ class Stock { return this; } - updateMesh(send) { + updateMesh(updates) { if (this.sends > 0 && this.subtracts === 0) { return; } @@ -282,12 +282,10 @@ class Stock { vertex: this.sharedVertexBuffer.bind(this) }); let sub = Date.now(); - this.send(send); - let snd = Date.now(); + updates.push(this); console.log({ update: this.id, time: sub - start, - send: snd - sub, subs, subms: (subs / (sub - start)).round(3) }); @@ -387,7 +385,7 @@ kiri.load(() => { stockSlices = []; const { x, y, z } = stock; - const sliceCount = 20; + const sliceCount = 1; const sliceWidth = stock.x / sliceCount; for (let i=0; i { let slice = new Stock(sliceWidth, y, z).translate(xmin, 0, z/2); slice.dim = { xmin: xmin - sliceWidth / 2, xmax: xmin + sliceWidth / 2 }; stockSlices.push(slice); - slice.updateMesh(send); + slice.updateMesh([]); + slice.send(send); send.data({ mesh_move: { id: slice.id, pos: center } }); } - // shared array buffers are not transferrable - // send.data({ mesh_add: { id: 0, ind: stockMesh.index, pos: stockMesh.vertex } }, [ ]); - // send.data({ mesh_move: { id: 0, pos: center } }); send.done(); }; @@ -547,17 +543,17 @@ kiri.load(() => { // send latest tool position and progress bar function renderUpdate(send) { - // console.time('renderUpdate'); if (toolUpdateMsg) { send.data(toolUpdateMsg); } - // console.time('updateMeshes'); + const updated = [] for (let slice of stockSlices) { - slice.updateMesh(send); + slice.updateMesh(updated); + } + for (let slice of updated) { + slice.send(send); } - // console.timeEnd('updateMeshes'); updates++; - // console.timeEnd('renderUpdate'); } // move tool mesh animation space, update client