IllegalArgumentException when trying to do HelloCollision tutorial with custom scene

Hey guys,



I tried to to HelloCollision tutorial with a custom scene (3 simple meshes with 3 different textures). The default town.zip example loads and plays fine. However, when I try to replace town scene with my own I get this:



[java]SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.IllegalArgumentException

at java.nio.ByteBuffer.allocate(Unknown Source)

at com.jme3.bullet.util.Converter.convert(Converter.java:224)

at com.jme3.bullet.collision.shapes.MeshCollisionShape.createCollisionMesh(MeshCollisionShape.java:70)

at com.jme3.bullet.collision.shapes.MeshCollisionShape.<init>(MeshCollisionShape.java:65)

at com.jme3.bullet.util.CollisionShapeFactory.createSingleMeshShape(CollisionShapeFactory.java:174)

at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:65)

at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:62)

at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:62)

at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:62)

at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:85)

at com.jme3.bullet.util.CollisionShapeFactory.createMeshCompoundShape(CollisionShapeFactory.java:94)

at com.jme3.bullet.util.CollisionShapeFactory.createMeshShape(CollisionShapeFactory.java:134)

at jme3test.helloworld.HelloCollision.simpleInitApp(HelloCollision.java:61)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:218)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:136)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:193)

at java.lang.Thread.run(Unknown Source)[/java]



Which seems to be caused by the call to CollisionShapeFactory’s createMeshShape method in this:

[java] assetManager.registerLocator(“level.zip”, ZipLocator.class.getName());

sceneModel = assetManager.loadModel(“level.scene”);

sceneModel.setLocalScale(2f);



// We set up collision detection for the scene by creating a

// compound collision shape and a static physics node with mass zero.

CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) sceneModel);[/java]





My scene loads and displays perfectly fine if I remove any code associated with collision detection (I am even able to fly around the scene and observe the model).



Any help is greatly appreciated!

Make sure your meshes only consist of triangles.

From the looks of it in jMP mesh only view there are triangles only (it’s a really simple mesh). Are you saying that some faces might be squares or there are loose vertices somewhere?

Yes, the physics will only work properly with triangle meshes. Rogue vertexes and strip fans etc. will make it go haywire.

Ok, the mesh is literally 2 triangles now (6 vertices). Still the same problem :frowning: Also, submeshes consist of of faces, and each face only has 3 vertices. Where do loose vertices come from then?

Try making single MeshCollisionShapes from each mesh in the model and see which one fails.

Yep. Tried all that. Scene now includes one mesh only, which is just a triangle (3 vertices). Still same problem.

No, I mean don’t use the factory. How do you import your meshes? Blender 2.49 + OgreXML exporter that comes with jMP?

Nope. Blender 2.56a + blender2ogre 0.3.0.

Took me a while to actually get models to load in jMP first. (more here. That one was fixed REALLY fast. After you sent me the link to source code, I went to look in parser code only to find the fix was submitted an hour ago:)). Is there code example for single MeshCollisionShape usage?

Oh, well it might be theres a quirk in that import path that makes the mesh incompatible to jbullet (can happen even if the model displays fine in jME) Creating a MeshCollisionShape from a mesh is not so hard… new MeshCollisionShape(mesh) :stuck_out_tongue:

RIght. But where do I get mesh object from? Can I create a mesh from my model?

geometry.getMesh()

To access a geometry in a loaded model, look at the structure in jMP and note the names of the geometry, then access like this:

[snippet id=“13”]

Ugh… Looks like it didn’t like my mesh.xml schema. I had to reformat it to conform with the schema presented in town example. Should I even bother going further with Blender 2.56a + blender2ogre 0.3.0? Are there plans to make parsers account for different schemas?

The recommended import path is the one I mentioned, we will migrate/update to blender 2.5 and the corresponding export scripts when both are stable.

ok , i need somehelp from you :smiley:

i’m new in this and i need u to tell me a hint or anything about how to make my own scene :smiley:

ahmed7 said:
ok , i need somehelp from you :D
i'm new in this and i need u to tell me a hint or anything about how to make my own scene :D


Did you test The Warlock?
http://hub.jmonkeyengine.org/2011/04/01/warlock-one-click-mmo-creator-the-only-plugin-you-will-ever-need/
It's incredibly handy....