From fd75da4aac6e0cc13552927781887f2b590e5007 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 1 Nov 2022 13:48:55 -0400 Subject: [PATCH] correct stock rendering when indexed --- src/kiri-mode/cam/client.js | 9 +++++++-- src/kiri/init.js | 2 +- src/kiri/layers.js | 1 + src/kiri/stack.js | 6 +++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/kiri-mode/cam/client.js b/src/kiri-mode/cam/client.js index 535ecaa9..3c71cd21 100644 --- a/src/kiri-mode/cam/client.js +++ b/src/kiri-mode/cam/client.js @@ -20,6 +20,7 @@ let isAnimate, camStock, camZBottom, current, + currentIndex, flipping, poppedRec, hoveredOp, @@ -78,7 +79,6 @@ CAM.init = function(kiri, api) { settings.process.camZAnchor = "middle"; } animVer = isIndexed ? 1 : 0; - updateStock(); SPACE.platform.setVisible(!isIndexed); for (let widget of api.widgets.all()) { widget.setIndexed(camStock && isIndexed ? camStock.scale.z : 0); @@ -95,7 +95,10 @@ CAM.init = function(kiri, api) { func.opAdd(popOp['|'].new()); } else if (!isIndexed && clockOp) { func.opDel(clockOp); + } else { + func.opRender(); } + updateStock(); } api.event.on("widget.add", widget => { @@ -586,6 +589,7 @@ CAM.init = function(kiri, api) { for (let widget of API.widgets.all()) { widget.setAxisIndex(-index); } + currentIndex = isIndexed ? index * (Math.PI / 180) : 0; }); func.opGCode = (label, field = 'gcode') => { @@ -1714,6 +1718,7 @@ function updateStock(args, event) { camStock.position.x = csox; camStock.position.y = csoy; camStock.position.z = csz / 2; + camStock.rotation.x = currentIndex || 0; if (isIndexed) { camStock.position.z = 0; } @@ -1752,7 +1757,7 @@ function updateStock(args, event) { const {x, y, z} = stock; if (x && y && z && !STACKS.getStack('bounds')) { - const render = new kiri.Layers().setLayer('bounds', { face: 0xaaaaaa, line: 0xaaaaaa }); + const render = new kiri.Layers().setLayer('bounds', { face: 0xaaaaaa, line: 0xaaaaaa, index: currentIndex }); const stack = STACKS.setFreeMem(false).create('bounds', SPACE.world); const hx = x/2, hy = y/2; const sz = stock.z || 0; diff --git a/src/kiri/init.js b/src/kiri/init.js index b585944e..3c2219a6 100644 --- a/src/kiri/init.js +++ b/src/kiri/init.js @@ -1917,8 +1917,8 @@ gapp.register("kiri.init", [], (root, exports) => { camSep: uc.newBlank({class:"pop-sep"}), camStockOffset: uc.newBoolean(LANG.cs_offs_s, onBooleanClick, {title:LANG.cs_offs_l, modes:CAM}), camStockClipTo: uc.newBoolean(LANG.cs_clip_s, onBooleanClick, {title:LANG.cs_clip_l, modes:CAM}), - camStockIndexed: uc.newBoolean(LANG.cs_indx_s, onBooleanClick, {title:LANG.cs_indx_l, modes:CAM}), camSep: uc.newBlank({class:"pop-sep"}), + camStockIndexed: uc.newBoolean(LANG.cs_indx_s, onBooleanClick, {title:LANG.cs_indx_l, modes:CAM, show: () => ui.camStockOn.checked}), camStockOn: uc.newBoolean(LANG.cs_offe_s, onBooleanClick, {title:LANG.cs_offe_l, modes:CAM}), camCommon: uc.newGroup(LANG.cc_menu, null, {modes:CAM}), diff --git a/src/kiri/layers.js b/src/kiri/layers.js index 87fbc42b..a2fd8add 100644 --- a/src/kiri/layers.js +++ b/src/kiri/layers.js @@ -59,6 +59,7 @@ class Layers { paths: undefined, // 3d extrusion / tube paths (used to be an array, now merged - FIX) cpath: undefined, // path colors indices color: colors || { + index: 0, check: 0, line: 0, face: 0, diff --git a/src/kiri/stack.js b/src/kiri/stack.js index 1b62ee61..551c6162 100644 --- a/src/kiri/stack.js +++ b/src/kiri/stack.js @@ -107,6 +107,7 @@ class Stack { } const { polys, lines, faces, cface, paths, cpath, color, off, norms } = layer; + const { index, opacity } = color; const meshes = []; const defstate = !off; const mats = []; @@ -125,7 +126,7 @@ class Stack { const vl = vert.length; const poly = polys[i]; addPoly(vert, poly); - const pc = poly.color !== undefined ? { line: poly.color, opacity: color.opacity } : color; + const pc = poly.color !== undefined ? { line: poly.color, opacity } : color; const pk = pc.line; const cc = cmap[pk] = cmap[pk] || { idx: cidx++, mat: createLineMaterial(pc, mat) }; if (last !== pk) { @@ -154,6 +155,7 @@ class Stack { } geo.setFromPoints(vert); const segs = new THREE.LineSegments(geo, mat); + if (index) segs.rotation.x = index; meshes.push(segs); group.add(segs); mats.appendAll(mat); @@ -184,6 +186,7 @@ class Stack { geo.addGroup(0, Infinity, 0); } const mesh = new THREE.Mesh(geo, mat); + if (index) mesh.rotation.x = index; // mesh.castShadow = true; // mesh.receiveShadow = true; meshes.push(mesh); @@ -218,6 +221,7 @@ class Stack { } const mesh = new THREE.Mesh(geo, mat); mesh.position.z = z; + if (index) mesh.rotation.x = index; // mesh.castShadow = true; // mesh.receiveShadow = true; meshes.push(mesh);