Javascript 在three.js中创建之字形结构?
我正在为我正在开发的3D工具设计一些结构,我想要一个像这样的锯齿形结构。到目前为止,我已经通过多次迭代生成“V”的相同函数来实现它,我希望使用单个几何体和网格来实现相同的效果Javascript 在three.js中创建之字形结构?,javascript,three.js,Javascript,Three.js,我正在为我正在开发的3D工具设计一些结构,我想要一个像这样的锯齿形结构。到目前为止,我已经通过多次迭代生成“V”的相同函数来实现它,我希望使用单个几何体和网格来实现相同的效果 function modelShape(points){ this.shape = new THREE.Shape(); this.shape.moveTo(points[0][0], points[0][1]); for(var i=1; i<points.length; i++){
function modelShape(points){
this.shape = new THREE.Shape();
this.shape.moveTo(points[0][0], points[0][1]);
for(var i=1; i<points.length; i++){
this.shape.lineTo(points[i][0], points[i][1]);
}
this.shape.lineTo(points[0][0], points[0][1]);
}
function structure(i){
points = [
[-1.5,0],
[-1.5,.5],
[0,3.5],
[1.5,.5],
[1.5,0],
[0,3]
];
modelShape.call(this, points);
var extrudeSettings = { amount: .25, bevelEnabled: true, bevelSegments: 0, steps: 1, bevelSize: 0, bevelThickness: 0 };
var geometry = new THREE.ExtrudeGeometry( this.shape, extrudeSettings );
geometry.dynamic = true;
geometry.colorsNeedUpdate = true;
var material = new THREE.MeshStandardMaterial({
color: 0xafafaf,
metalness: 0.9
});
this.mesh = new THREE.Mesh( geometry, material);
this.mesh.position.set(i*3,0,0)
}
for(i = 0;i < 20; i++){
var struc = new structure(i);
scene.add(struc.mesh);
}
函数模型形状(点){
this.shape=新的三个.shape();
this.shape.moveTo(点[0][0],点[0][1]);
对于(var i=1;i,这里有一个小函数,它根据一些参数生成点,以形成之字形:
//数量-锯齿形段的数量
//宽度-一段的宽度
//高度-一段的高度
//厚度-线条的厚度/宽度
函数generateZigZagPoints(数量、宽度、高度、厚度){
设点=[];
for(设i=0;i-1;i--){
点。推动([i*宽度+宽度/2,高度-厚度]);
点。推力([i*宽度,-厚度]);
}
返回点;
}
您可以通过循环重复点
中的数据,并在每次迭代中进行一些移位。