作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为正在开发的 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/
我是一名优秀的程序员,十分优秀!