Importing Milkshape Animation?

Hello guys!


I'm newbie, so there's 90% of chance that I'm doing something stupidly wrong.

So, I decided to make a simple animated model to work with in jME. I've tried Blender, but in my opinion, it's too advanced for a beginner. So, I've tried Milkshape in my friend's house and It was pretty good! So I made a model and animated it using bones. I don't know if it was the correct format to export my model, but I've used .obj Trying to load it with the exact same code from TestObjLoading.java which works, by the way. But it gives me an error:

[java]java.lang.ClassCastException: com.jme3.scene.Node cannot be cast to com.jme3.scene.Geometry
at net.thirdperson.TestMilkshapeAnim.simpleInitApp(TestMilkshapeAnim.java:25)
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(Thread.java:662)[/java]

I know that an .obj object can't have anims in it, so my model is supposed to be working, right?
P.S.: I imported my .obj model in milkshape and it says that it has no bones either anims. So this confirms what I've said before.

And another question, how can I export my Milkshape anims into jME?

Thanks in advance, borba. :P


The problem was solved, now I'm looking a way to import my Milkshape Animation to jME.

The error is in your code, you try to cast the loaded Spatial to a Geometry but its a Node.

Thanks for your reply, normen.



TestObjLoading.java:

[java]public void simpleInitApp() {

// create the geometry and attach it

Geometry teaGeom = (Geometry) assetManager.loadModel(“Models/Teapot/Teapot.obj”);



// show normals as material

Material mat = new Material(assetManager, “Common/MatDefs/Misc/ShowNormals.j3md”);

teaGeom.setMaterial(mat);



rootNode.attachChild(teaGeom);

}[/java]



My code:



[java]public void simpleInitApp() {

// create the geometry and attach it

Geometry charGeom = (Geometry) assetManager.loadModel(“Models/char.obj”);



// show normals as material

Material mat = new Material(assetManager, “Common/MatDefs/Misc/ShowNormals.j3md”);

charGeom.setMaterial(mat);



rootNode.attachChild(charGeom);

}[/java]



The code it’s almost the same.

Read the error log, in line 25 you try to cast a Node to a Geometry. Also dont set that showNormals material, you wont see the original material then.

Sorry normen, but can’t understand what you’re saying.



Why the same code runs with teapot.obj model and with char.obj model it doesn’t work? I can’t understand it.


java.lang.ClassCastException: com.jme3.scene.Node cannot be cast to com.jme3.scene.Geometry
net.thirdperson.TestMilkshapeAnim.simpleInitApp(TestMilkshapeAnim.java:25)


You can argue all the way you want, the error happens... Whats in this line 25? Can you please post it.

Duh, change the code to:

[java]public void simpleInitApp() {

// create the geometry and attach it

Node charGeom = (Node) assetManager.loadModel("Models/char.obj");



rootNode.attachChild(charGeom);

}[/java]

your problem is, the “teapot.obj” in the example consists of one model but your own model obviously consists of more than one models. So it’s loaded as a Node (which is nothing more than a group/tree of models) and you can’t cast this to Geometry, because it’s no subclass of Geometry (Geometry represents exact one model).

Thanks normen, I understand now what you were saying :slight_smile:



And now, how can I import my animation from Milkshape?

We had so many posts about this example, I would go as far as to say its a trap that we cast it to a Geometry and not a Spatial. :stuck_out_tongue:

Momoko_Fan said:
We had so many posts about this example, I would go as far as to say its a trap that we cast it to a Geometry and not a Spatial. :P

And the showNormals material is also creeping up every now and then ;)