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

Method LoadObjMorph

Source/Graphics/model.cpp:1991–2080  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1989}
1990
1991void Model::LoadObjMorph(const std::string &rel_path, const std::string &rel_base_path) {
1992 Dispose();
1993 char abs_path[kPathSize];
1994 ModID modsource;
1995 if (FindFilePath(rel_path.c_str(), abs_path, kPathSize, kDataPaths | kModPaths, true, NULL, &modsource) == -1) {
1996 FatalError("Error", "Could not find morph file: \"%s\"", rel_path.c_str());
1997 }
1998
1999 bool load_model = true;
2000
2001 size_t read_count = 0;
2002 unsigned short checksum = Checksum(abs_path);
2003 FILE *cache_file = my_fopen((GetWritePath(modsource) + rel_path + ".mcache").c_str(), "rb");
2004 if (cache_file) {
2005 unsigned short file_checksum = 0;
2006 read_count = fread(&file_checksum, sizeof(unsigned short), 1, cache_file);
2007 LOG_ASSERT(read_count == 1);
2008 unsigned short version;
2009 read_count = fread(&version, sizeof(unsigned short), 1, cache_file);
2010 LOG_ASSERT(read_count == 1);
2011 if (checksum == file_checksum && version == _morph_cache_version) {
2012 size_t count = 0;
2013 read_count = fread(&count, sizeof(int), 1, cache_file);
2014 LOG_ASSERT(read_count == 1);
2015 ResizeVertices(count);
2016 read_count = fread(&vertices[0], sizeof(GLfloat), count * 3, cache_file);
2017 LOG_ASSERT_EQ(read_count, count * 3);
2018 read_count = fread(&tex_coords[0], sizeof(GLfloat), count * 2, cache_file);
2019 LOG_ASSERT_EQ(read_count, count * 2);
2020 load_model = false;
2021 }
2022 fclose(cache_file);
2023 }
2024
2025 if (load_model) {
2026 // Load base model to get bounding box
2027 ObjFileStats obj_stats;
2028 GetObjFileStats(rel_base_path, obj_stats, true);
2029 TempModel base_model;
2030 LoadTempModel(rel_base_path, base_model, obj_stats);
2031 GetObjFileStats(rel_path, obj_stats, true);
2032 TempModel morph_model;
2033 LoadTempModel(rel_path, morph_model, obj_stats);
2034
2035 for (unsigned i = 0; i < base_model.fc * 3; ++i) {
2036 vertices.push_back(base_model.vertices[base_model.vert_indices[i] * 3 + 0]);
2037 vertices.push_back(base_model.vertices[base_model.vert_indices[i] * 3 + 1]);
2038 vertices.push_back(base_model.vertices[base_model.vert_indices[i] * 3 + 2]);
2039 }
2040
2041 std::vector<GLfloat> old_tex_coords;
2042 for (unsigned i = 0; i < base_model.fc * 3; ++i) {
2043 old_tex_coords.push_back(base_model.tex_coords[base_model.tex_indices[i] * 2 + 0]);
2044 old_tex_coords.push_back(base_model.tex_coords[base_model.tex_indices[i] * 2 + 1]);
2045 }
2046
2047 std::vector<GLfloat> old_vertices = vertices;
2048

Callers 1

LoadModelAsMorphMethod · 0.80

Calls 11

FindFilePathFunction · 0.85
ChecksumFunction · 0.85
my_fopenFunction · 0.85
GetWritePathFunction · 0.85
GetObjFileStatsFunction · 0.85
LoadTempModelFunction · 0.85
FatalErrorFunction · 0.50
c_strMethod · 0.45
push_backMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected