Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Setting Transparency recursively.  (Read 971 times)
0 Members and 1 Guest are viewing this topic.
Offline Amos Wenger

Senior Devvie




Everything's possible, but not everything's fun...


« Posted 2004-10-23 10:33:53 »

Can anyone help me ?
I have written a function to set all the shape3Ds of a BranchGroup transparent, but it don't display transparent.
Here is the source code :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
// Fonction activant ou désactivant l'affichage transparent
  void setAffTrans(Group group,boolean param) {

    TransparencyAttributes ta = new TransparencyAttributes();
    if( param ) {
      System.out.println("Met transparency à 0.5");
      ta.setTransparency(0.5f);
    }
    else {
      System.out.println("Met transparency à 0");
      ta.setTransparency(0);
    }
    //ta.setTransparencyMode(TransparencyAttributes.BLENDED);
    //ta.setMode(TransparencyAttributes.BLENDED);
   
    Enumeration e = group.getAllChildren();
    while(e.hasMoreElements()) {
      Node node = (Node) e.nextElement();
     
      if(node instanceof Group) {
        System.out.println("Transparence : c'est un group");
        setAffTrans((Group)node,param);
      }
      else {
        if(node instanceof Shape3D) {
          System.out.println("Transparence : c'est un Shape3D");
          Shape3D shp = (Shape3D)node;
          shp.getAppearance().setTransparencyAttributes(ta);
          shp.getAppearance().setChanged(true);
        }
      }
    }
 
  };

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline LaLiLuLeLo

Senior Newbie




Foooocus!


« Reply #1 - Posted 2004-11-09 19:43:47 »

My workaround was to make a new appearance and applying it to the shape as opposed to getting the appearance from the shape and modifying it. I think the lack of transparencies have something to do with the presence of materials. I'll let you know more as I delve into it.

1  
2  
3  
4  
5  
6  
7  
8  
9  
            //a = s.getAppearance();
            a = new Appearance();
            Material m = a.getMaterial();
            //m.setEmissiveColor(255f,0,0);
            //a.setMaterial(m);
            
            TransparencyAttributes ta = new TransparencyAttributes(TransparencyAttributes.BLENDED,0.4f);
            a.setTransparencyAttributes(ta);            
            s.setAppearance(a);


Edit:
Just found out that setting the material to null makes the transparency work. So you don't need to make a new appearance; just use the shape's one and set its material to null ...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
            Appearance a = s.getAppearance();
            //Material m = a1.getMaterial();
            //a = new Appearance();            
            //m.setEmissiveColor(255f,0,0);
            //a.setMaterial(m);
           
            TransparencyAttributes ta = new TransparencyAttributes(TransparencyAttributes.BLENDED,0.4f);
            a.setTransparencyAttributes(ta);
            a.setMaterial(null);
            s.setAppearance(a);
Offline ewills

Junior Devvie




Java skeletal animation systems rock!


« Reply #2 - Posted 2004-11-09 20:53:02 »

You could also try setting the Material's color target.  I had to do this to get transparency working.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline LaLiLuLeLo

Senior Newbie




Foooocus!


« Reply #3 - Posted 2004-11-10 12:21:26 »

Could you please explain this a little more? I tried this but no success...thanks  Smiley

1  
a.getMaterial().setColorTarget(Material.NONE);
Offline ewills

Junior Devvie




Java skeletal animation systems rock!


« Reply #4 - Posted 2004-11-10 16:19:34 »

Here is my default Appearance setup:

material = new Material();
material.setColorTarget(Material.DIFFUSE);
material.setAmbientColor(AMBIENT_COLOR);
material.setSpecularColor(SPECULAR_COLOR);
material.setShininess(96.0f);

coloringAttributes = new ColoringAttributes();
coloringAttributes.setColor(DIFFUSE_COLOR);

polygonAttributes = new PolygonAttributes();
polygonAttributes.setCullFace(PolygonAttributes.CULL_BACK);

appearance = new Appearance();
appearance.setMaterial(material);
appearance.setColoringAttributes(coloringAttributes);
appearance.setPolygonAttributes(polygonAttributes);

Transparency can then be set using:

TransparencyAttributes ta = new TransparencyAttributes();
ta.setTransparencyMode(TransparencyAttributes.BLENDED);
ta.setTransparency(t);
appearance.setTransparencyAttributes(ta);

Hope this helps Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (16 views)
2014-11-26 15:22:04

toopeicgaming1999 (16 views)
2014-11-26 15:20:36

toopeicgaming1999 (7 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (24 views)
2014-11-25 11:26:43

Gibbo3771 (22 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!