Problem when loading a texture

Hi all,



Sorry for my stupid question, but it my first program with JME.



I can load a model, but my model stay without texture :


      try {
         // Point to a URL of the models
         URL model;
         model = new File("models/vehicle/tank/m1abram/M1_Abrams.3DS").toURL();
         // Create something to convert .obj format to .jme
         FormatConverter converter = new MaxToJme();
         // This byte array will hold the .jme files
         ByteArrayOutputStream BO = new ByteArrayOutputStream();
         // Use the format converter to convert .obj to .jme
         converter.convert(model.openStream(), BO);
         converter.setProperty("mtllib", model);
         Node pers = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
         
         // Shrink the models
         pers.setLocalScale(.5f);
         pers.setLocalRotation(new Quaternion(0, 0, 0, 0));
         pers.setLocalTranslation(new Vector3f(0, 0, -100));
         pers.setModelBound(new BoundingSphere());
         pers.updateModelBound();
         
         // Apply texture
         Texture loadTexture = TextureManager.loadTexture
            (
               k6TestLoadModel.class.getClassLoader().getResource("jmetest/data/images/Monkey.png"),
               //k6TestLoadModel.class.getClassLoader().getResource("models/vehicle/tank/m1abram/M1_ABRAM.bmp"),
               Texture.MinificationFilter.BilinearNearestMipMap,
               Texture.MagnificationFilter.Bilinear
            );
         ts.setTexture(loadTexture);
         pers.setRenderState(ts);
         pers.updateRenderState();

         scene.attachChild(pers);
         
      } catch (IOException e) {
         e.printStackTrace();
         System.out.println("Loading error");
      }



I read any topics on this forum, but i don't know what to do.
Where is the problem ? In my eclips setup, in my code ?

Thanks

Does your model stay utterly untextured or is the "missing texture" texture on it?

Hi,



My model is completly white, then untextured i thing.





Tanks :wink:

maybe you have no light in your scene

It'd be black, not white then, no ?



And I have a shpere in my scene, and the texture is set :


      ts = display.getRenderer().createTextureState();
      ts.setEnabled(true);
      
      // Create our Sphere
      Sphere s = new Sphere("Sphere", 30, 30, 30);
      s.setLocalTranslation(new Vector3f(0, 0, -250));
      s.setModelBound(new BoundingBox());
      s.updateModelBound();

      ts.setTexture(TextureManager.loadTexture(
            k6TestLoadModel.class.getClassLoader().getResource("jmetest/data/images/Monkey.png"),
            Texture.MinificationFilter.BilinearNearestMipMap,
            Texture.MagnificationFilter.Bilinear));
      s.setRenderState(ts);

      scene.attachChild(s);

No, it'd be white. When there are no lights in a scene, objects default to their ambient color. The ambient color of objects is white by default.



Did your last post mean that the texture shows up on your sphere?



Wait–you're using the variable 'ts' twice. Each object needs its own render state.

Trussell said:

Did your last post mean that the texture shows up on your sphere?


Yes.

Trussell said:

Wait--you're using the variable 'ts' twice. Each object needs its own render state.


Indeed, i use ts with my two objects, i tried with a new one.

Thx :)

Now i try with this, but the model is still white :


   protected void initGame() {
      display.setTitle("k6online");
      scene = new Node("Scene graph root node");

      /*
      // Create our Sphere
      TextureState ts = display.getRenderer().createTextureState();
      ts.setEnabled(true);
      Sphere s = new Sphere("Sphere", 30, 30, 30);
      s.setLocalTranslation(new Vector3f(0, 0, -250));
      s.setModelBound(new BoundingBox());
      s.updateModelBound();

      ts.setTexture(TextureManager.loadTexture(
            k6TestLoadModel.class.getClassLoader().getResource("jmetest/data/images/Monkey.png"),
            Texture.MinificationFilter.BilinearNearestMipMap,
            Texture.MagnificationFilter.Bilinear));
      s.setRenderState(ts);
      scene.attachChild(s);
      */

      // Create tank
      try {
         URL model = new File("models/vehicle/tank/m1abram/M1_Abrams.3DS").toURL();
         FormatConverter converter = new MaxToJme();
         ByteArrayOutputStream BO = new ByteArrayOutputStream();
         converter.convert(model.openStream(), BO);
         Node pers = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));

         // Shrink the models
         pers.setLocalScale(.5f);
         pers.setLocalRotation(new Quaternion(0, 0, 0, 0));
         pers.setLocalTranslation(new Vector3f(0, 0, -100));
         pers.setModelBound(new BoundingSphere());
         pers.updateModelBound();

              // Apply texture
         TextureState ts2 = display.getRenderer().createTextureState();
         ts2.setEnabled(true);
         Texture loadTexture = TextureManager.loadTexture(
               // k6TestLoadModel.class.getClassLoader().getResource("jmetest/data/images/Monkey.png"),
               k6TestLoadModel.class.getClassLoader().getResource("models/vehicle/tank/m1abram/M1_ABRAM.bmp"),
               Texture.MinificationFilter.BilinearNearestMipMap,
               Texture.MagnificationFilter.Bilinear);
         ts2.setTexture(loadTexture);
         pers.setRenderState(ts2);
         pers.updateRenderState();

         scene.attachChild(pers);

      } catch (IOException e) {
         e.printStackTrace();
         System.out.println("Loading error");
      }

      // Update the scene graph for rendering
      scene.updateGeometricState(0.0f, true);
      scene.updateRenderState();
   }



I don't understand...

Thx for your answerds.

i dont see where you create your light

I don't create light but I see the texture of the sphere…



Where can I find a tuto to create a light ?



Thx :slight_smile:

Begin by looking through the tests. Then on the Wiki.

Try to extend SimpleGame…

My class extends the BaseGame class.



And I see the sphere texture…

The point he is continually trying to make (although it is indeed hard to understand through broken English) is this: if lighting were the issue, he wouldn't be able to see the Sphere texture.



Maybe your problem is that there's no valid UV map for your texture?