gpt4 book ai didi

javascript - 在 Three.js 中创建锯齿形结构?

转载 作者:行者123 更新时间:2023-12-03 01:05:31 25 4
gpt4 key购买 nike

我正在为正在开发的 3D 工具开发一些结构,我想要一个像这样的锯齿形结构 https://jsfiddle.net/cdu96z3c/21/ 。截至目前,我已经通过迭代多次产生“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++){
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);
}

最佳答案

这是一个小函数,它根据一些参数生成点以形成锯齿形状:

// amount - number of zigzag segments
// width - width of one segment
// height - height of one segment
// thickness - thickness/width of the line
function generateZigZagPoints(amount, width, height, thickness) {

let points = [];

for (let i = 0; i < amount; i++) {
points.push([ i * width, 0 ]);
points.push([ i * width + width / 2, height ]);
}

points.push([ amount * width, 0 ]);
points.push([ amount * width, -thickness ]);

for (let i = amount; i > -1; i--) {
points.push([ i * width + width / 2, height - thickness ]);
points.push([ i * width, -thickness ]);
}

return points;

}

关于javascript - 在 Three.js 中创建锯齿形结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52422283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com