Importing a .bullet file from Blender

Physics APIs, Physics file formats, Maya, Max, XSI, Cinema 4D, Lightwave, Blender, thinkingParticles™ and other simulation tools, exporters and importers
Post Reply
rob_marc2003
Posts: 5
Joined: Tue Nov 05, 2013 8:51 am

Importing a .bullet file from Blender

Post by rob_marc2003 »

Hi there,

After exporting a scene in Blender into .bullet file format according to this, I load the respective .bullet file in a simple application following the serialization wiki:

Code: Select all

btBulletWorldImporter* fileLoader = new btBulletWorldImporter(dynamicsWorld);
fileLoader->loadFile("h:\\testFile.bullet");
Question: how can I access rigid body parameters (like mass, dimensions, inertia etc.) in the Bullet world inside my program?

Thanks,
R
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Importing a .bullet file from Blender

Post by Dirk Gregorius »

I would guess after import you can access the rigid bodies, joints, and shapes from the world interface and iterate all the information you need.
rob_marc2003
Posts: 5
Joined: Tue Nov 05, 2013 8:51 am

Re: Importing a .bullet file from Blender

Post by rob_marc2003 »

I've managed to access rigid body properties via the following lines:

Code: Select all

for(int i=0; i < fileLoader->getNumRigidBodies(); i++)
{
	btCollisionObject* obj = fileLoader->getRigidBodyByIndex(i);
	btRigidBody* body = btRigidBody::upcast(obj);		

	// properties
	printf("  object name = %s\n", fileLoader->getNameForPointer(body));	// The Blender object name
    printf("  get position = (%4.3f,%4.3f,%4.3f)\n", 
		body->getCenterOfMassPosition().getX(),
		body->getCenterOfMassPosition().getY(), 
		body->getCenterOfMassPosition().getZ());			// Blender CoM
	printf("  get local scaling = (%4.3f,%4.3f,%4.3f)\n", 
		body->getCollisionShape()->getLocalScaling().getX(),
		body->getCollisionShape()->getLocalScaling().getY(),
		body->getCollisionShape()->getLocalScaling().getZ());		// Blender Dimensions
	if (body->getInvMass() == 0)
		printf("  static object\n");
	else
	{
		printf("  mass = %4.3f\n", 1/body->getInvMass());		// Blender Mass
		printf("  get gravity (z!) = %4.3f\n", body->getGravity().getZ());	// Blender Gravity
	}
	printf("\n");
}
I still don't know how to access the contstraints (i.e. hinges) after importing the .bullet file. Any thoughts on that?

Cheers,
Rob
rob_marc2003
Posts: 5
Joined: Tue Nov 05, 2013 8:51 am

Re: Importing a .bullet file from Blender

Post by rob_marc2003 »

short Update:
I've managed to access the hinges and it's properties:

Code: Select all

for(int i=0; i < dynamicsWorld->getNumConstraints(); i++)
	{
		btTypedConstraint*	constraint=dynamicsWorld->getConstraint(i);
		printf("  constraint type = %i\n", constraint->getConstraintType());
		printf("  collision shape type = %i\n", constraint->getRigidBodyA().getCollisionShape()->getShapeType());	
		printf("  get partA axisVector (part of quaternion) = (%4.3f,%4.3f,%4.3f)\n",
			constraint->getRigidBodyA().getCenterOfMassTransform().getRotation().getX(),
			constraint->getRigidBodyA().getCenterOfMassTransform().getRotation().getY(),
			constraint->getRigidBodyA().getCenterOfMassTransform().getRotation().getZ());
		printf("  get partA CenterOfGeometry = (%4.3f,%4.3f,%4.3f)\n",
			constraint->getRigidBodyA().getCenterOfMassPosition().getX(),
			constraint->getRigidBodyA().getCenterOfMassPosition().getY(),
			constraint->getRigidBodyA().getCenterOfMassPosition().getZ());
		
	}
Although I still can't find a way how to access a constraint's related rigidbodies names (i.e. hinge->rigidBodyA->name and hinge->rigidBodyB->name).

Any thoughts on this?
Post Reply