MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / LoadObj

Method LoadObj

Source/Graphics/model.cpp:930–1071  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

928}
929
930void Model::LoadObj(const std::string &rel_path, char flags, const std::string &alt_name, const PathFlags searchPaths) {
931 // LOGI << "Loading model: " << rel_path << std::endl;
932 const char *fail_whale = "./Data/Models/Default/default_model_2.obj";
933
934 bool center = (flags & _MDL_CENTER) != 0;
935 bool simple = (flags & _MDL_SIMPLE) != 0;
936 use_tangent = (flags & _MDL_USE_TANGENT) != 0;
937
938 bool load_model = true;
939
940 Dispose();
941
942 path = rel_path;
943
944 std::string name_to_load = rel_path;
945 const std::string &cache_name_to_load = SanitizePath(alt_name.empty() ? rel_path : alt_name);
946
947 char abs_path[kPathSize], abs_cache_path[kPathSize];
948 ModID modsource, cache_modsource;
949 bool found_model = (FindFilePath(name_to_load.c_str(), abs_path, kPathSize, searchPaths, false, NULL, &modsource) != -1);
950 bool found_cache = (FindFilePath((cache_name_to_load + ".cache").c_str(), abs_cache_path, kPathSize, searchPaths, false, NULL, &cache_modsource) != -1);
951
952 if (!found_model && !found_cache) { // To do: fix bug when only cache exists
953 std::string error_msg = "Whale fail :(\nModel file \"" + std::string(rel_path) + "\" not found. Loading the fail whale instead.";
954 DisplayError("Error", error_msg.c_str(), _ok, false);
955 name_to_load = fail_whale;
956 }
957
958 if (found_model) {
959 checksum = Checksum(abs_path);
960 }
961
962 if (found_cache) {
963 FILE *cache_file = my_fopen(abs_cache_path, "rb");
964 if (cache_file) {
965 unsigned short file_checksum = 0;
966 fread(&file_checksum, sizeof(unsigned short), 1, cache_file);
967 unsigned short version;
968 fread(&version, sizeof(unsigned short), 1, cache_file);
969 if (checksum == file_checksum && version == _model_cache_version) {
970 ReadFromFile(cache_file);
971 load_model = false;
972 modsource_ = cache_modsource;
973 }
974 fclose(cache_file);
975 }
976 }
977
978 if (load_model) {
979 int modelLoadError = SimpleLoadTriangleCutObj(name_to_load);
980
981 if (0 == modelLoadError) {
982 precollapse_num_vertices = vertices.size() / 3;
983
984 ObjFileStats obj_stats2;
985 bool uv2_file = GetObjFileStats(name_to_load + "_UV2", obj_stats2, false);
986 if (uv2_file) {
987 Model temp2;

Callers 7

loadModelMethod · 0.80
LoadResourcesMethod · 0.80
LoadMethod · 0.80
AddWireMeshMethod · 0.80
CreateConvexHullShapeFunction · 0.80
bulletworld.cppFile · 0.80

Calls 15

SanitizePathFunction · 0.85
FindFilePathFunction · 0.85
ChecksumFunction · 0.85
my_fopenFunction · 0.85
GetObjFileStatsFunction · 0.85
GetLoadErrorStringFunction · 0.85
GetWritePathFunction · 0.85
LoadObjFunction · 0.85
DisplayErrorFunction · 0.50
swapFunction · 0.50
sqrtfFunction · 0.50

Tested by

no test coverage detected