2010-03-19 82 views
0

今天我试着用Java 3D编程一个小鱼缸。 鱼缸旋转,鱼放入其中。 盒子中的鱼类是具有带alpha通道的PNG图片的Java 3D Boxes。没有激活的透明度,对象的顺序是正确的。但是当我启用它时,后面的一些鱼会出现在前面,看起来真的是错的。我尝试将NICEST,FASTEST和BLENDED作为透明选项,但我没有做任何努力。Java3D:具有透明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]

谢谢!

回答

1

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

0

是你应该使用的,而不是BranchGroup

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); 
OrderedGroup