有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何在Java 3D中绘制透明平面?

我试图在Java3D中绘制一个透明平面(X[0..100],Y[0..100],Z=0),但不知道如何绘制。我在教程页面上看过了,仍然找不到任何示例程序

我试图找到一个“平面”对象作为分支组添加到现有的TransformGroup中,但没有这样的平面对象;我应该用什么?我如何让它透明


共 (2) 个答案

  1. # 1 楼答案

    试试这个代码

    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.
    
  2. # 2 楼答案

    这是我在柱状图上使用的一段代码——这可能适用于平面

    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无关的旧库)