关于M3G纹理问题
代码如下:
protected void initialize() {
//读取两个M3G文件
firstWorld = (World) load(FILE_NAME)[0];
secondWorld = (World) load(FILE_NAME)[0];
//设置3D模型的背景
Image bgImage_1 = null;
Image bgImage_2 = null;
try {
bgImage_1 = Image.createImage( "/images/cj02_1.gif ");
bgImage_2 = Image.createImage( "/images/cj02_2.gif ");
} catch (
IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
Image2D bg2D_1 = null;
Image2D bg2D_2 = null;
if ((bgImage_1 != null) && (bgImage_2 != null)) {
bg2D_1 = new Image2D(Image2D.RGB, bgImage_1);
bg2D_2 = new Image2D(Image2D.RGB, bgImage_2);
}
background_1 = new Background();
background_1.setImage(bg2D_1);
firstWorld.setBackground(background_1);
background_2 = new Background();
background_2.setImage(bg2D_2);
secondWorld.setBackground(background_2);
//生成Texture2D对象
Image image = null;
try {
image = Image.createImage( "/images/texture03.jpg ");
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
Image2D image2D = new Image2D(Image2D.RGB,image);
texture = new Texture2D(image2D);
texture.setWrapping(Texture2D.WRAP_REPEAT, Texture2D.WRAP_REPEAT);
texture.setFiltering(Texture2D.FILTER_NEAREST, Texture2D.FILTER_NEAREST);
texture.setBlending(Texture2D.FUNC_DECAL);
//遍历所有mesh,设置纹理
traverse(firstWorld);
traverse(secondWorld);
}
private void traverse(Node aNode)
{
if (aNode instanceof Mesh)
{
Mesh mesh = (Mesh)aNode;
for (int i = 0; i < mesh.getSubmeshCount(); i++)
{