2021-04-07 03:46:16 +08:00
|
|
|
import * as THREE from '../node_modules/three/src/Three';
|
|
|
|
import { color, ptObj } from './shared'
|
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;
|
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-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-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) {
|
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-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-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-03-28 20:00:31 +08:00
|
|
|
const extrudeSettings = { depth: 8, 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
|
|
|
|
|
|
|
|
|
|
|
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-10 16:45:15 +08:00
|
|
|
// flatShading:true,
|
2021-03-31 07:20:24 +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-10 16:45:15 +08:00
|
|
|
const edges = new THREE.EdgesGeometry( geometry, 15 );
|
|
|
|
edges.type = 'BufferGeometry'
|
|
|
|
edges.parameters = undefined
|
|
|
|
|
|
|
|
const line = new THREE.LineSegments( edges, new THREE.LineBasicMaterial( { color: 0x000000 } ) );
|
|
|
|
line.userData.type = 'line'
|
|
|
|
|
|
|
|
const vertices = new THREE.Points( edges, new THREE.PointsMaterial() );
|
|
|
|
vertices.userData.type = 'point'
|
|
|
|
vertices.layers.enable(1)
|
|
|
|
|
|
|
|
mesh.add(line)
|
|
|
|
mesh.add(vertices)
|
|
|
|
|
|
|
|
// for (let i = 0; i < offSetPts.length; i += 2) {
|
|
|
|
// if (
|
|
|
|
// offSetPts[i] == offSetPts[i - 2] &&
|
|
|
|
// offSetPts[i + 1] == offSetPts[i - 1]
|
|
|
|
// ) continue;
|
|
|
|
// mesh.add(
|
|
|
|
// ptObj([offSetPts[i], offSetPts[i + 1], 0], false),
|
|
|
|
// ptObj([offSetPts[i], offSetPts[i + 1], 8], false),
|
|
|
|
// )
|
|
|
|
// }
|
2021-03-31 07:20:24 +08:00
|
|
|
|
2021-03-28 20:00:31 +08:00
|
|
|
|
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)
|
|
|
|
this.obj3d.add(mesh)
|
2021-03-28 20:00:31 +08:00
|
|
|
|
|
|
|
|
2021-04-07 05:10:07 +08:00
|
|
|
|
|
|
|
|
2021-03-29 18:27:34 +08:00
|
|
|
this.render()
|
2021-03-28 20:00:31 +08:00
|
|
|
|
2021-03-30 09:46:55 +08:00
|
|
|
// sketch.visible = false
|
2021-04-06 12:52:19 +08:00
|
|
|
this.store.dispatch({ type: 'rx-extrusion', mesh, sketchId: sketch.obj3d.name })
|
2021-03-26 12:30:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|