Adding multiple fixed rigid body shapes from one HKX file

Adding multiple fixed rigid body shapes from one HKX file

Hi,

Some of my students are running into an issue that whenthey load a HKX file that has more than one fixed rigid body in Maya only the parent is loaded. The children are not loaded.

Looking deeper we found that hkpPhysicsData can only find a rigid body by name so if you havemore than 1 you will need to have a list of names which is not efficient.

What's the optimal way to create a terrain collision meshwith multiple nodes in Maya and load an HKX file as a singlephysics system? One physic system with multiple rigid body objects?

This is the creation object construct that we are using when loading HKX files.

// creation of physics object from havok content tools
PhysicsObject::PhysicsObject(char* hkx_Path,char* entity_Name,GameObjectManager* gameManager,HavokObjectSubType hsType) :HavokObject()
{
physicsWorld = gameManager->GetWorld();
hkPackfileReader::AllocatedData* memData;
hkIstream infile(hkx_Path);
HK_ASSERT(0x215d080c, infile.isOk() );
physicsData = hkpHavokSnapshot::load(infile.getStreamReader(), &memData);
rigidBodyObject = physicsData->findRigidBodyByName(entity_Name);
physicsWorld->addEntity(rigidBodyObject);
if (hsType == PHYSICS_KEYFRAMED)
{
rigidBodyObject->setMotionType(hkpMotion::MOTION_KEYFRAMED);
//m_time = 0;
}
else if (hsType == PHYSICS_FIXED)
rigidBodyObject->setMotionType(hkpMotion::MOTION_FIXED);
hkVector4 pos(0,5,0,0);
rigidBodyObject->setPosition(pos);
rigidBodyObject->removeReference();
}

Thanks for your help,

jose

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi there, Jose

Assuming I've understood your issue, two methods that spring to mind:

#1) Why not use hkpWorld::addPhysicsSystem() to add all the bodies in the system rather than looking up a body based on a name? Do the HKX files have lots of bodies that you may not want to add?

#2) If you do need to use the name, you could create all the static rigid bodies as a single compound rigid body in modeler rather than having separate bodies. If you need direction on how to do this, there's a nice tutorial in the Havok manual under Havok Content Tools -> 3ds Max Tools (or Maya Tools or XSI Tools) -> Tutorial: More on Rigid Bodies.

Would either of these suit your use case? Let me know how it turns out.

Patrick

Developer Support Engineer
Havok
www.havok.com

Hi,

Thanks for the info.
So here's the modified code section that loads multiple fixed rigid body shapes as children of a parent node in Maya.

We used the addPhysicsSystem after passing the RootLevelContainer that had the Maya hierarchy from the Physics Data section.

Wrapper Code :

physicsWorld = gameManager->GetWorld();
// Load the data
m_packfileData =
static_cast(hkSerializeUtil::load(hkx_Path));
// Get the top level object in the file, which we know is a hkRootLevelContainer
hkRootLevelContainer* container = m_packfileData->getContents();
HK_ASSERT2(0xa6451543, container != HK_NULL,
"Could not load root level obejct" );
// Get the physics data
physicsData =
static_cast( container->findObjectByType( hkpPhysicsDataClass.getName() ) );
//Spliting the systems just in case - for future use - not required at the moment
hkpPhysicsData::SplitPhysicsSystemsOutput *output;
output=(hkpPhysicsData::SplitPhysicsSystemsOutput*)malloc(
sizeof(hkpPhysicsData::SplitPhysicsSystemsOutput));
rigidBodyObject = physicsData->findRigidBodyByName(entity_Name);
if (hsType == PHYSICS_KEYFRAMED)
{
rigidBodyObject->setMotionType(hkpMotion::MOTION_KEYFRAMED);
}
else if (hsType == PHYSICS_FIXED)
rigidBodyObject->setMotionType(hkpMotion::MOTION_FIXED);
hkVector4 pos(0,5,0,0);
rigidBodyObject->setPosition(pos);
rigidBodyObject->removeReference();
for(int i=0; i<(physicsData->getPhysicsSystems().getSize()); i++)
{
physicsWorld->addPhysicsSystem(physicsData->getPhysicsSystems()[i]);
}

Cheers,

jose

Leave a Comment

Please sign in to add a comment. Not a member? Join today