如何在 Babylon.js 中创建自定义网格? [英] How to create a custom mesh in Babylon.js?

查看:27
本文介绍了如何在 Babylon.js 中创建自定义网格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 babylonjs 3D WebGL 库.

I'm using the babylonjs 3D WebGL library.

这是一个很棒的库,但我在 THREE.JS 库中找不到相同的库.

It's great library, but I can't find the same, which exists in THREE.JS library.

例如,我在数据库中有 2D 多边形,我正在从中获取多边形数据,然后创建自定义网格并将其挤出.

For example, I have 2D polygons in database, I'm fetching the polygon data from it and then create a custom mesh and extruding it.

使用THREE.JS,没有任何问题,我可以添加到一些数组中:

With the THREE.JS, there isn't any problem, I can add to some array:

...
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 );

很简单.如何做同样的事情,我找不到.

It's very simple. How to do the same, I couldn't find.

我在这里只找到了一些信息:

I've found only some information here:

http://blogs.msdn.com/b/eternalcoding/archive/2013/06/27/babylon-js-a-complete-javascript-framework-for-building-3d-games-with-html-5-and-webgl.aspx

以这样的例子(来自msdn Ctrl + F -> 您还可以从顶点和面的列表中创建网格):

With such an example (from msdn by 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 中我不需要它,它也是一个只有平面的样本,我没有找到任何关于精确挤出的信息.

But's it's rather not the same as with the THREE.JS. For example I need to count index buffer manually where in THREE.JS I don't need it, also it's a sample with plane only and I didn't find any info about extruding exactly.

那么……也许,BabylonJS 中有一些简单的方法?

So... Maybe, there are some easy ways in BabylonJS?

推荐答案

目前不支持挤压,但这可能是一个很好的添加功能:) 我一定会将它添加到我们的路线图中.如果您想进一步讨论该问题,请在 babylon.js 论坛上提问.

There is no support for extrusion right now but this could be a great feature to add :) I will definitely add it to our roadmap. If you would like to discuss the issue further please ask on the babylon.js forum.

现在可以创建自定义形状.

Have ability to create custom shapes now.

http://doc.babylonjs.com/tutorials/parametric_shapes#extrusion

这篇关于如何在 Babylon.js 中创建自定义网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆