PhysicsNode Question

Hello all.

Once again, I have a fundemental lack of understanding something (sorry):

I have writen some simple code that utilizes a CollisionShapeFactory to generate a CollisionShape.  I use loadModel to load a .j3o file and construct a PhysicsNode.  In addition I create a simple Box spatial/geometry and create  an associated PhysicsNode

If I create the PhysicsNode for/from the loaded spatial  as follows:

 sp = this.assetManager.loadModel("Scenes/iwMESH1.j3o");
          CollisionShape gic = CollisionShapeFactory.createMeshShape(sp);
          PhysicsNode terain = new PhysicsNode(sp,gic,0);

the Box will collides with the 'terain' PhysicsNode properly.

However if I create the 'terain' PhysicsNode as such:

          sp = this.assetManager.loadModel("Scenes/iwMESH1.j3o");
          CollisionShape gic = CollisionShapeFactory.createMeshShape(sp);
          //PhysicsNode terain = new PhysicsNode(sp,gic,0);
          PhysicsNode terain = new PhysicsNode();

The collisions do not occur (the Box passes through the 'terain'). Is this the correct behaviour?

Here is the totallity of the code:

import com.jme3.bullet.collision.shapes.BoxCollisionShape;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.nodes.PhysicsNode;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.light.DirectionalLight;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;

public class TEST211 extends SimpleBulletApplication
    PhysicsNode pn, pn1;
    Geometry tempGeom;
    Spatial sp;

    public static void main(String[] args)
        TEST211 t1 = new TEST211();    

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

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


          Material mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
          mat.setColor("m_Color", ColorRGBA.Yellow);
          Node tempNode = new Node();

          Box s = new Box(Vector3f.ZERO, .5f, .5f, .5f);
          Geometry geom = new Geometry("S", s);
          pn = new PhysicsNode(geom, new BoxCollisionShape(Vector3f.UNIT_XYZ.mult(.5f)), 1 );
          pn.setLocalTranslation(new Vector3f(0, 0, 10));

          sp = this.assetManager.loadModel("Scenes/iwMESH1.j3o");
          CollisionShape gic = CollisionShapeFactory.createMeshShape(sp);
          //PhysicsNode terain = new PhysicsNode(sp,gic,0);
          PhysicsNode terain = new PhysicsNode();
          terain.setLocalTranslation(new Vector3f(0f, 0f, -150f));

Sorry, just realized I probably should have posted this to the Physics forum.

MeshShape MeshShape collision are not possible, as the Meshshape is optimized for static stuff.

Try using a GImpact shape instead for the box (or a box shape lol)

Sorry for being obtuse in both my explaination and understanding.

The Box (spatial/geometry) that is created is dynamic (mass = 1.f).  The other object is a static mesh (mass = 0.f).  The only difference in the behavoiur of my code (assuming it is correct) is that if I create the physics node for the static mesh using the default constructor and use the 'set' method to assign mass and  'attach' the geometry child, the collsions do not occur.  If I create the the PhysicsNode using PhysicsNode(Spatial, CollsionShape, mass), the collisions appear to occur correctly.

Once again sorry for being thick.

You have to divert the visual spatial and the physics collision shape in your mind. The physics collision shape can only be created from the information of a spatial. The physics node could collide with something even when theres no spatial attached when its got a collision shape. Similarly, the spatial can clip with other spatials when the collision shape is not in place or has a different form.

Hope this helps,


I was under the impression that :

        sp = this.assetManager.loadModel("Scenes/iwMESH1.j3o");
          CollisionShape gic = CollisionShapeFactory.createMeshShape(sp);
          PhysicsNode terain = new PhysicsNode();

would use the spatial (sp) to create the collisionshape (via CollisionShape gic = CollisionShapeFactory.createMeshShape(sp); )  and that terain.setCollisionShape(gic); would assign the create CollisionShape to the PhysicsNode.  No translations are assigned to either the CollisionShape (gic) or the Spatial (sp), only to the PhyscisNode after it creation.  I'm not sure why the Spatial and the CollisionShape would not be coincident.  As I said it seems to work fine if I don't use the default constructor.
Once again I'm truely sorry for not understanding.

It might be that theres still a bug in the rebuilding of the bullet physics object, I will check that when I am back in germany. The default constructor was not planned to be used in the PhysicsNode, I just recently changed it for load/save support. Without a collision shape bullet cannot create a physics object, so effectively it does not exist for bullet until one is created.

Many thanks for your reply.