Hey everyone, im having some trouble with this tutorial. I searched the forums and saw some other people had a similar problem but i still cant figure this out. The original code works perfectly and loads the maggie model.
/*
* Copyright (c) 2003-2008 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.
*/
package jmetest.TutorialGuide;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingSphere;
import com.jme.scene.Node;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.converters.FormatConverter;
import com.jmex.model.converters.ObjToJme;
/**
* Started Date: Jul 22, 2004<br><br>
*
* Demonstrates loading formats.
*
* @author Jack Lindamood
*/
public class HelloModelLoading extends SimpleGame {
private static final Logger logger = Logger
.getLogger(HelloModelLoading.class.getName());
public static void main(String[] args) {
HelloModelLoading app = new HelloModelLoading();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
// Turn the logger off so we can see the XML later on
app.start();
}
protected void simpleInitGame() {
// Point to a URL of my model
URL model=HelloModelLoading.class.getClassLoader().getResource("jmetest/data/model/maggie.OBJ");
// Create something to convert .obj format to .jme
FormatConverter converter=new ObjToJme();
// Point the converter to where it will find the .mtl file from
converter.setProperty("mtllib",model);
// This byte array will hold my .jme file
ByteArrayOutputStream BO=new ByteArrayOutputStream();
try {
// Use the format converter to convert .obj to .jme
converter.convert(model.openStream(), BO);
Node maggie=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
// shrink this baby down some
maggie.setLocalScale(.1f);
maggie.setModelBound(new BoundingSphere());
maggie.updateModelBound();
// Put her on the scene graph
rootNode.attachChild(maggie);
} catch (IOException e) { // Just in case anything happens
logger.logp(Level.SEVERE, this.getClass().toString(),
"simpleInitGame()", "Exception", e);
System.exit(0);
}
}
}
But as soon as i make my own model in 3ds max 2009 at UNI and export it in OBJ format.(The model is just 1 small box on a big box to keep it simple) it stops working.
All i did was change the model file name here in the original code
URL model=HelloModelLoading.class.getClassLoader().getResource("jmetest/data/model/box.OBJ");
I put the box.obj and box.mtl in the model folder.
It loads the config screen but when I click ok the program crashes with this error
SEVERE: Exception in game loop
java.lang.NullPointerException
at jmetest.TutorialGuide.HelloModelLoading.simpleInitGame(HelloModelLoading.java:80)
at com.jme.app.BaseSimpleGame.initGame(BaseSimpleGame.java:527)
at com.jme.app.BaseGame.start(BaseGame.java:71)
at jmetest.TutorialGuide.HelloModelLoading.main(HelloModelLoading.java:64)
Here are the export options for OBJ in max
Am i exporting the model wrong in 3dsmax?? I even imported the maggie model to max and re-exported it as maggie1 and tried this new version in the model source folder but it still crashed. hmmmmmmmmmmmmm any ideas?