three.cad/src/constraintEvents.js

112 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-04-14 18:19:51 +08:00
import { color } from './shared'
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;
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]
2021-04-14 18:19:51 +08:00
2021-04-09 07:05:52 +08:00
this.constraints.set(++this.c_id,
[
2021-04-14 18:19:51 +08:00
selection[idx[1]].userData.ccw !== undefined ? 'pt_on_circle' : 'pt_on_line'
, -1,
2021-04-09 07:05:52 +08:00
[selection[idx[0]].name, -1, selection[idx[1]].name, -1] ///////
2021-03-26 12:30:35 +08:00
]
)
2021-04-14 18:19:51 +08:00
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-04-11 07:16:08 +08:00
for (let x = 0; x < this.selected.length; x++) {
const obj = this.selected[x]
obj.material.color.set(color[obj.userData.type])
}
2021-04-08 12:05:54 +08:00
this.selected = []
this.obj3d.dispatchEvent({ type: 'change' })
}
2021-04-14 18:19:51 +08:00
export async function setOrdinate(dir = 0) {
let selection = await this.awaitSelection({ point: 2 }, { line: 1 })
if (selection == null) return;
2021-04-08 12:05:54 +08:00
2021-04-14 18:19:51 +08:00
let arr
if (this.selected.length == 1) {
arr = [-1, -1, selection[0].name, -1]
} else {
arr = [selection[0].name, selection[1].name, -1, -1]
}
2021-04-08 12:05:54 +08:00
this.constraints.set(++this.c_id,
[
dir ? 'vertical' : 'horizontal', -1,
2021-04-14 18:19:51 +08:00
arr
]
)
selection.forEach(element => {
element.userData.constraints.push(this.c_id)
});
this.updateOtherBuffers()
this.solve()
this.updateBoundingSpheres()
this.selected = []
this.obj3d.dispatchEvent({ type: 'change' })
}
export async function setTangent() {
let selection = await this.awaitSelection({ line: 2 })
if (selection == null) return;
let idx = -1
for (let i = 0; i < 2; i++) {
if (selection[i].userData.ccw == undefined) {
idx = i
break
}
}
let arr = idx == 0 ?
[-1, -1, selection[1].name, selection[0].name] :
[-1, -1, selection[0].name, selection[1].name];
let type = idx == -1 ? 'curve_curve_tangent' : 'arc_line_tangent'
this.constraints.set(++this.c_id,
[
type, -1,
arr
2021-04-08 12:05:54 +08:00
]
)
2021-04-14 18:19:51 +08:00
selection.forEach(element => {
element.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
2021-04-14 18:19:51 +08:00