0

I'm getting mixed results trying to render a basic alien that was done in Blender:

enter image description here

I export in to Ogre 3D and load it in Eclipse:

enter image description here

Then when I load it in my code and try to render it the material won't render:

enter image description here

Could you tell me what I must do to achieve the full alien in my scene? The code I use in Jmonkeyengine is

    Spatial model3 = assetManager
            .loadModel("objects/creatures/alien/alien.mesh.xml");
    model3.scale(0.3f, 0.3f, 0.3f);
    model3.setLocalTranslation(-40.0f, 3.5f, -20.0f);
    rootNode.attachChild(model3);

Update

I've got material files like these from the export:

dev@dev-OptiPlex-745:~$ ls workspace/DungeonWorld2/assets/objects/creatures/alien/
alien.mesh          Material.002.material  Material.005.material
alien.mesh.xml      Material.003.material
alien.skeleton.xml  Material.004.material
dev@dev-OptiPlex-745:~$ 

This material code actually produces a material in the scene but it's not the one from blender:

model3.setMaterial( new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md") );

Result:

enter image description here

However, loading a 3D model of an alephant without defining the material does work:

Spatial elephant = (Spatial) assetManager.loadModel("Models/Elephant/Elephant.mesh.xml");
float scale = 0.05f;
elephant.scale(scale,scale,scale);
elephant.setLocalTranslation(-50.0f, 3.5f, -20.0f);

    control = elephant.getControl(AnimControl.class);
    control.addListener(this);
    channel = control.createChannel();

    for (String anim : control.getAnimationNames())
        System.out.println("elephant can:"+anim);

The above code correctly renders the elephant so why can't I export a mesh like that for the alien? I tried to explcitly load the material but it's not working for me:

    Spatial model3 = assetManager
            .loadModel("objects/creatures/alien/alien.mesh.xml");
    model3.scale(0.3f, 0.3f, 0.3f);
    model3.setLocalTranslation(-40.0f, 3.5f, -20.0f);
    model3.setMaterial( new Material(assetManager,  
            "objects/creatures/alien/alien.material") );
    rootNode.attachChild(model3);

The above generates an exception and I don't really know what material file it is that I'm loading and what do to with the two or three other material files that the export generated:

java.lang.ClassCastException: com.jme3.material.MaterialList cannot be cast to com.jme3.material.MaterialDef
    at com.jme3.material.Material.<init>(Material.java:116)
    at adventure.Main.simpleInitApp(Main.java:309)
    at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)
    at java.lang.Thread.run(Thread.java:679)

Update

Loading other models this way is working:

    BlenderKey blenderKey = new BlenderKey(
            "objects/creatures/troll/troll.mesh.xml");

    Spatial troll = (Spatial) assetManager.loadModel(blenderKey);
    troll.setLocalTranslation(new Vector3f(-145, 15, -10));
    rootNode.attachChild(troll);

    BlenderKey blenderKey2 = new BlenderKey(
            "objects/creatures/spaceman/man.mesh.xml");

    Spatial man = (Spatial) assetManager.loadModel(blenderKey2);
    man.setLocalTranslation(new Vector3f(-140, 15, -10));
    rootNode.attachChild(man);

I get the models inside my game and they look alreight, both the troll and the spaceman that both originally were .blend files. enter image description here

Now it's much better when I did it over and it is loading the material. The only problem with the alien left now is the holes in the head that was also answered here.

    BlenderKey blenderKey = new BlenderKey(
            "objects/creatures/alien/alien.mesh.xml");

    Spatial alien = (Spatial) assetManager.loadModel(blenderKey);
    alien.setLocalTranslation(new Vector3f(-145, 15, -10));
    rootNode.attachChild(alien);

enter image description here

Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
  • 1
    Look at your *.material files to find out what material names do you really have. It's strange you got so many of them... And don't use a material file name, but the name from inside of the file. – kolenda Jul 30 '12 at 19:54
  • I tried with some other models and it worked. I think there might be some mistake with this model. I could export 2 other models to OgreXML with one material and skeleton per mesh and that worked perfectly to load in jme3. If I learn more Blender I might be able to modify the alien model to one that jme3 can load or I can select some other model to practice on. – Niklas Rosencrantz Jul 30 '12 at 23:39
  • Success! I now can load the alien material. But I also need to fix the doublesided rendering to get rid of the holes on the head. I don't know which geometry to use. – Niklas Rosencrantz Jul 31 '12 at 00:11

1 Answers1

1

You didn't write anything about your material - did you write one and used it correctly? The problem you get seems to be the lack of material to me.

In general you'll need some *.material file and probably some textures (if you used them in Blender). For the beginning you can use one of the materials that come with Ogre, you'll just need to add:

model3.setMaterialName( "Examples/Rockwall" );

Then look if it changes anything. If you still get the problem you can look into 'Ogre.log' file - it's always worth checking because all the errors goes there.


I also see the second problem here - you render the object as 'one sided' while blender probably render is as two-sided mesh, so you get the holes on the head. You can select in the material to be two sided, but it's better (and faster during rendering) to just create your models without the holes :).

kolenda
  • 2,741
  • 2
  • 19
  • 30
  • Thank you for the answer. I suspect it is something with my export that doesn't generate a material file the way it should. I'll look more into how the files are actually exporter to try and solve this. – Niklas Rosencrantz Jul 26 '12 at 12:36
  • I've updated the question with info about the material files. The instruction `model3.setMaterialName( "Examples/Rockwall" );` does not compile with jmonkeyengine, I must look there for how to do it. Many thanks for the help! – Niklas Rosencrantz Jul 28 '12 at 02:02
  • 1
    Do you use any textures in the material and added them into your assets? Have you checked the Ogre.log file for errors? – kolenda Jul 30 '12 at 15:14
  • I don't use texture for these tests to reduce the number of events that could go wrong. I can export a simple cube and more advanced objects but I can only load one mesh in jmonkeyengine. I absolutely will check the Ogre.log for what is says and update the question with more details, giving this another go after having given up on this use case for a couple of days. I'm looking at alternatively load the .blend model from jomonkeyengine but I can't do that either and I also don't know how to make j3m binary format so there are two more ways to go that I want to learn. – Niklas Rosencrantz Jul 30 '12 at 16:33
  • Thanks for all the help. Now it's much better. I had success now loading the model in jme3 as can be seen from the update. The only remaining problem is that I get the holes on the head which I understand can be fixed by making the material doublesided, but I don't know how to do that. I can do a `setMaterial`but there is no ´getMaterial` for Nodes or Spatial so I must get it from a geometry somehow and I don't know how to get the geometry for the alien. – Niklas Rosencrantz Jul 31 '12 at 07:14
  • 1
    I'm glad you managed it. But don't try to make alien material doublesided - in this case you'll get problems with lighting, just later. All you need to do is to edit alien model in Blender to add polygons where you have holes now. – kolenda Jul 31 '12 at 08:12
  • Many thanks for all the help! This really was some great steps forward for my development that I now actually can load 3D materials from blender. Soon I might be able to do an actual scene and then I might be able to make more of a game that I want. – Niklas Rosencrantz Jul 31 '12 at 09:18
  • @kolenda are you JMonkeyEngine expert ? – Mihir Jul 22 '13 at 04:20
  • @Mihir - I never used JMonkey, but I played a bit with Ogre and C++ so I remember few things.. :) – kolenda Jul 29 '13 at 08:11