From f2b5b42d7aaa22a3850b2e5fa39e13b8c0f84e5b Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sun, 22 Nov 2020 20:06:11 -0500 Subject: [PATCH] add click-to-delete manual supports --- src/kiri/main.js | 1 + src/kiri/widget.js | 11 ++++------ src/kiri/worker.js | 3 --- src/mode/fdm/client.js | 47 ++++++++++++++++++++++++++++++++++-------- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/kiri/main.js b/src/kiri/main.js index ece51d18..7519f271 100644 --- a/src/kiri/main.js +++ b/src/kiri/main.js @@ -565,6 +565,7 @@ let out = []; forAllWidgets(function(widget) { out.push(widget.mesh); + out.appendAll(widget.adds); }); return out; } diff --git a/src/kiri/widget.js b/src/kiri/widget.js index 56b31ecc..84443250 100644 --- a/src/kiri/widget.js +++ b/src/kiri/widget.js @@ -113,12 +113,15 @@ } // rotation stack (for undo) this.roto = []; + // added meshes + this.adds = []; + // THREE Mesh and points this.mesh = null; this.points = null; // todo resolve use of this vs. mesh.bounds this.bounds = null; + // wireframe this.wire = null; - this.topo = null; this.slices = null; this.settings = null; this.modified = true; @@ -564,9 +567,6 @@ if (reply.send_start) { widget.xfer = {start: reply.send_start}; } - if (reply.topo) { - widget.topo = reply.topo; - } if (reply.stats) { widget.stats = reply.stats; } @@ -576,9 +576,6 @@ if (reply.slice) { widget.slices.push(KIRI.codec.decode(reply.slice, {mesh:widget.mesh})); } - if (reply.polish) { - widget.polish = KIRI.codec.decode(reply.polish); - } if (reply.error) { ondone(false, reply.error); } diff --git a/src/kiri/worker.js b/src/kiri/worker.js index ab83199b..5440ee07 100644 --- a/src/kiri/worker.js +++ b/src/kiri/worker.js @@ -86,9 +86,6 @@ KIRI.worker = { slices.forEach(function(slice,index) { send.data({index: index, slice: slice.encode(state)}); }) - if (self.debug && widget.polish) { - send.data({polish: KIRI.codec.encode(widget.polish)}); - } send.data({send_end: time()}); } send.done({done: true}); diff --git a/src/mode/fdm/client.js b/src/mode/fdm/client.js index 8118ec30..a7789e6d 100644 --- a/src/mode/fdm/client.js +++ b/src/mode/fdm/client.js @@ -10,7 +10,7 @@ FDM = KIRI.driver.FDM, SPACE, API, p1, p2, iw, - lastMode, lastView, + lastMode, lastView, lastPillar, alert = [], func = {}; @@ -96,6 +96,21 @@ }); api.event.on("mouse.hover.up", int => { delbox('supp'); + if (lastPillar) { + const {widget, box, id} = lastPillar; + widget.adds.remove(box); + widget.mesh.remove(box); + delete widget.sups[id]; + let sa = API.widgets.annotate(widget.id).support; + let ix = 0; + sa.forEach((rec,i) => { + if (rec.id === id) { + ix = i; + } + }); + sa.splice(ix,1); + return; + } if (!iw) return; let hy = (p1.y + p2.y) / 2; let dh = Math.abs(p1.y - p2.y); @@ -103,23 +118,33 @@ let ip = iw.track.pos; let wa = api.widgets.annotate(iw.id); let ws = (wa.support = wa.support || []); - let x = p1.x - ip.x, y = -p1.z - ip.y, z = hy; - let id = Date.now(); - ws.push({x, y, z, dw, dh, id}); - addWidgetSupport(iw, {x, y, z, dw, dh, id}); + let x = p1.x - ip.x, y = -p1.z - ip.y, z = hy, id = Date.now(); + let rec = {x, y, z, dw, dh, id}; + ws.push(Object.clone(rec)); + addWidgetSupport(iw, rec); API.conf.save(); }); api.event.on("mouse.hover", data => { + // delbox('intZ'); + // delbox('intW'); + // addbox(point, 0xff0000, 'intZ'); + delbox('supp'); const { int, type, point } = data; + const pillar = int ? int.object.pillar : undefined; + if (lastPillar) { + lastPillar.box.material.color.r = 0; + lastPillar = null; + } + if (pillar) { + pillar.box.material.color.r = 0.5; + lastPillar = pillar; + return; + } if (int && type === 'widget') { iw = int.object.widget || iw; } else { iw = null; } - // delbox('intZ'); - // delbox('intW'); - // addbox(point, 0xff0000, 'intZ'); - delbox('supp'); p1 = point; let dir = new THREE.Vector3(0,1,0) let ray = new THREE.Raycaster(point, dir); @@ -178,7 +203,9 @@ // prevent duplicate restore from repeated settings load calls if (!sups[id]) { pos.box = addbox({x, y, z}, 0x0000dd, 'supp', { x:dw, y:dw, z:dh }, widget.mesh); + pos.box.pillar = Object.assign({widget}, pos); sups[id] = pos; + widget.adds.push(pos.box); } } @@ -202,8 +229,10 @@ function clearWidgetSupports(widget) { Object.values(widget.sups || {}).forEach(support => { + widget.adds.remove(support.box); widget.mesh.remove(support.box); }); + widget.sups = {}; delete API.widgets.annotate(widget.id).support; }