[HAVOK] Loading a hkpShape from File

Started by
3 comments, last by Oromis 13 years, 4 months ago
Hi,

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

Oromis_32
Advertisement
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");		m_world->lock();		for(int i=0;i<pd->getPhysicsSystems().getSize();++i)	{		m_world->addPhysicsSystem(pd->getPhysicsSystems());	}		m_world->unlock();	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.
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?
Correct, you can load an entire physics rigid body with shape and other stuff if you need (constraints, etc...) this way.
Nice :)

Thanks for the answer!

This topic is closed to new replies.

Advertisement