Static btBvhTriangleMeshShape assert

Post Reply
avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Static btBvhTriangleMeshShape assert

Post by avithohol »

Helllo,

I try to use btBvhTriangleMeshShape for static geometry, that is basically my non-moving environment, and it is created like this:

Code: Select all

    mTriangleIndexVertexArray = new btTriangleIndexVertexArray( (int)(mVertexIndexes.size()/3),  //number of triangle faces
                                                                (int*)&mVertexIndexes[0],         //index array
                                                                (int)(3*sizeof(vInt)),         //index stride
                                                                (int)mVertexPositions.size(),    //number of vertexes
                                                                (btScalar*)&mVertexPositions[0].x,       //vertex array
                                                                (int)sizeof(cVec3) );

    mCollisionShape = new btBvhTriangleMeshShape( mTriangleIndexVertexArray, true, true );
If I am not mistaken I need to create a rigid body to have it participate in the simulation:

Code: Select all

    mMotionState = new btDefaultMotionState( btTransform( btQuaternion( orientation.x, orientation.y, orientation.z, orientation.w),
                                                          btVector3(translation.x, translation.y, translation.z) ) );

	btScalar mass = 0;
	btVector3 btInertia = btVector3(0,0,0);
	btBvhTriangleMeshShape* triMeshShape = dynamic_cast<btBvhTriangleMeshShape*>(hull->getCollisionShape());
	triMeshShape->calculateLocalInertia( mass, btInertia);//HERE THE BULLETT ASSERT KICKS IN
	

    btRigidBody::btRigidBodyConstructionInfo rigidBodyConstructionInfo( mass, mMotionState, triMeshShape, btInertia);

    mRigidBody = new btRigidBody( rigidBodyConstructionInfo );
    mRigidBody->setFriction(1.5);

    dynamicsWorld->getPhysicsWorld()->addRigidBody( mRigidBody );

If I am not mistaken, I need to call calculateLocalInertia with 0 mass, and 0 inertia, to flag it as a non-moving shape.

My issue is that whenever I call calculateLocalInertia function (see above) an assert triggers in the following bullet code:

Code: Select all

void	btTriangleMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
	(void)mass;
	//moving concave objects not supported
	btAssert(0);
	inertia.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
}
telling me that I should not use that my btBvhTriangleMeshShape for moving concave objects.

Well, I do want to use it for static environment, but have no idea how to tell it to bullet then.

How can I tell bullett that, my btBvhTriangleMeshShape is a non-moving shape?
In which line of my code confuses Bullett?

Any help is greatly appreciated.

Thank you,
A
avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: Static btBvhTriangleMeshShape assert

Post by avithohol »

I have an ugly workaround.
When user pass 0 mass, I just do not call calculateLocalInertia.

I am still worried that my btBvhTriangleMeshShape is not properly constructed.

Can anybody review my btBvhTriangleMeshShape construction, especially when i create the rigid body for it.
ktfh
Posts: 44
Joined: Thu Apr 14, 2016 3:44 pm

Re: Static btBvhTriangleMeshShape assert

Post by ktfh »

use a btCollisionObject instead of a rigidbody http://bulletphysics.org/Bullet/BulletF ... bject.html
avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: Static btBvhTriangleMeshShape assert

Post by avithohol »

ktfh wrote:use a btCollisionObject instead of a rigidbody http://bulletphysics.org/Bullet/BulletF ... bject.html
Thanks for the reply!
That is the base class fot rigid bodies, I am not sure how this would help, could you elaborate?
ktfh
Posts: 44
Joined: Thu Apr 14, 2016 3:44 pm

Re: Static btBvhTriangleMeshShape assert

Post by ktfh »

avithohol wrote: That is the base class fot rigid bodies, I am not sure how this would help, could you elaborate?
rigid body extends collision object with mass and velocity behaviors that are incompatible with your concave shape, just use btCollisionObject instead.

Code: Select all

btCollisionObject* mObj = new btCollisionObject();
mObj->setCollisionShape(mCollisionShape);
mDynamicsWorld->addCollisionObject(mObj);
avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: Static btBvhTriangleMeshShape assert

Post by avithohol »

ktfh wrote:
avithohol wrote: That is the base class fot rigid bodies, I am not sure how this would help, could you elaborate?
rigid body extends collision object with mass and velocity behaviors that are incompatible with your concave shape, just use btCollisionObject instead.

Code: Select all

btCollisionObject* mObj = new btCollisionObject();
mObj->setCollisionShape(mCollisionShape);
mDynamicsWorld->addCollisionObject(mObj);
Makes sense now, it does work!
So no motion state anymore.

Thanks for the help! This thread is answered!
Post Reply