Can't get WorldBound of nodes

Hi,everyone;

I got a problem when test the demo of JME jmetestrendererTestMilkJmeWrite.java



I can't get WorldBound of Node at first,however got it when updating.



public class TestMilkJmeWrite2 extends SimpleGame{
    Node i=null;
    private static final Logger logger = Logger
            .getLogger(TestMilkJmeWrite.class.getName());
   
    public static void main(String[] args) {
        new TestMilkJmeWrite2().start();
    }

    protected void simpleInitGame() {
        try {
            ResourceLocatorTool.addResourceLocator(
                    ResourceLocatorTool.TYPE_TEXTURE,
                    new SimpleResourceLocator(TestMilkJmeWrite.class
                            .getClassLoader().getResource(
                                    "jmetest/data/model/msascii/")));
        } catch (URISyntaxException e1) {
            logger.log(Level.WARNING, "unable to setup texture directory.", e1);
        }

        MilkToJme converter=new MilkToJme();
        URL MSFile=TestMilkJmeWrite.class.getClassLoader().getResource(
        "jmetest/data/model/msascii/run.ms3d");
        ByteArrayOutputStream BO=new ByteArrayOutputStream();

        try {
            converter.convert(MSFile.openStream(),BO);
        } catch (IOException e) {
            logger.info("IO problem writting the file!!!");
            logger.info(e.getMessage());
            System.exit(0);
        }

       
        try {
            i=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
        } catch (IOException e) {
            logger.info("darn exceptions:" + e.getMessage());
        }
        i.setLocalScale(.1f);
        i.setModelBound(new BoundingSphere());
        i.updateModelBound();
      
        rootNode.attachChild(i);

        //create a sphere to compare
        Sphere target;
        target = new Sphere("my sphere", 15, 15, 1);
        target.setModelBound(new BoundingSphere());
        target.updateModelBound();
        rootNode.attachChild(target);
        System.out.println("bbb"+i.getWorldBound());//print null
        System.out.println("target"+target.getWorldBound());//print BoundingShpere
    }
    protected void simpleUpdate(){
        System.out.println("bbb"+i.getWorldBound());//print BoundingShpere
    }
}


Run results:


bbbnull
targetcom.jme.scene.BoundingSphere [Radius: 1.00002 Center: com.jme.math.Vector3f [X=5.9604645E-8, Y=1.4901161E-8, Z=0.0]]
cccom.jme.scene.BoundingSphere [Radius: 3.866392 Center: com.jme.math.Vector3f [X=0.13460055, Y=3.7336762, Z=0.31864902]]
cccom.jme.scene.BoundingSphere [Radius: 4.024398 Center: com.jme.math.Vector3f [X=0.29568264, Y=-0.016815811, Z=0.1889005]]
......


So,I want to know how can I get WorldBound at first.
Thanks!

This is mostly a guess since I am unfamiliar with what the world bounds even are (I'm a newb here so jME is about 90 still unknown to me), but i am guessing it has something to do with the calls to update the geometry information coming after your call to get world bounds (simpleInitGame is called before UpdateGeometricState in BaseSimpleGame.java, which SimpleGame.java extends):

        /** Let derived classes initialize. */
        simpleInitGame();

        timer.reset();

        /**
         * Update geometric and rendering information for both the rootNode and
         * fpsNode.
         */
        rootNode.updateGeometricState( 0.0f, true );
        rootNode.updateRenderState();



Not sure if this will work, but you could try calling the rootNode update stuff above in your simpleInitGame method prior to getting world bounds of an object. 

A somewhat educated guess at least, let me know if it works!


EDIT:  I just added the calls

        rootNode.updateGeometricState( 0.0f, true );
        rootNode.updateRenderState();


right after you attach the node, but before getworldBounds, and it worked for me.  I guess the real question is why did the sphere work and not the other node?  Thats beyond me :(

Thanks for your reply.

I found it need updateGeometricState before you want getWorldBound.

Just add


  i.updateGeometricState( 0.0f, true );




right after you attach the node, but before getworldBounds, and it worked for me.  I guess the real question is why did the sphere work and not the other node?  Thats beyond me 

Yes,I doubt about that too.