Getting userData from exported scene from Blender

Hi monkeys!

I have a problem with userdata and I need your help. Here is the situation:

I have a test scene with cubes and objects in it in Blender 2.69. I really just created some random objects for test purposes. I added userdata to the red cube called “redCube” in the Logic View and also in the Object Panel > Custom Properties. The image illustrates it:

Imgur

I exported the scene with OGRE Exporter which I installed via the SDK.

Here is the result .scene file’s contents. I stripped out the unimportant parts.
[java]<scene previous_export_time=“1392239819.8201144” formatVersion=“1.0.1” exported_by=“kruze” export_time=“1392240274.2753677” >
<nodes >

&lt;node name="redCube" &gt;
  &lt;position z="-28.775600" y="7.885125" x="0.249756" /&gt;
  &lt;rotation qz="-0.000000" qy="-0.069656" qx="0.000000" qw="0.997571" /&gt;
  &lt;scale z="1.000000" y="1.000000" x="1.000000" /&gt;
  &lt;user_data type="str" value="still happy" name="customData" /&gt;
  &lt;user_data type="str" value="happy" name="logicData" /&gt;
  &lt;game &gt;
    &lt;sensors /&gt;
    &lt;actuators /&gt;
  &lt;/game&gt;
  &lt;entity mass_radius="1.0" velocity_min="0.0" ghost="False" physics_type="STATIC" anisotropic_friction="False" inertia_tensor="0.4000000059604645" meshFile="Plane.002.mesh" velocity_max="0.0" mass="1.0" lock_trans_y="False" lock_trans_x="False" lock_trans_z="False" actor="False" name="Plane.002" damping_trans="0.03999999910593033" damping_rot="0.10000000149011612" lock_rot_z="False" lock_rot_x="False" lock_rot_y="False" friction_z="1.0" friction_y="1.0" friction_x="1.0" /&gt;
&lt;/node&gt;

</nodes>
<externals >
<item type=“material” >
<file name="/media/disk/source/maps/testzero/export/red.material" />
</item>
<item type=“material” >
<file name="/media/disk/source/maps/testzero/export/empty.material" />
</item>
</externals>
<environment >
<colourDiffuse r=“0.05087608844041824” g=“0.05087608844041824” b=“0.05087608844041824” />
<colourBackground r=“0.05087608844041824” g=“0.05087608844041824” b=“0.05087608844041824” />
<colourAmbient r=“0.0” g=“0.0” b=“0.0” />
</environment>
</scene>[/java]

It look like both the Logic Data properties and Custom Properties user data ended in a user_data node.

I’m trying to get the userdata from the code as follows:
[java]
// Loads my scene file
Node scene = (Node)assetManager.loadModel(getScenePath(sceneName));
Spatial redCube = scene.getChild(“redCube”);
redCube.getUserData(“customData”); // returns null
redCube.getUserData(“logicData”); // returns null
[/java]

I can’t get the userdata from the node redCube because it always returns null.

My question is: Why can’t I get neither of the user datas with the getUserData() function of the node called redCube? What am I doing wrong?

Here is the link for the image. It doesn’t show up for me in the post, so I just post the link to it.
Imgur

Idk if the importer fully translates the tags, does it work when you import the blend file directly?

@normen said: Idk if the importer fully translates the tags, does it work when you import the blend file directly?

Thank you for the quick response.

I just tried loading the blend file directly. (Ugly code I know…)
[java]
LoadingResults scene = (LoadingResults)assetManager.loadModel(MAP_PATH.replace("%s", meshName) + “.blend”);
Iterator<Node> it = scene.getObjects().iterator();

    while(it.hasNext()) {
        Node n = it.next();
        world.attachChild(n);
    }
    
    Spatial cube = world.getChild("redCube");
    
    System.out.println(cube.getName());
    System.out.println(cube.getUserData("customData"));
    System.out.println(cube.getUserData("logicData"));

[/java]

Results:
[java]
redCube
still happy
null
[/java]

Loading the scene as a blend file gives me the userdata I set at the Custom Properties panel but returns null to the one set at the Logic Panel.

Should I rely on the blend file for a final build for my application? Or should I use j3o instead?

Still… I’d like to figure out how can I get the userdata from the scene and j3o file. Any ideas?

You can convert the blend file to j3o and open it in the SDK, if theres any UserData you will see it there.

Oh…

I just converted it to j3o, loaded it in the game and I could access the userdata I defined at the Object Panel > Custom Properties section. Thanks for your help Normen!

Last question:

Which way is more accepted or supported by jme3?

  1. Creating scene in blender, exporting it as mesh.xml and converting it to j3o.

OR

  1. Creating scene in blender, saving as blend file, converting blend file to j3o.
@kruze said: Oh...

I just converted it to j3o, loaded it in the game and I could access the userdata I defined at the Object Panel > Custom Properties section. Thanks for your help Normen!

Last question:

Which way is more accepted or supported by jme3?

  1. Creating scene in blender, exporting it as mesh.xml and converting it to j3o.

OR

  1. Creating scene in blender, saving as blend file, converting blend file to j3o.

Well honestly we are in a transition from 1) to 2) :slight_smile:

Ideally you’d store your .blend file where you want your .j3o to be (probably under Models/) and your textures in the folders you want them to be (probably under Textures/), all in the assets folder. This way you can edit the file in blender using the same texture references and the game and SDK find all data because its in the assets folder and you can convert the .blend by simply double-clicking it. The .blend files will be excluded when you distribute the application so you use the j3o files in your application and can still edit the .blend files while you develop your game.

Edit: Check out this example

Yeah, that sounds really great. Then I just stop using the OGRE Exporter and go straight for blend files. Thanks for your help and for the link! =D