threejs图形拉升得到任意形状mesh
// 创建已经挖好洞的shape 完整形状的数组点位(一维数组) 洞的形状的数组点位(二维数组)
createShape(pointsArray3D:{ x: number; y: number }[],holePoints:{ x: number; y: number }[][]) {
// 先创建一块大的形状
const shape = this.addShape(pointsArray3D);
// 再挖洞
for (let index = 0; index < holePoints.length; index++) {
const hole = this.addShape(holePoints[index]);
shape.holes.push(hole);
}
return shape;
}
// 创建shape(各类形状都可以)
addShape(shapeArr: { x: number; y: number }[]) {
let shape = new THREE.Shape();
let flag = true;
for (let index = 0; index < shapeArr.length; index++) {
if (flag) {
shape.moveTo(shapeArr[index].x, shapeArr[index].y);
flag = false;
} else {
shape.lineTo(shapeArr[index].x, shapeArr[index].y);
}
}
return shape;
}