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();
terain.attachChild(sp);
terain.setMass(0.f);
terain.setCollisionShape(gic);
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.app.SimpleBulletApplication;
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)
{
System.out.print("ONE");
TEST211 t1 = new TEST211();
t1.start();
}
@Override
public void simpleInitApp()
{
this.flyCam.setMoveSpeed(25f);
Vector3f v3F = new Vector3f(2000, 2000, 2000);
PointLight pl = new PointLight();
pl.setColor(new ColorRGBA(.25f,.25f,.25f, .25f));
pl.setPosition(v3F);
DirectionalLight dl = new DirectionalLight();
dl.setColor(new ColorRGBA(0f,0f,.14f,.0f));
v3F.set(-2f, -2f, -2f);
dl.setDirection(v3F);
this.rootNode.addLight(pl);
rootNode.addLight(dl);
this.getPhysicsSpace().setGravity(Vector3f.UNIT_Z.mult(-9.8f));
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);
geom.setMaterial(mat);
pn = new PhysicsNode(geom, new BoxCollisionShape(Vector3f.UNIT_XYZ.mult(.5f)), 1 );
pn.setFriction(.99f);
pn.attachChild(tempNode);
pn.setLocalTranslation(new Vector3f(0, 0, 10));
pn.updateGeometricState();
rootNode.attachChild(pn);
this.getPhysicsSpace().add(pn);
sp = this.assetManager.loadModel("Scenes/iwMESH1.j3o");
CollisionShape gic = CollisionShapeFactory.createMeshShape(sp);
//PhysicsNode terain = new PhysicsNode(sp,gic,0);
PhysicsNode terain = new PhysicsNode();
terain.attachChild(sp);
terain.setMass(0.f);
terain.setCollisionShape(gic);
terain.setFriction(.99f);
terain.setLocalTranslation(new Vector3f(0f, 0f, -150f));
terain.updateGeometricState();
terain.updateModelBound();
this.rootNode.attachChild(terain);
this.getPhysicsSpace().addQueued(terain);
}
}