Createbox vs new box

I was trying to use this code to create 2 differents box (2 floors in fact).



It was working great, except for one thing. It was always transparent, there was no way I could put color or texture on it.

Like this:





this.plancher = this.getPhysicsSpace().createStaticNode();
this.rampelancement = getPhysicsSpace().createStaticNode();
this.rootNode.attachChild(this.plancher);
this.rootNode.attachChild(this.rampelancement);
PhysicsBox formePlancher = this.plancher.createBox("plancher");
formePlancher.setLocalScale(new Vector3f(PLANCHER_LONGUEUR, PLANCHER_EPAISSEUR, PLANCHER_LARGEUR));
PhysicsBox formeRampe = this.rampelancement.createBox("rampelancement");
formeRampe.setLocalScale(new Vector3f(1, PLANCHER_EPAISSEUR, 1));
rampelancement.getLocalTranslation().set( 0, 1, 0 );
formePlancher.setMaterial(Material.WOOD);
formeRampe.setMaterial(Material.WOOD);



The only way I found to put some color on it, like a real objet, was to change createbox for new box and then attach this "new box" to the staticnode.
Is it the right thing to do? What is the difference between createbox and new box() ? It seems my floor physics is not the same since I made the change, even if I keep the same material (wood)

It's probably a newbie question but I couldn't find a clear answer on the forum

   

this.plancher = this.getPhysicsSpace().createStaticNode();
this.rootNode.attachChild(this.plancher);
      
Box formePlancher = new Box("plancher",new Vector3f(),PLANCHER_LONGUEUR, PLANCHER_EPAISSEUR, PLANCHER_LARGEUR);
this.plancher.attachChild( formePlancher );

Box formeRampe = new Box("rampelancement", new Vector3f(), 1, PLANCHER_EPAISSEUR, 1);
this.plancher.attachChild( formeRampe );
formeRampe.getLocalTranslation().set( 0, 1, 0 );

this.plancher.setMaterial(Material.WOOD);
this.plancher.generatePhysicsGeometry();



Thanks for your help!

With PhysicsNode.createBox() you only create the physical representation of a box, this is without a geometry part.

If you want to actually see the Object and put Textures on it you need a Box() like in your second code part.



The wire frame stuff you see in your screen shot, is only the physics debug view.



The 'right' thing to to would be:

  • create a Visual box
  • let jmephysics create the physic representation with generatePhysicsGeometry()



    Something like this:


Box box = new Box("Box", new Vector3f(), 5.0f, 5.0f, 5.0f);
box.setModelBound(new BoundingBox());
box.updateModelBound();

DynamicPhysicsNode node = physicsSpace.createDynamicNode();
node.attachChild(box);

// generate the Physics box
node.generatePhysicsGeometry();
node.updateGeometricState(0.0f, true);

rootnode.attachChild(node);



Have a look at the different interactive-tests in the jmephysics source.