Semi-transparency

Started by Yatoom, February 03, 2013, 10:37:21 PM

Previous topic - Next topic

Yatoom

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.

EgonOlsen

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.

Yatoom

Quote from: EgonOlsen on February 03, 2013, 10:39:27 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?

EgonOlsen

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.

Yatoom

I am using a merge-call I think.


    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!

EgonOlsen

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.