@@ -23,7 +23,7 @@ void Scene::addSceneNode(SceneNode* node)
2323}
2424
2525
26- void Scene::fillByXMLNode (pugi::xml_node xml_node)
26+ void Scene::fillByXMLNode (const std::string& path, pugi::xml_node xml_node)
2727{
2828 unit_ = xml_node.attribute (" unit" ).as_string ();
2929
@@ -44,16 +44,54 @@ void Scene::fillByXMLNode(pugi::xml_node xml_node)
4444 setMetaDataEntry (key, value, type, preserve);
4545 }
4646
47+ if (!path.empty ())
48+ {
49+ for (pugi::xml_node object = resources.child (" object" ); object != nullptr ; object = object.next_sibling (" object" ))
50+ {
51+ SceneNode* temp_scene_node = createSceneNodeFromObject (path, xml_node, object);
52+ std::cout << " sub component " << temp_scene_node->getPath () << " :" << temp_scene_node->getId () << std::endl;
53+ scene_nodes_.push_back (temp_scene_node);
54+ }
55+ return ;
56+ }
57+
58+ std::vector<SceneNode*> scene_nodes;
4759 pugi::xml_node build = xml_node.child (" build" );
4860 for (pugi::xml_node item = build.child (" item" ); item != nullptr ; item = item.next_sibling (" item" ))
4961 {
5062 // Found a item in the build. The items are linked to objects by objectid.
63+ SceneNode* temp_scene_node = nullptr ;
5164 pugi::xml_node object_node = resources.find_child_by_attribute (" object" , " id" , item.attribute (" objectid" ).value ());
52- if (object_node != nullptr )
65+
66+ std::string path = item.attribute (" p:path" ).value ();
67+ if (!path.empty ())
68+ {
69+ auto id = item.attribute (" objectid" ).value ();
70+ bool found = false ;
71+ for (auto node : scene_nodes_)
72+ {
73+ if (node->getPath () == path && node->getId () == id)
74+ {
75+ temp_scene_node = new SceneNode ();
76+ temp_scene_node->setMeshData (node->getMeshData ());
77+ temp_scene_node->setTransformation (item.attribute (" transform" ).as_string ());
78+ found = true ;
79+ break ;
80+ }
81+ }
82+ if (!found)
83+ {
84+ std::cout << " sub component not found :( " << path << " :" << id << std::endl;
85+ }
86+ }
87+ else if (object_node != nullptr )
5388 {
54- SceneNode* temp_scene_node = createSceneNodeFromObject (xml_node, object_node);
89+ temp_scene_node = createSceneNodeFromObject (path, xml_node, object_node);
5590 temp_scene_node->setTransformation (item.attribute (" transform" ).as_string ());
91+ }
5692
93+ if (temp_scene_node)
94+ {
5795 // Get all metadata from the item and update that.
5896 const pugi::xml_node metadatagroup_node = item.child (" metadatagroup" );
5997 if (metadatagroup_node != nullptr )
@@ -73,21 +111,23 @@ void Scene::fillByXMLNode(pugi::xml_node xml_node)
73111 }
74112 }
75113
76- scene_nodes_ .push_back (temp_scene_node);
114+ scene_nodes .push_back (temp_scene_node);
77115 }
78116 else
79117 {
80118 // TODO: add proper error handling
81119 std::cout << " Could not find object by given ID" << std::endl;
82120 }
83121 }
122+ scene_nodes.swap (scene_nodes_);
84123}
85124
86- SceneNode* Scene::createSceneNodeFromObject (pugi::xml_node root_node, pugi::xml_node object_node)
125+ SceneNode* Scene::createSceneNodeFromObject (const std::string& path, pugi::xml_node root_node, pugi::xml_node object_node)
87126{
88127 pugi::xml_node components = object_node.child (" components" );
89128 auto * scene_node = new SceneNode ();
90129 scene_node->fillByXMLNode (object_node);
130+ scene_node->setPath (path);
91131
92132 std::map<std::string, std::string>::iterator it;
93133 const bool has_mesh_node = scene_node->getSettings ().find (" mesh_node_objectid" ) != scene_node->getSettings ().end ();
@@ -106,10 +146,33 @@ SceneNode* Scene::createSceneNodeFromObject(pugi::xml_node root_node, pugi::xml_
106146 for (pugi::xml_node component = components.child (" component" ); component != nullptr ; component = component.next_sibling (" component" ))
107147 {
108148 // This node has children. Add them one by one.
149+ std::string path = component.attribute (" p:path" ).value ();
150+ if (!path.empty ())
151+ {
152+ auto id = component.attribute (" objectid" ).value ();
153+ bool found = false ;
154+ for (auto node : scene_nodes_)
155+ {
156+ if (node->getPath () == path && node->getId () == id)
157+ {
158+ auto * child_node = new SceneNode ();
159+ child_node->setMeshData (node->getMeshData ());
160+ child_node->setTransformation (component.attribute (" transform" ).as_string ());
161+ scene_node->addChild (child_node);
162+ found = true ;
163+ break ;
164+ }
165+ }
166+ if (!found)
167+ {
168+ std::cout << " sub component not found :( " << path << " :" << id << std::endl;
169+ }
170+ continue ;
171+ }
109172 pugi::xml_node child_object_node = root_node.child (" resources" ).find_child_by_attribute (" object" , " id" , component.attribute (" objectid" ).value ());
110173 if (child_object_node != nullptr )
111174 {
112- SceneNode* child_node = createSceneNodeFromObject (root_node, child_object_node);
175+ SceneNode* child_node = createSceneNodeFromObject (path, root_node, child_object_node);
113176 if (has_mesh_node && mesh_node_object_id == component.attribute (" objectid" ).as_string ())
114177 {
115178 // Don't add a node with the mesh_node_objectid metadata. Store it until last so we can copy it's mesh to the parent node
0 commit comments