Texture doesn't work when i apply in model

Hi all,



I have four models(.3ds), that i created in blender, and when i apply the texture in these models, they're all dark.



I attach the files that i'm using.



I'm usign this code to set the texture and load the model:



      @Override
   protected void simpleInitGame() {
                Node node = loadModel3ds();
                TextureState ts = display.getRenderer().createTextureState();
      ts.setEnabled(true);
      Texture loadTexture = TextureManager.loadTexture(JmeSimpleLite.class
            .getResource("/").getPath()
            + "texture1.png",
            Texture.MinificationFilter.BilinearNearestMipMap,
            Texture.MagnificationFilter.Bilinear);
                ts.setTexture(loadTexture);
                node.setRenderState(ts);
                node.updateRenderState();
      
      rootNode.attachChild(node);
      }

      private Node loadModel3ds() {
      MaxToJme maxtojme = new MaxToJme();
      ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(); //For loading the raw file
      URL url = JmeSimpleLite.class.getClassLoader().getResource("piece1.3ds"); // File Path for the model
      BinaryImporter binaryImporter = BinaryImporter.getInstance();
      try {
         maxtojme.convert(url.openStream(), bytearrayoutputstream);
         return (Node) binaryImporter.load(new ByteArrayInputStream(bytearrayoutputstream.toByteArray()));
      } catch (IOException e) {
         e.printStackTrace();
      }
      return null;
   }




Thanks for all.

I loaded your model re-exported it to a jme xml file (see code below), and it looks like there are no texture coordinates or normals in the model. I'm not sure what lack of normals will do, but lack of texture coordinates will certainly not make the texture appear correctly. Likely it is defaulting to 0,0 on the image which is black or at least close to it. Thus, the whole model is black.



Here's the code I used to examine the model (loadModel3ds() is exactly as you defined it above):


Node node = loadModel3ds();
try {
    XMLExporter.getInstance().save(node, new File("temp.jme.xml"));
} catch (IOException e) {
    e.printStackTrace();
}

I'm not sure what lack of normals will do, but lack of texture coordinates will certainly not make the texture appear correctly.


Hi despotes,

The model doen't work because i had not enabled the UVTex in blender.

Now, how can i set the texture in only one face the model, but full face?

I updated the code for this:

TextureState ts = display.getRenderer().createTextureState();
      ts.setEnabled(true);
      Texture loadTexture = TextureManager.loadTexture(JmeSimpleLite.class
            .getResource("/").getPath()
            + "Data/pieces/Peca01.png",
            Texture.MinificationFilter.BilinearNoMipMaps,
            Texture.MagnificationFilter.Bilinear);
      loadTexture.setWrap(Texture.WrapMode.BorderClamp);
      loadTexture.setApply(Texture.ApplyMode.Decal);
      loadTexture.setEnvironmentalMapMode(EnvironmentalMapMode.EyeLinear);
      ts.setTexture(loadTexture);
      node.setRenderState(ts);
      node.updateRenderState();



I'm sorry for being a beginner in the subject.

Thanks for your reply.

If I understand your new problem correctly, you are trying to apply 4 different textures to 4 different objects? If that's the case, I believe you will have to break out the model into 4 separate Spatial objects so that you can apply a different texture state (and thus a different texture) to each one. There may be an easier way, but I haven't learned it yet.



By the way, no problem on being a beginner. We are all beginners at some point.  I'm pretty new to this stuff myself. :smiley:



Des

Hi Des,



I had to open a new thread, because I could not solve my new problem.



The link is: http://www.jmonkeyengine.com/forum/index.php?topic=12558.0



Thanks for all.