www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on August 08, 2006, 07:33:12 pm

Title: Texture Mapping
Post by: AGP on August 08, 2006, 07:33:12 pm
My x-wing is being loaded from a 3ds file. Upon loading it, the texture files are listed on the command prompt. Is it supposed to load texture-mapped, or am I supposed to do something else.

The 2-part wings, on Egon's suggestion, were loaded separately, and I've even tried getting the instance to Texture Manager and adding the wings' top texture. The following code is what I tried. Am I doing something wrong? Or am I supposed to call something during the rendering process?

   TextureManager manager = TextureManager.getInstance();
   Texture wingTop = new Texture("./WolfXWing/WINGTOP.JPG");
   manager.addTexture("WINGTOP", wingTop);
Title: Texture Mapping
Post by: EgonOlsen on August 08, 2006, 11:07:23 pm
The texture's name (i.e. the name you give it in the TextureManager) has to match the name that is used in the 3DS-file. That's the name that's being printed out during load. It's best practice to determine the names once and load them before loading the model to save some overhead.
Title: Texture Mapping
Post by: AGP on August 09, 2006, 12:19:46 am
Do you mean that instead of naming it "WINGTOP" I would have to name it "WINGTOP.JPG?" It worked, now, which I'm taking to mean that the textures have to be added before loading the mesh. Or is there another way? Thanks a lot for all your help so far.
Title: Texture Mapping
Post by: EgonOlsen on August 09, 2006, 12:22:30 am
If you don't load them before the loading of the model happens, you have to replace them afterwards (TextureManager.replace(...)). But that involves the creation of a dummy texture as a place holder during load, which isn't needed when loading them before.
Title: Texture Mapping
Post by: AGP on August 09, 2006, 06:07:13 am
Some parts of the model aren't coming out textured. I went so far as to load the file as an instance of awt/Image, drawing the image to the screen (which worked), and insantiating Texture from the Image instance. But the texture still won't load.
Title: Texture Mapping
Post by: Melssj5 on August 10, 2006, 03:38:08 am
Well, the textures should be correctly apllied if you have all of them, the no textured parts appears white?

Be sure that they are JPG images.
Title: Texture Mapping
Post by: Melssj5 on August 10, 2006, 03:40:32 am
Checkiew the console messages and check if they are being applied well. cometimes when filenames of textures are very long, some programs like 3d studio max rename the texture on the 3ds file.
Title: Texture Mapping
Post by: AGP on August 10, 2006, 04:08:36 am
No, it's not the file names. And the texture coordinates are all right. And I'm not getting any out-of-the-ordinary messages (just the usual "resizing to 256 pixels ones, but that's for all of the textures and most of them work).

And the untextured parts render as flat and grey.
Title: Texture Mapping
Post by: Melssj5 on August 10, 2006, 04:16:25 am
Are u using sw rendering or opengl, can you please give us the 3d model and the textures on a zip file to test.
Title: Texture Mapping
Post by: AGP on August 10, 2006, 05:23:05 am
Software renderer.

And who's "us?"
Title: Texture Mapping
Post by: Melssj5 on August 10, 2006, 05:50:38 am
Egon, me and anyone that wants to help!
Title: Texture Mapping
Post by: AGP on August 10, 2006, 05:59:04 am
Done. Any insights would be appreciated.
Title: Texture Mapping
Post by: EgonOlsen on August 10, 2006, 05:04:11 pm
The texture names used in the file are displayed while loading the model, if the texture can't be found by the manager. Like in this line:

"Texture named XWBACK.JPG added to TextureManager!"

What this means is, that the loader is looking for a texture named "XWBACK.JPG" in the TextureManager. If it doesn't find one, it creates one. So, before loading the model, you should add this texture like so:

Code: [Select]
TextureManager.getInstance().addTexture("XWBACK.JPG", <your texture>);


Do this for all of the textures that are printed out that way during load. If the texture is named "BLAHBLAH.TGA", use that name even if your actual texture is a jpg or has a completely different name. With the naming of the textures when adding them, you provide a mapping between the names in the 3ds file and the file names of your textures. The names are case sensitive, so if it prints out "XWBACK.JPG", name it "XWBACK.JPG" when adding....not "xwback.jpg" or so.
I hope this makes it a bit clearer.
Title: Texture Mapping
Post by: AGP on August 10, 2006, 06:42:32 pm
No, I got it the first time around. Did you manage to texture map all of it?

I did the whole thing step by step, including reassigning the JPEGs on MAX, so I'll find it very strange if you managed to do it by that line alone.
Title: Texture Mapping
Post by: manumoi on August 10, 2006, 07:07:55 pm
Hello,

Is it possible that your textures are just applied on the wrong side of your model (displayed "inside" the xWing instead of outside). I had such a problem one time but it was just because i created my own model using the JPCT primitives... Not sure if it can be reproduced with 3ds file... that s just a guess...

Manu
Title: Texture Mapping
Post by: AGP on August 10, 2006, 07:19:52 pm
It is possible that the Loader class would flip some faces upon importing them, but there are no flipped faces on the file itself. I even tried flipping them wrong in an attempt to get them right, but it didn't work. I don't think this is the problem, but thanks for the suggestion.
Title: Texture Mapping
Post by: EgonOlsen on August 10, 2006, 07:32:30 pm
I haven't got the time to try to texture it correctly. I just did a quick load without any display...i'll try that later.
Title: Texture Mapping
Post by: EgonOlsen on August 10, 2006, 08:22:51 pm
I gave it a try. It looks fine me. Granted, there are some parts that aren't textured (like the front of the lasers), but those don't seem to have a texture assigned at all (judging from what my viewer/converter software (DeepExploration) tells me). Here's the code:

Code: [Select]
import com.threed.jpct.*;
import org.lwjgl.opengl.*;
import org.lwjgl.input.*;

public class XWingTest {
   public static void main(String[] args) throws Exception {
      Config.maxPolysVisible=60000;
     
      World w=new World();
      TextureManager tm=TextureManager.getInstance();
     
      tm.addTexture("ENGINE2.TGA", new Texture("WolfXWing/ENGINE2.JPG"));
      tm.addTexture("WINGFRON.JPG", new Texture("WolfXWing/WINGFRON.jpg"));
      tm.addTexture("WINGBACK.TGA", new Texture("WolfXWing/WINGBACK.jpg"));
      tm.addTexture("WINGDOWN.JPG", new Texture("WolfXWing/WINGDOWN.jpg"));
      tm.addTexture("WINGTOP.JPG", new Texture("WolfXWing/WINGTOP.jpg"));
      tm.addTexture("LASER.TGA", new Texture("WolfXWing/LASER.jpg"));
      tm.addTexture("ENGINE.TGA", new Texture("WolfXWing/ENGINE.JPG"));
      tm.addTexture("XSIDE.JPG", new Texture("WolfXWing/XSIDE.jpg"));
      tm.addTexture("XWBACK.JPG", new Texture("WolfXWing/XWBACK.jpg"));
      tm.addTexture("XWTOP.JPG", new Texture("WolfXWing/XWTOP.JPG"));
      tm.addTexture("XWDOWN.JPG", new Texture("WolfXWing/XWDOWN.jpg"));
      tm.addTexture("PLATEOX2.TGA", new Texture("WolfXWing/PLATEOX2.JPG"));
      tm.addTexture("FRC.JPG", new Texture("WolfXWing/FRC.JPG"));
     
      Object3D xwing=Object3D.createDummyObj();
      Object3D windows=Object3D.createDummyObj();
     
      Object3D[] objs=Loader.load3DS("WolfXWing/XWing.3DS",1f);
      for (int i=0; i<objs.length; i++) {
         if (objs[i].getName().startsWith("windows")) {
            windows=Object3D.mergeObjects(windows, objs[i]);
         } else {
            xwing=Object3D.mergeObjects(xwing, objs[i]);
         }
      }
      w.addObject(windows);
      w.addObject(xwing);
      xwing.addChild(windows);
      windows.setTransparency(0);
     
      FrameBuffer fb=new FrameBuffer(640, 480, FrameBuffer.SAMPLINGMODE_HARDWARE_ONLY);
      fb.disableRenderer(IRenderer.RENDERER_SOFTWARE);
      fb.enableRenderer(IRenderer.RENDERER_OPENGL);

      w.buildAllObjects();
      w.getCamera().moveCamera(Camera.CAMERA_MOVEOUT, 500);
      w.getCamera().lookAt(xwing.getTransformedCenter());
      w.setAmbientLight(255,255,255);

      Mouse.create();

      while (!Display.isCloseRequested()) {
         fb.clear(java.awt.Color.BLUE);
         w.renderScene(fb);
         w.draw(fb);
         fb.displayGLOnly();
         xwing.rotateX(Mouse.getDY()/100f);
         xwing.rotateY(Mouse.getDX()/100f);
      }
     
      Mouse.destroy();
      fb.disableRenderer(IRenderer.RENDERER_OPENGL);
   }
}


And this is how it looks like:

(http://www.jpct.net/pics/xwing.jpg)
Title: Texture Mapping
Post by: AGP on August 10, 2006, 09:28:49 pm
Wow. Thanks a lot.

Now, why was the cockpit a separate object? Just for the transparency setting? And why the dummy objects? Those I don't get.
Title: Texture Mapping
Post by: EgonOlsen on August 10, 2006, 09:37:16 pm
Yes, for the transparency. Transparency is object, not polygon based. The dummy objects are for having something to merge with in the first run. Any empty object would do or you may also merge 1....x with objs[0] instead...it doesn't matter.
Title: Texture Mapping
Post by: Melssj5 on August 11, 2006, 02:08:16 am
Well, I just arrived home and when going to check the model it was already answered the question. Anyway
Title: Texture Mapping
Post by: AGP on August 11, 2006, 09:22:40 pm
The thing is that it's not totally answered: the software renderer (really, the part that interests me the most in this engine), still fails to map all parts of it.
Title: Texture Mapping
Post by: EgonOlsen on August 11, 2006, 10:34:03 pm
Can you post a screen shot? Have you called build() on the model after loading it?
Title: Texture Mapping
Post by: AGP on August 11, 2006, 11:20:20 pm
Yeah, I can post a screenshot. And yes, I called World.buildAllObjects(). Give me a couple of hours to get back home. Again, thanks for your time.
Title: Texture Mapping
Post by: AGP on August 12, 2006, 03:06:03 am
Sorry, my very newbie mistake. The screenshot follows and it looks exactly as it should. Thanks a lot for a very cool and straightforward engine. By the way, I expect partial transparency is not possible on the software renderer. Is that right?

(http://66.160.166.159/xWing.jpg)
Title: Texture Mapping
Post by: EgonOlsen on August 12, 2006, 07:38:58 pm
Quote from: "AGP"
By the way, I expect partial transparency is not possible on the software renderer. Is that right?
What do you mean with "partial"? Some parts are transparent and some not or that you can choose different levels of transparency up to almost opaque?
Title: Texture Mapping
Post by: AGP on August 12, 2006, 08:34:41 pm
I mean levels of transparency.
Title: Texture Mapping
Post by: EgonOlsen on August 12, 2006, 09:34:26 pm
Yes, you can do that in software like you would do it the hardware renderer (Object3D.setTransparency(<int>)). The formula for the transparency is different in software, so the result will most likely look different when compared to hardware, but not too much in the lower levels of transparency. If your texture is too dark (below 0f0f0f), it will be totally transparent but that's true for hardware too.
Title: Texture Mapping
Post by: AGP on August 15, 2006, 12:35:57 am
Oh, you know what it was? Another rookie mistake: since I was adding the cockpit as child to the x-wing, I wasn't adding it to the world, so the cockpit appeared completely transparent because it wasn't being rendered!
Title: Texture Mapping
Post by: san14 on February 08, 2007, 12:16:20 pm
Quote from: "manumoi"
Hello,

Is it possible that your textures are just applied on the wrong side of your model (displayed "inside" the xWing instead of outside). I had such a problem one time but it was just because i created my own model using the JPCT primitives... Not sure if it can be reproduced with 3ds file... that s just a guess...

Manu


Hi
 I am also facing similar kind of problem, could you let me know how to i change the side...of texture. I am also not geting texture to my wall of 3ds.
Title: Texture Mapping
Post by: EgonOlsen on February 08, 2007, 05:55:48 pm
What do you mean by "side of texture"? Maybe you can post a screen shot to illustrate the problem?