| 315 | } |
| 316 | |
| 317 | void XmlSerializer::ReadObject(XmlNode &node) { |
| 318 | int id = IdNotSet, pid = IdNotSet, pindex = IdNotSet; |
| 319 | bool hasId = getNodeAttribute(node, XmlTag::id, id); |
| 320 | if (!hasId) { |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | bool hasPid = getNodeAttribute(node, XmlTag::pid, pid); |
| 325 | bool hasPindex = getNodeAttribute(node, XmlTag::pindex, pindex); |
| 326 | |
| 327 | Object *obj = new Object(id); |
| 328 | for (XmlNode ¤tNode : node.children()) { |
| 329 | const std::string currentName = currentNode.name(); |
| 330 | if (currentName == D3MF::XmlTag::mesh) { |
| 331 | auto mesh = ReadMesh(currentNode); |
| 332 | mesh->mName.Set(ai_to_string(id)); |
| 333 | |
| 334 | if (hasPid) { |
| 335 | auto it = mResourcesDictionnary.find(pid); |
| 336 | if (hasPindex && it != mResourcesDictionnary.end()) { |
| 337 | if (it->second->getType() == ResourceType::RT_BaseMaterials) { |
| 338 | BaseMaterials *materials = static_cast<BaseMaterials *>(it->second); |
| 339 | mesh->mMaterialIndex = materials->mMaterialIndex[pindex]; |
| 340 | } else if (it->second->getType() == ResourceType::RT_Texture2DGroup) { |
| 341 | Texture2DGroup *group = static_cast<Texture2DGroup *>(it->second); |
| 342 | if (mesh->mTextureCoords[0] == nullptr) { |
| 343 | mesh->mNumUVComponents[0] = 2; |
| 344 | for (unsigned int i = 1; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { |
| 345 | mesh->mNumUVComponents[i] = 0; |
| 346 | } |
| 347 | |
| 348 | const std::string name = ai_to_string(group->mTexId); |
| 349 | for (size_t i = 0; i < mMaterials.size(); ++i) { |
| 350 | if (name == mMaterials[i]->GetName().C_Str()) { |
| 351 | mesh->mMaterialIndex = static_cast<unsigned int>(i); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | mesh->mTextureCoords[0] = new aiVector3D[mesh->mNumVertices]; |
| 356 | for (unsigned int vertex_idx = 0; vertex_idx < mesh->mNumVertices; vertex_idx++) { |
| 357 | mesh->mTextureCoords[0][vertex_idx] = |
| 358 | aiVector3D(group->mTex2dCoords[pindex].x, group->mTex2dCoords[pindex].y, 0.0f); |
| 359 | } |
| 360 | } else { |
| 361 | for (unsigned int vertex_idx = 0; vertex_idx < mesh->mNumVertices; vertex_idx++) { |
| 362 | if (mesh->mTextureCoords[0][vertex_idx].z < 0) { |
| 363 | // use default |
| 364 | mesh->mTextureCoords[0][vertex_idx] = |
| 365 | aiVector3D(group->mTex2dCoords[pindex].x, group->mTex2dCoords[pindex].y, 0.0f); |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | }else if (it->second->getType() == ResourceType::RT_ColorGroup) { |
| 370 | if (mesh->mColors[0] == nullptr) { |
| 371 | mesh->mColors[0] = new aiColor4D[mesh->mNumVertices]; |
| 372 | |
| 373 | ColorGroup *group = static_cast<ColorGroup *>(it->second); |
| 374 | for (unsigned int vertex_idx = 0; vertex_idx < mesh->mNumVertices; vertex_idx++) { |
nothing calls this directly
no test coverage detected