@@ -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,14 +44,26 @@ 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.
5163 pugi::xml_node object_node = resources.find_child_by_attribute (" object" , " id" , item.attribute (" objectid" ).value ());
5264 if (object_node != nullptr )
5365 {
54- SceneNode* temp_scene_node = createSceneNodeFromObject (xml_node, object_node);
66+ SceneNode* temp_scene_node = createSceneNodeFromObject (path, xml_node, object_node);
5567 temp_scene_node->setTransformation (item.attribute (" transform" ).as_string ());
5668
5769 // Get all metadata from the item and update that.
@@ -73,21 +85,23 @@ void Scene::fillByXMLNode(pugi::xml_node xml_node)
7385 }
7486 }
7587
76- scene_nodes_ .push_back (temp_scene_node);
88+ scene_nodes .push_back (temp_scene_node);
7789 }
7890 else
7991 {
8092 // TODO: add proper error handling
8193 std::cout << " Could not find object by given ID" << std::endl;
8294 }
8395 }
96+ scene_nodes.swap (scene_nodes_);
8497}
8598
86- SceneNode* Scene::createSceneNodeFromObject (pugi::xml_node root_node, pugi::xml_node object_node)
99+ SceneNode* Scene::createSceneNodeFromObject (const std::string& path, pugi::xml_node root_node, pugi::xml_node object_node)
87100{
88101 pugi::xml_node components = object_node.child (" components" );
89102 auto * scene_node = new SceneNode ();
90103 scene_node->fillByXMLNode (object_node);
104+ scene_node->setPath (path);
91105
92106 std::map<std::string, std::string>::iterator it;
93107 const bool has_mesh_node = scene_node->getSettings ().find (" mesh_node_objectid" ) != scene_node->getSettings ().end ();
@@ -106,10 +120,33 @@ SceneNode* Scene::createSceneNodeFromObject(pugi::xml_node root_node, pugi::xml_
106120 for (pugi::xml_node component = components.child (" component" ); component != nullptr ; component = component.next_sibling (" component" ))
107121 {
108122 // This node has children. Add them one by one.
123+ std::string path = component.attribute (" p:path" ).value ();
124+ if (!path.empty ())
125+ {
126+ auto id = component.attribute (" objectid" ).value ();
127+ bool found = false ;
128+ for (auto node : scene_nodes_)
129+ {
130+ if (node->getPath () == path && node->getId () == id)
131+ {
132+ auto * child_node = new SceneNode ();
133+ child_node->setMeshData (node->getMeshData ());
134+ child_node->setTransformation (component.attribute (" transform" ).as_string ());
135+ scene_node->addChild (child_node);
136+ found = true ;
137+ break ;
138+ }
139+ }
140+ if (!found)
141+ {
142+ std::cout << " sub component not found :( " << path << " :" << id << std::endl;
143+ }
144+ continue ;
145+ }
109146 pugi::xml_node child_object_node = root_node.child (" resources" ).find_child_by_attribute (" object" , " id" , component.attribute (" objectid" ).value ());
110147 if (child_object_node != nullptr )
111148 {
112- SceneNode* child_node = createSceneNodeFromObject (root_node, child_object_node);
149+ SceneNode* child_node = createSceneNodeFromObject (path, root_node, child_object_node);
113150 if (has_mesh_node && mesh_node_object_id == component.attribute (" objectid" ).as_string ())
114151 {
115152 // 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