本文介绍了从three.js中的网格中bullet/ammo.js中的刚体(形状)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将bullet/ammo.js与three.js一起使用.我有一个3D网格,我想使用精确的形状进行与软体的碰撞检测.有没有办法从网格(在three.js中)创建3d刚体(在子弹中)?

I am using bullet/ammo.js with three.js. I have a 3d mesh and I want to use the exact shape for collision detection with a soft body. Is there a way I can create a 3d rigid body (in bullet) from a mesh (in three.js)?

这里是一个示例: http://kidzinski.com/miamisura/lazy3d/(请耐心等待3D模型下载).我有一块布掉在3d的物体上,我需要模拟这块布与物体的碰撞.

Here is an example:http://kidzinski.com/miamisura/lazy3d/ (please wait a second for the 3d model to download). I have a cloth falling on a 3d body and I need to simulate collision of this cloth with the body.

对于这些框架,我是陌生的,如果我从根本上误解了某些东西,则感到遗憾.

I am new to these frameworks sorry if I fundamentally misunderstood something.

推荐答案

看起来您可以做一些工作,将任意Three.js网格转换为Bullet凹形网格. Physi.js支持此功能,这是一个将Three.js直接链接到ammo.js的即插即用解决方案.我个人不建议使用该项目(Physi.js),但您可以查看源代码以了解它们如何实现凹面网格.

It looks like you can do some work to turn an arbitrary Three.js mesh into a Bullet concave mesh. This is supported by Physi.js, which is a plug and play solution to link Three.js directly to ammo.js. I personally wouldn't recommend using the project (Physi.js) but you can look at the source code to see how they implement concave meshes.

首先,他们在几何上循环以在这几行Phys.js

First they loop over the geometry to create a custom list of "triangle" data objects on these lines of physi.js

for ( i = 0; i < geometry.faces.length; i++ ) {
    face = geometry.faces[i];
    if ( face instanceof THREE.Face3) {
        triangles.push([
            ...

然后将这些三角形传递给Ammo.js,以创建 new Ammo.btBvhTriangleMeshShape在这些行上:

Then these triangles are passed off to Ammo.js to make a new Ammo.btBvhTriangleMeshShape on these lines:

for ( i = 0; i < description.triangles.length; i++ ) {
    ...
    triangle_mesh.addTriangle( _vec3_1, _vec3_2, _vec3_3, true );
}

...

shape = new Ammo.btBvhTriangleMeshShape( triangle_mesh, true, true );

这应该是构建自己的Ammo.js自定义网格的良好起点.

This should be a good starting point for building your own Ammo.js custom mesh.

这篇关于从three.js中的网格中bullet/ammo.js中的刚体(形状)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 02:52