i have been trying both the tutorials from the jmonkeyengine wiki and those from the cvs download source,bt i keep getting the nullpointerexception even with source codes from the the jmetest and i rilly need to make a custom maxtojme converter to converter and load mymodels so i gave tried both
the collada,modeloader and this one form me
all have same error,am using hte netbeans as my java ide
:
this is jme:testmaxtojme source:
import java.io.BufferedInputStream;
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.Level;
import java.util.logging.Logger;
import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.math.Vector3f;
import com.jmex.model.util.ModelLoader;
import com.jme.scene.state.TextureState;
import com.jme.scene.Node;
import java.net.URL;
import com.jmex.terrain.TerrainBlock;
import com.jmex.model.converters.FormatConverter;
import com.jmex.model.converters.MaxToJme;
import com.jmex.model.converters.maxutils.TDSFile;
import java.io.IOException;
import java.io.BufferedInputStream;
import com.jmex.model.converters.maxutils.TDSFile;
import com.jme.util.BinaryFileReader;
import com.jme.util.export.Savable;
import com.jme.util.export.binary.BinaryImporter;
import com.jme.util.export.binary.BinaryExporter;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.File;
import com.jme.app.AbstractGame;
import java.io.BufferedInputStream;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
public class Modelloader extends SimpleGame{
private FormatConverter converter;
private String name;
private URL url;
private Node node;
private String fileformat;
private FileReader reader;
private FileWriter writer;
private BinaryExporter export;
private static final Logger logger = Logger.getLogger(Modelloader.class
.getName());
String end=".jme";
public Modelloader(){}
private URL modelToLoad = null;
private void setModelToLoad(String string) {
try {
modelToLoad = (new File(string)).toURI().toURL();
} catch (MalformedURLException e) {
}
}
protected void simpleInitGame() {
if (modelToLoad == null) {
modelToLoad = Modelloader.class.getClassLoader().getResource(
"C:/bike.3ds");
}
try {
MaxToJme C1 = new MaxToJme();
ByteArrayOutputStream BO = new ByteArrayOutputStream();
C1.convert(new BufferedInputStream(modelToLoad.openStream()), BO);
Node r1 = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
//Node r = new Node("parent stuff");
//r.attachChild(C1.get(new BufferedInputStream(modelToLoad.openStream()), BO));
//r.setLocalScale(.1f);
r1.setLocalScale(.1f);
if (r1.getChild(0).getControllers().size() != 0)
r1.getChild(0).getController(0).setSpeed(20);
Quaternion temp = new Quaternion();
temp.fromAngleAxis(FastMath.PI / 2, new Vector3f(-1, 0, 0));
rootNode.setLocalRotation(temp);
r1.setLocalTranslation(new Vector3f(10,0,0));
//rootNode.attachChild®;
rootNode.attachChild(r1);
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed to load Max file", e);
}
}
public static void main(String[] args){
Modelloader loader=new Modelloader();
loader.setDialogBehaviour(AbstractGame.ALWAYS_SHOW_PROPS_DIALOG);
loader.start();
}
}
and i get this:error:Apr 20, 2008 10:20:03 AM com.jme.app.BaseGame start
INFO: Application started.
Apr 20, 2008 10:20:03 AM com.jme.system.PropertiesIO <init>
INFO: PropertiesIO created
Apr 20, 2008 10:20:03 AM com.jme.system.PropertiesIO load
INFO: Read properties
Apr 20, 2008 10:20:06 AM com.jme.input.joystick.DummyJoystickInput <init>
INFO: Joystick support is disabled
Apr 20, 2008 10:20:06 AM com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
Apr 20, 2008 10:20:06 AM com.jme.system.lwjgl.LWJGLDisplaySystem getValidDisplayMode
INFO: Selected DisplayMode: 640 x 400 x 16 @60Hz
Apr 20, 2008 10:20:06 AM com.jme.system.PropertiesIO save
INFO: Saved properties
Apr 20, 2008 10:20:06 AM com.jme.app.BaseSimpleGame initSystem
INFO: jME version 1.0 alpha
Apr 20, 2008 10:20:07 AM com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W
: 640H: 400
Apr 20, 2008 10:20:08 AM com.jme.app.BaseSimpleGame initSystem
INFO: Running on: ati2dvag
Driver version: 6.14.10.6378
ATI Technologies Inc. - MOBILITY RADEON 7500 DDR x86/SSE2 - 1.3.3920 WinXP Release
Apr 20, 2008 10:20:08 AM com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
Apr 20, 2008 10:20:09 AM com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 1000 ticks per second
Apr 20, 2008 10:20:09 AM com.jme.scene.Node <init>
INFO: Node created.
Apr 20, 2008 10:20:09 AM com.jme.scene.Node <init>
INFO: Node created.
Apr 20, 2008 10:20:09 AM com.jme.scene.Node attachChild
INFO: Child (FPS label) attached to this node (FPS node)
Apr 20, 2008 10:20:09 AM class Modelloader start()
SEVERE: Exception in game loop
java.lang.NullPointerException
at Modelloader.simpleInitGame(Modelloader.java:88)
at com.jme.app.BaseSimpleGame.initGame(Unknown Source)
at com.jme.app.BaseGame.start(Unknown Source)
at Modelloader.main(Modelloader.java:113)
Apr 20, 2008 10:20:09 AM com.jme.app.BaseSimpleGame cleanup
INFO: Cleaning up resources.
Apr 20, 2008 10:20:09 AM com.jme.app.BaseGame start
INFO: Application ending.
BUILD SUCCESSFUL (total time: 12 seconds)
then
myown source:tested it with the hellomodelloading tutorials since it didnt work after running
: */
import com.jme.math.Vector3f;
import com.jmex.model.util.ModelLoader;
import com.jme.scene.state.TextureState;
import com.jme.scene.Node;
import java.net.URL;
import com.jmex.terrain.TerrainBlock;
import com.jmex.model.converters.FormatConverter;
import com.jmex.model.converters.MaxToJme;
import com.jmex.model.converters.maxutils.TDSFile;
import java.io.IOException;
import java.io.BufferedInputStream;
import com.jmex.model.converters.maxutils.TDSFile;
import com.jme.util.BinaryFileReader;
import com.jme.util.export.Savable;
import com.jme.util.export.binary.BinaryImporter;
import com.jme.util.export.binary.BinaryExporter;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.File;
import java.io.BufferedInputStream;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
public class Modelloader extends Node{
private FormatConverter converter;
private String name;
private URL url;
private Node node;
private String fileformat;
private FileReader reader;
private FileWriter writer;
private BinaryExporter export;
String end=".jme";
public Modelloader(){}
public void bytemodelloader(String name){
this.name=name;
try{
if(node.getName().endsWith(end)){
File file=new File(name);
node=(Node)BinaryImporter.getInstance().load(file);
}
url=Modelloader.class.getClassLoader().getResource(name);
converter=new MaxToJme();
ByteArrayOutputStream out=new ByteArrayOutputStream();
converter.convert(url.openStream(), out);
node=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(out.toByteArray()));
BinaryExporter.getInstance().save(node,out);
}
catch(IOException e){
System.out.println("model loading error,check system files"+e);
e.printStackTrace();
System.exit(0);
}
}
}
tested it in:
import com.jme.math.Vector3f;
import com.jmex.model.util.ModelLoader;
import com.jme.scene.state.TextureState;
import com.jme.scene.Node;
import java.net.URL;
import com.jmex.terrain.TerrainBlock;
import com.jmex.model.converters.FormatConverter;
import com.jmex.model.converters.MaxToJme;
import com.jmex.model.converters.maxutils.TDSFile;
import java.io.IOException;
import java.io.BufferedInputStream;
import com.jmex.model.converters.maxutils.TDSFile;
import com.jme.util.BinaryFileReader;
import com.jme.util.export.Savable;
import com.jme.util.export.binary.BinaryImporter;
import com.jme.util.export.binary.BinaryExporter;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.File;
import java.io.BufferedInputStream;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
public class Modelloader extends Node{
private FormatConverter converter;
private String name;
private URL url;
private Node node;
private String fileformat;
private FileReader reader;
private FileWriter writer;
private BinaryExporter export;
String end=".jme";
public Modelloader(){}
public void bytemodelloader(String name){
this.name=name;
try{
if(node.getName().endsWith(end)){
File file=new File(name);
node=(Node)BinaryImporter.getInstance().load(file);
}
url=Modelloader.class.getClassLoader().getResource(name);
converter=new MaxToJme();
ByteArrayOutputStream out=new ByteArrayOutputStream();
converter.convert(url.openStream(), out);
node=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(out.toByteArray()));
BinaryExporter.getInstance().save(node,out);
}
catch(IOException e){
System.out.println("model loading error,check system files"+e);
e.printStackTrace();
System.exit(0);
}
}
}
and i gt the same error,and yes am a noob.
Hello influx
Does the original jme 3ds loading test work for You ? (TestMaxJmeWrite)
If Yes, have You set up the classpath correctly ?
At first i advice You to get the original TestMaxJmeWrite test to work, then copy Your bike.3ds to where the model that is loaded resides and change the included test to load it.
If this doesn't work then report back.
(If it works then start to experiment from that point)
hth
thanks for your reply,i did as you said and tried the TestMaxJmeWrite tutorial from the cvs source and it worked when i run it from the jme source bt i copied the original source from it into one of my projects bt this time,it didnt work,which is surprising,could it be the fact of it nt beeing part of the original package file:jmetest.rederer.loader,which would be ridiclous knowing having writing other tutorials which where in the package into myown packages.so whats wrong.
Ok, good to hear it's working basically.
Could be Your classpath setup then.
Not sure but i think .class.getClassLoader().getResource(…) looks for Resources only in the classpath.
so "C:/bike.3ds" would be searched from the classpath which implies the classpath is set to a dirctory which is parent to C:/bike.3ds ???
So try to load a file "bike.3ds" which sits somewhere in the classpath.
Also take a look at the resource locator tool: http://www.jmonkeyengine.com/jmeforum/index.php?topic=5707.0
not sure if it loads models as well, but could be helpful in Your case.
thanks dude,will do that
GUYs,guys!.
i love jme alot,more than anything,bt right now am scruingup the java io system,lol,bt it woulod rily be cool if the guys at least jst write up a code,a modelloading test code,that rily work and solve everyone modelloading problem or wel atleast some problem and test it coz the helloworld tutorial didnt work,which to be honest is very surprising.
Note:make sure to put/copy all those resources,3d files into your projects src file,you can put it in a folder or jst copy them in,Netbeans will update ur source folder itself and show the files/folder.
i like to thank Winkman for his time and replies to my tiny problem,i know he has better things to do,bt truely appreciate his replies.Thanks man.
And my apologies to the guys at jme,mybad,your source works just fine,i just made a silly mistake on mypart,thanks for the wonderful game engine.
:?
Now for all you people on eclipse or netbeans(mostly netbeans) who by any chance are having a problem,
that is the same as mine or nearly same as mine,do me the biggest favor and raise one of ur hands on your head and slap your self softly with the other or you can do it hard,ur choice!
For y’all who have been crying that jme is having some resource loading or retrieving problems,lets jst say
maybe thats not the problem maybe you are the problem yourself,well like everyone who is using netbeans unlike JBuilder when you add an external resource like images,3d files,etc,it doesn’t fully initialise those resources as part of the project till you click build or clean and build,so while i was thinking off the problem,in that jme was unable to retrieve the files,resources i needed and writing different codes to do the same thing that the tiny HelloModelloading codes did for us all(talk bout re-inventing the test wheel),all i needed to do was clean and build myproject and it was working fine,though incase you loading a large object like the Character.3DS in the jme test,u shud tink of scaling it down a bit or you’ll get a explosive view of things.
So stop cracking your brains and compile/clean and build your project itself then run the HelloModelloading or your custom loader and relax and have a laugh on how freaky yet ridiculouse the situation was.
shoot me!thats life.lmao.lol
:-o
:-o
XD
heres the test:
import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.util.export.binary.BinaryImporter;
import com.jme.util.export.binary.BinaryExporter;
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.AbstractGame;
import java.io.File;
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.;
import com.jmex.model.util.ModelLoader;
import com.jmex.model.collada.;
import com.jmex.model.converters.;
import com.jmex.model.converters.maxutils.TDSFile;
import com.jme.util.export.binary.;
import com.jme.scene.Node;
import java.io.FileOutputStream;
public class Maxloader extends SimpleGame{
private URL url2;
public static void main(String[] args) {
Maxloader loader=new Maxloader();
loader.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
loader.start();
}
protected void simpleInitGame(){
Node model=loadmodel(“bike.3ds”);
model.setLocalScale(.0025f);
rootNode.attachChild(model);
}
protected Node loadmodel(String path){
url2=geturl(path);
Node modelnode=null;
FormatConverter conv=null;
ByteArrayOutputStream out=new ByteArrayOutputStream();
try{
if(path.endsWith(".jme")){
modelnode=(Node)BinaryImporter.getInstance().load(url2);
}else{
conv=new MaxToJme();
conv.getProperty(path);
conv.convert(url2.openStream(), out);
modelnode=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(out.toByteArray()));
File binaryfile=new File(name.substring(0,name.lastIndexOf("_")+1)+“jbin”);
BinaryExporter.getInstance().save((Savable)node, binaryfile);
}
}
catch(Exception e){e.printStackTrace();}
return modelnode;
}
protected static URL geturl(String name){
try{
URL url=Maxloader.class.getClassLoader().getSystemResource(name);
if(url.getFile()==null){
System.out.println(“unable to fetch file”+name);
System.out.println(“try another file”);
System.err.println(“error”);
}
return url; }
catch(Exception e){
e.printStackTrace();
e.getMessage();
System.err.println(“error occured with the url loac”+name);
return null; }
}
}
well, glad Your'e up and running influx
thanks winkman.