Hello, im new to havok, and already runned into some problems. Cant figure out how to read collision meshes from file runtime and add them to the world. Serialize demo seems to load something, but adding that to world crashes havok. As I understood, there is a whole phys system or even world in every .hkx/hkt file, not just a shape. And lots of related functions only confuses, cause i dont know what they all do. Can somebody write an example "file loader-to world adder" for me?
Also i may have some troubles with multithreading. I have main thread for initializing havok and ogre, which I am using for rendering, and then launch another thread, which i want to use for stable separated havok stepping. But this is crashes havok, i managed to move his initialization to start of his thread and that gone fine, until i tried to add working rigid body to havok world from main thread, wich caused crash. Found something about "initThread", but that funk didnt helpt me.
My code with threads (havok described as class):
class HavokClass {
public:
...
void initialize(void);
void InitThread(void);
...
hkMallocAllocator baseMalloc; //have them static for being able to access anytime anywhere
hkReal StepTime; //Time between frames
hkpWorld* world;
hkpPhysicsContext* context; //VDB
hkVisualDebugger* visualDebugger;
};
void HavokClass::initialize(void)
{
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault( &baseMalloc, hkMemorySystem::FrameInfo(1024 * 1024) );
hkBaseSystem::init( memoryRouter, errorReport );
world = new hkpWorld( hkpWorldCinfo() );
hkpAgentRegisterUtil::registerAllAgents( world->getCollisionDispatcher() );
hkpPhysicsContext::registerAllPhysicsProcesses();
context = new hkpPhysicsContext;
context->addWorld(world);
hkArray contexts;
contexts.pushBack(context);
visualDebugger = new hkVisualDebugger(contexts);
visualDebugger->serve();
}
void HavokClass::InitThread(void)
{
hkMemoryRouter memoryRouter;
hkMemorySystem::getInstance().threadInit( memoryRouter, "hkCpuJobThreadPool" );
hkBaseSystem::initThread(&memoryRouter);
}
void HavokClass::step(void)
{
world->stepDeltaTime(StepTime);
visualDebugger->step();
}
HavokClass Havok; //also global, temporary primitive code until i got a grip on how everything works
//havok thread, started as _beginthread ( PhysThreadLoop, 0, 0 );
void PhysThreadLoop( void* arg ) {
Havok.initialize();
Havok.MakeFloor(); //creates big flat box, works fine
Havok.StepTime = 1.0f / hkReal(60);
while (true) {
Havok.step();
Sleep ( 16 );
}
}
//everything works fine, until now
void cCoropcaMover::SpawnPhysHead(void)
{
Havok.InitThread(); //supposed to register thread so it wont crash havok, but its not
Havok.CreateBox(); //spawns rigid body box, works fine if used in havoks thread, but crashes if called from another, even through i call init thread
}


