Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
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 872 times)
0 Members and 1 Guest are viewing this topic.
Offline Amos Wenger

Senior Member




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


« Posted 2004-10-23 12: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 20: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 Member




Java skeletal animation systems rock!


« Reply #2 - Posted 2004-11-09 21: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 13: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 Member




Java skeletal animation systems rock!


« Reply #4 - Posted 2004-11-10 17: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.

xsi3rr4x (12 views)
2014-04-15 18:08:23

BurntPizza (10 views)
2014-04-15 03:46:01

UprightPath (24 views)
2014-04-14 17:39:50

UprightPath (10 views)
2014-04-14 17:35:47

Porlus (27 views)
2014-04-14 15:48:38

tom_mai78101 (49 views)
2014-04-10 04:04:31

BurntPizza (107 views)
2014-04-08 23:06:04

tom_mai78101 (207 views)
2014-04-05 13:34:39

trollwarrior1 (176 views)
2014-04-04 12:06:45

CJLetsGame (182 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!