我试图在Box
的两侧放置不同的纹理,但没有任何成功。Java3D 1.5.1 - 如何在Box部件上放置不同的纹理?
这里是我的代码:
BufferedImage texture1 = ...; // brown image
BufferedImage texture2 = ...; // green image
Box box = new Box(1f, 1f, 1f, Box.GENERATE_TEXTURE_COORDS, new Appearance());
TextureAttributes ta = new TextureAttributes();
ta.setTextureMode(TextureAttributes.MODULATE);
Appearance app = new Appearance();
app.setTexCoordGeneration(new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR, TexCoordGeneration.TEXTURE_COORDINATE_2));
app.setTexture(new TextureLoader(texture1).getTexture());
app.setTextureAttributes(ta);
box.setAppearance(Box.TOP, app);
Appearance app2 = new Appearance();
app2.setTexCoordGeneration(new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR, TexCoordGeneration.TEXTURE_COORDINATE_2));
app2.setTexture(new TextureLoader(texture2).getTexture());
app2.setTextureAttributes(ta);
box.setAppearance(Box.RIGHT, app2);
结果:
好了,它把两边的图片,但你可以看到,他们所迷离。
我认为这可能是由错误的TexCoordGeneration
应用于边的外观造成的。但我也不确定是否使用正确的参数创建Box
实例。
我该如何解决这个问题?
非常感谢您的回答!
Java 3D 1.5.1已过时,您应该切换到Java 3D 1.6:http://tinyurl.com/cf47kcb – gouessej