three.cad/src/sketcher/sketchLine.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-03-27 04:40:40 +08:00
import * as THREE from '../../node_modules/three/src/Three';
2021-03-31 07:20:24 +08:00
import {ptObj, lineObj} from '../utils/static'
2021-03-25 16:04:13 +08:00
export function sketchLine(mouseLoc) {
2021-03-31 07:20:24 +08:00
const p1 = ptObj()
2021-03-25 16:04:13 +08:00
p1.matrixAutoUpdate = false;
2021-03-31 16:07:34 +08:00
p1.userData.constraints = []
2021-03-25 16:04:13 +08:00
2021-03-31 07:20:24 +08:00
const p2 = ptObj()
2021-03-25 16:04:13 +08:00
p2.matrixAutoUpdate = false;
2021-03-31 16:07:34 +08:00
p2.userData.constraints = []
2021-03-25 16:04:13 +08:00
2021-03-31 07:20:24 +08:00
const line = lineObj()
2021-03-25 16:04:13 +08:00
line.matrixAutoUpdate = false;
line.frustumCulled = false;
2021-03-31 16:07:34 +08:00
line.userData.constraints = []
2021-03-25 16:04:13 +08:00
2021-03-31 07:20:24 +08:00
line.geometry.attributes.position.set(mouseLoc)
p1.geometry.attributes.position.set(mouseLoc)
2021-03-25 16:04:13 +08:00
if (this.subsequent) {
2021-03-26 12:30:35 +08:00
this.constraints.set(++this.c_id,
2021-03-25 16:04:13 +08:00
[
'coincident', -1,
2021-04-01 06:03:35 +08:00
[this.children[this.children.length - 2].name, p1.name, -1, -1]
2021-03-25 16:04:13 +08:00
]
)
2021-03-31 16:07:34 +08:00
p1.userData.constraints.push(this.c_id)
this.children[this.children.length - 2].userData.constraints.push(this.c_id)
2021-03-25 16:04:13 +08:00
}
return [p1, p2, line];
}
export function sketchLine2(mouseLoc, toPush) {
const [p1, p2, line] = toPush
p2.geometry.attributes.position.set(mouseLoc);
p2.geometry.attributes.position.needsUpdate = true;
p2.geometry.computeBoundingSphere();
line.geometry.attributes.position.set(mouseLoc, 3)
line.geometry.attributes.position.needsUpdate = true;
}