master
howard 2021-04-21 23:12:01 -07:00
parent f7cc65dda2
commit bc6cd77592
4 changed files with 46 additions and 50 deletions

View File

@ -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') {

View File

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

View File

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

View File

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