------------------------------------------------------------------------------------------------ Read file into given scene data structure
| 493 | // ------------------------------------------------------------------------------------------------ |
| 494 | // Read file into given scene data structure |
| 495 | void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { |
| 496 | io = pIOHandler; |
| 497 | std::unique_ptr<IOStream> file(pIOHandler->Open(pFile, "rb")); |
| 498 | |
| 499 | // Check whether we can read from the file |
| 500 | if (file == nullptr) { |
| 501 | throw DeadlyImportError("Failed to open LWS file ", pFile, "."); |
| 502 | } |
| 503 | |
| 504 | // Allocate storage and copy the contents of the file to a memory buffer |
| 505 | std::vector<char> mBuffer; |
| 506 | TextFileToBuffer(file.get(), mBuffer); |
| 507 | |
| 508 | // Parse the file structure |
| 509 | LWS::Element root; |
| 510 | const char *dummy = &mBuffer[0]; |
| 511 | const char *dummyEnd = dummy + mBuffer.size(); |
| 512 | root.Parse(dummy, dummyEnd); |
| 513 | |
| 514 | // Construct a Batch-importer to read more files recursively |
| 515 | BatchLoader batch(pIOHandler); |
| 516 | |
| 517 | // Construct an array to receive the flat output graph |
| 518 | std::list<LWS::NodeDesc> nodes; |
| 519 | |
| 520 | unsigned int cur_light = 0, cur_camera = 0, cur_object = 0; |
| 521 | unsigned int num_light = 0, num_camera = 0; |
| 522 | |
| 523 | // check magic identifier, 'LWSC' |
| 524 | bool motion_file = false; |
| 525 | std::list<LWS::Element>::const_iterator it = root.children.begin(); |
| 526 | |
| 527 | if ((*it).tokens[0] == "LWMO") { |
| 528 | motion_file = true; |
| 529 | } |
| 530 | |
| 531 | if ((*it).tokens[0] != "LWSC" && !motion_file) { |
| 532 | throw DeadlyImportError("LWS: Not a LightWave scene, magic tag LWSC not found"); |
| 533 | } |
| 534 | |
| 535 | // get file format version and print to log |
| 536 | ++it; |
| 537 | |
| 538 | if (it == root.children.end() || (*it).tokens[0].empty()) { |
| 539 | ASSIMP_LOG_ERROR("Invalid LWS file detectedm abort import."); |
| 540 | return; |
| 541 | } |
| 542 | unsigned int version = strtoul10((*it).tokens[0].c_str()); |
| 543 | ASSIMP_LOG_INFO("LWS file format version is ", (*it).tokens[0]); |
| 544 | first = 0.; |
| 545 | last = 60.; |
| 546 | fps = 25.; // seems to be a good default frame rate |
| 547 | |
| 548 | // Now read all elements in a very straightforward manner |
| 549 | for (; it != root.children.end(); ++it) { |
| 550 | const char *c = (*it).tokens[1].c_str(); |
| 551 | const char *end = c + (*it).tokens[1].size(); |
| 552 |
nothing calls this directly
no test coverage detected