1

我使用 Bullet Physics Engine 使用 btGImpactMeshShape 将 OBJ 模型加载到世界。我对使用这个引擎非常陌生

这是我的代码

//---------------------------------------//

//            load from obj              //

//---------------------------------------//

ConvexDecomposition::WavefrontObj wobj;
printf("load first try"); fflush( stdout );
std::string filename("bunny.obj");
int result = wobj.loadObj( "bunny.obj" );
if(!result)
{
printf("first try fail\n"); fflush( stdout );
printf("load second try");  fflush( stdout );
result = wobj.loadObj("../bunny.obj");
}

printf("--load status %d\n", result );
printf("--triangle: %d\n", wobj.mTriCount);
printf("--vertex: %d\n", wobj.mVertexCount);


btTriangleIndexVertexArray* colonVertexArrays = new btTriangleIndexVertexArray(
wobj.mTriCount,
wobj.mIndices,
                3*sizeof(int),
                wobj.mVertexCount,
                wobj.mVertices,
                3*sizeof(float)
                );

btGImpactMeshShape* bunnymesh = new btGImpactMeshShape(colonVertexArrays);
bunnymesh ->setLocalScaling( btVector3(0.5f, 0.5f, 0.5f) );
bunnymesh ->updateBound();
startTransform.setOrigin( btVector3(0.0, 0.0, 0.0) );
startTransform.getBasis().setEulerZYX( 0, 0, 0 );
localCreateRigidBody( bunnymesh , startTransform, 0.0 );
printf("Load done...\n");

在我加载的模型中......这个兔子是在 MAC 上使用 MeshLab 查看的

Meshlab 看到的原始兔子模型

我试图改变各种步幅参数,但这是我的程序的结果

使用子弹查看兔子 控制台输出

您对代码有什么问题有什么建议吗?

4

2 回答 2

0

wobj.mVertices 不是指向双精度数组的指针吗?btTriangleIndexVertexArray 需要一个指向浮点的指针,因此您必须创建一个新的浮点数组并复制并投射顶点。

于 2014-10-15T10:53:28.280 回答
0

Blender 将其索引命名为从 1 开始,而 Bullet Physics 从 0 开始。作为示例,下面是从 Blender 导出的立方体网格,然后渲染为btGImpactMeshShape3 个立方体btBoxShape。同样在下面,立方体网格的顶点和索引btTriangleIndexVertexArray应该如何在 Bullet Physics 中正确渲染为 btGImpactMeshShape. 有关更多信息,请单击链接以查看Bullet Physics 论坛上的类似主题。

要了解有关btTriangleIndexVertexArray和 的更多信息btGImpactMeshShape,还可以在 Bullet Physics SDK 中查看 GimpactTestDemo,它展示了一个圆环和……斯坦福兔子。

const int NUMBER_VERTICES = 8;
const int NUMBER_TRIANGLES = 12;

static float cubeVertices[NUMBER_VERTICES * 3] = {
    1.000000, -1.000000, -1.000000,
    1.000000, -1.000000, 1.000000,
   -1.000000, -1.000000, 1.000000,
   -1.000000, -1.000000, -1.000000,
    1.000000, 1.000000, -0.999999,
    0.999999, 1.000000, 1.000001,
   -1.000000, 1.000000, 1.000000,
   -1.000000, 1.000000, -1.000000
};

static int cubeIndices[NUMBER_TRIANGLES][3] = {
   { 1, 3, 0 },
   { 7, 5, 4 },
   { 4, 1, 0 },
   { 5, 2, 1 },
   { 2, 7, 3 },
   { 0, 7, 4 },
   { 1, 2, 3 },
   { 7, 6, 5 },
   { 4, 5, 1 },
   { 5, 6, 2 },
   { 2, 6, 7 },
   { 0, 3, 7 }
};

在此处输入图像描述

于 2017-11-11T21:49:40.100 回答