From f7cc65dda22fe98a7814e3a0a647456452908afe Mon Sep 17 00:00:00 2001 From: howard Date: Wed, 21 Apr 2021 21:39:23 -0700 Subject: [PATCH] point not working --- src/Scene.js | 2 ++ src/Sketch.js | 1 + src/drawEvents.js | 29 ++++++++++++++++------------- src/drawLine.js | 2 ++ src/mouseEvents.js | 19 +++++++------------ 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/Scene.js b/src/Scene.js index dffa5cc..c122a1d 100644 --- a/src/Scene.js +++ b/src/Scene.js @@ -56,6 +56,8 @@ export class Scene { cameraDist * Math.cos(xzAngle) ); + this.camera.layers.enable(3) + const controls = new TrackballControls(this.camera, this.canvas); controls.target.set(0, 0, 0); controls.update(); diff --git a/src/Sketch.js b/src/Sketch.js index ded65c3..36dd648 100644 --- a/src/Sketch.js +++ b/src/Sketch.js @@ -257,6 +257,7 @@ class Sketch { break; case 'p': this.mode = "point" + this.snap = true this.canvas.addEventListener('pointerdown', this.drawOnClick1, { once: true }) break; case 'd': diff --git a/src/drawEvents.js b/src/drawEvents.js index 64ec487..fc26960 100644 --- a/src/drawEvents.js +++ b/src/drawEvents.js @@ -71,13 +71,13 @@ export function drawOnClick1(e) { - } else if (this.mode == 'point') { + } else if (this.mode == "point") { this.toPush = drawPoint(mouseLoc) } - this.toPush.forEach(element => { - element.layers.enable(2) - }); + // this.toPush.forEach(element => { + // element.layers.enable(2) + // }); this.updatePoint = this.obj3d.children.length this.obj3d.add(...this.toPush) @@ -94,10 +94,8 @@ export function drawPreClick2(e) { const mouseLoc = this.getLocation(e).toArray(); if (this.mode == "line") { - this.snap = true drawLine2(mouseLoc, this.toPush) } else if (this.mode == 'arc') { - this.snap = true drawArc2(mouseLoc, this.toPush) } @@ -112,14 +110,18 @@ export function drawOnClick2(e) { this.updatePointsBuffer(this.updatePoint) this.updateOtherBuffers() - // a this.mode == "" will prevent event chain from persisisting - if (this.mode == "line") { + // a this.mode == "" here will prevent event chain from persisisting - if (this.hovered.length>=2) { + this.toPush.forEach(element => { + element.layers.enable(2) + }); + + if (this.mode == "line") { + if (this.hovered.length) { this.constraints.set(++this.c_id, //??? why incremennt before not after [ 'points_coincident', -1, - [this.hovered[this.hovered.length - 2].name, this.toPush[1].name, -1, -1] + [this.hovered[this.hovered.length - 1].name, this.toPush[1].name, -1, -1] ] ) this.updateOtherBuffers() @@ -133,11 +135,11 @@ export function drawOnClick2(e) { this.drawOnClick1(e) } else if (this.mode == "arc") { - if (this.hovered.length>=2) { + if (this.hovered.length) { this.constraints.set(++this.c_id, //??? why incremennt before not after [ 'points_coincident', -1, - [this.hovered[this.hovered.length - 2].name, this.toPush[1].name, -1, -1] + [this.hovered[this.hovered.length - 1].name, this.toPush[1].name, -1, -1] ] ) this.updateOtherBuffers() @@ -207,9 +209,10 @@ export function drawClear() { export function drawPoint(mouseLoc) { + console.log('heeeeeeeeer') const p1 = ptObj() p1.matrixAutoUpdate = false; p1.userData.constraints = [] - p1.geometry.attributes.position.set(mouseLoc) + p1.geometry.attributes.position.set(mouseLoc.slice()) return [p1] } \ No newline at end of file diff --git a/src/drawLine.js b/src/drawLine.js index eb3db8e..95425d4 100644 --- a/src/drawLine.js +++ b/src/drawLine.js @@ -17,6 +17,7 @@ export function drawLine(mouseLoc) { line.userData.constraints = [] + line.geometry.attributes.position.set(mouseLoc) p1.geometry.attributes.position.set(mouseLoc) @@ -34,4 +35,5 @@ export function drawLine2(mouseLoc, toPush) { line.geometry.attributes.position.set(mouseLoc, 3) line.geometry.attributes.position.needsUpdate = true; line.geometry.computeBoundingSphere(); + } \ No newline at end of file diff --git a/src/mouseEvents.js b/src/mouseEvents.js index 763e574..221a6de 100644 --- a/src/mouseEvents.js +++ b/src/mouseEvents.js @@ -1,13 +1,12 @@ import * as THREE from '../node_modules/three/src/Three'; import { raycaster, setHover } from './shared'; import { onDimMoveEnd } from './drawDimension' -import { connectAdvanced } from 'react-redux'; 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 + // if ((this.mode && this.mode != 'dimension' && !this.snap) || e.buttons) return + if (e.buttons) return raycaster.setFromCamera( new THREE.Vector2( @@ -23,10 +22,11 @@ export function onHover(e) { if (this.obj3d.userData.type != 'sketch') { this.selpoints[0].visible = false // hide selpoint[0] before each redraw raycaster.layers.set(1) - hoverPts = raycaster.intersectObjects(this.obj3d.children, true) // has side effect of updating bounding spheres + hoverPts = raycaster.intersectObjects(this.obj3d.children, true) } else { raycaster.layers.set(2) - // if (this.snap) return + // intersectObjects has side effect of updating bounding spheres + // which may lead to unexpected results if you leave boundspheres un-updated hoverPts = raycaster.intersectObjects([...this.dimGroup.children, ...this.obj3d.children]) } @@ -56,6 +56,7 @@ export function onHover(e) { if (idx.length) { // after filtering, if hovered objs still exists + // console.log(idx) if (hoverPts[idx[0]].object != this.hovered[0]) { // if the previous hovered obj is not the same as current @@ -71,13 +72,7 @@ export function onHover(e) { for (let x = 0; x < idx.length; x++) { let obj = hoverPts[idx[x]].object - if (this.snap) { - if (idx.length==1 || x != idx.length - 1) { - setHover(obj, 1, false) - } - } else { - setHover(obj, 1, false) - } + setHover(obj, 1, false) if (this.obj3d.userData.type != 'sketch' && obj.userData.type == 'point') {