Using rigid bodies from *.hkx

Using rigid bodies from *.hkx

Hello,

I have exported a simple scene witch features a piece of geometry that falls on top of another.
(i have used the create rigid bodies, shrink shapes, and prune types-with everything selected,
write to platform and preview scene filters)
In preview the scene looks at it is supposed;

I then load in code this file using

hkLoader myLoader;
hkRootLevelContainer *myContainer = myLoader.load("file.hkx");

Ho will I access the rigid bodies in order to add them to the world?

I have tried using a pointer:

void * myPointer = myContainer->findObjectByName("RigidBody");
hkpRigidBody *myBody = (hkpRigidBody*) &myPointer;

but the program crashes on physicsWorld->addEntity(RigidBody);

Thank you.

4 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

Hi again, spooky_paul,

Have a look at the WorldSnapshotDemo (DemosPhysicsApiDynamicsWorldWorldSnapshot) to see how to load in a world.

The
hkx file should come with a world in it. If you're having trouble with
that, you can set it up with the Create World filter to make sure it's
there and configured how you want it. Something like this is all you
need:

    // Some demo class members for data we need to keep around
hkpPhysicsData* m_physicsData;
hkPackfileReader::AllocatedData* m_loadedData;
hkpWorld* m_world; // This one already exists for you in the demo framework

...

hkIstream infile( "myExportedScene.hkx" );
// Check that the file exists and that we can access it
if (infile.isOk())
{
// Load the data from the file into m_physics Data
m_physicsData = hkpHavokSnapshot::load(infile.getStreamReader(), &m_loadedData);

// Find a rigid body. "myBox" is what we called it in Max
hkpRigidBody* myBoxRb = m_physicsData->findRigidBodyByName("myBox");

// Create the world from the data loaded from the hkx.
m_world = m_physicsData->createWorld()
}

I
haven't run this code but if you look at that demo you'll see how
similar it is. We keep m_loadedData and m_physicsData as members of the
class so they can be persistent until the end of the demo. Don't forget
to removeReference() them in your destructor!

When you create that world, all the rigid bodies should already be in
there so there's no need to look after adding them. Accessing the rigid
bodies is done by findRigidBodyByName(). You can also iterate through
all the bodies in the file if you'd rather do that, by going through
the array returned from hkpPhysicsData::getPhysicsSystems(), then
going through the array returned from hkpPhysicsSystem::getRigidBodies() if you'd rather do that.

Hope this helps!
Daniel

Hey Daniel,

This's it! Thank you :)

No problem :-)

Faça login para deixar um comentário.