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("nem开发者_如何学JAVAo.png")), this).getTexture()); } catch(IOException exc) { System.out.println(exc.getMessage()); } for(int i = 0; i
![alt text][1]
Thank you!
I recommend using an OrderedGroup to ensure your fish are drawn back-to-front.
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);
精彩评论