Sign in to follow this  

[HAVOK] Loading a hkpShape from File

Recommended Posts


I currently try to add Havok Physics to my space action game. Now I want to load collision models for my ships from files to use them as Shapes.

My question is now: How to load a file (*.hkt or *.hkx) and use it's geometry? Which implementation of hkpShape is appropriate for this usage?

thanks for your help


Share this post

Link to post
Share on other sites
I only load an entire physics system from file - so a rigid body with a shape etc...

You'll still have to get the shape from the rigid body or something like that, I think there is a demo which shows you how to load a shape only from file (one of the character rigid body demos I think).

I'm not sure if my method is suitable for this, as I never loaded shapes only from files.

Assert(m_world && "NXPHavokMain::GetRigidBodyByName");

hkObjectResource* loadedData = hkSerializeUtil::loadOnHeap(file.c_str());
Assert(loadedData && "NXPHavokMain::CreatePhysicsSystemFromFile");

hkRootLevelContainer* root=loadedData->stealContents<hkRootLevelContainer>();
Assert(root && "NXPHavokMain::CreatePhysicsSystemFromFile");

hkpPhysicsData* pd=static_cast<hkpPhysicsData*>(root->findObjectByType(hkpPhysicsDataClass.getName()));
Assert(pd && "NXPHavokMain::CreatePhysicsSystemFromFile");


for(int i=0;i<pd->getPhysicsSystems().getSize();++i)


delete loadedData; // 'loadedData' no longer owns the data and may now be destroyed

About which is appropriate: anything that isn't a "mesh" (that isn't concave).
Maybe you could get away by using just primitives (box, sphere,...) or make a simple convex mesh.

Share this post

Link to post
Share on other sites
OK, if I interprete your code snippet correctly, I could store the whole physical data belonging to an object in a hkt file and load it in order to use it as a physical representation of this object.

And the hkpPhysicsSystem includes the RigidBody, which I need to get transformation data?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this