jPCT - a 3d engine for Java => Support => Topic started by: Tornado7 on June 11, 2004, 04:40:48 pm

Title: A texture error…
Post by: Tornado7 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.setRotationMatrix(new Matrix());

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
Title: A texture error…
Post by: EgonOlsen 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.
Title: A texture error…
Post by: Tornado7 on June 14, 2004, 05:49:59 pm
Ok, all right  :D