How to load trianglemesh using btBvhTriangleMeshShape

Post Reply
hiwu501
Posts: 5
Joined: Tue Oct 23, 2018 4:41 am

How to load trianglemesh using btBvhTriangleMeshShape

Post by hiwu501 »

I'm very new to bullet and I meet a problem that the shape generated by bullet doesn't match the loaded mesh.
the loaded mesh
Image
debug draw
Image
And I save the indices and vertices in vector<> format.

Code: Select all

auto meshInterface = new btTriangleIndexVertexArray(
                static_cast<int>(mpObjLoader->getIdxNums()),
                reinterpret_cast<int*>(mpObjLoader->getTriIndices()),
                sizeof(int)*3,
                static_cast<int>(mpObjLoader->getVertNums()),
                mpObjLoader->getVertices(),
                sizeof(float)*3
                );

        bool useQuantizedAabbCompression = true;
        auto trimeshShape = new btBvhTriangleMeshShape(meshInterface,useQuantizedAabbCompression);
below it's how to get vertices. This function returns pointer to vector

Code: Select all

float *PlyLoader::getVertices() const {
    return mvVertices->data();
}
So anybody know what's wrong? Thank you very much!!!
hiwu501
Posts: 5
Joined: Tue Oct 23, 2018 4:41 am

Re: How to load trianglemesh using btBvhTriangleMeshShape

Post by hiwu501 »

Now I changed a method, but it also failed. This shows many strange straight lines.
Image

Code: Select all

auto triIndices = mpObjLoader->getTriIndices();
        auto vertices = mpObjLoader->getVertices();
        auto meshInterface = new btTriangleMesh();
        for(int i=0; i < triIndices->size(); i+=3)
        {
            int index1, index2, index3;
            index1 = (*triIndices)[i];
            index2 = (*triIndices)[i+1];
            index3 = (*triIndices)[i+2];

            btVector3 v1((*vertices)[3*index1], (*vertices)[3*index1+1], (*vertices)[index1+2]),
            v2((*vertices)[3*index2], (*vertices)[3*index2+1], (*vertices)[3*index2+2]),
            v3((*vertices)[3*index3], (*vertices)[3*index3+1], (*vertices)[3*index3+2]);

            meshInterface->addTriangle(v3, v2, v1);
        }

        auto trimeshShape = new btBvhTriangleMeshShape(meshInterface, true);
hiwu501
Posts: 5
Joined: Tue Oct 23, 2018 4:41 am

Re: How to load trianglemesh using btBvhTriangleMeshShape

Post by hiwu501 »

The model file is .ply format.
Could anyone help me???
Thank you.
hiwu501
Posts: 5
Joined: Tue Oct 23, 2018 4:41 am

Re: How to load trianglemesh using btBvhTriangleMeshShape

Post by hiwu501 »

okay, I solved my problem.
just return vector<> solved.
But I don't know why...... :?:
Post Reply