Author Topic: Multiple Textures per Object  (Read 8313 times)

Albareth

  • Guest
Multiple Textures per Object
« on: January 02, 2004, 05:49:47 pm »
I have an object carrierh.3ds, and it requires multiple textures (TipMap.jpg, DreadHull.jpg & DreadHullSpec.jpg) on some of it's parts (the runways, the control centers, the bulkheads, the hull and the engines).  How is this done?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Multiple Textures per Object
« Reply #1 on: January 03, 2004, 01:27:17 pm »
The 3ds-loader can do this for you. Taken from the Javadocs:

Quote
The loader will read the textures' names out of the 3DS-file and will add dummy textures with these names to the texture-manager (If the name is already in use, no new dummy texture will be added). So one may load some textures and add them to the manager with the appropiate names before loading the 3DS-file or replace the ones generated by the loader after loading is finished. If the materials used in the file are not using textures, no textures will be generated.


What this means is: If the texture in the 3ds-file is named "Plonk.jpg", the loader will create a texture with this name or use an existing texture with this name. Have a look at the fps-example, which uses this method.
Another solution would be to split the object into seperate ones based on the used textures but i don't think that's a good one.

BTW: This documented behaviour will change slightly in the next version in a way that the loader will create textures for material without texture too to simulate material colors.

Albareth

  • Guest
Multiple Textures per Object
« Reply #2 on: January 03, 2004, 03:26:51 pm »
Does jPCT utilise UV maps?

Albareth

  • Guest
Multiple Textures per Object
« Reply #3 on: January 03, 2004, 03:50:53 pm »
As well, this code (taken from JPCTDemo) doesn't seem to work with my project...  No object is being found.
Code: [Select]
Object3D[] bttlParts=Loader.load3DS("d:/13th/SESD/com/resources/carrierh.3ds", 1);
      Object3D battlecruiser=new Object3D(0);

      for (int i=0; i<bttlParts.length; i++) {
        Object3D part = bttlParts[i];

        part.setCenter(SimpleVector.ORIGIN);
        part.rotateX( (float) - Math.PI / 2);
        part.rotateMesh();
        part.setRotationMatrix(new Matrix());

        battlecruiser = Object3D.mergeObjects(battlecruiser, part);
      }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Multiple Textures per Object
« Reply #4 on: January 03, 2004, 04:59:20 pm »
Quote from: "Albareth"
Does jPCT utilise UV maps?
It reads the UV-coordinates from the file and maps the textures accordingly..if that's what you mean!?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Multiple Textures per Object
« Reply #5 on: January 03, 2004, 05:02:36 pm »
Quote from: "Albareth"
As well, this code (taken from JPCTDemo) doesn't seem to work with my project...  No object is being found.
Is bttlParts.length==0 or can't the file be found at all? Any output to the console available?

Albareth

  • Guest
Multiple Textures per Object
« Reply #6 on: January 03, 2004, 09:44:20 pm »
I guess I wasn't really clear enough with my statement...  My object is being loaded, but it is not showing up in window...  The model exists, its not a blank file, it's just that the model isn't being loaded from the *.3ds

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Multiple Textures per Object
« Reply #7 on: January 04, 2004, 01:27:54 am »
Quote from: "Albareth"
I guess I wasn't really clear enough with my statement...  My object is being loaded, but it is not showing up in window...  The model exists, its not a blank file, it's just that the model isn't being loaded from the *.3ds
Make sure that you've added "battlecruiser" to your world and check for it's position in objectspace (the model's center in objectspace is not always (0,0,0)...it depends on the model). Maybe the camera is placed inside the model or even before it.

BTW: The rotations before the merge may not be necessary in your case.

Albareth

  • Guest
Multiple Textures per Object
« Reply #8 on: January 04, 2004, 06:23:01 pm »
Now that my previous problem has been fixed, I am struck with a few more... 1) The textures are not appearing on my model, and 2) I have set the model creation to a key, but during the loading process of the model, the program window dies...  this may be a bug...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Multiple Textures per Object
« Reply #9 on: January 04, 2004, 07:28:13 pm »
As mentioned, the naming of the textures in the 3DS-material and in the TextureManager has to match. Have a look at the console output: If a texture with the appropiate name can't be found by the TextureManager when loading the model, a new (plain white) texture with this name will be created. Check the output for a message like "Texture named blahblah.jpg has been created!" (or similar). If this happens, your texture is not present or at least not named correctly. You may add a texture with this name before loading the model or replace the white dummy texture afterwards (i prefer the first solution).
About your loading problem: Don't know...maybe your listener reports the key as pressed all the time and you are starting a gazillion of loading threads this way? Just a guess...
What do you mean exactly by "the program window dies"? Does it close or does it just hang?
And make sure that the loading doesn't interfere with the rendering. jPCT is not thread-save. I suggest to let the keylistener set a flag only and to do the actual loading in the thread that runs the main loop. You'll have to do this anyway when using OpenGL, because you can't access the OpenGL context via different threads.

Albareth

  • Guest
Multiple Textures per Object
« Reply #10 on: January 05, 2004, 12:37:29 am »
Can I send you the code?  I can't find anything wrong with my code, maybe, you, as the creator of jPCT, might be able to find something...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Multiple Textures per Object
« Reply #11 on: January 05, 2004, 10:33:03 am »
Quote from: "Albareth"
Can I send you the code?  I can't find anything wrong with my code, maybe, you, as the creator of jPCT, might be able to find something...
Sure, feel free to send it to me.