Skip to main content

transparent png24 as texture… how to get rid of material?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
4 replies [Last post]
rhavin
Offline
Joined: 2011-02-09

Hi folks;-) i Just started programming in Java a couple of weeks ago, and im quite impressed with that language;-)

Now im stuck with Java3D and didnt find a solution for a problem that *should* be easy to solve … here it comes:

i have an image of a fireball photoshopped as png24, looks like this: (http://q-pool.de/img/myspace/fireball.png)

now i set up a little test-universe and put the fireball on QuadArray-plane. My problem is, that the material (i didnt specify any…!?) keeps shining thru the texture, looks like this: (http://q-pool.de/img/myspace/notrans.jpg)

that - of course - is not exactly what i want;-) i use a function to create textured planes and i basically want to have that fn make the planes' pixels modified by the Alpha-value of the texture: 50% alpha = 50% of bkground shining thru, no matter what lighting occurs on that pixel. That fn currently looks like this:

// --------------------------------------------------------------------------
public void addTexturedPlane(Group branch, Point3f[] pfa, TexCoord2f[] qfa,
Texture2D tex)
{
Appearance appear = new Appearance();
QuadArray  plane  = new QuadArray(4, GeometryArray.COORDINATES
| GeometryArray.TEXTURE_COORDINATE_2 | QuadArray.NORMALS
);

TextureAttributes textAttr = new TextureAttributes();
textAttr.setTextureBlendColor(0.01f, 0.01f, 0.01f, 0.0f);
textAttr.setTextureMode(TextureAttributes.MODULATE);
appear.setTextureAttributes(textAttr);
GeometryInfo giQuads = new GeometryInfo(GeometryInfo.QUAD_ARRAY);
giQuads.reset(GeometryInfo.QUAD_ARRAY);
giQuads.setCoordinates(pfa);
normals.generateNormals(giQuads);
plane.setNormals(0, giQuads.getNormals());

appear.setTexture(tex);
plane.setCoordinates(0,pfa);
plane.setTextureCoordinates(0, 0, qfa);

Shape3D shape = new Shape3D(plane);
shape.setAppearance(appear);
branch.addChild(shape);
}

so i'm pretty shure that has to be possible somehow and its no problem with 2D… so what do i have to do here?
the image loading was btw done like this:

	File f = new File(strFile);
if (!f.exists())
return;

BufferedImage img = null;
try
{
img = ImageIO.read(f);
}
catch (IOException e)
{
System.out.print("IOException for " + strFile +"\n");
return;
};
Texture2D tex = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGBA, w, h);
ImageComponent2D img2D =
new ImageComponent2D(ImageComponent2D.FORMAT_RGBA, img);

tex.setImage(0, img2D);

THX for helpin,

~.rhavin;)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rhavin
Offline
Joined: 2011-02-09

Alright, after getting some sleep (nasty human habbit wasting useful lifetime), i found out that adding those lines solved the problem:

TransparencyAttributes transAttr = new TransparencyAttributes();
transAttr.setTransparency(0.0f);
transAttr.setTransparencyMode(TransparencyAttributes.BLENDED);
appear.setTransparencyAttributes(transAttr);

~.rhavin;)

sproketboy
Offline
Joined: 2006-08-07

I have a similar issue.
I want to make certain walls appear as though they are crumbling.
It ends up looking like this:
http://goldchest.sourceforge.net/transparentprob.jpg
which is not good since I can see through all the walls. :(

sproketboy
Offline
Joined: 2006-08-07

What are you working on? Looks like an RPG. Check out my project http://goldchest.sourceforge.net if your interested in helping out just email me.

rhavin
Offline
Joined: 2011-02-09

One litte hint:: http://q-pool.de/img/myspace/runes.gif

3 new elements, 3 new forms, 3 new alignments, three dimensions.

;-)