MD2 model Problem

Hi all,



I've created a simple Icosphere in blender and exported it as an MD2 model,  http://chumbalum.swissquake.ch/md2v/ this viewer loaded it correctly.  However it results in this error when loaded into JME.  Note: I just edited the testMd2Loader




/*
 * loadMd2Ball.java
 *
 * Created on November 26, 2007, 11:21 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package jme_Tester;

/**
 *
 * Copyright (c) 2003-2007 jMonkeyEngine
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
 *   may be used to endorse or promote products derived from this software
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Logger;

import javax.swing.JOptionPane;

import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.image.Texture;
import com.jme.input.KeyBindingManager;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Controller;
import com.jme.scene.Node;
import com.jme.scene.state.MaterialState;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.animation.KeyframeController;
import com.jmex.model.converters.Md2ToJme;

/**
 * Started Date: Jun 14, 2004<br><br>
 * Test class to test the ability to load and save .md2 files to jME binary format
 *
 * @author Jack Lindamood
 */
public class loadMd2Ball extends SimpleGame{
    private static final Logger logger = Logger.getLogger(loadMd2Ball.class
            .getName());
   
    float totalFPS;
    long totalCounts;
   
    public static void main(String[] args) {
       
        loadMd2Ball app=new loadMd2Ball();
        app.setDialogBehaviour(AbstractGame.FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG);
        app.start();
    }
    protected void simpleInitGame() {

        Md2ToJme converter=new Md2ToJme();
        ByteArrayOutputStream BO=new ByteArrayOutputStream();

        URL textu= getClass().getResource( "/Images/Ball_Textures/ball_-1.png");
        URL freak= getClass().getResource( "/Models/sphere.md2");

       
        Node freakmd2=null;

        try {
            long time = System.currentTimeMillis();
            converter.convert(freak.openStream(),BO);
            logger.info("Time to convert from md2 to .jme:"+ ( System.currentTimeMillis()-time));
        } catch (IOException e) {
            logger.info("damn exceptions:" + e.getMessage());
        }

        try {
            long time=System.currentTimeMillis();
            freakmd2=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            logger.info("Time to convert from .jme to SceneGraph:"+ ( System.currentTimeMillis()-time));
        } catch (IOException e) {
            logger.info("damn exceptions:" + e.getMessage());
        }

        TextureState ts = display.getRenderer().createTextureState();
        ts.setEnabled(true);
        ts.setTexture(
        TextureManager.loadTexture(
            textu,
            Texture.MM_LINEAR_LINEAR,
            Texture.FM_LINEAR));
        freakmd2.setRenderState(ts);
       
        MaterialState ms = display.getRenderer().createMaterialState();
        ms.setSpecular(new ColorRGBA(0,0,0,1));
        ms.setShininess(128f);
        ms.setMaterialFace(MaterialState.MF_FRONT_AND_BACK);
        freakmd2.setRenderState(ms);
       
        freakmd2.setLocalTranslation(new Vector3f(0,0,-20));
        freakmd2.setLocalScale(.5f);
       
       
        lightState.setGlobalAmbient(new ColorRGBA(ColorRGBA.white.clone()));
        lightState.get(0).setAmbient(new ColorRGBA(ColorRGBA.white.clone()));
       
        rootNode.attachChild(freakmd2);
     }
   
   
   
 }




Nov 27, 2007 9:49:06 AM class jme_billiards.loadMd2Ball start()
SEVERE: Exception in game loop
java.lang.ArrayIndexOutOfBoundsException: 163
        at com.jmex.model.converters.Md2ToJme$Md2ConverterCopy.parseMesh(Unknown Source)
        at com.jmex.model.converters.Md2ToJme$Md2ConverterCopy.<init>(Unknown Source)
        at com.jmex.model.converters.Md2ToJme.convert(Unknown Source)
        at jme_billiards.loadMd2Ball.simpleInitGame(loadMd2Ball.java:111)
        at com.jme.app.BaseSimpleGame.initGame(Unknown Source)
        at com.jme.app.BaseGame.start(Unknown Source)
        at jme_billards.Main.main(Main.java:24)
Nov 27, 2007 9:49:06 AM com.jme.app.BaseSimpleGame cleanup


The model viewer shows that the number of vertices is 162, so maybe that has something to do with it.
I will be happy to supply the model if anyone can help me with this problem.

Also, I created a simple Cube and exported it in the same way and jME loads then displays it correctly...

Both models were created in Windows then loaded in jME in Mac OSX, could it be an OS issue (I really don't think so, but anything is possible)

Here are the Models I used:



http://ito-mt.com/_TEMP/models.zip

Okay, so it's been 2 days; so either this is a really dumb question, no one has a clue, or no one wants to help.  I would really appreciate any feedback on this problem ('cept for negative  :stuck_out_tongue: )


Use a different exporter?



It's possible that either the model viewer or jME incorrectly parse the format, so you get different results. Either way whoever wrote the md2 loader needs to take a look at those models and fix the problem(s) if there are any.

did you try another md2 loader?

Yup, not only did I re-open it with Blender successfully, but this loader did too http://jerome.jouvie.free.fr/JNLP/JNLP.php?jnlpRef=OglPrj03J

I just tried loading the model in windows with jME and it resulted in the exact same error  :expressionless: .  I am really wondering what the heck the problem could be.

Sorry Momoko_Fan, I must have been blind earlier and didn't see your response.  I am just using the standard MD2 export script that comes with blender.

The problem is that the model is referencing md2 normals (preset normals) that are outside the official set of predefined normals.  I'll have it ignore invalid values for now.

In cvs.