[PATCH] OgreMax dotScene loading

The JME ogre scene loader fails to load scene files exported with the OgreMax dotScene exporter for Maya.



Here is a sample scene I was testing with.



There were a few issues.

  • It doesn't have an externals section so materialList is null

  • The environment section is before the nodes tag, so the root node is null when we set an ambient light - so I set root when we parse the scene tag.

  • The environment element has a clipping subelement, not just camera.

  • The camera element has a rotation subelement, not just nodes.


[patch]diff --git a/engine/src/ogre/com/jme3/scene/plugins/ogre/SceneLoader.java b/engine/src/ogre/com/jme3/scene/plugins/ogre/SceneLoader.java
index 19df402..3a38ae3 100644
--- a/engine/src/ogre/com/jme3/scene/plugins/ogre/SceneLoader.java
+++ b/engine/src/ogre/com/jme3/scene/plugins/ogre/SceneLoader.java
@@ -340,10 +340,6 @@ public class SceneLoader extends DefaultHandler implements AssetLoader {
logger.log(Level.WARNING, "Unrecognized version number"
+ " in dotScene file: {0}", version);
}
- } else if (qName.equals("nodes")) {
- if (root != null) {
- throw new SAXException("dotScene parse error: nodes element was specified twice");
- }
if (sceneName == null) {
root = new com.jme3.scene.Node("OgreDotScene" + (++sceneIdx));
} else {
@@ -390,8 +386,9 @@ public class SceneLoader extends DefaultHandler implements AssetLoader {
checkTopNode("node");
parseCamera(attribs);
} else if (qName.equals("clipping")) {
- checkTopNode("camera");
- parseCameraClipping(attribs);
+ if (elementStack.peek().equals("camera")) {
+ parseCameraClipping(attribs);
+ }
} else if (qName.equals("position")) {
if (elementStack.peek().equals("node")) {
node.setLocalTranslation(SAXUtil.parseVector3(attribs));
@@ -399,7 +396,11 @@ public class SceneLoader extends DefaultHandler implements AssetLoader {
cameraNode.setLocalTranslation(SAXUtil.parseVector3(attribs));
}
} else if (qName.equals("quaternion") || qName.equals("rotation")) {
- node.setLocalRotation(parseQuat(attribs));
+ if (elementStack.peek().equals("node")) {
+ node.setLocalRotation(parseQuat(attribs));
+ } else if (elementStack.peek().equals("camera")) {
+ cameraNode.setLocalRotation(parseQuat(attribs));
+ }
} else if (qName.equals("scale")) {
node.setLocalScale(SAXUtil.parseVector3(attribs));
} else if (qName.equals("light")) {
@@ -496,7 +497,7 @@ public class SceneLoader extends DefaultHandler implements AssetLoader {
// == Run 1st pass over XML file to determine material list ==
materialList = materialLoader.load(assetManager, folderName, info.openStream());

- if (materialList.isEmpty()) {
+ if (materialList == null || materialList.isEmpty()) {
// NOTE: No materials were found by searching the externals section.
// Try finding a similarly named material file in the same folder.
// (Backward compatibility only!)
[/patch]
2 Likes