From 14359325b96d795aa8314e83c2a28019a6c5e99b Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Wed, 25 Nov 2020 12:51:18 -0500 Subject: [PATCH] add cam visualization for imported gcode when stock set --- notes.md | 2 ++ src/geo/bounds.js | 1 + src/kiri/print.js | 1 + src/mode/cam/animate.js | 32 +++++++++++++++++++------------- src/mode/cam/client.js | 11 ++++++++++- src/mode/cam/tool.js | 11 ++++++++--- 6 files changed, 41 insertions(+), 17 deletions(-) diff --git a/notes.md b/notes.md index a55b3c82..dae231a1 100644 --- a/notes.md +++ b/notes.md @@ -23,6 +23,8 @@ * `P` duplicate objects should share same slice data unless rotated or scaled * `P` worker state cache cleanup and organization * `P` client/worker interface normalization +* `P` optimize object import to vertices + indexes to save memory +* `P` allow selection to me decimated on demand (context menu?) # FDM diff --git a/src/geo/bounds.js b/src/geo/bounds.js index 11529ca4..a89ecc4b 100644 --- a/src/geo/bounds.js +++ b/src/geo/bounds.js @@ -39,6 +39,7 @@ b.miny = this.miny; b.maxx = this.maxx; b.maxy = this.maxy; + b.maxy = this.maxy; return b; }; diff --git a/src/kiri/print.js b/src/kiri/print.js index 4886245c..dc2ccbaa 100644 --- a/src/kiri/print.js +++ b/src/kiri/print.js @@ -261,6 +261,7 @@ G0G1(false, line); break; case 'M6': + tool = parseInt(line[0].substring(1)); break; } }); diff --git a/src/mode/cam/animate.js b/src/mode/cam/animate.js index 1ef1c0f2..b9f0ac84 100644 --- a/src/mode/cam/animate.js +++ b/src/mode/cam/animate.js @@ -28,6 +28,9 @@ self.kiri.loader.push(function() { WORLD = SPACE.platform.world; KIRI.client.animate_setup(API.conf.get(), data => { checkMeshCommands(data); + if (!(data && data.mesh_add)) { + return; + } const UC = API.uc; const layer = $('layer-animate'); layer.innerHTML = ''; @@ -71,6 +74,7 @@ self.kiri.loader.push(function() { mesh.position.x = pos.x; mesh.position.y = pos.y; mesh.position.z = pos.z; + SPACE.update(); } } if (data.mesh_update) { @@ -136,9 +140,6 @@ self.kiri.loader.push(function() { function handleGridUpdate(data) { checkMeshCommands(data); - if (data && data.done) { - console.log('done', data); - } } if (KIRI.client) @@ -158,20 +159,21 @@ self.kiri.loader.push(function() { // ---( WORKER FUNCTIONS )--- - let path, pathIndex, stock, grid, gridX, gridY, tool, tools, rez, last; + let path, pathIndex, stock, grid, gridX, gridY, tool, tools, rez, last, toolID = 1; if (KIRI.worker) KIRI.worker.animate_setup = function(data, send) { const { settings } = data; + const print = current.print; const density = parseInt(settings.controller.animesh) * 1000; pathIndex = 0; + path = print.output.flat(); tools = settings.tools; stock = settings.stock; - path = current.print.output.flat(); + rez = 1/Math.sqrt(density/(stock.x * stock.y)); - // const center = stock.center; const step = rez; const stepsX = Math.floor(stock.x / step); const stepsY = Math.floor(stock.y / step); @@ -186,7 +188,12 @@ self.kiri.loader.push(function() { animating = false; animateClear = false; - send.done({ mesh_add: { id: 0, pos, ind } }); + const center = Object.assign({}, stock.center); + center.z -= stock.z / 2; + + send.data({ mesh_add: { id: 0, pos, ind } }); + send.data({ mesh_move: { id: 0, pos: center } }); + send.done(); }; function createGrid(stepsX, stepsY, size, step) { @@ -269,17 +276,16 @@ self.kiri.loader.push(function() { } animating = true; stepsRemain--; - if (next.tool && (!tool || tool.getNumber() !== next.tool)) { + if (next.tool >= 0 && (!tool || tool.getNumber() !== next.tool)) { updateTool(next.tool, send); } - const id = tool.getID(); + const id = toolID; if (last) { const lp = last.point, np = next.point; const dx = np.x - lp.x, dy = np.y - lp.y, dz = np.z - lp.z; - // skip moves that are closer than resolution if (Math.sqrt(dx*dx +dy*dy + dz*dz) < rez) { - setTimeout(() => { renderPath(send, 0) }); + setTimeout(() => { renderPath(send) }, 0); return; } @@ -363,7 +369,7 @@ self.kiri.loader.push(function() { function updateTool(toolnum, send) { if (tool) { - send.data({ mesh_del: tool.getID() }); + send.data({ mesh_del: toolID }); } tool = new CAM.Tool({ tools }, undefined, toolnum); tool.generateProfile(rez); @@ -381,7 +387,7 @@ self.kiri.loader.push(function() { const dz = prof[i++]; pos[(dx * pix + dy) * 3 + 2] = -dz; } - send.data({ mesh_add: { id:tool.getID(), pos, ind }}); + send.data({ mesh_add: { id:++toolID, pos, ind }}); } }); diff --git a/src/mode/cam/client.js b/src/mode/cam/client.js index d4d25e50..933cc1f4 100644 --- a/src/mode/cam/client.js +++ b/src/mode/cam/client.js @@ -13,6 +13,7 @@ isAnimate, isArrange, isCamMode, + isParsed, camStock, API, SPACE, STACKS, MODES, VIEWS, UI, UC; @@ -70,13 +71,21 @@ ], updateStock); api.event.on("preview.end", () => { + isParsed = false; if (camStock) STACKS.getStack("bounds").button("animate", animate); }); + + api.event.on("code.loaded", (info) => { + if (isCamMode && camStock) { + isParsed = true; + STACKS.getStack("parse", SPACE.platform.world).button("animate", animate); + } + }); }; function animate() { isAnimate = true; - API.widgets.opacity(0.75); + API.widgets.opacity(isParsed ? 0 : 0.75); API.hide.slider(); STACKS.clear(); CAM.animate(API); diff --git a/src/mode/cam/tool.js b/src/mode/cam/tool.js index 1bf40ca9..11750acf 100644 --- a/src/mode/cam/tool.js +++ b/src/mode/cam/tool.js @@ -13,9 +13,14 @@ class Tool { constructor(settings, id, number) { if (number >= 0) { - this.tool = settings.tools.filter(tool => tool.number === number)[0]; + this.tool = settings.tools.filter(tool => tool.number == number)[0]; } else { - this.tool = settings.tools.filter(tool => tool.id === id)[0]; + this.tool = settings.tools.filter(tool => tool.id == id)[0]; + } + if (!this.tool) { + this.tool = Object.assign({}, settings.tools[0]); + this.tool.number = number >= 0 ? number : this.tool.number; + this.tool.id = id >= 0 ? id : this.tool.id; } } @@ -112,7 +117,7 @@ this.profile = toolOffset; this.profileDim = { size: flute_diameter, - pix: profile_pix_iter + pix: profile_pix_iter + 2 }; return this; }