CollisionShapeFactory question

Hopefully I can covey my question with some clarity (no promises  :D)

I have created a .j3o file from an orgrescene/ogremesh:  an array of 3 long cylindrical meshes  with their z axes parallel, each displaced in the xy plane and rotated about the z axis. I use the following to import the spatial and create a CompoundCollisionShape:

         Spatial model = getAssetManager().loadModel("Models/3CYL_ALL.j3o");
         CollisionShape cs = CollisionShapeFactory.createDynamicMeshShape(model);

When rendered the geometry displays as it should.  However the collision shape(s) do not appear to be created in their translated (relative to the spatial origin) positions:   the Spatial  freely rolls (on a floor) about the spatial's z axis (only).

Also, if each cylinder's axis is skewed by some amount such that their z axes are no longer parallel, the Spatial no longer rolls freely (about any axis).  From observation of how the spatial comes to a rest, it appears that the individual collision shapes are locally rotated (correctly???) but once again the are not displaced.

Am I using the CollisionShapeFactory correctly, or do I still need to position the individual collision shapes to coincide with their corresponding geometry?

   public void simpleInitApp()
        Vector3f v3F = new Vector3f(0, 10000, 10000);
        PointLight pl = new PointLight();
        pl.setColor(new ColorRGBA(.25f,.25f,.25f,.5f));

        v3F.set(2f, 2f, -2f);
        DirectionalLight dl = new DirectionalLight();
        dl.setColor(new ColorRGBA(.25f,.25f,.25f,.5f));


         Spatial model = getAssetManager().loadModel("Models/3CYL_ALL.j3o");
         CollisionShape cs = CollisionShapeFactory.createDynamicMeshShape(model);
         this.physicsNode = new PhysicsNode(model, cs, 10);
         this.physicsNode.setSleepingThresholds(0f, 0f);

         Box bx = new Box(Vector3f.ZERO, 10000.f, 10000.f, 5f);
         Geometry gm = new Geometry("TEST", bx);
         Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/ShowNormals.j3md");
         mat.setColor("m_Color", ColorRGBA.Blue);
         BoxCollisionShape bs = new BoxCollisionShape( new Vector3f(10000.f, 10000.f, 5f));
         PhysicsNode pNode= new PhysicsNode(gm, bs, 0);

        inputManager.addMapping("FWD", new KeyTrigger(KeyInput.KEY_U));
        getInputManager().addMapping("AFT",  new KeyTrigger(KeyInput.KEY_J));
        getInputManager().addMapping("LEFT",  new KeyTrigger(KeyInput.KEY_H));
        getInputManager().addMapping("RIGHT",  new KeyTrigger(KeyInput.KEY_K));
        getInputManager().addMapping("STOP",  new KeyTrigger(KeyInput.KEY_RETURN));
        this.inputManager.addListener(this, "FWD");
        this.inputManager.addListener(this, "AFT");
        this.inputManager.addListener(this, "LEFT");
        this.inputManager.addListener(this, "RIGHT");
        this.inputManager.addListener(this, "STOP");


Using this specific call (createDynamicMeshShape) I found that there was an updateGeometricState() call missing in the code, just updateGeometric() your root node before creating the shape and it should work. (Edit: fix committed)

The collisionShapeFactory always uses the world rotation and location of the spatials encountered. So it should not be connected to a parent node when creating the collision shape, as then the world coordinates would be affected by that as well.



Excellent.  Many thanks.

No problem, btw, you should really use MeshShapes instead of "Dynamic"MeshShapes (GImpact shapes) when they are not supposed to move, GImpact shapes are really expensive.

Understood.  That is indeed how I've been coding. 

Again, many thanks.