3ds and texture problem

Hi all!! i try to apply texture to a model (.3ds) but no work at all :frowning: so i try to modify the example that came with jME



jmetest.renderer.loader.TestMaxJmeWrite



but didn't work at all :frowning: the texture never applied to the model, can you help me with that? what its wrong in the code that i modified



  protected void simpleInitGame() {
       
       
          // code added for me to apply texture to a 3ds model
          URL tex=TestMaxJmeWrite.class.getClassLoader().getResource("jmetest/data/texture/dirt.jpg");
           TextureState ts1=display.getRenderer().createTextureState();
           ts1.setTexture(TextureManager.loadTexture(tex,Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear));
           ts1.setEnabled(true);
          
                  
       
        if (modelToLoad == null) {
            modelToLoad = TestMaxJmeWrite.class.getClassLoader().getResource(
                    "jmetest/data/model/char.3ds");
        }
        try {
            MaxToJme C1 = new MaxToJme();
            ByteArrayOutputStream BO = new ByteArrayOutputStream();
            C1.convert(new BufferedInputStream(modelToLoad.openStream()), BO);
            Node r1 = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            //Node r = new Node("parent stuff");
            //r.attachChild(C1.get(new BufferedInputStream(modelToLoad.openStream()), BO));
            //r.setLocalScale(.1f);
            r1.setLocalScale(.1f);
            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));
            rootNode.setLocalRotation(temp);
            r1.setLocalTranslation(new Vector3f(10,0,0));
            r1.setRenderState(ts1); // just apply the texture
            //rootNode.attachChild(r);
            rootNode.attachChild(r1);
        } catch (IOException e) {
            logger.log(Level.SEVERE, "Failed to load Max file", e);
        }
    }

?

Hi, all the variable are set with no null and with the correct info, can you explain how to

Makes far more sense to just load up the model outside of the render thread, but thats the second hitch with jme, it then requires you to be in the render thread to create the darn texture - Doh.



There is a simple hack you can do in the model loaders, just store the texture names on loading the model, then when ready you can apply the actual textures to it.  this allows you to load the model outside the render thread, then create and assign the textures in the render thread.

IMHO the model loading is designed wrong. It expects to load a texture whilst loading the model, would allow far more flexibility in that you can assign a real texture to map it to the model String of a texture name ( usually a file name ).



Makes far more sense to just load up the model outside of the render thread, but thats the second hitch with jme, it then requires you to be in the render thread to create the darn texture - Doh.



There is a simple hack you can do in the model loaders, just store the texture names on loading the model, then when ready you can apply the actual textures to it.  this allows you to load the model outside the render thread, then create and assign the textures in the render thread.



Yes, your problem, reccomnd putting a break point on the line  URL tex=TestMaxJmeWrite.class.getClassLoader().getResource("jmetest/data/texture/dirt.jpg"), step over and make sure the url isnt null, Then step into the TextureManager.loadTexture and make sure it can find the texture. Make sure ts1 is not null. Quite often things are not on the expected classpath










i don't see any

.updateRenderState();

on the code you have provied, make sure you have this at any point after applying any RenderState (TextureState is one of those) or they will not take effect.

r1.updateRenderState();



this method solve your problem…