Static node to dynamic node problem

I want to change a spatial from static node to dynamic node (with jmePhysic2).





I have this hierarchy:

StaticNode-Node-Container  (It's the container I want to change to dynamic)

  Support



When container become dynamic, instead of staying at is place waiting for a force to move it, it goes nowhere  and turn arownd himself.



It seems static node physicbounds does not refesh.





Is it a bug or i forgot to call a refresh methods (which one ?)?



Here an example code.



Wait 5 secondes to see the change :





package tests.statictodynamic;

import com.acarter.scenemonitor.SceneMonitor;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.util.SimplePhysicsGame;

public class StaticToDynamic extends SimplePhysicsGame{
   boolean activa = true;
   boolean activa1 = false;
   StaticPhysicsNode staticNode;
   Box visualFallingBox;
   Node n = null;
   
    protected void simpleInitGame() {

        staticNode = getPhysicsSpace().createStaticNode();

        rootNode.attachChild( staticNode );

        n = new Node("StaticNode");
       
        final Box visualFloorBox = new Box( "floor", new Vector3f(), 5, 0.25f, 5 );
        //staticNode.attachChild( visualFloorBox );

        visualFallingBox = new Box( "falling box", new Vector3f(), 0.5f, 0.5f, 0.5f );
        visualFallingBox.getLocalTranslation().set( 0, 1f, 0 );
        //staticNode.attachChild(visualFallingBox);

        n.attachChild(visualFloorBox);
        n.attachChild(visualFallingBox);
        staticNode.attachChild(n);
       
        staticNode.generatePhysicsGeometry();
      SceneMonitor.getMonitor().showViewer(true);
      SceneMonitor.getMonitor().registerNode(rootNode);

    }

   
   @Override
   protected void simpleUpdate() {
      SceneMonitor.getMonitor().updateViewer(timer.getTimeInSeconds());
      
      if((activa)&&((timer.getTimeInSeconds()>5))){
           System.out.println("Start");
          
           //Remove static node :
           staticNode.detachChild(visualFallingBox);
   
           DynamicPhysicsNode dynamicNode = getPhysicsSpace().createDynamicNode();
           dynamicNode.setAffectedByGravity(false);
           rootNode.attachChild( dynamicNode );
           dynamicNode.attachChild( visualFallingBox );
           dynamicNode.generatePhysicsGeometry();
           activa=false;
           activa1=true;
      }

   }
   
    /**
     * The main method to allow starting this class as application.
     *
     * @param args command line arguments
     */
    public static void main( String[] args ) {
        new StaticToDynamic().start();
    }

}









I'm going to fill a bug report to JME Physics 2 developpers.



I think the cube shouldn't move like this after it's transformation in dynamicNode



Someone know if the project is always active ?

You need to remove the physics collision geometry from the static node. Detaching the visuals does not remove the generated physics bounds. To make this easier you should make the detachable part a separate static physics node initially and delete it when converting to dynamic.

Thank you for your reply.



I did some test. It's the .generatePhysicsGeometry() method which cause the problem.



But I found something weird. When I move the mesh to dynamic node, and detach his physics collision geometry in the static node(I don't call .generatePhysicsGeometry() method). The the dynamic node don't have any physics collision geometry but it detect collision and I can be moved by force.



Is there any cache where the physics collision geometry is stored ?