Java3D:具有透明 PNG 纹理的对象顺序问题
今天我尝试用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用 OrderedGroup 来确保您的鱼是从后到前绘制的。
I recommend using an OrderedGroup to ensure your fish are drawn back-to-front.
是的,您应该使用 OrderedGroup 而不是 BranchGroup
AND
Yes you should use OrderedGroup instead of BranchGroup
AND