three.cad/src/sketcher/constraintEvents.js

89 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-03-26 12:30:35 +08:00
export function addDimension(ent1, ent2, distance) {
// if (ent1.type ==)
this.constraints.set(++this.c_id,
[
'distance', distance,
[p1, p2, -1, -1]
]
)
ent1.constraints.add(this.c_id)
ent2.constraints.add(this.c_id)
}
// function findTouching(node) {
// const res = [node]
// for (let t of node.constraints) {
// if (this.constraints.get(t)[0] != 'coincident') continue
// for (let i = 0; i < 2; i++) {
// let d = this.constraints.get(t)[2][i]
// if (d != node) res.push(d)
// }
// }
// return res
// }
// export function setCoincident(ent1, ent2) {
// for (let n1 of findTouching.call(this,ent1)) {
// for (let n2 of findTouching.call(this,ent2)) {
// this.constraints.set(++this.c_id,
// [
// 'coincident', -1,
// [n1, n2, -1, -1]
// ]
// )
// n1.constraints.add(this.c_id)
// n2.constraints.add(this.c_id)
// }
// }
// }
export function setCoincident() {
const s = new Set()
const toComb = []
for (let node of this.selected) {
const xc = node.geometry.attributes.position.array[0]
if (!s.has(xc)) {
toComb.push(node)
s.add(xc)
}
}
for (let i = 1; i < toComb.length; i++) {
this.constraints.set(++this.c_id,
[
'coincident', -1,
2021-03-30 06:12:46 +08:00
[toComb[i - 1].id, toComb[i].id, -1, -1] ///////
2021-03-26 12:30:35 +08:00
]
)
toComb[i].constraints.add(this.c_id)
toComb[i - 1].constraints.add(this.c_id)
}
2021-03-29 05:34:55 +08:00
this.updateOtherBuffers()
this.solve()
// update state of points
for (let obj of this.selected) {
obj.geometry.computeBoundingSphere()
obj.material.color.set(0x555555)
}
this.selected.clear()
this.dispatchEvent({ type: 'change' })
2021-03-26 12:30:35 +08:00
}