Texture problem

I made a sphere in 3dmax and i put  a texture on it then i render to texture and i save its texture for an other file(***.tga).

after that i put this sphere in jme and i want  to put on the texture that was rendered.

the problem is:when i tried to put on the texture in jme,it is not showed.these are the codes i use



URL tex=Modeller.class.getClassLoader().getResource("jmetest/data/texture/nicegrass.jpg");

            TextureState ts=display.getRenderer().createTextureState();

            ts.setTexture(TextureManager.loadTexture(tex,Texture.MM_LINEAR,Texture.FM_LINEAR));

            ts.setEnabled(true);

            r1.setRenderState(ts);

 

but it isn't working.i will be happy if you help me

r1.updateRenderState();

:smiley:

Perhaps we should add a hint to the jME-Banner: "Serious Monkeys. Serious Engine. Call updateRenderState();" :wink:

i tried .updateRenderState().

Textures put some models, but dont put some models.

why?

zabo said:

Textures put some models, but dont put some models.
why?


I dont get what your are saying. Maybe a good screenshot can help?

this model puts my texture.


Node objects = new Node( "objects" );
if (modelToLoad11 == null) {
            modelToLoad11 = ModelYerlestir.class.getClassLoader().getResource(
                    "jmetest/data/model/yeni/kutu.3DS");
        }
        try {
            MaxToJme C1 = new MaxToJme();
            ByteArrayOutputStream BO = new ByteArrayOutputStream();
            C1.convert(new BufferedInputStream(modelToLoad11.openStream()), BO);
            Node r1 = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            r1.setLocalScale(.10f);
      
            if (r1.getChild(0).getControllers().size() != 0)
                r1.getChild(0).getController(0).setSpeed(20);
            
            Quaternion temp = new Quaternion();
            temp.fromAngleAxis(FastMath.PI / 2, new Vector3f(-1, 0, 0));
            objects.setLocalRotation(temp);
            r1.setLocalTranslation(new Vector3f(22,-20,15));
  
            
            URL tex=Modeller.class.getClassLoader().getResource("jmetest/data/texture/yeni/road.jpg");
            TextureState ts=display.getRenderer().createTextureState();
            ts.setTexture(TextureManager.loadTexture(tex,Texture.MM_LINEAR,Texture.FM_LINEAR));
            ts.setEnabled(true);
            r1.setRenderState(ts);
            r1.updateRenderState();
                      
             objects.attachChild( r1 );
            
        } catch (IOException e) {
            logger.log(Level.SEVERE, "Failed to load Max file", e);
        }
        return objects;
}



this model doesnt put my texture.


Node objects = new Node( "objects" );
if (modelToLoad11 == null) {
            modelToLoad11 = ModelYerlestir.class.getClassLoader().getResource(
                    "jmetest/data/model/yeni/kutu1.3DS");
        }
        try {
            MaxToJme C1 = new MaxToJme();
            ByteArrayOutputStream BO = new ByteArrayOutputStream();
            C1.convert(new BufferedInputStream(modelToLoad11.openStream()), BO);
            Node r1 = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            r1.setLocalScale(.10f);
      
            if (r1.getChild(0).getControllers().size() != 0)
                r1.getChild(0).getController(0).setSpeed(20);
            
            Quaternion temp = new Quaternion();
            temp.fromAngleAxis(FastMath.PI / 2, new Vector3f(-1, 0, 0));
            objects.setLocalRotation(temp);
            r1.setLocalTranslation(new Vector3f(22,-20,15));
  
            
            URL tex=Modeller.class.getClassLoader().getResource("jmetest/data/texture/yeni/road.jpg");
            TextureState ts=display.getRenderer().createTextureState();
            ts.setTexture(TextureManager.loadTexture(tex,Texture.MM_LINEAR,Texture.FM_LINEAR));
            ts.setEnabled(true);
            r1.setRenderState(ts);
            r1.updateRenderState();
                          
            objects.attachChild( r1 );
            
        } catch (IOException e) {
            logger.log(Level.SEVERE, "Failed to load Max file", e);
        }
        return objects;

}


seems strange, may be because the second model does not have texture coordinates? did you do anything different when you exported it?

i didnt do anything different when exported. i have texture coordinates when exported.



are there any different problems?

well, it can be much, try playing around with light and MaterialState. But first try .setLightCombineMode(…) to off. so you see if its a light issue.



if nothing works, search for the SceneMonitor. Makes it easier to expore the SceneGraph and to find bugs.

scene worker has a texture unit/coords inspector now so you can see wether or not your texture coordinates are ok…

thread http://www.jmonkeyengine.com/jmeforum/index.php?topic=11526.0

you need to call updateRenderState() after attaching it to another node.



your version:


            r1.updateRenderState();                         
            objects.attachChild( r1 );



better do:


            objects.attachChild( r1 );
            objects.updateRenderState();                         

Thanks Core-Dump,

Core-Dump said:


you need to call updateRenderState() after attaching it to another node.



your version:


            r1.updateRenderState();                         
            objects.attachChild( r1 );



better do:


            objects.attachChild( r1 );
            objects.updateRenderState();                         



but this code doesnt solve my problem.
dhdd said:

well, it can be much, try playing around with light and MaterialState. But first try .setLightCombineMode(..) to off. so you see if its a light issue.

if nothing works, search for the SceneMonitor. Makes it easier to expore the SceneGraph and to find bugs.

thanks dhdd, but i dont understand you.
how i use .setLightCombineMode(..) method?

r1.setLightCombineMode(LightCombineMode.Off);



but I doubt thats really it  :wink:



Take a look at the SceneWorker (link above)