2010-03-19 39 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