three.js 根据路径绘制墙体
时间: 2023-09-28 13:12:55 浏览: 146
对于three.js来说,可以使用THREE.Shape对象和THREE.ExtrudeGeometry对象来创建墙体。首先创建一个二维形状,然后将其沿着一个路径进行拉伸。具体的代码实现如下:
//创建二维形状
var shape = new THREE.Shape();
shape.moveTo(0, 0);
shape.lineTo(0, 10);
shape.lineTo(5, 15);
shape.lineTo(20, 15);
shape.lineTo(20, 0);
shape.lineTo(0, 0);
//创建路径
var path = new THREE.Path();
path.lineTo(0, 0);
path.lineTo(0, 10);
path.lineTo(-5, 15);
path.lineTo(-20, 15);
path.lineTo(-20, 0);
path.lineTo(0, 0);
//创建拉伸对象
var geometry = new THREE.ExtrudeGeometry(shape, {
steps: 1,
amount: 50,
bevelEnabled: false,
extrudePath: path
});
//创建墙体网格对象
var material = new THREE.MeshBasicMaterial({ color: 0xffffff });
var wall = new THREE.Mesh(geometry, material);
scene.add(wall);
阅读全文