Author Topic: merging objects with transparency  (Read 3841 times)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
merging objects with transparency
« on: September 22, 2010, 07:37:57 pm »
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:

Code: [Select]
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:
Code: [Select]
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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: merging objects with transparency
« Reply #1 on: September 22, 2010, 09:03:35 pm »
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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: merging objects with transparency
« Reply #2 on: September 22, 2010, 11:23:23 pm »
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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: merging objects with transparency
« Reply #3 on: September 23, 2010, 09:18:17 am »
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. .

Offline peter

  • byte
  • *
  • Posts: 24
    • View Profile
Re: merging objects with transparency
« Reply #4 on: August 03, 2016, 07:37:27 pm »
I try the same thing. use setVertexAlpha to prevent transparency lost from merge. I didn't get NPE, but transparency still lost after merge

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: merging objects with transparency
« Reply #5 on: August 03, 2016, 08:59:39 pm »
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.