three.cad/src/constraintEvents.js

67 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-03-26 12:30:35 +08:00
2021-04-09 07:05:52 +08:00
export async function setCoincident() {
let selection = await this.awaitSelection({ point: 2 }, { point: 1, line: 1 })
if (selection == null) return;
2021-03-26 12:30:35 +08:00
2021-04-09 07:05:52 +08:00
if (selection.every(e => e.userData.type == 'point')) {
2021-03-26 12:30:35 +08:00
this.constraints.set(++this.c_id,
[
2021-04-03 03:33:09 +08:00
'points_coincident', -1,
2021-04-09 07:05:52 +08:00
[selection[0].name, selection[1].name, -1, -1] ///////
]
)
} else {
const idx = selection[0].userData.type == 'point' ? [0, 1] : [1, 0]
this.constraints.set(++this.c_id,
[
'pt_on_line', -1,
[selection[idx[0]].name, -1, selection[idx[1]].name, -1] ///////
2021-03-26 12:30:35 +08:00
]
)
}
2021-04-09 07:05:52 +08:00
selection[1].userData.constraints.push(this.c_id)
selection[0].userData.constraints.push(this.c_id)
2021-03-29 05:34:55 +08:00
this.updateOtherBuffers()
this.solve()
2021-04-08 12:05:54 +08:00
this.updateBoundingSpheres()
2021-03-29 05:34:55 +08:00
// update state of points
2021-04-08 12:05:54 +08:00
// for (let obj of this.selected) {
// obj.geometry.computeBoundingSphere()
// obj.material.color.set(0x555555)
// }
this.selected = []
this.obj3d.dispatchEvent({ type: 'change' })
}
export function setOrdinate(dir = 0) {
const line = this.selected[0]
this.constraints.set(++this.c_id,
[
dir ? 'vertical' : 'horizontal', -1,
[-1, -1, line.name, -1] ///////
]
)
line.userData.constraints.push(this.c_id)
2021-04-09 07:05:52 +08:00
2021-04-08 12:05:54 +08:00
this.updateOtherBuffers()
this.solve()
this.updateBoundingSpheres()
2021-03-31 07:20:24 +08:00
this.selected = []
2021-04-01 13:35:08 +08:00
this.obj3d.dispatchEvent({ type: 'change' })
2021-03-26 12:30:35 +08:00
}
2021-04-08 12:05:54 +08:00