我试图在Java 3D中绘制一个透明平面(X [0..100],Y [0..100],Z = 0),但无法弄清楚如何。我查看了教程页面,仍然找不到任何示例程序。
我试图找到一个“平面”对象作为BranchGroup添加到我现有的TransformGroup,但是没有这样的平面对象;我该怎么用?我如何让它变得透明?
答案 0 :(得分:0)
这是我在直方图上使用的一段代码 - 这可能适用于平面。
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);
}
如果我没记错的话,关键是TransparencyAttributes
。我希望我能告诉你更多,但我现在无法编译(缺少一些与3D无关的旧库)。
答案 1 :(得分:0)
试试这段代码......
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.