diff --git a/src/kiri-mode/cam/animate.js b/src/kiri-mode/cam/animate.js index 5d9b6863..ec2f496a 100644 --- a/src/kiri-mode/cam/animate.js +++ b/src/kiri-mode/cam/animate.js @@ -224,9 +224,9 @@ kiri.load(() => { } function replay() { - CAM.animate_clear(api); + animate_clear(api); setTimeout(() => { - CAM.animate(api, 50); + animate(api, 50); }, 250); } @@ -554,31 +554,6 @@ kiri.load(() => { send.data({ mesh_add: { id:++toolID, ind, sab }}); } - // load renderer code in worker context only - if (kiri.worker && false) - fetch('/wasm/kiri-ani.wasm') - .then(response => response.arrayBuffer()) - .then(bytes => WebAssembly.instantiate(bytes, { - env: { - reportf: (a,b) => { console.log('[f]',a,b) }, - reporti: (a,b) => { console.log('[i]',a,b) } - } - })) - .then(results => { - let {module, instance} = results; - let {exports} = instance; - let heap = new Uint8Array(exports.memory.buffer); - let wasm = self.wasm = { - heap, - memory: exports.memory, - updateMesh: exports.updateMesh - }; - // heap[0] = 5; - // heap[100] = 6; - // heap[200] = 8; - // let rv = self.wasm.updateMesh(0, 0, 100, 200); - }); - }); }); diff --git a/src/kiri-mode/cam/animate2.js b/src/kiri-mode/cam/animate2.js index 61b15b2a..f0ec2c57 100644 --- a/src/kiri-mode/cam/animate2.js +++ b/src/kiri-mode/cam/animate2.js @@ -194,7 +194,15 @@ kiri.load(() => { mesh.position.x = pos.x; mesh.position.y = pos.y; mesh.position.z = pos.z; - space.update(); + space.refresh(); + } + } + if (data.mesh_index) { + const { id, index } = data.mesh_index; + const mesh = meshes[id]; + if (mesh) { + mesh.rotation.x = (Math.PI / 180) * index; + space.refresh(); } } if (data.mesh_update) { @@ -217,9 +225,9 @@ kiri.load(() => { } function replay() { - CAM.animate_clear2(api); + animate_clear2(api); setTimeout(() => { - CAM.animate2(api, 50); + animate2(api, 50); }, 250); } }); @@ -330,7 +338,9 @@ kiri.load(() => { let stock, center, rez; let path, pathIndex, tool, tools, last; + let stockIndexMsg = false; let stockSlices; + let stockIndex; let startTime; let toolID = -1; @@ -372,6 +382,7 @@ kiri.load(() => { last = null; animating = false; animateClear = false; + stockIndex = 0; indexCount = 0; startTime = 0; updates = 0; @@ -542,9 +553,6 @@ kiri.load(() => { // send latest tool position and progress bar function renderUpdate(send) { - if (toolUpdateMsg) { - send.data(toolUpdateMsg); - } const updated = [] for (let slice of stockSlices) { slice.updateMesh(updated); @@ -552,6 +560,15 @@ kiri.load(() => { for (let slice of updated) { slice.send(send); } + if (toolUpdateMsg) { + send.data(toolUpdateMsg); + } + if (stockIndexMsg) { + for (let slice of stockSlices) { + send.data({ mesh_index: { id: slice.id, index: -stockIndex } }); + } + stockIndexMsg = false; + } send.data({ progress: pathIndex / path.length }); updates++; } @@ -561,10 +578,19 @@ kiri.load(() => { const lpos = tool.pos || { x:0, y:0, z:0 }; tool.pos = pos; toolUpdateMsg = { mesh_move: { id: toolID, pos }}; - const delta = [ pos.x - lpos.x, pos.y - lpos.y, pos.z - lpos.z ]; - const oldmesh = toolMesh.mesh; - toolMesh.mesh = toolMesh.mesh.translate(pos.x - lpos.x, pos.y - lpos.y, pos.z - lpos.z); - oldmesh.delete(); + if (toolMesh.mesh) { + toolMesh.mesh.delete(); + } + toolMesh.mesh = toolMesh.root.translate(pos.x, pos.y, pos.z); + if (pos.a !== undefined) { + let tmp = toolMesh.mesh.rotate([ pos.a, 0, 0 ]); + toolMesh.mesh.delete(); + toolMesh.mesh = tmp; + if (pos.a !== stockIndex) { + stockIndexMsg = true; + stockIndex = pos.a; + } + } } // delete old tool mesh, generate tool mesh, send to client @@ -590,7 +616,7 @@ kiri.load(() => { } mesh = mesh.translate(0, 0, (flen + slen) / 2); const { vertex, index } = mesh.getMesh({ normal: () => undefined }); - toolMesh = { mesh, index, vertex }; + toolMesh = { root: mesh, index, vertex }; send.data({ mesh_add: { id:--toolID, ind: index, pos: vertex }}); } diff --git a/src/kiri-mode/cam/client.js b/src/kiri-mode/cam/client.js index 466e39e0..2e4ac8f7 100644 --- a/src/kiri-mode/cam/client.js +++ b/src/kiri-mode/cam/client.js @@ -19,27 +19,28 @@ let isAnimate, camStock, camZBottom, current, + flipping, poppedRec, hoveredOp, API, FDM, SPACE, STACKS, MODES, VIEWS, UI, UC, LANG, MCAM; let zaxis = { x: 0, y: 0, z: 1 }, popOp = {}, + animVer = 1, seed = Date.now(), func = { hover: noop, hoverUp: noop - }, - flipping; + }; -function animFn(v) { +function animFn() { return [{ animate: CAM.animate, animate_clear: CAM.animate_clear },{ animate: CAM.animate2, animate_clear: CAM.animate_clear2 - }][0]; + }][animVer]; } CAM.restoreTabs = restoreTabs; @@ -79,7 +80,7 @@ CAM.init = function(kiri, api) { api.event.on("function.export", (mode) => { if (isAnimate) { - animFn(0).animate_clear(api); + animFn().animate_clear(api); isAnimate = false; } }); @@ -102,7 +103,7 @@ CAM.init = function(kiri, api) { api.event.on("view.set", (mode) => { isArrange = (mode === VIEWS.ARRANGE); isAnimate = false; - animFn(0).animate_clear(api); + animFn().animate_clear(api); func.clearPops(); $('camops').style.display = isCamMode && isArrange ? 'flex' : ''; }); @@ -1527,7 +1528,7 @@ function animate() { API.widgets.opacity(isParsed ? 0 : 0.75); API.hide.slider(); STACKS.clear(); - animFn(0).animate(API); + animFn().animate(API); } function updateStock(args, event) {