我正在使用 babylonjs 3D WebGL 库。
这是一个很棒的库,但我在 THREE.JS 库中找不到相同的库。
例如,我在数据库中有 2D 多边形,我从中获取多边形数据,然后创建一个自定义网格并拉伸它。
使用 THREE.JS,没有任何问题,我可以添加到一些数组:
...
points.push( new THREE.Vector2( part.x, -part.y ) );
...
var shape = new THREE.Shape( points );
var extrusion = {
amount: building.height,
bevelEnabled: false
};
var geometry = new THREE.ExtrudeGeometry( shape, extrusion );
var mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial({
ambient: 0xbbbbb,
color: 0xff0000
});
...
scene.add( mesh );
这很简单。如何做到这一点,我找不到。
我在这里只找到了一些信息:
有这样一个例子(来自 msdn 的 Ctrl + F -> You can also create a mesh from a list of vertices and faces
):
var plane = new BABYLON.Mesh(name, scene);
var indices = [];
var positions = [];
var normals = [];
var uvs = [];
// Vertices
var halfSize = size / 2.0;
positions.push(-halfSize, -halfSize, 0);
normals.push(0, 0, -1.0);
uvs.push(0.0, 0.0);
positions.push(halfSize, -halfSize, 0);
normals.push(0, 0, -1.0);
uvs.push(1.0, 0.0);
positions.push(halfSize, halfSize, 0);
normals.push(0, 0, -1.0);
uvs.push(1.0, 1.0);
positions.push(-halfSize, halfSize, 0);
normals.push(0, 0, -1.0);
uvs.push(0.0, 1.0);
// Indices
indices.push(0);
indices.push(1);
indices.push(2);
indices.push(0);
indices.push(2);
indices.push(3);
plane.setVerticesData(positions, BABYLON.VertexBuffer.PositionKind);
plane.setVerticesData(normals, BABYLON.VertexBuffer.NormalKind);
plane.setVerticesData(uvs, BABYLON.VertexBuffer.UVKind);
plane.setIndices(indices);
return plane;
但它与 THREE.JS 不同。例如,我需要在 THREE.JS 中我不需要它的地方手动计算索引缓冲区,它也是一个只有平面的样本,我没有找到任何关于精确挤出的信息。
所以......也许,BabylonJS 中有一些简单的方法?