2021-04-07 03:46:16 +08:00
|
|
|
import * as THREE from '../node_modules/three/src/Three';
|
2021-04-13 09:37:16 +08:00
|
|
|
import { color} from './shared'
|
2021-04-15 16:36:54 +08:00
|
|
|
export function extrude(sketch, depth) {
|
|
|
|
console.log(sketch,'here')
|
2021-03-26 12:30:35 +08:00
|
|
|
|
2021-03-29 18:27:34 +08:00
|
|
|
let constraints = sketch.constraints;
|
|
|
|
let linkedObjs = sketch.linkedObjs;
|
2021-04-01 13:35:08 +08:00
|
|
|
let children = sketch.obj3d.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 = []
|
2021-03-31 07:20:24 +08:00
|
|
|
let offSetPts = []
|
2021-04-11 07:50:12 +08:00
|
|
|
|
2021-04-01 08:04:14 +08:00
|
|
|
|
2021-03-26 12:30:35 +08:00
|
|
|
|
|
|
|
function findPair(node) {
|
2021-04-03 12:05:28 +08:00
|
|
|
if (node.userData.construction) return;
|
2021-03-26 12:30:35 +08:00
|
|
|
visited.add(node)
|
2021-03-31 16:07:34 +08:00
|
|
|
let linkedObj = linkedObjs.get(node.userData.l_id)
|
2021-03-26 12:30:35 +08:00
|
|
|
let arr;
|
|
|
|
if (linkedObj[0] == 'line') {
|
2021-03-30 06:12:46 +08:00
|
|
|
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]))
|
|
|
|
}
|
|
|
|
|
2021-04-03 12:05:28 +08:00
|
|
|
offSetPts.push(arr[0], arr[1]) //make work points for sketch creation
|
|
|
|
// offSetPts.push(arr[arr.length - 3], arr[arr.length - 2])
|
2021-03-31 07:20:24 +08:00
|
|
|
|
2021-03-26 12:30:35 +08:00
|
|
|
for (let i = 0; i < 2; i++) {
|
2021-04-01 06:03:35 +08:00
|
|
|
let d = children[
|
|
|
|
objIdx.get(
|
|
|
|
linkedObj[1][i]
|
|
|
|
)
|
|
|
|
]
|
2021-03-26 12:30:35 +08:00
|
|
|
if (d == -1 || d == node) continue;
|
2021-04-13 09:37:16 +08:00
|
|
|
if (d == children[4]) {
|
2021-03-26 12:30:35 +08:00
|
|
|
console.log('pair found')
|
|
|
|
};
|
|
|
|
findTouching(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function findTouching(node) {
|
2021-03-31 16:07:34 +08:00
|
|
|
for (let t of node.userData.constraints) {
|
2021-04-03 12:05:28 +08:00
|
|
|
if (constraints.get(t)[0] != 'points_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-04-13 09:37:16 +08:00
|
|
|
if (d == children[4]) {
|
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-04-08 12:05:54 +08:00
|
|
|
findPair(children[4]) //??? need fixing
|
2021-03-26 12:30:35 +08:00
|
|
|
|
|
|
|
const shape = new THREE.Shape(v2s);
|
2021-04-15 16:36:54 +08:00
|
|
|
const extrudeSettings = { depth, bevelEnabled: false };
|
2021-04-07 05:10:07 +08:00
|
|
|
|
|
|
|
|
2021-03-26 12:30:35 +08:00
|
|
|
const geometry = new THREE.ExtrudeGeometry(shape, extrudeSettings);
|
2021-04-10 16:45:15 +08:00
|
|
|
|
2021-04-11 07:16:08 +08:00
|
|
|
// const material = new THREE.MeshLambertMaterial({
|
|
|
|
const material = new THREE.MeshPhongMaterial({
|
2021-04-05 11:52:17 +08:00
|
|
|
color: color.mesh,
|
2021-03-31 07:20:24 +08:00
|
|
|
emissive: color.emissive,
|
|
|
|
});
|
2021-04-11 07:50:12 +08:00
|
|
|
|
2021-04-07 05:10:07 +08:00
|
|
|
const mesh = new THREE.Mesh(geometry, material)
|
|
|
|
mesh.name = 'm' + id++
|
2021-04-05 11:52:17 +08:00
|
|
|
mesh.userData.type = 'mesh'
|
2021-04-10 16:45:15 +08:00
|
|
|
mesh.layers.enable(1)
|
2021-03-31 07:20:24 +08:00
|
|
|
|
2021-04-11 07:50:12 +08:00
|
|
|
const vertices = new THREE.Points(mesh.geometry, new THREE.PointsMaterial({ size: 0 }));
|
2021-04-10 16:45:15 +08:00
|
|
|
vertices.userData.type = 'point'
|
|
|
|
vertices.layers.enable(1)
|
|
|
|
|
|
|
|
mesh.add(vertices)
|
2021-03-29 18:27:34 +08:00
|
|
|
mesh.matrixAutoUpdate = false;
|
2021-04-01 13:35:08 +08:00
|
|
|
mesh.matrix.multiply(sketch.obj3d.matrix)
|
2021-04-11 07:50:12 +08:00
|
|
|
|
2021-04-01 13:35:08 +08:00
|
|
|
this.obj3d.add(mesh)
|
2021-03-28 20:00:31 +08:00
|
|
|
|
2021-04-06 12:52:19 +08:00
|
|
|
this.store.dispatch({ type: 'rx-extrusion', mesh, sketchId: sketch.obj3d.name })
|
2021-04-11 15:57:39 +08:00
|
|
|
|
|
|
|
if (this.activeSketch == sketch) {
|
|
|
|
this.activeSketch = null
|
|
|
|
sketch.deactivate()
|
|
|
|
}
|
|
|
|
|
2021-04-15 16:36:54 +08:00
|
|
|
// this.clearSelection()
|
2021-04-11 15:57:39 +08:00
|
|
|
this.render()
|
2021-03-26 12:30:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|