Features of blender importer

mifth said:
sorry, what is "cast"? o you mean to use DesktopAssetManager?

[java]
DesktopAssetManager dam = (DesktopAssetManager)assetManager;
dam.clearCache();
[/java]
:roll:?

Edit: http://www.tutorialspoint.com/java/java_polymorphism.htm
1 Like

WOW! thanks!!! It seems it works.

Just want to say THANKS again for the blender loader and add my scene loader to this topic. You can load any models with unique names.



[java]

package basic_examples;







/*You can get transforms from *.blend files and use your models for it.

  • Blender could be used as a World Editor or scene composer.
  • Names of JME objects and blend objects should be like:
  • JME names - Box, Sphere
  • blend names - Box, Box.000, Box.001, Box.002… Sphere, Sphere.000, Sphere.001…

    /





    import com.jme3.app.SimpleApplication;

    import com.jme3.asset.BlenderKey;

    import com.jme3.asset.DesktopAssetManager;

    import com.jme3.material.Material;

    import com.jme3.math.
    ;

    import com.jme3.scene.;

    import com.jme3.scene.Node;

    import com.jme3.scene.shape.
    ;





    public class blender_scene_composer extends SimpleApplication {



    Geometry geom_a;

    Geometry geom_b;

    Node ndmd;





    public static void main(String[] args) {

    blender_scene_composer app = new blender_scene_composer();

    app.start();

    }



    public void Models () {



    //Create an empty node for models

    ndmd = new Node("Models");



    // Create a box Geometry

    Box box_a = new Box(Vector3f.ZERO, 1, 1, 1);

    geom_a = new Geometry("Box", box_a);

    geom_a.updateModelBound();

    Material mat_box = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    mat_box.setColor("m_Color", ColorRGBA.Blue);

    geom_a.setMaterial(mat_box);

    ndmd.attachChild(geom_a);



    // Create a sphere Geometry

    Sphere sphr_a = new Sphere(10, 10, 1);

    geom_b = new Geometry("Sphere", sphr_a);

    geom_b.updateModelBound();

    Material mat_sphr = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    mat_sphr.setColor("m_Color", ColorRGBA.Red);

    geom_b.setMaterial(mat_sphr);

    ndmd.attachChild(geom_b);



    }







    @Override

    public void simpleInitApp() {



    Models();





    // Load a blender file.

    DesktopAssetManager dsk = (DesktopAssetManager) assetManager;

    BlenderKey bk = new BlenderKey("Models/blender_test_scene/blender_test_scene.blend");

    Node nd = (Node) dsk.loadAsset(bk);



    //Create empty Scene Node

    Node ndscene = new Node("Scene");



    // Get Names and Transforms of Objects from the blend file

    for (int i=0; i<nd.getChildren().size(); i++) {



    Node ndempty = new Node(nd.getChild(i).getName());



    ndempty.setLocalTransform(nd.getChild(i).getLocalTransform());

    ndscene.attachChild(ndempty);



    // System.out.print(ndscene.getChild(i).getName());

    // System.out.println(ndscene.getChild(i).getLocalTransform());

    }



    // Attach boxes with names and transformations of the blend file to a Scene



    for (int j=0; j<ndmd.getChildren().size();j++){

    String strmd = ndmd.getChild(j).getName();



    for (int i=0; i<ndscene.getChildren().size(); i++) {



    String strndscene = ndscene.getChild(i).getName();

    if (strmd.length() < strndscene.length()) strndscene = strndscene.substring(0, strmd.length());





    if (strndscene.equals(strmd) == true){

    Node ndGet = (Node) ndscene.getChild(i);

    ndGet.attachChild(ndmd.getChild(j).clone());



    }

    }

    }



    rootNode.attachChild(ndscene);



    // Clear Cache

    nd.detachAllChildren();

    nd.removeFromParent();

    dsk.clearCache();





    flyCam.setMoveSpeed(30);







    }





    }



    [/java]







    And another question is: HOW TO LOAD ONLY MODELS FROM BLENDER? I mean only meshes without materials and textures…

    I just think if the scene will be with 100000 of objects, so there will be too much data(textures, materials, meshes) to load.

Here is a screenshot for the blender scene composer.





http://imageshack.us/photo/my-images/585/ee1r.jpg/







Uploaded with ImageShack.us

1 Like

Really nice :D. Just a tip, avoid using ā€œ_ā€ for attributes and class names, It’s not a good practise…

For example :

Instead : ā€œblender_scene_composerā€

Use: ā€œBlenderSceneComposerā€ā€¦

1 Like

hm, I’m still not able to load animations properly (using the latest svn-checkout).



If I use the BlenderLoader, the resultSet doesn’t contain any animation. With the BlenderModelLoader I’m getting a null-pointer-exception because of a bone with a null-name (the strange thing is, that this bone doesn’t exist in my scene. The Loader always loads one bone more than I have created). Also I wasn’t able to load the animation with the ManualBlenderTester-class from the test-package.



I’m using blender 2.58. The animation is made of an armature which bones are asigned to a vertGroup.



Is there a testcase for explicit animation loading?

The animations may not work 100% properly yet.

Sorry about that.

I’m currently finishin my work with textures which is most urgent at the moment.

But after I’m done with that I’ll switch to animations.



Probably some things changed in jme in animations and were not updated in blender loader.

But textures goes first at the moment :wink:

Hello, thanks very much for this help! I’m still having trouble understanding how this all works, so small question; in the first line:



assetManager.registerLocator(ā€œblender/file/pathā€, ChosenLocatorClass.class);



I take it ā€œblender/file/pathā€ is the location where all your model files are saved? Secondly, what is the ChosenLocatorClass supposed to be?

For the nightly version of jme3 the blender loader is already registered, you can simply load models like

[java]Spatial spat = assetManager.loadModel("Models/MyModel.blend");[/java]

Note however that the blend format is less than ideal for distribution and you should convert the models to j3o format using e.g. the jMonkeyEngine SDK.

Thanks for the answer Normen. I’ve tried using this method, and it throws a NullPointerException: The pointer points to nothing. Here’s the first part of the error stack:

java.lang.NullPointerException: The pointer points to nothing!

at com.jme3.scene.plugins.blender.file.Pointer.fetchData(Pointer.java:92)

at com.jme3.scene.plugins.blender.meshes.MeshHelper.getVertices(MeshHelper.java:548)

at com.jme3.scene.plugins.blender.meshes.MeshHelper.toMesh(MeshHelper.java:120)



Now naturally this means something is invalid in the .blend file, but could anyone give some advice as to where to find the problem or how to solve it? Our modeller is still learning the ropes too, so I don’t think he’ll know the answer himself.

I have problems loading scenes with BlenderLoader. I tried the following:



[java]

assetManager.registerLoader(BlenderLoader.class, ā€œblendā€);

LoadingResults level = (LoadingResults) assetManager.loadModel(ā€œlevels/00/00/00_00.blendā€);



for (Spatial scene : level.getScenes())

rootNode.attachChild(scene);



for (Light l : level.getLights())

rootNode.addLight(l);

[/java]



But this gives me an empty scene. (The file only has one single scene, in case you are wondering.) From jME’s output, it seems that no object is ever added to the ā€œSceneā€ node. The following works:



[java]

assetManager.registerLoader(BlenderLoader.class, ā€œblendā€);

LoadingResults level = (LoadingResults) assetManager.loadModel(ā€œlevels/00/00/00_00.blendā€);



for (Spatial object : level.getObjects())

rootNode.attachChild(object);



for (Light l : level.getLights())

rootNode.addLight(l);

[/java]



(I don’t want to use that version as I fear that this breaks parenting relationships between objects.)

OK I’ll check this out.

Maybe I’ve missed something during attaching nodes to the scene :slight_smile:

OK,

I’ve made some changes and bugfixing.



Try now to load the scene and let me know if it worked :wink:

Nice work! Tested this a little, unfortunately having some problems with texturing:

I can texture blender’s (2.59) default cube, and its duplicates (using Shift+D) with different textures and these works. But if I create new object and texture it, that texture doesnt show up in my jme3 test.

I load my scene just using

[java]

Spatial scene = assetManager.loadModel(ā€œModels/test.blendā€);

rootNode.attachChild(scene);

[/java]

Oops, my bad, I forgot to add MATERIALS to new objects (I just drag’n’dropped TEXTURES to them). Now I can see my beautiful couch scene with textures :slight_smile:

I have the problem, that my imported blender models, don’t receive any ambient light. Maybe there’s a setting somewhere that I have missed. I’ve tried different material shading and texture influence settings and ambient color in the world dialog as well. An .obj file works fine if I set an ambient color in the blender world panel. I am using Blender 2.59 and the latest nightly of the monkey SDK.

My .blend scenes does not render right any more, some objects have wrong positions and rotations (I have updated jme & jmp+plugins).

Big thanks so far, I’ve really been waiting for something like this. However I’m facing some problems.


  • I tried to assign a bump map material to a cube (1 material, which has 2 textures - one for color, one of heights). But jme tells me that only the first texture could be loaded. Is this not supported or did I do something wrong?


  • I added the blender monkey to the scene and rotated it, but in my game the mesh was still in its default position(rotation).


  • Last thing, I tried to do a simple animation: rotating a cube. I inserted a keyframe, then another one and rotated it. But it seems that the LoadingResults didnt contain this animation. Again, is this kind of animation not supported or did I do sth wrong?



    PS: Im very noob in blender and still pretty unexperienced in jme. So I may missed some basic stuff.

Hello,

I have some problems importing blender models.

In blender I have a textured object without UV problems.



I put the blender file in my assets/models folder and the jpg texture file in the assets/testures folder.

Then I used the code

[java]

Spatial sofa = assetManager.loadModel(ā€œModels/CanapĆ© 3D-Ressources.blendā€);

Material mat_sofa = new Material(

assetManager, ā€œCommon/MatDefs/Misc/Unshaded.j3mdā€);

mat_sofa.setTexture(ā€œColorMapā€,

assetManager.loadTexture(ā€œTextures/tissu.jpgā€));

sofa.setMaterial(mat_sofa);

rootNode.attachChild(sofa);

[/java]

I obtain in jme my object with bad UV.





What do I have to do?



Thanks.

SOrry, the two images were :

blender :

an djme :