Cant import ModelLoader

Hi,



I am trying to use this code snippet: http://www.jmonkeyengine.com/wiki/doku.php?id=unified_model_loading

But I was not able to find the class ModelLoader, BinaryImporter and BinaryExporter in the jme framework. I also serached these classes in the Java 5.0 framework and in the Lightweight Java Game Library, because I thought that the Importer and Exporter could be Java classes…

These jme jar’s are imported to my Eclipseproject:

jinput.jar

jme.rar

jme-awt.rar

jme-effects.jar

jme-model.jar

jme-sound.jar

jme-terrain.jar



Can someone help me? 

jme.rar?

my fault:

jme.jar

jme-awt.jar

Have you tried getting jME from CVS? I don't know what's in the jars, but ModelLoader is in com.jmex.model.util in CVS, so it is part of jme. If eclipse knows about a class it will auto complete it when you press ctrl-space, if you want a quick way to check. For example type "ModelLo" then ctrl-space.

jep I know the ctrl-space function  :wink:

I am gonne check the CVS for the missed classes… but why should be the released jar's different to the CVS files?

Anyway I will see… and thx  :slight_smile:

Hello again…



I checked out the CVS and found:



com.jmex.model.util.ModelLoader.Java

com.jme.util.export.binary.BinaryImporter.Java

com.jme.util.export.binary.BinaryExporter.Java



Does it make sence to compile em and put em into my project. Or are they remains of an older version of the jme.

Anyway I waste time thinking of it, just because of a little code snippet.



But can someone tell me why there is nothing about these classes in the documentation, and why there are on the CVS?






jme CVS is always the newest version of jme. that means that new functionality will be first available in CVS, but that's also true for eventual bugs.

it's up to you if you want to settle on using a certain version of jme, or go with the CVS (i would recommend the latter).



so those classes you "found" are not remnants of some old jme version, but quite new (more or less) :slight_smile:

to your question about compiling them and adding them to your project: it only makes sense to use a certain version/revision of jme. so make sure you don't mix up classes form CVS with the ones from the releases. that would result in a lot of mess.

By the way, I've found useful to implement a timestamp checking inside the unified loader. That way, if the model changes it is converted again. Also, if the original is not found, I still load the converted file if it exists.



This is the code. Be warned it is a bit dependant on my application and that I'm working directly with files (not Class.getClassLoader()…).



All (positive) credit goes to the Unified Model Loader writer, whoever he is.



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

import com.jme.scene.Node;
import com.jme.util.TextureKey;
import com.jme.util.export.binary.BinaryExporter;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.XMLparser.Converters.AseToJme;
import com.jmex.model.XMLparser.Converters.FormatConverter;
import com.jmex.model.XMLparser.Converters.MaxToJme;
import com.jmex.model.XMLparser.Converters.Md2ToJme;
import com.jmex.model.XMLparser.Converters.Md3ToJme;
import com.jmex.model.XMLparser.Converters.MilkToJme;
import com.jmex.model.XMLparser.Converters.ObjToJme;

public class MeshUtil {
      
   private static final Logger logger = Logger.getLogger(MeshUtil.class.toString());
   
   /*
    *  This method opens a model in various format evaluating the extension
    *  In case in the same directory is already present the same model in jbin format loads it.
    *  Otherways load the model and save a jbin copy for the next time.
    */      
   private static Node convertModel (String originalFilename) {
      
      Node loadedModel = null;
      FormatConverter formatConverter = null;
      
      String originalExtension = originalFilename.substring(originalFilename.lastIndexOf(".") + 1, originalFilename.length());
      String convertedFilename = originalFilename.substring(0, originalFilename.lastIndexOf(".") + 1)   + "jbin";

      File originalFile = new File(originalFilename);
      File convertedFile = new File(convertedFilename);
      
      URL convertedURL = null;
      try {
         convertedURL = convertedFile.toURL();
      } catch (MalformedURLException e) {
         logger.warning("Could not resolve the model " + convertedFilename);
         return loadedModel;
      }

      // Check to see if the model has changed since last conversion
      boolean forceConvert = false;
      if (originalFile.exists() && convertedFile.exists()) {
         if (originalFile.lastModified() != convertedFile.lastModified()) {
            forceConvert = true;
         }
      }
      
      // Verify the presence of the jbin model
      if (! (convertedFile.exists())||(forceConvert)) {

         // Evaluate the format
         if (originalExtension.equals("3ds")) {
            formatConverter = new MaxToJme();
         }
         if (originalExtension.equals("md2")) {
            formatConverter = new Md2ToJme();
         }
         if (originalExtension.equals("md3")) {
            formatConverter = new Md3ToJme();
         }
         if (originalExtension.equals("ms3d")) {
            formatConverter = new MilkToJme();
         }
         if (originalExtension.equals("ase")) {
            formatConverter = new AseToJme();
         }
         if (originalExtension.equals("obj")) {
            formatConverter = new ObjToJme();
         }
         
         formatConverter.setProperty("mtllib", convertedURL);

         // Do the conversion
         try {
            logger.info("Converting file " + originalFilename);
            ByteArrayOutputStream BO = new ByteArrayOutputStream();
            formatConverter.convert(originalFile.toURL().openStream(), BO);
            loadedModel = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            BinaryExporter.getInstance().save(loadedModel, convertedFile);
            convertedFile.setLastModified(originalFile.lastModified());
         } catch (IOException e) {
            logger.warning("Could not convert the model " + convertedFile + ": " + e);
            return loadedModel;
         }
         
      } else {
         
         try {
            // Import mesh (cast from Loadable to Node)
            BinaryImporter binaryImporter = new BinaryImporter();
            TextureKey.setOverridingLocation(convertedFile.getParentFile().toURL());
            loadedModel = (Node) binaryImporter.load(convertedFile);
         } catch (Exception err) {
            logger.severe("Error loading model:" + err);
            return null;
         }
         
      }
      
      return loadedModel;
   }   
   

}