three.cad/src/sketcher/extrude.js

73 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-03-26 12:30:35 +08:00
import * as THREE from 'three/src/Three'
export function extrude() {
let constraints = this.constraints;
let linkedObjs = this.linkedObjs;
2021-03-26 14:00:34 +08:00
let children = this.sketch.children;
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') {
arr = linkedObj[1][2].geometry.attributes.position.array
} else if (linkedObj[0] == 'arc') {
arr = linkedObj[1][3].geometry.attributes.position.array
}
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++) {
let d = linkedObj[1][i]
if (d == -1 || d == node) continue;
2021-03-26 14:08:38 +08:00
if (d == children[0]) {
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
for (let d of constraints.get(t)[2]) {
if (d == -1 || d == node) continue;
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-26 14:08:38 +08:00
findPair(children[0])
2021-03-26 12:30:35 +08:00
const shape = new THREE.Shape(v2s);
const extrudeSettings = { amount: 8, bevelEnabled: false};
const geometry = new THREE.ExtrudeGeometry(shape, extrudeSettings);
const phong = new THREE.MeshPhongMaterial( { color: 0x156289, emissive: 0x072534, side: THREE.DoubleSide, flatShading: true } );
const mesh = new THREE.Mesh(geometry, phong);
this.add(mesh)
2021-03-26 14:08:38 +08:00
// this.sketch.visible = false
2021-03-26 12:30:35 +08:00
}