merging objects with transparency

Started by raft, September 22, 2010, 07:37:57 PM

Previous topic - Next topic

raft

seems as it has no effect merging objects with transparency. in the final merged object all transparency has gone. is this intentional ?

i've also tried setting one of object's transparency via PolygonManager, but in that case merging objects throws a NPE. ie. following code:

Object3D one = Primitives.getBox(1, 1);
//one.setTransparency(0);
for (int p = 0; p < one.getPolygonManager().getMaxPolygonID(); p++) {
one.getPolygonManager().setVertexAlpha(p, 0, 0f);
one.getPolygonManager().setVertexAlpha(p, 1, 0f);
one.getPolygonManager().setVertexAlpha(p, 2, 0f);
}

Object3D two = Primitives.getBox(1, 1);
two.translate(0, 3f, 0);
two.translateMesh();
two.getTranslationMatrix().setIdentity();

Object3D merged = Object3D.mergeObjects(one, two);


throws:
Exception in thread "main" java.lang.NullPointerException
at com.threed.jpct.Object3D.appendToObject(Unknown Source)
at com.threed.jpct.Object3D.mergeObjects(Unknown Source)
at tmp.MergeTransparent.main(MergeTransparent.java:34)


btw, i'm a bit unclear what PolygonManager().setVertexAlpha(..) does. in my tries i saw no effect of it.
we set alpha values of vertices not the polygon. how exactly does it work ?

EgonOlsen

Yes, that's by design. Transparency is object based. If you merge transparent with opaque objects, transparency will be lost. Or in other words, you can only merge objects with the same or none transparency without losing some information.
Vertex alpha works just like normal transparency but based on vertices. To use it, you have to set the object to transparent though. I used it in the terrain demo to create the blending between the height levels.
However, that npe should not happen. Most likely because merging assumes that if one object has vertex alpha, all will.

raft

i see. thanks. i've set vertex alpha on both objects but still get a NPE.

does this approach has any performance issues ? i mean merging transparent and non transparent (alpha 1 actually) objects ?

EgonOlsen

Strange...i'll look into it when i'm back home. About performance...it shouldn't matter much. But if you want to use that feature on Android, i've no idea how it will behave. I've never tested it...albeit the code is the same, so it should work, but given the faulty gl implementation in some phones like mine, you can't be sure. .

peter

I try the same thing. use setVertexAlpha to prevent transparency lost from merge. I didn't get NPE, but transparency still lost after merge

EgonOlsen

Just don't do it. The merged result, even if it would work, won't be sorted correctly and will most likely look very stange. If transparent and opaque objects are part of a larger object, just merge them in two buckets and "join" then by defining a child/parent relation between them.