JPhysX Debug Renderer

Hi everyone.

For those interested in JPhysX, I've implemented the JPhysXDebugRenderer and JPhysXDebugNode classes.

This way it's easier to render the physics objects, joints etc. It uses the native NxDebugRenderer, where you can define what to render in a PhysX standard way. (See the AGEIA Development Support (Lesson 301: Debug Renderer))

It's easy to add the renderer to your code:

protected void simpleInitGame() {
  NxSceneDesc sceneDesc = new NxSceneDesc();
  NxScene physicScene = JPhysXAdapter.getPhysicsSDK().createScene(sceneDesc);
  JPhysXAdapter.getPhysicsSDK().setParameter(NxParameter.NX_VISUALIZATION_SCALE, 1);
  JPhysXAdapter.getPhysicsSDK().setParameter(NxParameter.NX_VISUALIZE_COLLISION_SHAPES, 1);
  //Here is the Debug Renderer
  JPhysXDebugRenderer.initialize(display, rootNode, physicScene);

It's working, but has an ugly workaround in the initialize() method:

//Ugly workaround. Don't know why but to render the debugNode we need this first.
Box box = new Box("",new Vector3f(5000,10000,5000),.1f,.1f,.1f);

Looks like jme doesn't like to render my DebugNode if I don't attach at least a simple geometry, like a Box.
I would be glad if someone fix it, or point to the right direction.

JPhysXDebugRenderer is an extension of LWJGLRenderer which overrides the draw(Spatial s) method rendering the JPhysXDebugNode which extends Geometry.

That's the way I found to keep the transformations and camera properties to render the physic scene properly.

The code can be downloaded here:

Thanks, and good luck with it :P


Or you can use jME Physics 2 with JPhysX and it's debug view (jME Physics view plus PhysX view). :wink:

This is great!

However I get only lines, data.getNbTriangles() return zero, I checked. Any idea what I've done wrong?

this is my initPhysics:

NxSceneDesc sceneDesc = new NxSceneDesc();
        sceneDesc.setGravity(new NxVec3(0, -4.8f, 0));
        JPhysXAdapter.getPhysicsSDK().setParameter(NxParameter.NX_SKIN_WIDTH, 0.01f);
        //Debug parameters
        JPhysXAdapter.getPhysicsSDK().setParameter(NxParameter.NX_VISUALIZATION_SCALE, 1);
        JPhysXAdapter.getPhysicsSDK().setParameter(NxParameter.NX_VISUALIZE_COLLISION_SHAPES, 1);
        JPhysXAdapter.getPhysicsSDK().setParameter(NxParameter.NX_VISUALIZE_ACTOR_AXES, 1);
        JPhysXAdapter.getPhysicsSDK().setParameter(NxParameter.NX_VISUALIZE_COLLISION_FNORMALS, 1);
        JPhysXAdapter.getPhysicsSDK().setParameter(NxParameter.NX_VISUALIZE_JOINT_LOCAL_AXES, 1);
        JPhysXAdapter.getPhysicsSDK().setParameter(NxParameter.NX_VISUALIZE_JOINT_WORLD_AXES, 1);
        JPhysXAdapter.getPhysicsSDK().setParameter(NxParameter.NX_VISUALIZE_COLLISION_SHAPES, 1);
        physicsScene = JPhysXAdapter.getPhysicsSDK().createScene(sceneDesc);
        NxMaterial defaultMaterial = physicsScene.getMaterialFromIndex(0);

I never got trimeshes either - seems they simply don't make much use of them for the debug viz.

Ok thanks, good to know.

But then why is there a getNbTriangles() and getTriangle(i) etc in the NxDebugRenderable? And why did they bother calling them in the Debug Renderer tutorial? Or do the triangles and points get lost in the wrapper?

Probably they get used for e.g. cloth…

Yes, you're probably right, that thought never occured to me.