From 33f572e3c2d6d85ea73566c81ef3e7161942f2b0 Mon Sep 17 00:00:00 2001 From: howard Date: Wed, 21 Apr 2021 14:45:14 -0700 Subject: [PATCH] working click 1 snap --- src/Sketch.js | 3 +++ src/drawEvents.js | 30 ++++++++++++++++++++++++++++++ src/mouseEvents.js | 8 ++++---- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Sketch.js b/src/Sketch.js index a40d8d2..ded65c3 100644 --- a/src/Sketch.js +++ b/src/Sketch.js @@ -246,11 +246,14 @@ class Sketch { drawClear.call(this) } this.mode = "line" + this.snap = true this.canvas.addEventListener('pointerdown', this.drawOnClick1, { once: true }) break; case 'a': this.mode = "arc" + this.snap = true this.canvas.addEventListener('pointerdown', this.drawOnClick1, { once: true }) + // this.canvas.addEventListener('pointerdown', this.drawOnClick1, { once: true }) break; case 'p': this.mode = "point" diff --git a/src/drawEvents.js b/src/drawEvents.js index 75a273c..c745409 100644 --- a/src/drawEvents.js +++ b/src/drawEvents.js @@ -31,11 +31,41 @@ export function drawOnClick1(e) { p1.userData.constraints.push(this.c_id) this.obj3d.children[this.obj3d.children.length - 2].userData.constraints.push(this.c_id) + } else { + + if (this.hovered.length) { + + this.constraints.set(++this.c_id, //??? why incremennt before not after + [ + 'points_coincident', -1, + [this.hovered[this.hovered.length - 1].name, this.toPush[0].name, -1, -1] + ] + ) + this.updateOtherBuffers() + + } + + } } else if (this.mode == "arc") { this.toPush = drawArc(mouseLoc) + + if (this.hovered.length) { + this.constraints.set(++this.c_id, //??? why incremennt before not after + [ + 'points_coincident', -1, + [this.hovered[this.hovered.length - 1].name, this.toPush[0].name, -1, -1] + ] + ) + this.updateOtherBuffers() + + } + + + + } else if (this.mode == 'point') { this.toPush = drawPoint(mouseLoc) } diff --git a/src/mouseEvents.js b/src/mouseEvents.js index 2a8d59e..36bd547 100644 --- a/src/mouseEvents.js +++ b/src/mouseEvents.js @@ -7,7 +7,6 @@ let ptLoc export function onHover(e) { if ((this.mode && this.mode != 'dimension' && !this.snap) || e.buttons) return // if (( this.mode && this.mode!='dimension') || e.buttons) return - // console.log('here') raycaster.setFromCamera( new THREE.Vector2( @@ -35,6 +34,7 @@ export function onHover(e) { const thresh = this.snap ? 1 : 0.0001 if (hoverPts.length) { + console.log('here', hoverPts) let minDist = Infinity; for (let i = 0; i < hoverPts.length; i++) { if (!hoverPts[i].distanceToRay) continue; @@ -47,7 +47,7 @@ export function onHover(e) { } } - if (!idx.length) { + if (!idx.length && !this.snap) { idx.push(0) } @@ -70,9 +70,9 @@ export function onHover(e) { for (let x = 0; x < idx.length; x++) { let obj = hoverPts[idx[x]].object - if (!this.snap || (this.snap && x < idx.length-1) ) { + // if (!this.snap || (this.snap && x < idx.length-1) ) { setHover(obj, 1, false) - } + // } if (this.obj3d.userData.type != 'sketch' && obj.userData.type == 'point') { ptLoc = obj.geometry.attributes.position.array