[英]Java3D: Problem with order of objects that have a transparent PNG texture
Today I tried to program a little fish tank with Java 3D. 今天,我尝试用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.
盒子里的鱼是Java 3D盒子,带有带有Alpha通道的PNG图片。 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.
我尝试了NICEST,FASTEST和BLENDED作为透明选项,但我没有做出任何努力。
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] ![替代文字] [1]
Thank you! 谢谢!
我建议使用OrderedGroup来确保鱼是从头到尾绘制的。
Yes you should use OrderedGroup instead of BranchGroup 是的,您应该使用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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.