Dynamic loading/unloading

I'm a newbie to jME.

I want to manage models dynamically in my virtual world.

I divided my virtual world in 512*512 units.

Only when avatar enter into a unit, models in the unit are loaded.



Here is code:



    public class World{
    ...
   public static Hashtable<Integer, Hashtable<Integer, Vector<Object3D>>> objTable = new Hashtable<Integer, Hashtable<Integer, Vector<Object3D>>>();
    ...
    }

    public class Object3D{
        private float x_pos;
        private float y_pos;
        private float z_pos;
        private String model;
        private boolean loaded = false;
        private Node model;

        /**
         * constructor
         * @param parent - parent object attached this model.
         * @param model - 3d object model file name.
         */
        public Object3D(Node parent, float x, float y, float z, String model)
        {
            this.parent = parent;
            this.x_pos = x_pos;
            this.y_pos = y_pos;
            this.z_pos = z_pos;
            this.model = model;

            

            // convert avatar's position to unit.
            int cell_x = World.convert2Unit(x_pos);
            int cell_z = World.convert2Unit(z_pos); 


            // add this 3d object to object table.
            Hashtable<Integer, Vector<Object3D>> x_objs = World.objTable.get(new Integer(cell_x));
            if(null == x_objs){
                x_objs = new Hashtable<Integer, Vector<Object3D>>();
                World.objTable.put(new Integer(cell_x), x_objs);
            }
            Vector<Object3D> objs = x_objs.get(new Integer(cell_z));
            if(null == objs){
                objs = new Vector<Object3D>();
                x_objs.put(new Integer(cell_z), objs);
            }
            objs.add(this);
        }


        public void load()
        {
            if(loaded)
                return;
            model = ModelLoader.loadJme(model, x_pos, y_pos, z_pos);
            parent.attachChild(model);
            loaded = true;
        }

        public void unload()
        {
            if(!loaded)
                return;
            parent.detachChild(model);
            model = null;
            loaded = false;
          
            Runtime.getRuntime().gc();
            Runtime.getRuntime().gc();
            Runtime.getRuntime().gc();
        }

    }

        ...

    public class ModelLoader {


        public static Node loadJme(String file, float x_pos, float y_pos, float z_pos)
        {
            try {
                Node model = (Node)BinaryImporter.getInstance().load(new FileInputStream(file));
                model.setLocalScale(1.0f);
                model.setLocalTranslation(x_pos, y_pos, z_pos);
                model.setModelBound(new BoundingBox());
                model.updateModelBound();
              
                return model;
            }
            catch(IOException e){
                e.printStackTrace();
            }
            return null;
        }

    }

 



My app extends from SimpleGame class.
For same model, it works fine in first loading(in simpleInitGame()).
But, in second loading(in updateGame()), can't see any textures.
Is this a bug?
If not, what don't I know?

Thanks for any help & replies.
Sorry for my english. I'm not english.

try to call rootNode.updateRenderState() after loading the model in your updateGame() method

Thanks one hundred.

It does work well.

In future, I expect more and more your helps.



Xacker