In ogre-format you can also add user-defined properties(meta-data) to scene-objects.
e.g. in blender you can select an object swtich to LogicView(F4) and add a property
(STRING,FLOAT,TIME,BOOL,INT)
In the scene-xml you can find it here:
* <scene formatVersion="1.0.0">
* <nodes>
* <node>
* …
* <userData>
* <property type="STRING" name="specialName" data="xyz"/>
* <property type="FLOAT" name="prop" data="0.0"/>
* <property type="BOOL" name="prop1" data="1"/>
* <property type="INT" name="prop2" data="0"/>
* <property type="TIME" name="prop3" data="3.0"/>
* </userData>
* </node>
* </scene>
That tag was not implemented yet. To do so I created a specialized DotScene-Object that extends com.jme.scene.Node and has a HashMap for collecting the properties. After the scene is loaded you can
access the data via the corresponding dotScene-node's getUserProperty(String name)-Method
Here the new class:
package com.jmex.model.ogrexml;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import com.jme.scene.Node;
public class DotSceneNode extends Node{
/**
*
* DotSceneNode for ogre dotscene files
*
* Adds user defined properties to scene-objects that can be exported
* by the OgreScene-Exporter
*
* There a 5 different types that are mapped to Java-Wrappers:
* STRING->String
* FLOAT->Float
* TIME->Float
* BOOL->Boolean
* INT->Integer
*
* (e.g. blender:
* - LogicPanel(F4)->Add Property
* - select LogicProperties in OgreScene-Exporter
* )
*
* It can be found in the dotscene.xml - file:
*
* <scene formatVersion="1.0.0">
* <nodes>
* <node>
* ...
* <userData>
* <property type="STRING" name="specialName" data="xyz"/>
* <property type="FLOAT" name="prop" data="0.0"/>
* <property type="BOOL" name="prop1" data="1"/>
* <property type="INT" name="prop2" data="0"/>
* <property type="TIME" name="prop3" data="3.0"/>
* </userData>
* </node>
* </scene>
*
* @author Thomas Trocha (thomas.trocha (at) gmail.com)
*
*/
private static final long serialVersionUID = 1L;
private HashMap<String,Object> userProperties;
public DotSceneNode() {
super();
userProperties = new HashMap<String, Object>();
}
public DotSceneNode(String name) {
super(name);
userProperties = new HashMap<String, Object>();
}
protected void addUserProperty(String key,Object value)
{
userProperties.put(key, value);
}
/**
*
* get user-defined property
*
* @param key
* @return
*/
public Object getUserProperty(String key)
{
return userProperties.get(key);
}
public Set<String> getUserPropertyKeys()
{
return userProperties.keySet();
}
}
Here the patch for SceneLoader.java
Index: src/com/jmex/model/ogrexml/SceneLoader.java
===================================================================
--- src/com/jmex/model/ogrexml/SceneLoader.java (revision 4366)
+++ src/com/jmex/model/ogrexml/SceneLoader.java (working copy)
@@ -276,10 +276,45 @@
lightNode = childNode;
}
} else if (tagName.equals("node")) {
- com.jme.scene.Node newNode = new com.jme.scene.Node();
+ DotSceneNode newNode = new DotSceneNode();
loadNode(newNode, childNode); // This is the recurse!
targetJmeNode.attachChild(newNode);
- } else if (!(childNode instanceof Text)) {
+ }
+ else if (tagName.equals("userData"))
+ {
+ NodeList props = childNode.getChildNodes();
+ for (int j=0;j<props.getLength();j++)
+ {
+ Node propNode = props.item(j);
+ tagName = propNode.getNodeName();
+ if (tagName.equals("property"))
+ {
+ String propType = getAttribute(propNode, "type");
+ String propKey = getAttribute(propNode,"name");
+ String propValue = getAttribute(propNode,"data");
+ Object property;
+ if (propType.equalsIgnoreCase("FLOAT") || propType.equalsIgnoreCase("TIME"))
+ {
+ property = new Float(propValue);
+ }
+ else if (propType.equalsIgnoreCase("BOOL"))
+ {
+ property = new Boolean(propValue);
+ }
+ else if (propType.equalsIgnoreCase("INT"))
+ {
+ property = new Integer(propValue);
+ }
+ else
+ {
+ property = new String(propValue);
+ }
+ ((DotSceneNode)targetJmeNode).addUserProperty(propKey, property);
+ }
+ System.out.println(tagName);
+ }
+ }
+ else if (!(childNode instanceof Text)) {
logger.warning("Ignoring unexpected element '" + tagName
+ "' of type " + childNode.getClass().getName());
}
Actually that would be the first time I will comit something….so I will have to ask for write access!