MCPcopy Create free account
hub / github.com/assimp/assimp / ReadMultipartFile

Method ReadMultipartFile

code/AssetLib/MD3/MD3Loader.cpp:526–651  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------ Read a multi-part Q3 player model

Source from the content-addressed store, hash-verified

524// ------------------------------------------------------------------------------------------------
525// Read a multi-part Q3 player model
526bool MD3Importer::ReadMultipartFile() {
527 // check whether the file name contains a common postfix, e.g lower_2.md3
528 std::string::size_type s = filename.find_last_of('_'), t = filename.find_last_of('.');
529
530 if (t == std::string::npos)
531 t = filename.size();
532 if (s == std::string::npos)
533 s = t;
534
535 const std::string mod_filename = filename.substr(0, s);
536 const std::string suffix = filename.substr(s, t - s);
537
538 if (mod_filename == "lower" || mod_filename == "upper" || mod_filename == "head") {
539 const std::string lower = path + "lower" + suffix + ".md3";
540 const std::string upper = path + "upper" + suffix + ".md3";
541 const std::string head = path + "head" + suffix + ".md3";
542
543 aiScene *scene_upper = nullptr;
544 aiScene *scene_lower = nullptr;
545 aiScene *scene_head = nullptr;
546 std::string failure;
547
548 aiNode *tag_torso, *tag_head;
549 std::vector<AttachmentInfo> attach;
550
551 ASSIMP_LOG_INFO("Multi part MD3 player model: lower, upper and head parts are joined");
552
553 // ensure we won't try to load ourselves recursively
554 BatchLoader::PropertyMap props;
555 SetGenericProperty(props.ints, AI_CONFIG_IMPORT_MD3_HANDLE_MULTIPART, 0);
556
557 // now read these three files
558 BatchLoader batch(mIOHandler);
559 const unsigned int _lower = batch.AddLoadRequest(lower, 0, &props);
560 const unsigned int _upper = batch.AddLoadRequest(upper, 0, &props);
561 const unsigned int _head = batch.AddLoadRequest(head, 0, &props);
562 batch.LoadAll();
563
564 // now construct a dummy scene to place these three parts in
565 aiScene *master = new aiScene();
566 aiNode *nd = master->mRootNode = new aiNode();
567 nd->mName.Set("<MD3_Player>");
568
569 // ... and get them. We need all of them.
570 scene_lower = batch.GetImport(_lower);
571 if (!scene_lower) {
572 ASSIMP_LOG_ERROR("M3D: Failed to read multi part model, lower.md3 fails to load");
573 failure = "lower";
574 goto error_cleanup;
575 }
576
577 scene_upper = batch.GetImport(_upper);
578 if (!scene_upper) {
579 ASSIMP_LOG_ERROR("M3D: Failed to read multi part model, upper.md3 fails to load");
580 failure = "upper";
581 goto error_cleanup;
582 }
583

Callers

nothing calls this directly

Calls 11

SetGenericPropertyFunction · 0.85
RemoveSingleNodeFromListFunction · 0.85
aiMatrix4x4Class · 0.85
DeadlyImportErrorFunction · 0.85
AddLoadRequestMethod · 0.80
LoadAllMethod · 0.80
GetImportMethod · 0.80
emplace_backMethod · 0.80
sizeMethod · 0.45
SetMethod · 0.45
FindNodeMethod · 0.45

Tested by

no test coverage detected