Hi
Is there a built in way in java3d to to texture a shape3d using this transparency of a GIF?
I was looking over some code that read in an image and then specified a colour for transparency manually - is the neccesary, this is the code I was looking at
TextureLoader loader = new TextureLoader(fileurl,GameFrame.frame);
ImageComponent2D image = loader.getImage();
BufferedImage bim = image.getImage();
WritableRaster wr = bim.getRaster();
int[] pix = new int[4];
for (int i=0; i<wr.getHeight(); i++)
for (int j=0; j<wr.getWidth(); j++)
{
wr.getPixel(i,j,pix);
if (pix[0] == 0 // pure blue pixels are changed to pure transparent pixels
&& pix[1] == 0
&& pix[2] == 255)
{
pix[2] = 0;
pix[3] = 0;
}
else // all other pixels have the transparency and tint applied
{
if (tint != null)
{
pix[0] *= tint.getRed()/255f;
pix[1] *= tint.getGreen()/255f;
pix[2] *= tint.getBlue()/255f;
}
pix[3] = transparency;
}
wr.setPixel(i,j,pix);
}
bim.setData(wr);
image.set(bim);
WritableRaster testrast = image.getImage().getRaster();
int[] testpixel = new int[4];
testrast.getPixel(0,0,testpixel);
if(image == null)
{
System.out.println("load failed for texture " + fileurl);
System.exit(-1);
}
else
{
Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image.getWidth(), image.getHeight());
TransparencyAttributes tranattrib = new TransparencyAttributes();
tranattrib.setTransparencyMode(tranattrib.NICEST);
tranattrib.setTransparency(1f);
texture.setImage(0, image);
texture.setMagFilter(texture.BASE_LEVEL_LINEAR);
texture.setBoundaryModeS(texture.CLAMP);
texture.setBoundaryModeT(texture.CLAMP);
appearance.setTexture(texture);
appearance.setTransparencyAttributes(tranattrib);
}
I refer here to Arabian Flights, the open-source Java3D game by Mike Prosser. The appearance is applied to an OrientedShape3D so any blue pixels (0, 0, 255) are transparent.
Any suggestions? ;D