فهرست منبع

Fixed issue with parsing tags in .scene file for nested nodes.

sgrenier 12 سال پیش
والد
کامیت
d15a5bab08
2فایلهای تغییر یافته به همراه20 افزوده شده و 7 حذف شده
  1. 18 7
      gameplay/src/SceneLoader.cpp
  2. 2 0
      gameplay/src/SceneLoader.h

+ 18 - 7
gameplay/src/SceneLoader.cpp

@@ -94,15 +94,10 @@ Scene* SceneLoader::loadInternal(const char* url)
         SceneNodeProperty::TRANSLATE);
     applyNodeProperties(sceneProperties, SceneNodeProperty::COLLISION_OBJECT);
 
-    // Apply node tags (TODO : update for child nodes)
+    // Apply node tags
     for (size_t i = 0, sncount = _sceneNodes.size(); i < sncount; ++i)
     {
-        SceneNode& sceneNode = _sceneNodes[i];
-        for (std::map<std::string, std::string>::const_iterator itr = sceneNode._tags.begin(); itr != sceneNode._tags.end(); ++itr)
-        {
-            for (size_t n = 0, ncount = sceneNode._nodes.size(); n < ncount; ++n)
-                sceneNode._nodes[n]->setTag(itr->first.c_str(), itr->second.c_str());
-        }
+        applyTags(_sceneNodes[i]);
     }
 
     // Set active camera
@@ -156,6 +151,22 @@ Scene* SceneLoader::loadInternal(const char* url)
     return _scene;
 }
 
+void SceneLoader::applyTags(SceneNode& sceneNode)
+{
+    // Apply tags for this scene node
+    for (std::map<std::string, std::string>::const_iterator itr = sceneNode._tags.begin(); itr != sceneNode._tags.end(); ++itr)
+    {
+        for (size_t n = 0, ncount = sceneNode._nodes.size(); n < ncount; ++n)
+            sceneNode._nodes[n]->setTag(itr->first.c_str(), itr->second.c_str());
+    }
+
+    // Process children
+    for (size_t i = 0, count = sceneNode._children.size(); i < count; ++i)
+    {
+        applyTags(sceneNode._children[i]);
+    }
+}
+
 void SceneLoader::addSceneAnimation(const char* animationID, const char* targetID, const char* url)
 {
     std::string urlStr = url ? url : "";

+ 2 - 0
gameplay/src/SceneLoader.h

@@ -83,6 +83,8 @@ private:
 
     Scene* loadInternal(const char* url);
 
+    void applyTags(SceneNode& sceneNode);
+
     void addSceneAnimation(const char* animationID, const char* targetID, const char* url);
 
     void addSceneNodeProperty(SceneNode& sceneNode, SceneNodeProperty::Type type, const char* url = NULL, int index = 0);