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

发布于 2024-07-29 13:19:50 字数 185 浏览 2 评论 0原文

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

我试图找到一个“平面”对象作为 BranchGroup 以添加到我现有的 TransformGroup,但没有这样的平面对象; 我应该用什么? 以及如何使其透明?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝咒 2024-08-05 13:19:50

这是我在直方图上使用的代码片段 - 这可能适用于平面。

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

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).

夜空下最亮的亮点 2024-08-05 13:19:50

试试这个代码...

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.

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文