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;
p1.constraints = new Set()
2021-03-31 07:20:24 +08:00
const p2 = ptObj()
2021-03-25 16:04:13 +08:00
p2.matrixAutoUpdate = false;
p2.constraints = new Set()
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;
line.constraints = new Set()
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-03-30 06:12:46 +08:00
[this.children[this.children.length - 2].id, p1.id, -1, -1]
2021-03-25 16:04:13 +08:00
]
)
p1.constraints.add(this.c_id)
2021-03-28 20:00:31 +08:00
this.children[this.children.length - 2].constraints.add(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;
}