Java3D:具有透明 PNG 纹理的对象顺序问题

发布于 2024-08-26 08:51:45 字数 737 浏览 4 评论 0原文

今天我尝试用Java 3D 编写一个小鱼缸。 鱼缸旋转,鱼放入其中。 盒子里的鱼是 Java 3D 盒子,带有带有 Alpha 通道的 PNG 图片。如果没有激活透明度,对象的顺序是正确的。但是当我启用它时,后面的一些鱼会来到前面,这看起来真的很不对劲。我尝试了“最好”、“最快”和“混合”作为透明度选项,但我没有付出任何努力。

有人知道问题可能是什么吗?

Vector3f[] posf = new Vector3f[5];
posf[0] = new Vector3f(-0.22f, -0.1f, -0.2f);
posf[1] = new Vector3f(-0.34f, 0.1f, 0.2f);
posf[2] = new Vector3f(0.3f, -0.2f, 0.3f);

Appearance fischapp = new Appearance();
fischapp.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST, 1f));

try
{
  fischapp.setTexture(new TextureLoader(ImageIO.read(new File("nemo.png")), this).getTexture());
}
catch(IOException exc)
{
  System.out.println(exc.getMessage());
}

for(int i = 0; i 

![替代文本][1]

谢谢!

Today I tried to program a little fish tank with Java 3D.
The fish tank rotates and fishes are placed in it.
The fishes in the box are Java 3D Boxes with a PNG picture that has an alpha channel. Without activated transparency the order of the objects is correct. But when I enable it, some fishes in the back come to the front what looks really wrong. I tried NICEST, FASTEST and BLENDED as Transparency Options but I had no effort.

Does someone know what the problem could be?

Vector3f[] posf = new Vector3f[5];
posf[0] = new Vector3f(-0.22f, -0.1f, -0.2f);
posf[1] = new Vector3f(-0.34f, 0.1f, 0.2f);
posf[2] = new Vector3f(0.3f, -0.2f, 0.3f);

Appearance fischapp = new Appearance();
fischapp.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST, 1f));

try
{
  fischapp.setTexture(new TextureLoader(ImageIO.read(new File("nemo.png")), this).getTexture());
}
catch(IOException exc)
{
  System.out.println(exc.getMessage());
}

for(int i = 0; i 

![alt text][1]

Thank you!

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

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

发布评论

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

评论(2

邮友 2024-09-02 08:51:45

我建议使用 OrderedGroup 来确保您的鱼是从后到前绘制的。

I recommend using an OrderedGroup to ensure your fish are drawn back-to-front.

橘味果▽酱 2024-09-02 08:51:45

是的,您应该使用 OrderedGroup 而不是 BranchGroup

AND

TextureAttributes texAtt = new TextureAttributes();
texAtt.setTextureMode(TextureAttributes.MODULATE);
fischapp.setTextureAttributes(texAtt);

TransparencyAttributes ta = new TransparencyAttributes();
ta.setTransparencyMode( TransparencyAttributes.NICEST );
ta.setTransparency(.5f);
fischapp.setTransparencyAttributes(ta);

Yes you should use OrderedGroup instead of BranchGroup

AND

TextureAttributes texAtt = new TextureAttributes();
texAtt.setTextureMode(TextureAttributes.MODULATE);
fischapp.setTextureAttributes(texAtt);

TransparencyAttributes ta = new TransparencyAttributes();
ta.setTransparencyMode( TransparencyAttributes.NICEST );
ta.setTransparency(.5f);
fischapp.setTransparencyAttributes(ta);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文