VisualDebugger and mesh shape

VisualDebugger and mesh shape

Hi!

I've added a simple triangle to a hkpExtendedMeshShape using addTrianglesSubpart().

Everything seems to run fine but in the VisualDebugger I can only see a bounding box, the a visual representation of the mesh like for example with a simple sphere and box I'm using in the world.

Is there anything I have to do to make my mesh visible?

Or should it be visible right away and my vertices/indices have to be wrong?

Thank you,
S_W

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I'm sorry I've inadvertently deleted a section of the text. The second paragraph should have been:

Everything seems to run fine but in the VisualDebugger I can only see a
bounding box, not a visual representation of the mesh like for example
with a simple sphere and box I'm using in the world.

Hi S_W,

I have a couple of questions about this. Can you see it fine in the normal viewer, but not in the visual debugger? Are you using a render mesh on the game side and hkpExtendedMeshShape just for physics? Have you tried just creating a single triangle?

There is an example of creating a hkpExtendedMeshShape in code in the MeshMaterialDemo.cpp and information on the Visual Debugger in the docs, The Visual Debugger Game Side. I hope this helps.

Thanks,
Sean

Developer Support Engineer Havok www.havok.com

Hi Sean,

I'm not using any visual meshes right now, only rigidbodys. I've created a single triangle using the following code:

size_t vertex_count, index_count;
float* vertices;
unsigned long* indices;

vertex_count = 3;
index_count = 3;
vertices = new float[vertex_count * 3];
indices = new unsigned long[index_count];

vertices[0] = -1;
vertices[1] = 1;
vertices[2] = 0;

vertices[3] = 1;
vertices[4] = -1;
vertices[5] = 0;

vertices[6] = -1;
vertices[7] = -1;
vertices[8] = 0;

indices[0] = 0;
indices[1] = 1;
indices[2] = 2;

{
hkpExtendedMeshShape::TrianglesSubpart part;

part.m_vertexBase = vertices;
part.m_vertexStriding = sizeof(float)*3;
part.m_numVertices = vertex_count;
part.m_indexBase = indices;
part.m_indexStriding = sizeof(unsigned long)*3;
part.m_numTriangleShapes = index_count/3;
part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16;

extendedMeshShape->addTrianglesSubpart(part);
}

hkpRigidBodyCinfo info;
info.m_shape = extendedMeshShape; // removeReference() required for shape?
info.m_motionType = hkpMotion::MOTION_FIXED;
info.m_position.set( 0, 10, 0 );

hkpRigidBody* rb = new hkpRigidBody(info);

m_world->addEntity(rb);
rb->removeReference();

Now this is what I can see in the Visual Debugger (the box and sphere have been created using the predefined shapes):

Hi S_W,
You definitely want your index striding to be
part.m_stridingType = hkpExtendedMeshShape::INDICES_INT32;
(instead of INT16), because you're using unsigned longs for the indices.

I don't have the code in front of me at the moment, but you might also need your index striding to be sizeof(unsigned long). If the first change doesn't help, try that one too :)

Hope that helps...

-Chris

Hi Chris,

using hkpExtendedMeshShape::INDICES_INT32 the program crahes with an access violation on connecting with the visual debugger, using 16 bit indicies and long/short it works well, which seems really strange. The index striding is sizeof(unsigned long) * 3. Still it results in an access violation.

Is it possible that the visual debugger is setup wrong or anything I've could forgotten?

Thanks,
S_W

Maybe this can help as well, this is the part of my code I use to initialize Havok:

//...
//-------------------------------------------------------------------------------------------------

// #define USE_DEBUG_MEMORY

void initPhysics()
{
// Initialize the base system including our memory system

#ifdef USE_DEBUG_MEMORY
hkDebugMemory* memoryManager = hkDebugMemory::create();
threadMemory = new hkThreadMemory( memoryManager, 0 );
#else
hkPoolMemory* memoryManager = new hkPoolMemory();
threadMemory = new hkThreadMemory( memoryManager, 16 );
#endif

hkBaseSystem::init( memoryManager, threadMemory, HK_NULL );
memoryManager->removeReference();

// Replace default error handler
hkError::replaceInstance( new hkCustomError() );

// We now initialize the stack area to 2 MB (fast temporary memory to be used by the engine)
char* stackBuffer;
{
int stackSize = 2*1024*1024; // 2 MB stack

stackBuffer = hkAllocate( stackSize, HK_MEMORY_CLASS_BASE );
threadMemory->setStackArea( stackBuffer, stackSize);
}

// Create the physics world
{
// 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_CONTINUOUS;

m_world = new hkpWorld(worldInfo);
}

//
// 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( m_world->getCollisionDispatcher() );
}

//
// 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( m_world ); // add the physics world so the viewers can see it

vdb = setupVisualDebugger( context );

#ifndef USE_DEBUG_MEMORY
//hkOstream hkcout( "havok_memstats.log" );
//hkMemory::getInstance().printStatistics( &hkcout );
#endif
}

//...
//-----------------------------------------------
--------------------------------------------------

hkVisualDebugger* setupVisualDebugger(hkpPhysicsContext* physicsWorlds)
{
// Setup the visual debugger
hkArray contexts;
contexts.pushBack(physicsWorlds);

hkVisualDebugger* vdb = new hkVisualDebugger(contexts);
vdb->serve();

return vdb;
}

//...
//-------------------------------------------------------------------------------------------------

const hkReal m_timestep = 1.0f / 60.0f;

void updatePhysics( const float timeSinceLastFrame )
{
// time accumulator
static float elapsed = 0.0f;

elapsed += timeSinceLastFrame;

mPhysicsStepsLastFrame = 0;

// update using time slicer
while ( elapsed > m_timestep )
{
m_world->stepDeltaTime( m_timestep );
vdb->step( m_timestep );

updateDisplay( m_world );

elapsed -= m_timestep;

mPhysicsStepsLastFrame++;
}

// update physics stats
if ( mPhysicsStepsLastFrame < mPhysicsStepsMin )
mPhysicsStepsMin = mPhysicsStepsLastFrame;
if ( mPhysicsStepsLastFrame > mPhysicsStepsMax )
mPhysicsStepsMax = mPhysicsStepsLastFrame;
}

//-------------------------------------------------------------------------------------------------

Hi!

I've just copied the sample code from the mesh material demo and is seems to work (in the visual debugger as well). So I guess my vertext/index data has just been setup in a wrong way.

Thanks,
S_W

Leave a Comment

Please sign in to add a comment. Not a member? Join today