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

Method SaveSimplificationCache

Source/Objects/riggedobject.cpp:3976–4045  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3974static const int simp_cache_vers = 11;
3975
3976void RiggedObject::SaveSimplificationCache(const std::string& path) {
3977 FILE* file;
3978 Path found_path = FindFilePath(path.c_str(), kAnyPath, false);
3979 if (found_path.isValid())
3980 file = my_fopen((GetWritePath(found_path.GetModsource()).c_str() + path + ".lod_cache").c_str(), "wb");
3981 else {
3982 LOGW << "Couldn't find path to \"" << path << "\" when saving simplification cache. This might result in a mod writing to the wrong directory" << std::endl;
3983 file = my_fopen((GetWritePath(CoreGameModID).c_str() + path + ".lod_cache").c_str(), "wb");
3984 }
3985 unsigned short checksum = skeleton_.skeleton_asset_ref->checksum() +
3986 Models::Instance()->GetModel(model_id[0]).checksum;
3987 for (auto& morph_target : morph_targets) {
3988 checksum += morph_target.checksum;
3989 }
3990 fwrite(&simp_cache_vers, sizeof(int), 1, file);
3991 fwrite(&checksum, sizeof(unsigned short), 1, file);
3992 for (unsigned i = 1; i < 4; ++i) {
3993 const Model& model = Models::Instance()->GetModel(model_id[i]);
3994 int model_num_verts = model.vertices.size() / 3;
3995 fwrite(&model_num_verts, sizeof(int), 1, file);
3996 fwrite(&model.vertices[0], sizeof(GLfloat), model_num_verts * 3, file);
3997 fwrite(&model.bone_weights[0], sizeof(vec4), model_num_verts, file);
3998 fwrite(&model.bone_ids[0], sizeof(vec4), model_num_verts, file);
3999 fwrite(&model.tex_coords[0], sizeof(GLfloat), model_num_verts * 2, file);
4000 int num_faces = model.faces.size() / 3;
4001 fwrite(&num_faces, sizeof(int), 1, file);
4002 fwrite(&model.faces[0], sizeof(GLuint), model.faces.size(), file);
4003 }
4004
4005 {
4006 int num_morphs = morph_targets.size();
4007 fwrite(&num_morphs, sizeof(int), 1, file);
4008 }
4009
4010 std::queue<MorphTarget*> queue;
4011 for (auto& morph_target : morph_targets) {
4012 queue.push(&morph_target);
4013 }
4014 while (!queue.empty()) {
4015 MorphTarget& morph = (*queue.front());
4016 queue.pop();
4017 for (auto& morph_target : morph.morph_targets) {
4018 queue.push(&morph_target);
4019 }
4020 for (unsigned i = 1; i < 4; ++i) {
4021 const Model& model = Models::Instance()->GetModel(morph.model_id[i]);
4022 int model_num_verts = model.vertices.size() / 3;
4023 fwrite(&model.vertices[0], sizeof(GLfloat), model_num_verts * 3, file);
4024 fwrite(&model.tex_coords[0], sizeof(GLfloat), model_num_verts * 2, file);
4025 std::vector<char>& vm = morph.verts_modified[i];
4026 fwrite(&vm[0], sizeof(char), model_num_verts, file);
4027 int mv_size = morph.modified_verts[i].size();
4028 fwrite(&mv_size, sizeof(int), 1, file);
4029 if (mv_size) {
4030 std::vector<int>& mv = morph.modified_verts[i];
4031 fwrite(&mv[0], sizeof(int), mv_size, file);
4032 }
4033

Callers

nothing calls this directly

Calls 13

FindFilePathFunction · 0.85
my_fopenFunction · 0.85
GetWritePathFunction · 0.85
GetModsourceMethod · 0.80
c_strMethod · 0.45
isValidMethod · 0.45
checksumMethod · 0.45
GetModelMethod · 0.45
sizeMethod · 0.45
pushMethod · 0.45
emptyMethod · 0.45
frontMethod · 0.45

Tested by

no test coverage detected