【问题标题】:Using Bullet Physics to Load OBJ model to btGImpactMeshShape but the result is wrong使用 Bullet Physics 将 OBJ 模型加载到 btGImpactMeshShape 但结果错误
【发布时间】:2014-06-16 03:35:20
【问题描述】:

我使用 Bullet Physics Engine 将 OBJ 模型加载到使用 btGImpactMeshShape 的世界中。 我是使用这个引擎的新手

这是我的代码

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

//            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 查看的

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

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

【问题讨论】:

    标签: polygon game-physics mesh bullet wavefront


    【解决方案1】:

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

    【讨论】:

    • 感谢您的建议。但是我怎么能将指针设置为浮动。问题与我的模型有关吗?还是我必须更改代码的任何部分。
    【解决方案2】:

    Blender 将其索引命名为从 1 开始,而 Bullet Physics 从 0 开始。 例如,下面是从 Blender 导出的立方体网格,然后渲染为 btGImpactMeshShape 和 3 个立方体渲染为 btBoxShape。同样低于btTriangleIndexVertexArray 的顶点和索引应该如何在子弹物理中正确渲染为btGImpactMeshShape 的立方体网格。更多内容,请点击链接查看Bullet Physics forum.上的类似主题

    要了解有关 btTriangleIndexVertexArraybtGImpactMeshShape 的更多信息,另请参阅 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 }
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多