How to draw a transparent plane in Java 3D?
Question
I am trying to draw a transparent plane (X[0..100],Y[0..100],Z=0) in Java 3D, but can't figure out how. I've looked on the tutorial page and still can't find any sample programs.
I am attempting to find a "plane" object as a BranchGroup to add to my existing TransformGroup, but there isn't such a plane object; what should I use? And how do I make it transparent?
Solution
This is a snippet of code I used on a histogram - this might work on a flat plane.
private static void createAppearances() {
normalAppearance = new Appearance();
normalAppearance.setMaterial(normalMaterial);
selectedAppearance = new Appearance();
selectedAppearance.setMaterial(selectedMaterial);
TransparencyAttributes ta = new TransparencyAttributes();
ta.setTransparencyMode (TransparencyAttributes.BLENDED);
ta.setTransparency (DEFAULT_HISTOGRAM_ALPHA);
normalAppearance.setTransparencyAttributes (ta);
selectedAppearance.setTransparencyAttributes(ta);
}
The key is the TransparencyAttributes
if I remember correctly. I wish I could tell you more but I can't get this to compile right now (missing some old libraries that aren't related to 3D).
OTHER TIPS
Try this code...
BranchGroup group = new BranchGroup(); //Content branch.
PolygonAttributes p = new PolygonAttributes(); //Not sure how to make it transparent/try code above.
Appearance planeAppearance = new Appearance();
planeAppearance.setPolygonAttributes (p);
Color3f planeColor = new Color3f (1.0f, 1.0f, 1.0f); //This makes it white.
ColoringAttributes planeCA = new ColoringAttributes (planeColor, 1);
planeAppearance.setColoringAttributes(planeCA);
QuadArray plane = new QuadArray (4, QuadArray.COORDINATES); //This makes the plane.
plane.setCoordinate(0, new Point3f(-5f, -5f, -15f)); //You specify your own cornerpoints...
plane.setCoordinate(1, new Point3f(5f, -5f, -15f));
plane.setCoordinate(2, new Point3f(5f, 5f, -15f));
plane.setCoordinate(3, new Point3f(-5f, 5f, -15f));
group.addChild(new Shape3D(plane, planeAppearance)); //Add plane to content branch.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow