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

Function SimplifyModel

Source/Graphics/models.cpp:54–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52//-----------------------------------------------------------------------------
53
54void SimplifyModel(std::string name, Model& model, int edge_target) {
55 LOGI << "Simplification - starting..." << std::endl;
56
57 char path[kPathSize];
58 FormatString(path, kPathSize, "%s%slow.obj", GetWritePath(CoreGameModID).c_str(), name.c_str());
59 CreateParentDirs(path);
60
61#ifdef _WIN32
62 createfile(path);
63 string short_path = path;
64 ShortenWindowsPath(short_path);
65 string output_filename = short_path.c_str();
66#else
67 string output_filename = path;
68#endif
69
70 Simplify::vertices.clear();
71 for (int i = 0; i < model.vertices.size(); i += 3) {
72 Simplify::Vertex v;
73 v.p.x = model.vertices[i + 0];
74 v.p.y = model.vertices[i + 1];
75 v.p.z = model.vertices[i + 2];
76 Simplify::vertices.push_back(v);
77 }
78
79 Simplify::triangles.clear();
80 for (int i = 0; i < model.faces.size(); i += 3) {
81 Simplify::Triangle t;
82
83 t.v[0] = model.faces[i + 0];
84 t.v[1] = model.faces[i + 1];
85 t.v[2] = model.faces[i + 2];
86 t.deleted = false;
87 t.dirty = false;
88 t.attr = 0UL;
89 t.material = -1;
90 Simplify::triangles.push_back(t);
91 }
92
93 LOGW << "Simplifying terrain mesh, face count in: " << model.faces.size() << std::endl;
94 Simplify::simplify_mesh(edge_target);
95 LOGW << "Simplified terrain mesh, face count out: " << Simplify::triangle_count() << std::endl;
96
97 Simplify::write_obj(output_filename.c_str());
98
99 LOGW << "Saving simplified terrain mesh to \"" << output_filename << "\"" << std::endl;
100}
101
102int Models::CopyModel(int model_id) {
103 int id = AddModel();

Callers 1

Calls 12

FormatStringFunction · 0.85
GetWritePathFunction · 0.85
CreateParentDirsFunction · 0.85
createfileFunction · 0.85
ShortenWindowsPathFunction · 0.85
simplify_meshFunction · 0.85
triangle_countFunction · 0.85
write_objFunction · 0.50
c_strMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected