Author Topic: A texture error…  (Read 4031 times)

Offline Tornado7

  • byte
  • *
  • Posts: 45
    • View Profile
A texture error…
« on: June 11, 2004, 04:40:48 pm »
Hi Egon,

another question/problem….. I’m loading textures in a generic way as follow:

Code: [Select]

File dir=new File("C:/Programmi/Java_SDK/bin/textures");    
       String[] files=dir.list();

        for (int i=0; i<files.length; i++) {
         String name=files[i];
         if (name.endsWith(".jpg")) {
            texMan.addTexture(name, new Texture(getDocumentBase(),"textures/"+name));
         }
       }


in init() method. In my previous version I’ve loaded some objs separately from my world in init() method too, as follow:
Code: [Select]

      Object3D[] ferito1Array=Loader.load3DS(getDocumentBase(),"3ds/ferito1.3ds", 20f);
      ferito1=new Object3D(0);
      ferito1=ferito1Array[0];
      ferito1.setCenter(SimpleVector.ORIGIN);
      ferito1.rotateX((float)-Math.PI/2);
      ferito1.rotateMesh();
      ferito1.setRotationMatrix(new Matrix());
     
      ferito1.createTriangleStrips(2);
      ferito1.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
      ferito1.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
     
      ferito1.enableLazyTransformations();


Now, I’m using a config file where I can decide to load or not the above obj, so I’ve decide to move the above code in another method, defined  by myself named loadFerito(). The problem is that when I perform this, the Sun Java Console says:

Code: [Select]
ERROR: A texture with the name 'ferito1.jpg' has been declared twice!

where ferito1.jpg is the texture associated with ferito1.3ds and the obj in the applet is obviously white.
If I move back the loading/defition obj code into the init() method everything works fine. Any explanation ? Bye and thanks

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
A texture error…
« Reply #1 on: June 11, 2004, 04:50:16 pm »
I think it's a problem with the order in which you are doing things. The 3DS-loader will look for materials (i.e. texture names) in the file and then, it tries to get a matching texture from the TextureManager. If there is none, a new one with this name will be created. If you try to add another texture with this name later in the code, you'll get this error. So you either have to move the loading of your textures to a position before you load the object(s) or you have to use the replaceTexture()-method in the texture manager to replace the white dummy texture with that name with the correct texture.

Hope this helps.

Offline Tornado7

  • byte
  • *
  • Posts: 45
    • View Profile
A texture error…
« Reply #2 on: June 14, 2004, 05:49:59 pm »
Ok, all right  :D