Model loads, no textures?

Hi guys,



Sorry for all the threads but I feel like iam on a roll.



Currently I have a nice scene, planet earth rotating with the nice StarDust particles around (Thanks for the class). However, I have a spaceship that loads but it is entirely white! Even the bike from the tutorial shows up white.



I try to override the textures by doing the same for the planet, create a texture and set the renderstate of either, the model, or the node that holds the model to the texture.



Still white.



This is how I initialize the player with the same earth textures as a test for the ship.

Both the model as the player node are also set with this texture.



private void initPlayer(){
        Node model = loadModel("file:/h:/spaceship.3ds");
      
        model.setRenderState(makeTexture("file:/h:/earth.jpg"));
        player=new Ship("Player 1",model, 10,10,10,10,10);
        player.setRenderState(makeTexture("file:/h:/earth.jpg"));
        root.attachChild(player);
    }



What can I be doing wrong?

Call updateRenderState() after setting render states.

Ok, but how come the bike doesn't load with its predefined textures? I dont need updaterenderstate when I simply load the model and attach it to a player node or am I wrong?



Edit: The updateRenderState didnt work when I load textures onto the model as well.

frankthetank said:

Ok, but how come the bike doesn't load with its predefined textures? I dont need updaterenderstate when I simply load the model and attach it to a player node or am I wrong?

Edit: The updateRenderState didnt work when I load textures onto the model as well.


you need to call updateRenderstate() on the rootNode after you attach a loaded model to the rootnode, because the loaded model will probably have renderstates set on it.

That didnt work either :frowning:





Here is my loadModel code:



private Node loadModel(String url){
        Node model = null;
        try {
           MaxToJme C1 = new MaxToJme();
           ByteArrayOutputStream BO = new ByteArrayOutputStream();
           URL maxFile = new URL(url);
           C1.convert(new BufferedInputStream(maxFile.openStream()),BO);
           model = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
          
        } catch (IOException e) {
           e.printStackTrace();
        }
       
        return model;
       
    }



Feeding it a url returns the model, though only the white framework.


private void initPlayer(){
        Node model = loadModel("file:/c:/spaceship.3ds");
           
        player=new Ship("Player 1",model, 10,10,10,10,10);      

        root.attachChild(player);
        root.updateRenderState();
    }



Constructor of the new player class:


     model.setLocalScale(0.010f);
        model.setModelBound(new BoundingBox());
        model.updateModelBound();

        model.setLocalRotation( new Quaternion().fromAngleAxis(  FastMath.PI, new Vector3f(0,1,0)) );       
        model.updateGeometricState(0.0f, true);
       
        model.setLocalRotation( new Quaternion().fromAngleAxis(  -FastMath.PI/2, new Vector3f(1,0,0)) );
        model.updateGeometricState(0.0f, true);
                     
        this.updateGeometricState(0.0f, true);
     
        setLocalTranslation(new Vector3f(0,0, 0));
        attachChild(model);
        updateWorldBound();



The player is actually a node so I attach the ship to this node itself.

What is going wrong?

Oh, I also noticed my debugger:



27-dec-2007 16:04:57 com.jme.util.resource.ResourceLocatorTool locateResource

WARNING: Unable to locate: BUBING_2.GIF



Since I dont use this gif I assume its from the model. How come it cant locate this gif when the model itself loads fine? :frowning:

Got it working!! :slight_smile:



Read the forums and found the answer.



Added in the model loader:


SimpleResourceLocator  srl = new SimpleResourceLocator(new URL("file:c://"));
           ResourceLocatorTool.addResourceLocator(
            ResourceLocatorTool.TYPE_TEXTURE,
            srl);