Author Topic: Semi-transparency  (Read 1191 times)

Offline Yatoom

  • byte
  • *
  • Posts: 8
    • View Profile
Semi-transparency
« on: February 03, 2013, 10:37:21 pm »
I have made a terrain mesh as one object and added one water-plane as another object. I want the water to be transparent.

How it turns out to be:
http://i.troll.ws/8e76be95.png

How I want it to be:
http://i.troll.ws/3c3e930d.png

I tried using setTransparency, but when I put for example value 0 in, then the terrain also becomes transparent, and when I put value 255 in, nothing is transparent, except for the black spots I left on the map. I also tried setting useAlpha to true in Texture(java.awt.Image image, boolean useAlpha), but I didn't see any effect.

I don't know if I did something wrong in Blender or in jPCT. You can see all the settings (or most of) I used in the second screenshot.
« Last Edit: February 03, 2013, 10:39:48 pm by Yatoom »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: Semi-transparency
« Reply #1 on: February 03, 2013, 10:39:27 pm »
If it's another object, it should be sufficient to do setTransparency(...) on it just as you did. There's no reason why this should affect the terrain unless you are merging the two together. If you are doing this: Don't do it.

Offline Yatoom

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Semi-transparency
« Reply #2 on: February 03, 2013, 10:43:38 pm »
If it's another object,

The terrain and the water are two separate objects in Blender, but I export it as one 3ds model. So, just to make sure... I guess this counts as one object?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: Semi-transparency
« Reply #3 on: February 03, 2013, 10:49:07 pm »
That depends. In the code that loads this file, are you doing a merge or mergeAll-call? If so, don't do this for the water. Make at least sure that the terrain and the water end up as two objects in jPCT, because transparency is per object.

Offline Yatoom

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Semi-transparency
« Reply #4 on: February 03, 2013, 11:14:41 pm »
I am using a merge-call I think.

Code: [Select]
    private Object3D loadModel(String filename, float scale) {
        Loader.setVertexOptimization(false);
        Object3D[] model = Loader.load3DS(filename, scale);

        Object3D o3d = new Object3D(0);

        Object3D temp = null;

        for (int i = 0; i < model.length; i++) {
            temp = model[i];
            temp.setCenter(SimpleVector.ORIGIN);
            temp.rotateX((float)( -.5*Math.PI));
            temp.rotateMesh();
            temp.setRotationMatrix(new Matrix());
            o3d = Object3D.mergeObjects(o3d, temp);
            o3d.build();
        }
        return o3d;
    }

I think I can figure the rest out myself. Thank you very much for your help!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11746
    • View Profile
    • http://www.jpct.net
Re: Semi-transparency
« Reply #5 on: February 03, 2013, 11:31:21 pm »
It might still be a good idea to do some merging, just don't merge the transparent with the opaque objects. The 3ds loader loads the transparency from the file if the exporter has stored it correctly (that's not always the case, which is why i mention it). So it's worth a try to see if this works for your object and if it does, just merge objects with the same level of transparency.