Author Topic: Bug in .OBJ format with Colors (v1.15)  (Read 5845 times)

Offline sbaltes

  • byte
  • *
  • Posts: 5
    • View Profile
Bug in .OBJ format with Colors (v1.15)
« on: December 03, 2007, 02:13:04 pm »
Hi, I've a problem loading the following .OBJ file:

http://88.198.204.8:8080/IsoDemo/MAnn1.obj
http://88.198.204.8:8080/IsoDemo/MAnn1.mtl

In this .mtl there is only color information, no texture image. The colors doesn't look right: It should be a blue jacket, but in JPCT it looks a little bit different (more like a teenage rap star, the jacket is white / blue / golden). This is the first time I load a .OBJ from Poser with plain color textures. I can import this file in Milkshape with correct colors so I think it's a JPCT Bug (or a Bug in the .OBJ format that JPCT has no workaround for ;-)

Best Regards
Sebastian

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Bug in .OBJ format with Colors (v1.15)
« Reply #1 on: December 03, 2007, 06:07:27 pm »
It's a bug in jPCT's loader. Or to put it in other words: The OBJ-format stinks so much IMHO, that it makes me feel sick. Why on earth can everything be located everywhere in the file? There seems to be no rule for that except that there is none...anyway, i'll fix this.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Bug in .OBJ format with Colors (v1.15)
« Reply #2 on: December 03, 2007, 07:08:54 pm »

Offline sbaltes

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Bug in .OBJ format with Colors (v1.15)
« Reply #3 on: December 04, 2007, 10:20:20 am »
It works, thank you very much for this super fast reply  :)

I'm sorry that we have to use this strange format, but after all it's working best with poser. Ok, poser itself could be considered a bug ;-)

Offline sbaltes

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Bug in .OBJ format with Colors (v1.15)
« Reply #4 on: December 04, 2007, 11:15:21 am »
Just one more question, a missing feature: Poser seems to use a .tiff and additional color information for it's textures. The texture is overlaid with some color. JPCT seems to ignore the color information if a bitmap is present. An example from the .mtl-file:

newmtl jacket
Ns 30
Ka 0 0 0
Kd 0.317647 0.317647 0.317647
Ks 0.00784314 0.00784314 0.00784314
map_Kd Biz Man Texture.tif

Would it be a problem to add support for this in JPCT?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Bug in .OBJ format with Colors (v1.15)
« Reply #5 on: December 04, 2007, 02:45:26 pm »
I'm sorry, but that's not possible. jPCT uses textures if available. If there are none, the diffuse color will be used. There's no way to combine both, because that would require the definition of additional vertex colors per polygon and that isn't supported.

Offline sbaltes

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Bug in .OBJ format with Colors (v1.15)
« Reply #6 on: December 05, 2007, 01:49:42 pm »
That sounds difficult... so I've implemented a workaround: I parse the .mtl file myself and add the color for each image with the following code:

Code: [Select]
    BufferedImage result = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
    int cr = color.getRed();
    int cg = color.getGreen();
    int cb = color.getBlue();
    for (int y = 0; y < image.getHeight(); ++y) {
      for (int x = 0; x < image.getWidth(); ++x) {
        int v = image.getRGB(x, y);
        int r = (v >> 16) & 0xFF;
        int g = (v >> 8) & 0xFF;
        int b = (v >> 0) & 0xFF;
        r = r * cr / 255;
        g = g * cg / 255;
        b = b * cb / 255;
        v = ((255 & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF) << 0);
        result.setRGB(x, y, v);
      }
    }

Then I add the image under the name of the mtl-material to the TextureManager, and I create my own transient .mtl file where each texture has the name of the mtl-material and give that to the Loader.

The result looks the same like in poser.

But I think there is a little bug in Loader.createOBJObject, at the moment it is:

Code: [Select]
tid = tm.getTextureID("mtlName");

if it were

Code: [Select]
tid = tm.getTextureID(mtlName);

then I wouldn't need to create a transient .mtl file.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Bug in .OBJ format with Colors (v1.15)
« Reply #7 on: December 05, 2007, 06:00:25 pm »
But I think there is a little bug in Loader.createOBJObject....
Yes, it is...what a stupid mistake. I've updated the zip-file with a fixed version. The problem never surfaced, because that code is never used for regular models.