关于网友提出的“ 关于M3G纹理问题”问题疑问,本网通过在网上对“ 关于M3G纹理问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 关于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++)
{
Appearance app = mesh.getAppearance(i);
app.setTexture(0, texture);
}
}
if (aNode instanceof Group)
{
Group group = (Group)aNode;
for (int i = 0; i < group.getChildCount(); i++)
{
traverse(group.getChild(i));
}
}
}
执行到render方法时,抛出了异常:
java.lang.IllegalStateException
at javax.microedition.m3g.Util3D.throwEx(+79)
at javax.microedition.m3g.Graphics3D.render(+185)
at cn.edu.upc.trojan.MyGraphics3D.render(+40)
at cn.edu.upc.trojan.MyGraphics3D.render(+20)
at cn.edu.upc.trojan.MyGraphics3D.render(+15)
at cn.edu.upc.trojan.MyCanvas.paint(+78)
at javax.microedition.lcdui.Canvas.callPaint(+80)
at javax.microedition.lcdui.Display.repaint(+77)
at javax.microedition.lcdui.Display.registerNewCurrent(+237)
at javax.microedition.lcdui.Display.access$400(+6)
at javax.microedition.lcdui.Display$DisplayAccessor.foregroundNotify(+46)
at javax.microedition.lcdui.Display$DisplayManagerImpl.notifyWantsForeground(+152)
at javax.microedition.lcdui.Display$DisplayManagerImpl.access$100(+6)
at javax.microedition.lcdui.Display.setCurrentImpl(+115)
at javax.microedition.lcdui.Display.setCurrent(+29)
at cn.edu.upc.trojan.MainMIDLET.startApp(+63)
at javax.microedition.midlet.MIDletProxy.startApp(+7)
at com.sun.midp.midlet.Scheduler.schedule(+270)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+116)
不加纹理的话,两个模型都可以正常显示
纹理图片是一个16*16的单色JPG图片
请问这是什么问题呀?
解决方案1: 首先, 用png.......
以上介绍了“ 关于M3G纹理问题”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2000397.html