2021-03-27 04:40:40 +08:00
|
|
|
import * as THREE from '../../node_modules/three/src/Three';
|
2021-03-30 06:12:46 +08:00
|
|
|
import { pointMaterial } from '../utils/static'
|
2021-03-29 18:27:34 +08:00
|
|
|
export function extrude(sketch) {
|
2021-03-26 12:30:35 +08:00
|
|
|
|
2021-03-29 18:27:34 +08:00
|
|
|
let constraints = sketch.constraints;
|
|
|
|
let linkedObjs = sketch.linkedObjs;
|
|
|
|
let children = sketch.children;
|
2021-03-30 06:12:46 +08:00
|
|
|
let objIdx = sketch.objIdx;
|
2021-03-26 12:30:35 +08:00
|
|
|
let visited = new Set()
|
|
|
|
let v2s = []
|
|
|
|
|
|
|
|
function findPair(node) {
|
|
|
|
visited.add(node)
|
|
|
|
let linkedObj = linkedObjs.get(node.l_id)
|
|
|
|
let arr;
|
|
|
|
if (linkedObj[0] == 'line') {
|
2021-03-30 06:12:46 +08:00
|
|
|
// console.log(children, objIdx, linkedObj)
|
|
|
|
arr = children[objIdx.get(linkedObj[1][2])].geometry.attributes.position.array
|
2021-03-26 12:30:35 +08:00
|
|
|
} else if (linkedObj[0] == 'arc') {
|
2021-03-30 06:12:46 +08:00
|
|
|
arr = children[objIdx.get(linkedObj[1][3])].geometry.attributes.position.array
|
2021-03-26 12:30:35 +08:00
|
|
|
}
|
|
|
|
for (let i = 0; i < arr.length; i += 3) {
|
|
|
|
v2s.push(new THREE.Vector2(arr[i], arr[i + 1]))
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < 2; i++) {
|
2021-03-30 06:12:46 +08:00
|
|
|
// let d = linkedObj[1][i]
|
|
|
|
let d = children[objIdx.get(linkedObj[1][i])]
|
2021-03-26 12:30:35 +08:00
|
|
|
if (d == -1 || d == node) continue;
|
2021-03-28 20:00:31 +08:00
|
|
|
if (d == children[1]) {
|
2021-03-26 12:30:35 +08:00
|
|
|
console.log('pair found')
|
|
|
|
};
|
|
|
|
findTouching(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function findTouching(node) {
|
|
|
|
for (let t of node.constraints) {
|
|
|
|
if (constraints.get(t)[0] != 'coincident') continue
|
2021-03-30 06:12:46 +08:00
|
|
|
for (let c of constraints.get(t)[2]) {
|
|
|
|
if (c == -1) continue;
|
|
|
|
const d = children[objIdx.get(c)]
|
|
|
|
if (d == node) continue;
|
2021-03-26 12:30:35 +08:00
|
|
|
if (d == children[1]) {
|
2021-03-26 14:00:34 +08:00
|
|
|
console.log('loop found')
|
2021-03-26 12:30:35 +08:00
|
|
|
} else {
|
|
|
|
if (!visited.has(d)) {
|
|
|
|
findPair(d)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-28 20:00:31 +08:00
|
|
|
findPair(children[1])
|
2021-03-26 12:30:35 +08:00
|
|
|
|
|
|
|
const shape = new THREE.Shape(v2s);
|
2021-03-28 20:00:31 +08:00
|
|
|
const extrudeSettings = { depth: 8, bevelEnabled: false };
|
2021-03-26 12:30:35 +08:00
|
|
|
const geometry = new THREE.ExtrudeGeometry(shape, extrudeSettings);
|
2021-03-28 20:00:31 +08:00
|
|
|
const phong = new THREE.MeshPhongMaterial({ color: 0x156289, emissive: 0x072534, side: THREE.DoubleSide, flatShading: true });
|
2021-03-29 18:27:34 +08:00
|
|
|
const mesh = new THREE.Mesh(geometry, phong)
|
|
|
|
// mesh.applyMatrix4(sketch.inverse)
|
|
|
|
// mesh.matrix.premultiply(sketch.matrix).multiply(sketch.inverse)
|
2021-03-28 20:00:31 +08:00
|
|
|
|
2021-03-29 18:27:34 +08:00
|
|
|
mesh.matrixAutoUpdate = false;
|
|
|
|
mesh.matrix.multiply(sketch.matrix)
|
|
|
|
this.scene.add(mesh)
|
2021-03-28 20:00:31 +08:00
|
|
|
|
|
|
|
const wireframe = new THREE.WireframeGeometry(geometry);
|
|
|
|
|
|
|
|
const pts = new THREE.Points(wireframe, pointMaterial);
|
2021-03-29 18:27:34 +08:00
|
|
|
pts.matrixAutoUpdate = false;
|
|
|
|
pts.matrix.multiply(sketch.matrix)
|
|
|
|
this.scene.add(pts)
|
2021-03-28 20:00:31 +08:00
|
|
|
|
2021-03-29 18:27:34 +08:00
|
|
|
this.render()
|
2021-03-28 20:00:31 +08:00
|
|
|
|
2021-03-29 18:27:34 +08:00
|
|
|
// this.dispatchEvent({ type: 'change' })
|
2021-03-28 20:00:31 +08:00
|
|
|
// this.visible = false
|
2021-03-26 12:30:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|