jPCT - a 3d engine for Java > Bugs

Bug in .OBJ format with Colors (v1.15)

<< < (2/2)

EgonOlsen:
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.

sbaltes:
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: ---    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);
      }
    }

--- End code ---

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: ---tid = tm.getTextureID("mtlName");

--- End code ---

if it were


--- Code: ---tid = tm.getTextureID(mtlName);

--- End code ---

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

EgonOlsen:

--- Quote from: sbaltes on December 05, 2007, 01:49:42 pm ---But I think there is a little bug in Loader.createOBJObject....

--- End quote ---
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.

Navigation

[0] Message Index

[*] Previous page

Go to full version