How to use ogreloader?

Hi, im new to jMonkey. So far I have managed to get the last lesson of flag rush tutorial with jgn, working. I have only made minor modifications, like scaled the pumpy ground.



Now I want to put other models and animations on my scene. For example change the flag rush bike to a running man.



I am using 3Ds Max for modelling and animations. I tried 3dsmax->collada exporter->jme, but was only able to load a model without skins and animation into jme scene(the jmetest animation worked well though). My animation didnt work in jme, when i loaded model with texture, i got nullpointerexception on this line



//we can then retrieve the skin from the importer as well as the skeleton

        SkinNode sn = ColladaImporter.getSkinNode(ColladaImporter.getSkinNodeNames().get(0));



Then i thought, ok, ill try another format. I tried 2 md5 exporters for max, which didnt work.



Now I'm left with Ogre mesh.xml and skeleton.xml. I have the OgreMax exporter and ogreloader checked out from googlecode, but I have no clue how to use ogreloader to get a textured animation to a scene.



I would appreciate if anybody could give me complete example code of using the ogreloader to load and play an skeletal animation with textured mesh. It would be eaven better if the example mesh.xml and skeleton.xml files would also be attached.


I tried 2 md5 exporters for max, which didnt work.


This exporter works for max
http://www.doom3world.org/phpbb2/viewtopic.php?t=1914

it seems to freeze for a while on export, like windows tells me the program is not responding, but give it a while and it works.

sorry this is no help wwith ogreloader

All the example files are in the mxml/data directory:

http://code.google.com/p/radakan/source/browse/trunk#trunk/ogreloader/src/com/radakan/jme/mxml/data



The code to load a model is available in the TestMeshLoading class:

http://code.google.com/p/radakan/source/browse/trunk/ogreloader/src/com/radakan/jme/mxml/test/TestMeshLoading.java

protected void loadMeshModel(){
        OgreLoader loader = new OgreLoader();
        MaterialLoader matLoader = new MaterialLoader();
       
        try {
            URL matURL = TestMeshLoading.class.getClassLoader().getResource("com/radakan/jme/mxml/data/Example.material");
            URL meshURL = TestMeshLoading.class.getClassLoader().getResource("com/radakan/jme/mxml/data/ninja.mesh.xml");
           
            if (matURL != null){
                matLoader.load(matURL.openStream());
                if (matLoader.getMaterials().size() > 0)
                    loader.setMaterials(matLoader.getMaterials());
            }
           
            model = (Node) loader.loadModel(meshURL);
        } catch (IOException ex) {
            Logger.getLogger(TestMeshLoading.class.getName()).log(Level.SEVERE, null, ex);
        }
    }



Once you have the model loaded, retrieve the MeshAnimationController and then you can do stuff with it:

MeshAnimationController animControl = (MeshAnimationController) model.getController(0);
animControl.setAnimation("Walk");

Ok, now i got my models loaded into jme scene, but i can't get my animations and textures.



I used oFusion 1.86 ogre exporter to export my scene from 3DsMax, then i used OgreXMLConverter to make the .mesh and .skeleton files to .mesh.xml and .skeleton.xml.



My models load, but without textures. When i try to use animations, I get Excpetions. The example animations (ninja, robot, turret) work fine though.



Should I use some other 3dsmax exporter? Which version of OgreLoader should I use? I'm currently using the version i checked out from svn, but I just read a topic where was said that it is not recommended to use the svn version.



Currently i'm getting these warning and Exception:



4.04.2009 15:25:23 com.radakan.jme.mxml.anim.SkeletonLoader loadSkeleton

WARNING: Rotation axis not normalized

4.04.2009 15:25:23 com.radakan.jme.mxml.anim.SkeletonLoader loadSkeleton

WARNING: Rotation axis not normalized

4.04.2009 15:25:23 com.radakan.jme.mxml.anim.SkeletonLoader loadSkeleton

WARNING: Rotation axis not normalized

4.04.2009 15:25:23 com.radakan.jme.mxml.anim.SkeletonLoader loadSkeleton

WARNING: Rotation axis not normalized

4.04.2009 15:25:23 com.radakan.jme.mxml.anim.SkeletonLoader loadSkeleton

WARNING: Rotation axis not normalized

4.04.2009 15:25:23 com.jme.scene.Node attachChild

INFO: Child (flag) attached to this node (OgreMesh)

4.04.2009 15:25:23 com.jme.scene.Node <init>

INFO: Node created.

4.04.2009 15:25:23 com.jme.scene.Node attachChild

INFO: Child (flag) attached to this node (OgreMesh)

4.04.2009 15:25:23 com.jme.scene.Node attachChild

INFO: Child (OgreMesh) attached to this node (rootNode)

4.04.2009 15:25:23 class com.gtas.test.MyTestMeshLoading start()

SEVERE: Exception in game loop

java.lang.IllegalArgumentException

at java.nio.Buffer.position(Unknown Source)

at com.radakan.jme.mxml.anim.MeshAnimationController.softwareSkinUpdate(MeshAnimationController.java:336)

at com.radakan.jme.mxml.anim.MeshAnimationController.update(MeshAnimationController.java:417)

at com.jme.scene.Spatial.updateWorldData(Spatial.java:541)

at com.jme.scene.Node.updateWorldData(Node.java:383)

at com.jme.scene.Spatial.updateGeometricState(Spatial.java:517)

at com.jme.scene.Node.updateWorldData(Node.java:395)

at com.jme.scene.Spatial.updateGeometricState(Spatial.java:517)

at com.gtas.test.MyTestMeshLoading.simpleInitGame(MyTestMeshLoading.java:203)

at com.jme.app.BaseSimpleGame.initGame(BaseSimpleGame.java:544)

at com.jme.app.BaseGame.start(BaseGame.java:74)

at com.gtas.test.MyTestMeshLoading.main(MyTestMeshLoading.java:70)

4.04.2009 15:25:23 com.jme.app.BaseSimpleGame cleanup



I just noticed that in my animations, the keyframes look like this:

                <keyframe time="0.0333333">

                            <translate x="32.2682" y="40.2445" z="-0.237703" />

                            <rotate angle="5.84685">

                                <axis x="-7.94016e-008" y="1" z="4.49624e-007" />

                            </rotate>

                        </keyframe>



but in ogreloader test animations:



                        <keyframe time="0.666667">

                            <translate x="0.131791" y="-0.0782161" z="0" />

                            <rotate angle="0.210844">

                                <axis x="0" y="0" z="1" />

                            </rotate>

                        </keyframe>



the values of x, y, z only varie form -1 to 1 at <axis tag

The axis values don't really matter, they are normalized anyway. The actual error happens in softwareSkinUpdate, I have no idea why it happens, if the data given was incorrect the error should have occured elsewhere. For your texture issue, I think you might have forgot to set up proper paths using ResourceLocatorTool, take a look at the example and make sure the textures, materials, etc have paths properly set. You can also try different exporters and see if they work, try to use the newest one. If you still can't get it to work, you can send me the problematic model (in XML format) so that I can take a look at it.

Ok, im gonna give it another try with different exporters and different versions of 3DsMax if I have to, but I still have some questions:



Could anybody describe their 3DsMax->OgreXML->JME workflow that works? Which ogre exporter and 3DsMax version you are using?



I also have blender and milkshape, which i could use to import/export. Is it also possible to go 3DsMax->Blender or Milkshape->OgreXML->jME, with some format? And would it be reasonable?

I made a box in max with 1 bone and the animation worked in jme, i still dont know why my more complex animations dont work.



I get this exception:



INFO: Child (OgreMesh) attached to this node (rootNode)
31.03.2009 23:15:38 class test.MyTestMeshLoading start()
SEVERE: Exception in game loop
java.lang.IllegalArgumentException
   at java.nio.Buffer.position(Unknown Source)
   at com.radakan.jme.mxml.anim.MeshAnimationController.softwareSkinUpdate(MeshAnimationController.java:336)
   at com.radakan.jme.mxml.anim.MeshAnimationController.update(MeshAnimationController.java:419)
   at com.jme.scene.Spatial.updateWorldData(Spatial.java:541)
   at com.jme.scene.Node.updateWorldData(Node.java:383)
   at com.jme.scene.Spatial.updateGeometricState(Spatial.java:517)
   at com.jme.scene.Node.updateWorldData(Node.java:395)
   at com.jme.scene.Spatial.updateGeometricState(Spatial.java:517)
   at test.MyTestMeshLoading.simpleInitGame(MyTestMeshLoading.java:202)
   at com.jme.app.BaseSimpleGame.initGame(BaseSimpleGame.java:544)
   at com.jme.app.BaseGame.start(BaseGame.java:74)
   at test.MyTestMeshLoading.main(MyTestMeshLoading.java:70)
31.03.2009 23:15:38 com.jme.app.BaseSimpleGame cleanup
INFO: Cleaning up resources.
31.03.2009 23:15:38 com.jme.app.BaseGame start
INFO: Application ending.



In softwareSkinUpdate, with these rows:

                ib.position(ib.position()+fourMinusMaxWeights);
                wb.position(wb.position()+fourMinusMaxWeights);

When i comment them out, the animation starts to work, but my model starts to look weird.


The model is supposed to look like this:


I have uploaded the mesh, skeleton and max scene to:
     http://84.50.48.243/Spring

It would be great if somebody could check it out and tell me what am I doing wrong.



Hi Henri, thanks for the bug report. I am currently investigating this. It seems other people who attempted to export from Max have gotten this issue.



Deleting the lines

ib.position(ib.position()+fourMinusMaxWeights);
wb.position(wb.position()+fourMinusMaxWeights);


will not help as they are integral to the skinning code. It seems the issue might be indirectly caused by something else.
Henri said:

I made a box in max with 1 bone and the animation worked in jme, i still dont know why my more complex animations dont work.

I get this exception:


INFO: Child (OgreMesh) attached to this node (rootNode)
31.03.2009 23:15:38 class test.MyTestMeshLoading start()
SEVERE: Exception in game loop
java.lang.IllegalArgumentException
   at java.nio.Buffer.position(Unknown Source)
   at
...




Check your vertex assignments in your modeling program and make sure each one is assigned to NO more than ONE bone.

Additional have a look here:



http://www.ogre3d.org/wiki/index.php/Tools:_Blender



There are some helpful suggestions about the export. Somewhere in the net is a blender-script that recalculates the weights so that one vertex is in influence of maximum four bones.(sadly I don't find it at the moment)



Good luck :smiley:

cv459 said:

I get this exception:


INFO: Child (OgreMesh) attached to this node (rootNode)
31.03.2009 23:15:38 class test.MyTestMeshLoading start()
SEVERE: Exception in game loop
java.lang.IllegalArgumentException
   at java.nio.Buffer.position(Unknown Source)
   at
...



Recently a patch was applied that should fix this issue. Please update from SVN and try again!

Yeah…congratulations that this bug is fixed now… :smiley:



EDIT:

Tested it with two new models of me and works perfectly for me…GJ



Recently a patch was applied that should fix this issue. Please update from SVN and try again!


Thanks momoko_fan.  Works for me also.  XD