Forum Jump

Select Group :
Select Forum :
Sorted By :
Sort Order :
From The :
 
Thread Tools  Search this thread 
gonx
Total Points:
745
Status Points:
0
Green Belt
July 6, 2008 11:02 PM PDT
[Noob Question]Tutorials for Integrating Havok with 3rd party graphics engine
Hi,

Would there be any recommended tutorials and approach for integrating havok to open source graphics engines? I've been studying the docs and sample sources(havok demo framework) but  am still looking for a way. I was wondering if anyone can point a noob in the right direction.
ominae392
Total Points:
112
Registered User
August 5, 2008 5:53 PM PDT
Rate
 
#26 Reply to #25
Alright I'll give that a shot.

My old source code is back up at www.daystems.net/svn/public/HavokTest1   Minus the Havok licensed stuff.

Login: Guest
pass: guest



bingobeawr
August 5, 2008 6:51 PM PDT
Rate
 
#27

I want to know which is the best free and open source Gpaphics Engine. From what I looked up..

Ogre 3D--No way, no quality

Irrlichit--Better but could be improved.

UnrealEngine 2 Level Editor-AWESOME but cant do much without license. Even the tutorial are for liceners only who have their personalized logins.

 

So what should I choose or do you know any other good Graphic Engine.

Can you export a 3D Level from 3D Max to Irrlichit Editor?

Thank Yousmiley [:-)]



ominae392
Total Points:
112
Registered User
August 5, 2008 8:43 PM PDT
Rate
 
#28 Reply to #27
havokdaniel, I've seen a few older posts regarding the hkx file format.  Is there any API for creating hkx files from c++?  I'm not a modeller but I do know how to handle 3D data and I'd like to be able to convert from .obj, ply, and a few other formats without having to get a Maya or 3DS.  If that's the only route then so be it.



havokdaniel
August 6, 2008 10:35 AM PDT
Rate
 
#29 Reply to #28
Hi Ominae392,

.hkx files are just serialized Havok objects. If you can get anything loaded into Havok then you can create a .hkx file with the hkBinaryPackfileWriter or hkXmlPackfileWriter.

There are a couple of options for taking geometry in some arbitrary format into Havok. Here are a few I can think of:
  • Load it up in Max/Maya/XSI and use the respective scene exporter with the filter manager to export to .hkx.
  • Load it up in some other modeler (like Blender) and write your own scene exporter (which would still use the same filter manager) to export to .hkx.
  • Parse the geometry file and output an XML .hkx. This would require a little reverse-engineering on your part but I don't think it's impossible to do.
  • Parse the geometry file and use that data to create Havok objects in the Havok runtime. Then serialize out this code using the hkPackfileWriter.
That last one seems like the easiest if you don't want to use one of the supported modelers.

Thanks,
Daniel


havokchris
Total Points:
3,764
Status Points:
3,264
Brown Belt
August 6, 2008 10:50 AM PDT
Rate
 
#30 Reply to #25
havokdaniel:
The reason why .hkx files are much faster is that they can be saved as platform-specific binary files and then loaded straight into memory. No parsing of vertices or construction of geometry is necessary, just a memcpy().


The other nice thing is that you can compute the MOPP (collision bounding volume structure) offline, instead of every time you load your level. Building the MOPP may be fast for a small mesh, but it definitely starts to slow down as the size increases. Anything that decreases level load time is a Good Thing, both for the people playing the game, and for you when you're trying to debug something.

Last but not least, the binary .hkx files should be smaller than the .tk files, since it doesn't store the floating point values as string.

-Chris


mseare
Total Points:
138
Status Points:
0
Green Belt
August 8, 2008 5:02 PM PDT
Rate
 
#31 Reply to #30
I can vouch for that.  The binary .hkx files are much smaller and load much, much faster.  Even relatively large MOPP scenes load pretty fast.

Hi Chris!


gonx
Total Points:
745
Status Points:
0
Green Belt
August 26, 2008 12:48 PM PDT
Rate
 
#32 Reply to #31
Hi,

It's been a while since my last post. So far i've been making some progress in understanding the API .

What  i did was study the standAloneDemos included in the havok download.

Currently i've had success in loading some .hkx files based from the .chm manual included in the havok engine download. Managed to advance the timestep and viewed the simulation in the visualdebugger . Problem is how can  i update my 3rd party graphics objects from the API ..

Some questions though maybe someone has had similar problems.

In the code:

...
physicsWorld->resetThreadTokens();
multithreadingUtil->startStepWorld( timestep );
multithreadingUtil->waitForStepWorldFinished();
...

Where the physics world has advanced a timestep. How can i get the updated positions of my rigid bodies ? Would there be a data structure that is being returned from hkpWorld that  i can use to update may 3rd party graphics object?


havokdaniel
August 26, 2008 3:00 PM PDT
Rate
 
#33 Reply to #32
Hi gonx,

Have a look at this thread and see if it answers any of your questions:
http://software.intel.com/en-us/forums//topic/59714

Daniel



gonx
Total Points:
745
Status Points:
0
Green Belt
September 1, 2008 11:31 PM PDT
Rate
 
#34 Reply to #33

Hi Guys,

So far i've been successful in getting rigid body data from the hkx  in addition to loading it in the ogre graphics engine. Right now i've been having problems in trying to step the simulation.

In the code below:

class HavokProgram {

hkpWorld *physicsWorld;

hkpMultiThreadUtil *multithreadingUtil;

public void initHavok() { <do memory allocations, hkx loading and createWorld>}

}

============

class OgreProgram {

void OgreProgram::step() {

HavokProgram *havok;

...

havok->physicsWorld->resetThreadTokens();
havok->multithreadingUtil->startStepWorld( timestep );
havok->multithreadingUtil->waitForStepWorldFinished();

...
}

}

I've traced my program and it seems that it crashes when reaching the waitForStepWorldFinished() part of the program.

In the pseudocode above this was the part where im trying to advance the simulation step. A couple of questions I've thought of  so i can get back on track.

1. I've read in some of the forums here

(http://software.intel.com/en-us/forums//topic/59300)

("basically i found that the havok step delta needs to be called from the same thread where havok was initialized ..")

that the stepping of the simulation should be executed on the same thread where havok was initialized? Would this be the reason why waitForStepWorldFinished() is crashing?

2.I've also read from these forums that there is this callstack one can use to debug. How does one print the callstack?

 

Thanks.



sean.thurston
Total Points:
8,322
Status Points:
0
Brown Belt
September 3, 2008 11:49 AM PDT
Rate
 
#35 Reply to #34
Hi gonx,

Can I see how you are setting up memory and and the multithreading util? There is an example of doing multithreaded simulation in the ConsoleExampleMt. Also make sure to check the docs Havok Physics->Multithreading and specifically the section called Running Physics Multithreaded.

If you are using Visual Studio, the call stack is typically in the lower right had window. It is tabbed along with Breakpoints and Output. When you crash it is typically brought to the front. You can just grab the information there.

I hope this helps.

Thanks,
Sean


bobobo1618
September 4, 2008 5:22 PM PDT
Rate
 
#36 Reply to #35

Hello, I have managed to create an exporter for TK files. It is a script for blender. You can go and put it in your .blender/scripts folder, then you can export TK files which can be read by Havok.

http://rapidshare.com/files/142686628/export_tk.py.html



gonx
Total Points:
745
Status Points:
0
Green Belt
September 8, 2008 7:34 PM PDT
Rate
 
#37 Reply to #35

sean.thurston:
Hi gonx,

Can I see how you are setting up memory and and the multithreading util? There is an example of doing multithreaded simulation in the ConsoleExampleMt. Also make sure to check the docs Havok Physics->Multithreading and specifically the section called Running Physics Multithreaded.

If you are using Visual Studio, the call stack is typically in the lower right had window. It is tabbed along with Breakpoints and Output. When you crash it is typically brought to the front. You can just grab the information there.

I hope this helps.

Thanks,
Sean

Hi Sean,

Thanks for the reply. Sorry for the late reply as i have been reading the other posts and comparing my code to the examples of the SDK in trying to solve this problem. Pasting some of my code below. Hope it turns out ok.

I'm currently loading an hkx file to setup the world. It's just like the one in ConsoleExampleMt by replacing the part below:

  {

   // The world cinfo contains global simulation parameters, including gravity, solver settings etc.

   hkpWorldCinfo worldInfo;

   // Set the simulation type of the world to multi-threaded.worldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;

physicsWorld = new hkpWorld(worldInfo);

  }

===============================

Here is the method where i try to call the stepping.

void HavokPhysics::initHavok(std::vector<hkpRigidBody *> *tempbodies) {

 

 // Initialize the base system including our memory system

 hkPoolMemory* memoryManager = new hkPoolMemory();

 threadMemory = new hkThreadMemory(memoryManager, 16);

 hkBaseSystem::init( memoryManager, threadMemory, errorReport );

 memoryManager->removeReference();

 

 // We now initialize the stack area to 100k (fast temporary memory to be used by the engine).

 //char* stackBuffer;

 {

  int stackSize = 0x100000;

  stackBuffer = hkAllocate<char>( stackSize, HK_MEMORY_CLASS_BASE);

  hkThreadMemory::getInstance().setStackArea( stackBuffer, stackSize);

 }

 

 {

  

  // Create the physics world

  //hkpWorld* physicsWorld;

  /*

  {

   // The world cinfo contains global simulation parameters, including gravity, solver settings etc.

   hkpWorldCinfo worldInfo;

 

   // Set the simulation type of the world to multi-threaded.

   worldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;

 

   physicsWorld = new hkpWorld(worldInfo);

  }

  */

  // Open the file

  hkIstream infile( "test_Default.hkx" );

  if(infile.isOk()){

   WriteToLog("infile is OK!! ");

  }

  // Load the file into a binary packfile reader.  Use a hkXmlP ackfileReader here if your data is XML.

  hkBinaryPackfileReader packfileReader;

  packfileReader.loadEntireFile( infile.getStreamReader() );

 

  // Version contents

  hkVersionUtil::updateToCurrentVersion( packfileReader, hkVersionRegistry::getInstance() );

 

  // Get the contents of the binary packfile.

  packfileContents = static_cast<hkRootLevelContainer*>(packfileReader.getContents( hkRootLevelContainerClass.getName() ));

 

  

  // Store a reference to the physics data in the packfile contents container

  physicsData = static_cast<hkpPhysicsData*>(packfileContents->findObjectByType( hkpPhysicsDataClass.getName() ));

 

 

 

  (*physicsData->getWorldCinfo()).m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;

  // Create a world and add the physics systems to it

  physicsWorld = new hkpWorld( *physicsData->getWorldCinfo() );

 


  

  

  //

  // Pre-allocate some larger memory blocks. These are used by the physics system when in multithreaded mode

  // The amount and size of these depends on your physics usage.  Larger simulation islands will use larger memory blocks.

  //

  {

   hkMemory::getInstance().preAllocateRuntimeBlock(512000, HK_MEMORY_CLASS_BASE);

   hkMemory::getInstance().preAllocateRuntimeBlock(256000, HK_MEMORY_CLASS_BASE);

   hkMemory::getInstance().preAllocateRuntimeBlock(128000, HK_MEMORY_CLASS_BASE);

   hkMemory::getInstance().preAllocateRuntimeBlock(64000, HK_MEMORY_CLASS_BASE);

   hkMemory::getInstance().preAllocateRuntimeBlock(32000, HK_MEMORY_CLASS_BASE);

   hkMemory::getInstance().preAllocateRuntimeBlock(16000, HK_MEMORY_CLASS_BASE);

   hkMemory::getInstance().preAllocateRuntimeBlock(16000, HK_MEMORY_CLASS_BASE);

  }

 

 

  //

  // When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks

  // to make sure only one thread is modifying the world at once to prevent multithreaded bugs. Each thread

  // must call markForRead / markForWrite before it modifies the world to enable these checks.

  //

 

  physicsWorld->markForWrite();

  

 

  //

  // Register all collision agents, even though only box - box will be used in this particular example.

  // It's important to register collision agents before adding any entities to the world.

  //

  {

   hkpAgentRegisterUtil::registerAllAgents( physicsWorld->getCollisionDispatcher() );

  }

 

  //

  // Create a multi-threading utility.  This utility will create a number of threads that will run the

  // physics step i n parallel. The main thread calls functions in the utility which signal these threads

  // to start a new step, or wait for step completion.

  //

  hkpMultithreadingUtilCinfo info;

  // Add all the physics systems to the world

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

  {

   physicsWorld->addPhysicsSystem( physicsData->getPhysicsSystems()[i] );

  }

  info.m_world = physicsWorld;

  info.m_numThreads = NUM_THREADS;

 

  // In this example we enable timers. The multi-threading util will allocate a buffer per thread for capturing timer data.

  // If you leave this flag to false, no timers will be enabled.

  info.m_enableTimers = true;

  multithreadingUtil = new hkpMultithreadingUtil(info);

 

 

  // Create all the physics rigid bodies

  //setupPhysics( physicsWorld );

 

 

  //

  // Initialize the visual debugger so we can connect remotely to the simulation

  // The context must exist beyond the use of the VDB instance, and you can make

  // whatever contexts you like for your own viewer types.

  //

 

  context = new hkpPhysicsContext();

  hkpPhysicsContext::registerAllPhysicsProcesses(); // all the physics viewers

  context->addWorld(physicsWorld); // add the physics world so the viewers can see it

 

  hkVisualDebugger* vdb = setupVisualDebugger(context);

 

  context->m_monitorStreamBegins.setSize(NUM_THREADS);

  context->m_monitorStreamEnds.setSize(NUM_THREADS);

 

 

  // Now we have finished modifying the world, release our write marker.

  physicsWorld->unmarkForWrite();

 

 

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

 

   hkpPhysicsSystem *const ps = physicsData->getPhysicsSystems()[i];

 

   for(int j=0; j<ps->getRigidBodies().getSize();j++) {

    hkpRigidBody *const rb = ps->getRigidBodies()[j] ;

    hkpRigidBody  *cloney = rb->clone();

    tempbodies->push_back(cloney);

   }

  }

}

========================================

On a different class i do the stepping. I'm using Ogre for this one. This is the part where im getting my errors

bool OgreFrameListener::frameStarted(const FrameEvent &evt)

    {

        bool started = ExampleFrameListener::frameStarted(evt);

        stepping();

        return started;

    }

 

void OgreFrameListener::stepping() {

  havok->getWorld()->resetThreadTokens();

  // This will signal all threads which are in the wait state, to start processing stepDeltaTime() concurrently.

  havok->getMultithreadingUtil()->startStepWorld( 1.0f/60.0f );

  havok->getMultithreadingUtil()->waitForStepWorldFinished();  <==================== Program crashes here.

 

  std::vector <hkpRigidBody*> rigidbodies = this->bodies;

   <do stuff with bodies>

  // Pause until the actual time has passed

  while (stopWatch.getElapsedSeconds() < lastTime + timestep);

  lastTime += timestep;

}

Thanks again for the quick reply. I'm currently looking into this problem by looking at the examples from the sdk and looking at the forums on the "stepping".

Regards,

gonx



sean.thurston
Total Points:
8,322
Status Points:
0
Brown Belt
September 10, 2008 6:11 PM PDT
Rate
 
#38 Reply to #37
Hi gonx,

You shouldn't have to update the world in the same thread that the world is initialized in. Can you make sure to compile in full debug mode and can you give a callstack of the crash. Debug mode will turn on all the asserts and we can make sure that everything happening is thread-safe.

Thanks,
Sean


gonx
Total Points:
745
Status Points:
0
Green Belt
September 10, 2008 7:15 PM PDT
Rate
 
#39 Reply to #38

sean.thurston:
Hi gonx,

You shouldn't have to update the world in the same thread that the world is initialized in. Can you make sure to compile in full debug mode and can you give a callstack of the crash. Debug mode will turn on all the asserts and we can make sure that everything happening is thread-safe.

Thanks,
Sean

Hi sean,

Thanks for the quick response. Below is a callstack i'm getting in debug mode. I also see some accessCheck() methods in the stack.

 

testy.exe!hkMultiThreadCheck::accessCheck(hkMultiThreadCheck::AccessType type=HK_ACCESS_RO)  Line 186 + 0x6f bytes    C++
     testy.exe!hkMultiThreadCheck::accessCheckWithParent(const hkMultiThreadCheck * parentLock=0x03b2bd98, hkMultiThreadCheck::AccessType parentType=HK_ACCESS_IGNORE, const hkMultiThreadCheck & lock={...}, hkMultiThreadCheck::AccessType type=HK_ACCESS_RO)  Line 245 + 0xd bytes    C++
     testy.exe!hkpRigidBody::getCinfo(hkpRigidBodyCinfo & info={...})  Line 318    C++
     testy.exe!hkpRigidBody::clone()  Line 390    C++
>    testy.exe!HavokPhysics::initHavok(std::vector<hkpRigidBody *,std::allocator<hkpRigidBody *> > * tempbodies=[0]())  Line 251 + 0x15 bytes    C++
     testy.exe!OgreFrameListener::OgreFrameListener(Ogre::RenderWindow * win=0x0144fcc8, Ogre::Camera * cam=0x014a6140, Ogre::SceneManager * sceneMgr=0x0149c630)  Line 26    C++
     testy.exe!TutorialApplication::createFrameListener()  Line 193 + 0x43 bytes    C++
     testy.exe!ExampleApplication::setup()  Line 140 + 0xf bytes    C++
     testy.exe!ExampleApplication::go()  Line 89 + 0xf bytes    C++
     testy.exe!WinMain(HINSTANCE__ * hInst=0x00400000, HINSTANCE__ * __formal=0x00000000, char * strCmdLine=0x00161f01, HINSTANCE__ * __formal=0x00000000)  Line 218 + 0x8 bytes    C++
     testy.exe!__tmainCRTStartup()  Line 574 + 0x35 bytes    C
     testy.exe!WinMainCRTStartup()  Line 399    C
     kernel32.dll!7c816ff7()    
     [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]   
 
I'll be  looking more into this again later this evening.

Thanks again!



sean.thurston
Total Points:
8,322
Status Points:
0
Brown Belt
September 10, 2008 7:47 PM PDT
Rate
 
#40 Reply to #39
Hi gonx,

Try moving your unmarkForWrite() method call to after your cloning code. See if that helps.

Thanks,
Sean


gonx
Total Points:
745
Status Points:
0
Green Belt
September 11, 2008 10:52 AM PDT
Rate
 
#41 Reply to #40
sean.thurston:
Hi gonx,

Try moving your unmarkForWrite() method call to after your cloning code. See if that helps.

Thanks,
Sean


Hi sean,

Many thanks for your informative and timely response. It definitely did helped the problem. Open-mouthed smiley [:-D] . But now I'm encountering some other stack traces which i am unable to find the cause. The debugger currently breaks at a '}' so i am unable to figure out the exact problem. The stack trace and source code to my initHavok method are included below:

I have some thoughts on this but just want to ask again with the stack trace below so i can identify the source of the error.

1. Does the stack below indicate that I have to again use a markForWrite/unmarkForWrite to some hkpRigidBody that havok can't seem to destroy?

2. Or i forgot to do a <object>->removeReference somewhere?



=========
Stack
=========
>    testy.exe!hkMultiThreadCheck::accessCheck(hkMultiThreadCheck::AccessType type=HK_ACCESS_RW)  Line 177 + 0x67 bytes    C++
     testy.exe!hkMultiThreadCheck::accessCheckWithParent(const hkMultiThreadCheck * parentLock=0x03b2bd98, hkMultiThreadCheck::AccessType parentType=HK_ACCESS_IGNORE, const hkMultiThreadCheck & lock={...}, hkMultiThreadCheck::AccessType type=HK_ACCESS_RW)  Line 245 + 0xd bytes    C++
     testy.exe!hkpRigidBody::~hkpRigidBody()  Line 309 + 0x24 bytes    C++
     testy.exe!hkpRigidBody::`scalar deleting destructor'()  + 0x8 bytes    C++
     testy.exe!cleanupLoadedObjecthkpRigidBody(void * p=0x03b55fd0)  Line 22 + 0xc bytes    C++
     testy.exe!hkPackfileData::callDestructors()  Line 33 + 0x39 bytes    C++
     testy.exe!hkPackfileData::~hkPackfileData()  Line 44    C++
     testy.exe!hkBinaryPackfileReader::BinaryPackfileData::`scalar deleting destructor'()  + 0x8 bytes    C++
     testy.exe!hkBinaryPackfileReader::~hkBinaryPackfileReader()  Line 339    C++
     testy.exe!HavokPhysics::initHavok(std::vector<hkpRigidBody *,std::allocator<hkpRigidBody *> > * tempbodies=[0x00000002](0x03b2a100,0x03b29f00))  Line 355 + 0xf bytes    C++
     testy.exe!OgreFrameListener::OgreFrameListener(Ogre::RenderWindow * win=0x0144fcc8, Ogre::Camera * cam=0x014a6140, Ogre::SceneManager * sceneMgr=0x0149c630)  Line 26    C++
     testy.exe!TutorialApplication::createFrameListener()  Line 193 + 0x43 bytes    C++
     testy.exe!ExampleApplication::setup()  Line 140 + 0xf bytes    C++
     testy.exe!ExampleApplication::go()  Line 89 + 0xf bytes    C++
     testy.exe!WinMain(HINSTANCE__ * hInst=0x00400000, HINSTANCE__ * __formal=0x00000000, char * strCmdLine=0x00161f01, HINSTANCE__ * __formal=0x00000000)  Line 218 + 0x8 bytes    C++
     testy.exe!__tmainCRTStartup()  Line 574 + 0x35 bytes    C
     testy.exe!WinMainCRTStartup()  Line 399    C
     kernel32.dll!7c816ff7()    
     [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]   
     testy.exe!hkpLinearParametricCurve::getBinormal(float t=-2.3555805e-038, hkVector4 & up={...})  Line 314 + 0x82 bytes    C++

=============
Source
=============

void HavokPhysics::initHavok(std::vector<hkpRigidBody *> *tempbodies) {

    // Initialize the base system including our memory system
    hkPoolMemory* memoryManager = new hkPoolMemory();
    threadMemory = new hkThreadMemory(memoryManager, 16);
    hkBaseSystem::init( memoryManager, threadMemory, errorReport );
    memoryManager->removeReference();

    // We now initialize the stack area to 100k (fast temporary memory to be used by the engine).
    //char* stackBuffer;
    {
        int stackSize = 0x100000;
        stackBuffer = hkAllocate<char>( stackSize, HK_MEMORY_CLASS_BASE);
        hkThreadMemory::getInstance().setStackArea( stackBuffer, stackSize);
    }

    {
       
        // Create the physics world
        //hkpWorld* physicsWorld;
        /*
        {
            // The world cinfo contains global simulation parameters, including gravity, solver settings etc.
            hkpWorldCinfo worldInfo;

            // Set the simulation type of the world to multi-threaded.
            worldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;

            physicsWorld = new hkpWorld(worldInfo);
        }
        */
        // Open the file
        hkIstream infile( "test_Default.hkx" );
        if(infile.isOk()){
            WriteToLog("infile is OK!! ");
        }
        // Load the file into a binary packfile reader.  Use a hkXmlPackfileReader here if your data is XML.
        hkBinaryPackfileReader packfileReader;
        packfileReader.loadEntireFile( infile.getStreamReader() );

        // Version contents
        hkVersionUtil::updateToCurrentVersion( packfileReader, hkVersionRegistry::getInstance( ) );

        // Get the contents of the binary packfile.
        packfileContents = static_cast<hkRootLevelContainer*>(packfileReader.getContents( hkRootLevelContainerClass.getName() ));
        // Get the top level object in the file
        //hkTypeInfoRegistry reg;
        //hkRegisterHavokClasses::registerAll(reg);
       
        //hkpPhysicsData* physicsData = static_cast<hkpPhysicsData*>( packfileReader.getContents( &hkpPhysicsDataClass, &reg ) );
       
        // Store a reference to the physics data in the packfile contents container
        physicsData = static_cast<hkpPhysicsData*>(packfileContents->findObjectByType( hkpPhysicsDataClass.getName() ));

        WriteToLog("[HavokPhysics 1] physicsData done..size(%d) ", physicsData->getPhysicsSystems().getSize());
        (*physicsData->getWorldCinfo()).m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;

        // Create a world and add the physics systems to it
        physicsWorld = new hkpWorld( *physicsData->getWorldCinfo() );

       
       
        //
        // Pre-allocate some larger memory blocks. These are used by the physics system when in multithreaded mode
        // The amount and size of these depends on your physics usage.  Larger simulation islands will use larger memory blocks.
        //
        {
            hkMemory::getInstance().preAllocateRuntimeBlock(512000, HK_MEMORY_CLASS_BASE);
            hkMemory::getInstance().preAllocateRuntimeBlock(256000, HK_MEMORY_CLASS_BASE);
            hkMemory::getInstance().preAllocateRuntimeBlock(128000, HK_MEMORY_CLASS_BASE);
            hkMemory::getInstance().preAllocateRuntimeBlock(64000, HK_MEMORY_CLASS_BASE);
            hkMemory::getInstance().preAllocateRuntimeBlock(32000, HK_MEMORY_CLASS_BASE);
            hkMemory::getInstance().preAllocateRuntimeBlock(16000, HK_MEMORY_CLASS_BASE);
            hkMemory::getInstance().preAllocateRuntimeBlock(16000, HK_MEMORY_CLASS_BASE);
        }


        //
        // When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks
        // to make sure only one thread is modifying the world at once to prevent multithreaded bugs. Each thread
        // must call markForRead / markFo rWrite before it modifies the world to enable these checks.
        //

        physicsWorld->markForWrite();


        //
        // Register all collision agents, even though only box - box will be used in this particular example.
        // It's important to register collision agents before adding any entities to the world.
        //
        {
            hkpAgentRegisterUtil::registerAllAgents( physicsWorld->getCollisionDispatcher() );
        }

        //
        // Create a multi-threading utility.  This utility will create a number of threads that will run the
        // physics step in parallel. The main thread calls functions in the utility which signal these threads
        // to start a new step, or wait for step completion.
        //
        hkpMultithreadingUtilCinfo info;
        // Add all the physics systems to the world
        for ( int i = 0; i < physicsData->getPhysicsSystems().getSize(); ++i )
        {
            physicsWorld->addPhysicsSystem( physicsData->getPhysicsSystems()[i] );
        }
        info.m_world = physicsWorld;
        info.m_numThreads = NUM_THREADS;
       
        // In this example we enable timers. The multi-threading util will allocate a buffer per thread for capturing timer data.
        // If you leave this flag to false, no timers will be enabled.
        info.m_enableTimers = true;
        multithreadingUtil = new hkpMultithreadingUtil(info);

        //
        // Initialize the visual debugger so we can connect remotely to the simulation
        // The context must exist beyond the use of the VDB instance, and you can make
        // whatever contexts you like for your own viewer types.
        //

        context = new hkpPhysicsContext();
        hkpPhysicsContext::registerAllPhysicsProcesses(); // all the physics viewers
        context->addWorld(physicsWorld); // add the physics world so the viewers can see it

        hkVisualDebugger* vdb = setupVisualDebugger(context);

        context->m_monitorStreamBegins.setSize(NUM_THREADS);
        context->m_monitorStreamEnds.setSize(NUM_THREADS);

        WriteToLog("[HavokPhysics 2] physicsData done..size(%d) ", physicsData->getPhysicsSystems().getSize());

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

            hkpPhysicsSystem *ps = physicsData->getPhysicsSystems()[i];

            for(int j=0; j<ps->getRigidBodies().getSize();j++) {
                hkpRigidBody *rb = ps->getRigidBodies()[j] ;
               
                hkpRigidBody  *cloney = rb->clone();
               
                rb->removeReference();
                WriteToLog("pushing name=%s mass=%f ",cloney->getName(), cloney->getMass());
                tempbodies->push_back(cloney);
               
            }
           
        }
        physicsWorld->unmarkForWrite();
        WriteToLog("Got %d rigid bodies ", tempbodies->size());
    }
   
}
Thanks.


sean.thurston
Total Points:
8,322
Status Points:
0
Brown Belt
September 11, 2008 3:37 PM PDT
Rate
 
|Best Answer
#42 Reply to #41
Hey gonx,

At the end of your initHavok method, the hkPackfileReader is being deleted because it is a local variable. The hkPackfileData (stored in hkPackFileReader) gets a removeReference() call in the hkPackfileReader destructor. hkPackfileData no longer has any references and is destroyed. It calls the destructors of all the objects it contains and now you are going to get a write access becuase it happens after your unmarkForWrite method call.

I would suggest making the hkPackfileData of the hkPackFileReader a member variable of your class and then calling addReference() when you grab it out of the hkPackFileReader.

I think it would be good to check out the Common Havok Components->Serialization->Memory Considerations of the docs. There is also a short Packfile section under Common Havok Components->Serialization->PackFiles.

One other thing I noticed is that you are calling new hkpWorld() twice. You might want to take a look at that.

Let me know if you have any other problems with this.

Thanks,
Sean


gonx
Total Points:
745
Status Points:
0
Green Belt
September 13, 2008 5:59 AM PDT
Rate
 
#43 Reply to #42
Hi sean,

sean.thurston:

At the end of your initHavok method, the hkPackfileReader is being deleted because it is a local variable. The hkPackfileData (stored in hkPackFileReader) gets a removeReference() call in the hkPackfileReader destructor. hkPackfileData no longer has any references and is destroyed. It calls the destructors of all the objects it contains and now you are going to get a write access becuase it happens after your unmarkForWrite method call.

I would suggest making the hkPackfileData of the hkPackFileReader a member variable of your class and then calling addReference() when you grab it out of the hkPackFileReader.

You were right in this one. I placed addRefence for every hkpRigidBody that gave me an access check exception during debug mode and didnt see anymore access exceptions on my release.

sean.thurston:

I think it would be good to check out the Common Havok Components->Serialization->Memory Considerations of the docs. There is also a short Packfile section under Common Havok Components->Serialization->PackFiles.

One other thing I noticed is that you are calling new hkpWorld() twice. You might want to take a look at that.

yes but actually they were commented out. I just forgot to remove it during my posting. Nevertheless thanks for pointing it out.

Many thanks for helping out with this one. I am now able to load an hkx into ogre3d graphics engine and make it move. Smiley with tongue out [:-P] it's not much as it just shows a sphere falling on a box. I made the meshes in autodesk maya. Exported it with the havok content tool and again exported it into .mesh using blender.

Thanks.


gonx
Total Points:
745
Status Points:
0
Green Belt
September 16, 2008 7:21 PM PDT
Rate
 
#44 Reply to #43

Hi,

Has anyone experienced this problem before?

- Using autodesk maya to create 2 meshes. A box and a sphere. Sphere is a moving body falling onto the box.

- Exported to .hkx using havok content tools. *Note transform scene was set to use SCALE_FEET_XXX

- Confirmed with preview scene that sphere falls until it hits the box.

- Loaded hkx unto the graphics engine

- Sphere falls and collides somewhere in mid-air and does not seem to reach the box

- In visual debugger the sphere falls unto the box correctly. This is the same time the sphere stops in mid-air using the main program i made.

Currently i use hkpRigidBody getRotation() and getPosition() to update my main program's graphics object. I could adjust the bodies in my graphics program manually but i'd like to find out if there are other solutions to this through havok content tools.

Thanks.



sean.thurston
Total Points:
8,322
Status Points:
0
Brown Belt
September 18, 2008 12:26 PM PDT
Rate
 
#45 Reply to #44
Hey gonx,

The visual debugger shows what the physics engine sees in terms of positions and orientations of rigid bodies. When you look at your box and sphere before they fall, do they look to be the same distance apart when you look at the sphere and the box in the vdb? It might be worth it to look at the sections in the docs under Havok Physics->Physics Articles->Rotation, Handedness, and all that.

I think that this thread might be getting a little cluttered. It might be best for any future problems, after this one, to start a new thread. It will just make the forum a little easier to search for people coming here with problems.

Thanks,
Sean


gonx
Total Points:
745
Status Points:
0
Green Belt
September 19, 2008 7:24 PM PDT
Rate
 
#46 Reply to #45
Will post this one on a different thread. Thanks for your quick reply to my questions




Intel Software Network Forums Statistics

8491 users have contributed to 31629 threads and 100764 posts to date.
In the past 24 hours, we have 32 new thread(s) 141 new posts(s), and 200 new user(s).

In the past 3 days, the most popular thread for everyone has been gemm(A,A,A) like possible? The most posts were made to Crash when loading skeleton The post with the most views is Dear Steve, excuse me for a d

Please welcome our newest member shadowwolf99