- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 babylonjs 3D WebGL 库。
这是很棒的库,但我找不到相同的库,它存在于 THREE.JS 库中。
例如,我在数据库中有 2D 多边形,我从中获取多边形数据,然后创建自定义网格并对其进行拉伸(stretch)。
有了 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 -> 你也可以从顶点和面的列表中创建一个网格
):
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 中手动计算索引缓冲区,而在 THREE.JS 中我不需要它,这也是一个只有平面的示例,我没有找到任何关于精确挤压的信息。
所以...也许,BabylonJS 中有一些简单的方法?
最佳答案
目前不支持挤压,但这可能是一个很棒的功能:)我一定会把它添加到我们的路线图中。如果您想进一步讨论该问题,请在 the babylon.js forum 上提问.
编辑:
现在可以创建自定义形状。
http://doc.babylonjs.com/tutorials/parametric_shapes#extrusion
关于javascript - 如何在 Babylon.js 中创建自定义网格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26274620/
我是一名优秀的程序员,十分优秀!