diff --git a/src/Sketch.js b/src/Sketch.js index 36dd648..53d75b7 100644 --- a/src/Sketch.js +++ b/src/Sketch.js @@ -258,7 +258,22 @@ class Sketch { case 'p': this.mode = "point" this.snap = true - this.canvas.addEventListener('pointerdown', this.drawOnClick1, { once: true }) + this.canvas.addEventListener('pointerdown', (e)=> { + if (this.mode !== 'point') return + const pt = ptObj() + + pt.matrixAutoUpdate = false; + pt.userData.constraints = [] + + pt.geometry.attributes.position.set( + this.getLocation(e).toArray() + ) + pt.layers.enable(2) + + this.obj3d.add(pt) + this.updatePointsBuffer(this.obj3d.children.length-1) + this.scene.render() + }) break; case 'd': if (this.mode != 'dimension') { diff --git a/src/drawDimension.js b/src/drawDimension.js index dd447b7..8e6360f 100644 --- a/src/drawDimension.js +++ b/src/drawDimension.js @@ -67,7 +67,7 @@ export async function drawDimension() { disp = tagPos.clone().sub(p1) proj = dir.multiplyScalar(disp.dot(dir)) perpOffset = disp.clone().sub(proj) - dimVal = Math.sqrt(perpOffset.x ** 2 + perpOffset.y ** 2) + dimVal = Math.sign(perpOffset.y)*Math.sqrt(perpOffset.x ** 2 + perpOffset.y ** 2) constraint = [ 'pt_line_distance', dimVal, diff --git a/src/drawEvents.js b/src/drawEvents.js index fc26960..035f632 100644 --- a/src/drawEvents.js +++ b/src/drawEvents.js @@ -18,45 +18,21 @@ export function drawOnClick1(e) { this.toPush = drawLine(mouseLoc) if (this.subsequent) { - const p1 = this.toPush[0] // we pre-increment because we need to push the same c_id to the constraints // map. we push into constraints map second because it makes more semantic sense - this.constraints.set(++this.c_id, + this.constraints.set(++this.c_id, [ 'points_coincident', -1, - [this.obj3d.children[this.obj3d.children.length - 2].name, p1.name, -1, -1] + [this.obj3d.children[this.obj3d.children.length - 2].name, this.toPush[0].name, -1, -1] ] ) - p1.userData.constraints.push(this.c_id) this.obj3d.children[this.obj3d.children.length - 2].userData.constraints.push(this.c_id) + this.toPush[0].userData.constraints.push(this.c_id) - } else { + } else if (this.hovered.length) { - console.log(this.hovered) - 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.hovered[this.hovered.length - 1].userData.constraints.push(this.c_id) - this.toPush[0].userData.constraints.push(this.c_id) - 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 + this.constraints.set(++this.c_id, [ 'points_coincident', -1, [this.hovered[this.hovered.length - 1].name, this.toPush[0].name, -1, -1] @@ -71,13 +47,25 @@ export function drawOnClick1(e) { - } else if (this.mode == "point") { - this.toPush = drawPoint(mouseLoc) + } else if (this.mode == "arc") { + this.toPush = drawArc(mouseLoc) + + if (this.hovered.length) { + this.constraints.set(++this.c_id, + [ + 'points_coincident', -1, + [this.hovered[this.hovered.length - 1].name, this.toPush[0].name, -1, -1] + ] + ) + this.hovered[this.hovered.length - 1].userData.constraints.push(this.c_id) + this.toPush[0].userData.constraints.push(this.c_id) + this.updateOtherBuffers() + + } + + } - // this.toPush.forEach(element => { - // element.layers.enable(2) - // }); this.updatePoint = this.obj3d.children.length this.obj3d.add(...this.toPush) @@ -118,12 +106,14 @@ export function drawOnClick2(e) { if (this.mode == "line") { if (this.hovered.length) { - this.constraints.set(++this.c_id, //??? why incremennt before not after + this.constraints.set(++this.c_id, [ 'points_coincident', -1, [this.hovered[this.hovered.length - 1].name, this.toPush[1].name, -1, -1] ] ) + this.hovered[this.hovered.length - 1].userData.constraints.push(this.c_id) + this.toPush[1].userData.constraints.push(this.c_id) this.updateOtherBuffers() } @@ -131,17 +121,17 @@ export function drawOnClick2(e) { this.subsequent = true this.drawOnClick1(e) - } else if (this.mode == "point") { - this.drawOnClick1(e) } else if (this.mode == "arc") { if (this.hovered.length) { - this.constraints.set(++this.c_id, //??? why incremennt before not after + this.constraints.set(++this.c_id, [ 'points_coincident', -1, [this.hovered[this.hovered.length - 1].name, this.toPush[1].name, -1, -1] ] ) + this.hovered[this.hovered.length - 1].userData.constraints.push(this.c_id) + this.toPush[1].userData.constraints.push(this.c_id) this.updateOtherBuffers() } @@ -208,11 +198,3 @@ 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.slice()) - return [p1] -} \ No newline at end of file diff --git a/src/mouseEvents.js b/src/mouseEvents.js index 221a6de..28bf27c 100644 --- a/src/mouseEvents.js +++ b/src/mouseEvents.js @@ -56,7 +56,6 @@ 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 @@ -78,7 +77,7 @@ export function onHover(e) { if (this.obj3d.userData.type != 'sketch' && obj.userData.type == 'point') { ptLoc = obj.geometry.attributes.position.array .slice( - 3 * hoverPts[idx[x]].index, + 3 * hoverts[idx[x]].index, 3 * hoverPts[idx[x]].index + 3 ) this.selpoints[0].geometry.attributes.position.array.set(ptLoc)