[SOLVED]loading model from blender

hi i have made a lovely racetrack model in blender and i want to load it into my game.

jme doesn't let you load .blend files so do i have to convert it to a 3ds or what?



please help :slight_smile:

http://www.jmonkeyengine.com/wiki/doku.php?id=exporting_animated_.md5_models_from_blender

http://www.jmonkeyengine.com/wiki/doku.php?id=exporting_animated_.md3_models_from_blender

http://www.jmonkeyengine.com/wiki/doku.php?id=exporting_.obj_models_from_blender

ok nice one, i ran the test game from the bottom link with my new .obj file and it said:



SEVERE: Exception in game loop

java.lang.ClassCastException: com.jme.scene.Node cannot be cast to com.jme.scene.TriMesh

at TestObjJmeWrite.simpleInitGame(TestObjJmeWrite.java:72)

at com.jme.app.BaseSimpleGame.initGame(Unknown Source)

at com.jme.app.BaseGame.start(Unknown Source)

at TestObjJmeWrite.main(TestObjJmeWrite.java:56)

at __SHELL0.run(__SHELL0.java:7)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at bluej.runtime.ExecServer$3.run(ExecServer.java:792)

20-Nov-2007 00:14:09 com.jme.app.BaseSimpleGame cleanup

INFO: Cleaning up resources.

20-Nov-2007 00:14:09 com.jme.app.BaseGame start

INFO: Application ending.



any help?

pleeease someone, i really need this to work :frowning:

ok i changed everything from a node to a trimesh and the model is now loading into the game, but when i get close to it the game crashes and it says:



#

An unexpected error has been detected by Java Runtime Environment:

#

java.lang.OutOfMemoryError: requested 32756 bytes for ChunkPool::allocate. Out of swap space?

#

#  Internal Error (414C4C4F434154494F4E0E4350500065), pid=2264, tid=2772

#

Java VM: Java HotSpotâ„¢ Server VM (1.6.0_02-b06 mixed mode)

An error report file with more information is saved as hs_err_pid2264.log

#

If you would like to submit a bug report, please visit:

http://java.sun.com/webapps/bugreport/crash.jsp

#

#

An unexpected error has been detected by Java Runtime Environment:

#

java.lang.OutOfMemoryError: requested 32756 bytes for ChunkPool::allocate. Out of swap space?

#

#  Internal Error (414C4C4F434154494F4E0E4350500065), pid=1632, tid=3640

#

Java VM: Java HotSpotâ„¢ Server VM (1.6.0_02-b06 mixed mode)

An error report file with more information is saved as hs_err_pid1632.log

#

If you would like to submit a bug report, please visit:

http://java.sun.com/webapps/bugreport/crash.jsp

#



erg.

http://www.jmonkeyengine.com/jmeforum/index.php?action=search



Please accept the fact that if you want to learn java programming by making a game, you have taken a path that will require a LOT of work and time on your end. Searching the forum before asking questions is just one small step towards your goal, but a neccessary one. If at all possible, you should postpone your game project and learn the basics of java programming first.



I don't mean to give you a hard time, this is really the best advice I can give you to help you get anywhere near completion with your project:

Start small! You will get frustrated and dump your project eventually if you aim too high, and that's what you are doing right now.

To find a solution for your problem you should search for "java OutOfMemoryError" on g00gle or alike.

apparently its not to do with java but the machine itself, anyway, i ran the game without any other programs running and it worked!



problem now is that the model i loaded in is untextured, how do i keep the textures i applied in blender?

By reading the documentation and searching the forum.

iv been searching through the forums for ages and its not getting me anywhere…



i keep getting errors like:

java.lang.ClassCastException: com.jme.scene.TriMesh cannot be cast to com.jme.scene.Node



the class on the end changes when i change converter.setProperty("texdir", model) to converter.setProperty("mtllib", model)



from reading the other posts i assume getting these textures to work involves these "keys"(whatever that means).

when i run the example program (HelloModelLoading) the model is loaded and the texture says "texture missing" compared to normal, just white, this is a step in the right direction, both have identical code…what am i doing wrong???



here is my code atm:


private void buildRoad() {
        TriMesh model = new TriMesh("roadNode");
        try {
           
            
            ObjToJme C1 = new ObjToJme();
            ByteArrayOutputStream BO = new ByteArrayOutputStream();
            URL maxFile = Fulstrom.class.getClassLoader().getResource("images/untitled.obj");
            //C1.setProperty("mtllib",model);
            C1.convert(new BufferedInputStream(maxFile.openStream()),BO);
            model = (TriMesh)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
           
            //scale it to be MUCH smaller than it is originally
            model.setLocalScale(10f);
            model.setModelBound(new BoundingBox());
            model.updateModelBound();
     } catch (IOException e) {
         System.out.println("lame");
        }
       
 model.setModelBound(new BoundingBox());
 model.updateGeometricState(0.0f, true);
 model.updateModelBound();
//        
       
        this.attachChild(model);
        this.updateGeometricState(0, true);
        model.updateWorldBound();
    }


Cast to Spatial

nope still nothing, here is the updated code:



private void buildRoad() {
        Spatial model = new TriMesh("roadNode");
        try {
           
            
            ObjToJme C1 = new ObjToJme();
            ByteArrayOutputStream BO = new ByteArrayOutputStream();
            URL maxFile = Fulstrom.class.getClassLoader().getResource("images/untitled.obj");
            //C1.setProperty("texdir",model);
            C1.convert(new BufferedInputStream(maxFile.openStream()),BO);
            model = (Spatial)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
           
            //scale it to be MUCH smaller than it is originally
            model.setLocalScale(10f);
            model.setModelBound(new BoundingBox());
            model.updateModelBound();
     } catch (IOException e) {
         System.out.println("this is why");
        }
       
 model.setModelBound(new BoundingBox());
 model.updateGeometricState(0.0f, true);
 model.updateModelBound();
//        
       
        this.attachChild(model);
        this.updateGeometricState(0, true);
        model.updateWorldBound();
    }

The setProperty is intended to be an URL or a String, not a Spatial.

i dont get what the setProperty method is for at all!!



i only have it there because it was in the example, what does it do?

aaah i got it to display the "missing texture" picture now…getting there…

arrrghh one of the textures is displaying now, the other is still displayed in plain white… how could this be happening?