working click 1 snap

master
howard 2021-04-21 14:45:14 -07:00
parent 7176bee65d
commit 33f572e3c2
3 changed files with 37 additions and 4 deletions

View File

@ -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"

View File

@ -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)
}

View File

@ -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