| 213 | } |
| 214 | |
| 215 | void XmlSerializer::ImportXml(aiScene *scene) { |
| 216 | if (nullptr == scene) { |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | scene->mRootNode = new aiNode(XmlTag::RootTag); |
| 221 | XmlNode node = mXmlParser.getRootNode().child(XmlTag::model); |
| 222 | if (node.empty()) { |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | XmlNode resNode = node.child(XmlTag::resources); |
| 227 | for (auto ¤tNode : resNode.children()) { |
| 228 | const std::string currentNodeName = currentNode.name(); |
| 229 | if (currentNodeName == XmlTag::texture_2d) { |
| 230 | ReadEmbeddecTexture(currentNode); |
| 231 | } else if (currentNodeName == XmlTag::texture_group) { |
| 232 | ReadTextureGroup(currentNode); |
| 233 | } else if (currentNodeName == XmlTag::object) { |
| 234 | ReadObject(currentNode); |
| 235 | } else if (currentNodeName == XmlTag::basematerials) { |
| 236 | ReadBaseMaterials(currentNode); |
| 237 | } else if (currentNodeName == XmlTag::meta) { |
| 238 | ReadMetadata(currentNode); |
| 239 | } else if (currentNodeName == XmlTag::colorgroup) { |
| 240 | ReadColorGroup(currentNode); |
| 241 | } |
| 242 | } |
| 243 | StoreMaterialsInScene(scene); |
| 244 | XmlNode buildNode = node.child(XmlTag::build); |
| 245 | if (buildNode.empty()) { |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | for (auto ¤tNode : buildNode.children()) { |
| 250 | const std::string currentNodeName = currentNode.name(); |
| 251 | if (currentNodeName == XmlTag::item) { |
| 252 | int objectId = IdNotSet; |
| 253 | std::string transformationMatrixStr; |
| 254 | aiMatrix4x4 transformationMatrix; |
| 255 | getNodeAttribute(currentNode, D3MF::XmlTag::objectid, objectId); |
| 256 | bool hasTransform = getNodeAttribute(currentNode, D3MF::XmlTag::transform, transformationMatrixStr); |
| 257 | |
| 258 | auto it = mResourcesDictionnary.find(objectId); |
| 259 | if (it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_Object) { |
| 260 | Object *obj = static_cast<Object *>(it->second); |
| 261 | if (hasTransform) { |
| 262 | transformationMatrix = parseTransformMatrix(transformationMatrixStr); |
| 263 | } |
| 264 | |
| 265 | addObjectToNode(scene->mRootNode, obj, transformationMatrix); |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | // import the metadata |
| 271 | if (!mMetaData.empty()) { |
| 272 | const size_t numMeta = mMetaData.size(); |
no test coverage detected