I'm not sure if this has been answered yet, but what works for me is
to load objects from a file, and descend the branchgroup to the
Shape3D objects and use
getAppearance().setTransparencyAttributes(...)
If you're object consists of multiple shapes each one must be altered
to become transparent. I use the following recusive methods in a
subclass of branchgroup to retrieve all of it's component shapes:
public Shape3D [] getShapes() {
ArrayList shapes = new ArrayList();
getShapes(getAllChildren(), shapes);
Shape3D [] result = new Shape3D[0];
result = (Shape3D []) shapes.toArray(result);
return result;
}
public void getShapes(Enumeration p_children, ArrayList p_shapes) {
while(p_children.hasMoreElements()) {
Object object = p_children.nextElement();
if (object instanceof Shape3D) {
p_shapes.add(object);
}
if(object instanceof Group) {
getShapes(((Group)object).getAllChildren(), p_shapes);
}
}
}
--- Leif Oppermann <[EMAIL PROTECTED]> wrote:
> Hi all, hoping for help as well ;)
>
> My problem is the following:
> I'd like to load a Wavefront OBJ and set its transparency
> afterwards to
> achieve a water-like effect.
> The OBJ only consist of one texture-mapped plane.
>
> Without transparency, everything works well.
> I just cannot get it to work/compile with added transparency code
> (being
> a java-beginner).
>
> I figured out, that I cannot set the Appearance of the BranchGroup.
> As
> well as I cannot
> set the Appearance of the Scene in the loader class.
>
> Does anyone have an idea/codesnippet of how to set the transparency
> of
> the loaded object?
>
> thanks,
>
> . leif
>
> -------------------------
>
> // Excerpt from my public BranchGroup Class loadObject:
>
> ObjectFile f = new ObjectFile(flags, (float)(creaseAngle * Math.PI
> /
> 180.0));
> Scene s = null;
> try { s = f.load(filename);} [...catch...]
> return s.getSceneGroup();
>
>
> // My first try
>
> BranchGroup wasser = loadObject(".\\wasser.obj", 60, false,
> true);
>
> Appearance app = new Appearance();
> TransparencyAttributes ta = new TransparencyAttributes();
> ta.setTransparencyMode(ta.BLENDED);
> ta.setTransparency(0.5f);
> app.setTransparencyAttributes(ta);
> wasser.setAppearance(app); // Branchgroup couldn't do
> that
> // -> idea: making a shape (try 2)
> objScale.addChild(wasser);
>
>
>
> // My second try
>
> //Create TransparencyAttributes to set the transparency amount
> and
> mode
> TransparencyAttributes myTA = new TransparencyAttributes();
> myTA.setTransparency( 0.5f );
> myTA.setTransparencyMode( TransparencyAttributes.BLENDED );
>
> //Create Appearance , set the transparency attributes, and
> assemble
> the shape
> Appearance myAppear = new Appearance( );
> myAppear.setTransparencyAttributes( myTA );
> Shape3D myShape = new Shape3D( wasser, myAppear ); //
> doesn't
> work ;(
> objScale.addChild(myShape);
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in
> the body
> of the message "signoff JAVA3D-INTEREST". For general help, send
> email to
> [EMAIL PROTECTED] and include in the body of the message
"help".
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".