How to create a transparency texture on plane

Hi all, i would like to know how to create a transparency texture on plane.I just arrived to make a plane transparent, but not the Texture2D .

This is my piece of code :

public class Plane2D extends TransformGroup {

private static final TextureLoader tl; 
private static final Material mat; 
private static final TransparencyAttributes ta; 
private com.xith3d.scenegraph.Texture2D textureCube = null;
private com.xith3d.loaders.texture.TextureLoader tloalder = new com.xith3d.loaders.texture.TextureLoader();

static{ 
    tl = new TextureLoader(); 
    mat = new Material(); 
    mat.setLightingEnable(false); 
    ta = new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.5f); 
} 

public Plane2D(String text, String PATH) { 
    super(); 
    tloalder.registerPath(PATH);
    textureCube = (com.xith3d.scenegraph.Texture2D)tloalder.getMinMapTexture("model/"+text);
    Appearance app = new Appearance(); 
    app.setMaterial(mat); 
    app.setTexture(textureCube); 
    app.setTransparencyAttributes(ta); 

    Billboard billboard = new Billboard(GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2, (float)textureCube.getWidth()/100f , (float) textureCube.getHeight()/100f);
    this.addChild(new Shape3D(billboard, app)); 
}  

}

Thanks for help :slight_smile:

I’m assuming you want just parts of the texture to be transparent, not the whole thing.

First, you need a picture with an alpha (transparency channel) in it. That means gif or png (and maybe others), but afaik no jpeg.

Then, you need to load the image using one of the functions that let you specify the format, and specify “RGBA” to support the Alpha channel in the image.

If you plan to run your code from a jar file (applet, web start etc) the below code can be quite useful:


  BufferedImage skinImg = null;
            try {
                  skinImg = ImageIO.read(cl.getResource("filename.png"));
            } catch (IOException e1) {
                  e1.printStackTrace();
            }
            Texture2D skin = (Texture2D)tl.constructTexture(skinImg,
                        "RGBA",
                        false,
                        Texture.BASE_LEVEL,        // Mag-Filter
                        Texture.BASE_LEVEL_LINEAR, // Min-Filter
                        Texture.WRAP,                        // Boundry-Mode
                        false,
                        0);             

Then, apply the transparancy attributes as you already do, note that you can set the transparancy value to 0.0f and still have the trasparent parts of the texture be transparent.

If it still doesn’t work, take a look at the Text2D code I have posted at https://xith-tk.dev.java.net

Good luck

Terje

Thanks orz for your help :slight_smile:
If you want to try.


public class Plane2D extends com.xith3d.scenegraph.TransformGroup {
    
    private static final com.xith3d.scenegraph.Material mat; 
    private static final com.xith3d.scenegraph.TransparencyAttributes ta; 
    private com.xith3d.scenegraph.Texture2D textureCube = null;
    private com.xith3d.loaders.texture.TextureLoader tloalder = new com.xith3d.loaders.texture.TextureLoader();

    static{ 
        mat = new com.xith3d.scenegraph.Material(); 
        mat.setLightingEnable(false); 
        ta = new com.xith3d.scenegraph.TransparencyAttributes(com.xith3d.scenegraph.TransparencyAttributes.BLENDED, 0.1f); 
    } 
  
    public Plane2D(String s){
        super();
        
        java.awt.image.BufferedImage bi = null;
        try{
            bi = javax.imageio.ImageIO.read(this.getClass().getResource("model/"+s));
        } catch (java.io.IOException e1){
            e1.printStackTrace();
        }
        
        textureCube = (com.xith3d.scenegraph.Texture2D) tloalder.constructTexture(
            bi, 
            "RGBA", 
            false, 
            com.xith3d.scenegraph.Texture.BASE_LEVEL, 
            com.xith3d.scenegraph.Texture.BASE_LEVEL_LINEAR, 
            com.xith3d.scenegraph.Texture.WRAP, 
            false, 
            com.xith3d.loaders.texture.TextureLoader.SCALE_DRAW_BEST);
        
        com.xith3d.scenegraph.Appearance app = new com.xith3d.scenegraph.Appearance();
        app.setMaterial(mat);
        app.setTexture(textureCube);
        app.setTransparencyAttributes(ta);

        com.xith3d.scenegraph.Billboard billboard = new com.xith3d.scenegraph.Billboard(com.xith3d.scenegraph.GeometryArray.COORDINATES | com.xith3d.scenegraph.GeometryArray.TEXTURE_COORDINATE_2, (float)textureCube.getWidth()/100f , (float) textureCube.getHeight()/100f);
        this.addChild(new com.xith3d.scenegraph.Shape3D(billboard, app)); 
    }  
}

Now i’ve another question.

How i can animated this image?

Thank :slight_smile:

I wrote a couple of texture and texture animation tutorials over at xith.org