Edge collision problems after editing btBvhTriangleMeshShape

Post Reply
Silverlan
Posts: 27
Joined: Thu Oct 30, 2014 9:15 pm

Edge collision problems after editing btBvhTriangleMeshShape

Post by Silverlan »

I want to change the vertex positions of a btBvhTriangleMeshShape, but after doing so I get a lot of collision problems near triangle edges:
https://youtu.be/7sW7YdmywHo
(Original triangle mesh shown at the beginning of the video works fine. After changing the vertex positions at 00:21,the collisions are all wrong.)

Here's my code, all I'm doing is moving the vertices slightly up on the y-axis:

Code: Select all

btTriangleIndexVertexArray *iva = shape->GetBtIndexVertexArray();
uint8_t *vertexBase = nullptr;
int32_t numVerts = 0;
int32_t vertexStride = 0;
PHY_ScalarType scalarType {};
uint8_t *indexBase = nullptr;
int32_t indexStride = 0;
int32_t numFaces = 0;
PHY_ScalarType indexType {};
int32_t subPart = 0;
iva->getLockedVertexIndexBase(&vertexBase,numVerts,scalarType,vertexStride,&indexBase,indexStride,numFaces,indexType,subPart);

for(auto i=decltype(numVerts){0};i<numVerts;++i)
{
    switch(scalarType)
    {
        case PHY_ScalarType::PHY_FLOAT:
        {
            auto *v = reinterpret_cast<float*>(vertexBase +i *vertexStride);
            v[1] += 0.5f;
            break;
        }
        case PHY_ScalarType::PHY_DOUBLE:
        {
            auto *v = reinterpret_cast<double*>(vertexBase +i *vertexStride);
            v[1] += 0.5;
            break;
        }
    }
}

iva->unLockVertexBase(subPart);

shape->setTriangleInfoMap(nullptr); // btGenerateInternalEdgeInfo doesn't do anything if the shape already has an info map
btGenerateInternalEdgeInfo(shape,infoMap);
Post Reply