| 264 | } |
| 265 | |
| 266 | void X3DImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { |
| 267 | mpIOHandler = pIOHandler; |
| 268 | |
| 269 | Clear(); |
| 270 | std::stringstream ss = ConvertVrmlFileToX3dXmlFile(pFile); |
| 271 | const bool isReadFromMem{ ss.str().length() > 0 }; |
| 272 | if (!isReadFromMem) { |
| 273 | std::shared_ptr<IOStream> stream(pIOHandler->Open(pFile, "rb")); |
| 274 | if (!stream) { |
| 275 | throw DeadlyImportError("Could not open file for reading"); |
| 276 | } |
| 277 | } |
| 278 | std::string::size_type slashPos = pFile.find_last_of("\\/"); |
| 279 | |
| 280 | mScene = pScene; |
| 281 | pScene->mRootNode = new aiNode(pFile); |
| 282 | pScene->mRootNode->mParent = nullptr; |
| 283 | pScene->mFlags |= AI_SCENE_FLAGS_ALLOW_SHARED; |
| 284 | |
| 285 | if (isReadFromMem) { |
| 286 | ParseFile(ss); |
| 287 | } else { |
| 288 | pIOHandler->PushDirectory(slashPos == std::string::npos ? std::string() : pFile.substr(0, slashPos + 1)); |
| 289 | ParseFile(pFile, pIOHandler); |
| 290 | pIOHandler->PopDirectory(); |
| 291 | } |
| 292 | |
| 293 | //search for root node element |
| 294 | |
| 295 | mNodeElementCur = NodeElement_List.front(); |
| 296 | if (mNodeElementCur == nullptr) { |
| 297 | return; |
| 298 | } |
| 299 | while (mNodeElementCur->Parent != nullptr) { |
| 300 | mNodeElementCur = mNodeElementCur->Parent; |
| 301 | } |
| 302 | |
| 303 | { // fill aiScene with objects. |
| 304 | std::list<aiMesh *> mesh_list; |
| 305 | std::list<aiMaterial *> mat_list; |
| 306 | std::list<aiLight *> light_list; |
| 307 | |
| 308 | // create nodes tree |
| 309 | Postprocess_BuildNode(*mNodeElementCur, *pScene->mRootNode, mesh_list, mat_list, light_list); |
| 310 | // copy needed data to scene |
| 311 | if (!mesh_list.empty()) { |
| 312 | std::list<aiMesh *>::const_iterator it = mesh_list.begin(); |
| 313 | |
| 314 | pScene->mNumMeshes = static_cast<unsigned int>(mesh_list.size()); |
| 315 | pScene->mMeshes = new aiMesh *[pScene->mNumMeshes]; |
| 316 | for (size_t i = 0; i < pScene->mNumMeshes; i++) |
| 317 | pScene->mMeshes[i] = *it++; |
| 318 | } |
| 319 | |
| 320 | if (!mat_list.empty()) { |
| 321 | std::list<aiMaterial *>::const_iterator it = mat_list.begin(); |
| 322 | |
| 323 | pScene->mNumMaterials = static_cast<unsigned int>(mat_list.size()); |
nothing calls this directly
no test coverage detected