Page 1 of 1
Importing a .bullet file from Blender
Posted: Mon Jan 27, 2014 5:00 pm
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
Re: Importing a .bullet file from Blender
Posted: Tue Jan 28, 2014 3:29 am
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.
Re: Importing a .bullet file from Blender
Posted: Tue Jan 28, 2014 6:13 pm
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
Re: Importing a .bullet file from Blender
Posted: Thu Jan 30, 2014 3:13 pm
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?