Using Raster

Well although this is probably a silly question that I should have been able to find the answers to, I’ve spent enough time searching that I think I’m ready to call out for help. I’m using a Raster in my scene:


image = ImageIO.read(getURL());
				
ImageComponent2D image2D = new ImageComponent2D(ImageComponent2D.FORMAT_RGBA, image);
Raster raster = new Raster();
raster.setType(Raster.RASTER_COLOR);
raster.setImage(image2D);
raster.setSize(image.getWidth(), image.getHeight());

then I create a new Shape3D(raster) and use it in my scene.

I’m having two problems with this. My first problem is that the position of the Raster is at the top left of the image. I want it to be at the center. In Java2D I would just translate by (-image.getWidth()/2, -image.getHeight()/2) but I’ve found no such equivalent here. I tried setting the Raster position to that and it flies off the screen, obviously using a different scale. Then I tried (-.5, -.5) which was closer but that moved it too far. I read that it uses “object coordinates” so I assume that it’s referring to the scale of my scene as thats what it appears to be doing. But why in the world would it have its own personal embedded method to do that when I can just attach the Shape3D to a TransformGroup and move it in my scene like every other Geometry object?

My second problem is with the alpha. I tried loading in a .gif with single color transparency and a .png with an alpha channel. I made sure that in Java2D they are loaded in properly with the alpha working. I put them in my code here in Java3D and I just get the white background to the image. I tried mucking with the Appearance stuff but I can’t find the answer there either. I assume if the answer is anywhere that’s where it is. Could someone help me with that also?

About your second problem: the default appearance is white, so that’s why the background is white. Secondly, image transparancy is only useful when the object itself is transparent. You should make its appearance transparent first:


Shape3D shape=new Shape3D();
shape.setGeometry(raster);
Appearance appearance=new Appearance();
TransparencyAttributes ta=new (TransparencyAttributes.FASTEST,1f);
appaearance.setTransparencyAttributes(ta);
shape.setAppearance(appearance);

I haven’t got a clue about your first problem though, sorry.

I tried your suggestion and the image disappears completely. I also tried:
transparency.setTransparencyMode(TransparencyAttributes.NICEST);

and that didn’t have any effect. Have any other ideas?

Strange that it didn’t work, it did work for me when I made a shadow out of an image. But I’m still convinced the object appearing white is caused because the object itself has trhe default appearance.

Hm, I draw an Image on a compatible BufferedImage, and BufferedImage has a function to get the raster. This works.

-JAW