Change texture of a model

hi,



i created a Spatial model and put a texture… how i change this texture?




anyone?

Grab the texture state and set a new texture …





You havent descrbed the scenario, if the above will not work, describe in more detail what you a doing

ok



i have a model.3ds and i imported this model in my scene:






public Spatial getModel ()
    {
       

                Spatial model = null;
      ByteArrayOutputStream outStream = new ByteArrayOutputStream();


        // add texture_1

        File textures;
        textures = new File( "D:/Texture_1.jpg" );
           try {
                try {
                    location = new SimpleResourceLocator(textures.toURI().toURL());
                } catch (URISyntaxException ex) {
                    Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (MalformedURLException ex) {
                Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
            }
        ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, location );


      // add texture_2

   
        File textures;
        textures = new File( "D:/Texture_2.jpg" );
           try {
                try {
                    location = new SimpleResourceLocator(textures.toURI().toURL());
                } catch (URISyntaxException ex) {
                    Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (MalformedURLException ex) {
                Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
            }
        ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, location );
       

                    // add model

                    FileInputStream rawIn;
                    try {
                        rawIn = new FileInputStream("D:/model.3ds");
                        try
                        {
                            CONVERTER_3DS.convert(rawIn, outStream);
                        }
                        catch (IOException ex)
                        {
                            Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        try
                        {
                            rawIn.close();
                        }
                        catch (IOException ex)
                        {
                            Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
                        }

                    }
                    catch (FileNotFoundException ex)
                    {
                        Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
                    }


        ByteArrayInputStream convertedIn =new ByteArrayInputStream(outStream.toByteArray());
                    try
                    {
                        model = (Spatial) BinaryImporter.getInstance().load(convertedIn);
                    }
                    catch (IOException ex)
                    {
                        Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
                    }



        model.setLocalTranslation(20,0,0);
        model.setModelBound(new BoundingSphere());
        model.updateWorldBound();
        model.updateModelBound();
        model.updateRenderState();
        model.updateGeometricState( 0, true );

       

       
        return model;

    }




this code load de model with its textures....

how i change this textures?

if possible, give-me a exemple...

Texture myNewTex = TextureLoader.loadTexture(/*stuff*/);
TextureState ts = (TextureState)model.getRenderState(StateType.Texture);
ts.setTexture(myNewTex);
ts.updateRenderState();

how do I get different textures in different parts of my modelo.3ds?



For example, I have a character in my game (character .3 ds) … how can I change the texture of his clothes?



with TextureState I can only change the texture of a part of the model … I can not control that part of my model I change the textures …



how I do it?

You'll need to use several different textures that are UV mapped to the parts of the model that you want to change.

how i do it?



can u give-me a exemplle?

You need to read about it. UV Mapping

well, I think this is not what I need …



I need a way to give texture to each internal node of my model.3ds …



how is the second parameter of this method "ts.setTexture (LoadTexture, 0);"?



this number would be the number corresponding to the internal node model.3ds?



Anybody know if I have a way to give texture to a specific internal node of my model.3ds or no way to do this?

… you should be applying the texture you want to the internal nodes. When you import the model, print out it's children. You'll notice that all of the nodes of the 3ds model are children of the Node that you set the model to.



Then you put a texture state on each individual part.

I understand the logic …



but I do not know how I get these child nodes of my model … these nodes have come into my model … nodes were made in 3d studio max and were joined to form a single node that turned the model.3ds …



how would I take these child nodes of model.3ds so I can put new textures for them?



can you give me an example?

You need to look at the Node API. Use the "getChildren()" method. If that doesn't work, you exported your model in a way that the nodes were merged permanently and you can't do what you're trying to–you'll need to separate them into their own nodes again (in 3DS Max) and re-export the model.

im using this logic:


ts.setEnabled(true);
              Texture loadTexture = TextureManager.loadTexture(Main.class
            .getResource("/").getPath()
            + "INT_MAP.JPG",
            Texture.MinificationFilter.BilinearNearestMipMap,
            Texture.MagnificationFilter.Bilinear);
                ts.setTexture(loadTexture);

             
                a = (Node) mo;
                Node a0 = (Node) a.getChild(0);
             
                a0.getChild(41).setRenderState(ts);
               



but ever change texture in the same place...

is my logic incorrect or iss the model.3ds incorrect?