1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
|
From: =?utf-8?q?Timo_R=C3=B6hling?= <timo@gaussglocke.de>
Date: Wed, 2 Dec 2020 00:20:52 +0100
Subject: Remove debug code
---
gltf/gltfpack.cpp | 37 ---------
gltf/mesh.cpp | 217 -----------------------------------------------------
src/simplifier.cpp | 15 ----
3 files changed, 269 deletions(-)
diff --git a/gltf/gltfpack.cpp b/gltf/gltfpack.cpp
index 73dda5d..19b48d2 100644
--- a/gltf/gltfpack.cpp
+++ b/gltf/gltfpack.cpp
@@ -303,39 +303,12 @@ static void process(cgltf_data* data, const char* input_path, const char* output
markNeededMaterials(data, materials, meshes, settings);
-#ifndef NDEBUG
- std::vector<Mesh> debug_meshes;
-
- for (size_t i = 0; i < meshes.size(); ++i)
- {
- if (settings.simplify_debug > 0)
- {
- Mesh kinds = {};
- Mesh loops = {};
- debugSimplify(meshes[i], kinds, loops, settings.simplify_debug);
- debug_meshes.push_back(kinds);
- debug_meshes.push_back(loops);
- }
-
- if (settings.meshlet_debug > 0)
- {
- Mesh meshlets = {};
- Mesh bounds = {};
- debugMeshlets(meshes[i], meshlets, bounds, settings.meshlet_debug);
- debug_meshes.push_back(meshlets);
- debug_meshes.push_back(bounds);
- }
- }
-#endif
for (size_t i = 0; i < meshes.size(); ++i)
{
processMesh(meshes[i], settings);
}
-#ifndef NDEBUG
- meshes.insert(meshes.end(), debug_meshes.begin(), debug_meshes.end());
-#endif
filterEmptyMeshes(meshes); // some meshes may become empty after processing
@@ -1056,16 +1029,6 @@ int main(int argc, char** argv)
{
settings.simplify_aggressive = true;
}
-#ifndef NDEBUG
- else if (strcmp(arg, "-sd") == 0 && i + 1 < argc && isdigit(argv[i + 1][0]))
- {
- settings.simplify_debug = float(atof(argv[++i]));
- }
- else if (strcmp(arg, "-md") == 0 && i + 1 < argc && isdigit(argv[i + 1][0]))
- {
- settings.meshlet_debug = atoi(argv[++i]);
- }
-#endif
else if (strcmp(arg, "-tu") == 0)
{
settings.texture_ktx2 = true;
diff --git a/gltf/mesh.cpp b/gltf/mesh.cpp
index 438aa2b..4192d40 100644
--- a/gltf/mesh.cpp
+++ b/gltf/mesh.cpp
@@ -753,220 +753,3 @@ void processMesh(Mesh& mesh, const Settings& settings)
}
}
-#ifndef NDEBUG
-extern unsigned char* meshopt_simplifyDebugKind;
-extern unsigned int* meshopt_simplifyDebugLoop;
-extern unsigned int* meshopt_simplifyDebugLoopBack;
-
-void debugSimplify(const Mesh& source, Mesh& kinds, Mesh& loops, float ratio)
-{
- Mesh mesh = source;
- assert(mesh.type == cgltf_primitive_type_triangles);
-
- // note: it's important to follow the same pipeline as processMesh
- // otherwise the result won't match
- filterStreams(mesh);
- filterBones(mesh);
- reindexMesh(mesh);
- filterTriangles(mesh);
-
- // before simplification we need to setup target kind/loop arrays
- size_t vertex_count = mesh.streams[0].data.size();
-
- std::vector<unsigned char> kind(vertex_count);
- std::vector<unsigned int> loop(vertex_count);
- std::vector<unsigned int> loopback(vertex_count);
- std::vector<unsigned char> live(vertex_count);
-
- meshopt_simplifyDebugKind = &kind[0];
- meshopt_simplifyDebugLoop = &loop[0];
- meshopt_simplifyDebugLoopBack = &loopback[0];
-
- simplifyMesh(mesh, ratio, /* aggressive= */ false);
-
- meshopt_simplifyDebugKind = 0;
- meshopt_simplifyDebugLoop = 0;
- meshopt_simplifyDebugLoopBack = 0;
-
- // fill out live info
- for (size_t i = 0; i < mesh.indices.size(); ++i)
- live[mesh.indices[i]] = true;
-
- // color palette for display
- static const Attr kPalette[] = {
- {0.5f, 0.5f, 0.5f, 1.f}, // manifold
- {0.f, 0.f, 1.f, 1.f}, // border
- {0.f, 1.f, 0.f, 1.f}, // seam
- {0.f, 1.f, 1.f, 1.f}, // complex
- {1.f, 0.f, 0.f, 1.f}, // locked
- };
-
- // prepare meshes
- kinds.nodes = mesh.nodes;
- kinds.skin = mesh.skin;
-
- loops.nodes = mesh.nodes;
- loops.skin = mesh.skin;
-
- for (size_t i = 0; i < mesh.streams.size(); ++i)
- {
- const Stream& stream = mesh.streams[i];
-
- if (stream.target == 0 && (stream.type == cgltf_attribute_type_position || stream.type == cgltf_attribute_type_joints || stream.type == cgltf_attribute_type_weights))
- {
- kinds.streams.push_back(stream);
- loops.streams.push_back(stream);
- }
- }
-
- // transform kind/loop data into lines & points
- Stream colors = {cgltf_attribute_type_color};
- colors.data.resize(vertex_count);
-
- for (size_t i = 0; i < vertex_count; ++i)
- colors.data[i] = kPalette[kind[i]];
-
- kinds.type = cgltf_primitive_type_points;
-
- kinds.streams.push_back(colors);
-
- for (size_t i = 0; i < vertex_count; ++i)
- if (live[i] && kind[i] != 0)
- kinds.indices.push_back(unsigned(i));
-
- loops.type = cgltf_primitive_type_lines;
-
- loops.streams.push_back(colors);
-
- for (size_t i = 0; i < vertex_count; ++i)
- if (live[i] && (kind[i] == 1 || kind[i] == 2))
- {
- if (loop[i] != ~0u && live[loop[i]])
- {
- loops.indices.push_back(unsigned(i));
- loops.indices.push_back(loop[i]);
- }
-
- if (loopback[i] != ~0u && live[loopback[i]])
- {
- loops.indices.push_back(loopback[i]);
- loops.indices.push_back(unsigned(i));
- }
- }
-}
-
-void debugMeshlets(const Mesh& source, Mesh& meshlets, Mesh& bounds, int max_vertices)
-{
- Mesh mesh = source;
- assert(mesh.type == cgltf_primitive_type_triangles);
-
- reindexMesh(mesh);
- optimizeMesh(mesh, false);
-
- const Stream* positions = getStream(mesh, cgltf_attribute_type_position);
- assert(positions);
-
- const size_t max_triangles = 126;
-
- std::vector<meshopt_Meshlet> mr(meshopt_buildMeshletsBound(mesh.indices.size(), max_vertices, max_triangles));
- mr.resize(meshopt_buildMeshlets(&mr[0], &mesh.indices[0], mesh.indices.size(), positions->data.size(), max_vertices, max_triangles));
-
- // generate meshlet meshes, using unique colors
- meshlets.nodes = mesh.nodes;
-
- Stream mv = {cgltf_attribute_type_position};
- Stream mc = {cgltf_attribute_type_color};
-
- for (size_t i = 0; i < mr.size(); ++i)
- {
- const meshopt_Meshlet& ml = mr[i];
-
- unsigned int h = unsigned(i);
- h ^= h >> 13;
- h *= 0x5bd1e995;
- h ^= h >> 15;
-
- Attr c = {{float(h & 0xff) / 255.f, float((h >> 8) & 0xff) / 255.f, float((h >> 16) & 0xff) / 255.f, 1.f}};
-
- unsigned int offset = unsigned(mv.data.size());
-
- for (size_t j = 0; j < ml.vertex_count; ++j)
- {
- mv.data.push_back(positions->data[ml.vertices[j]]);
- mc.data.push_back(c);
- }
-
- for (size_t j = 0; j < ml.triangle_count; ++j)
- {
- meshlets.indices.push_back(offset + ml.indices[j][0]);
- meshlets.indices.push_back(offset + ml.indices[j][1]);
- meshlets.indices.push_back(offset + ml.indices[j][2]);
- }
- }
-
- meshlets.type = cgltf_primitive_type_triangles;
- meshlets.streams.push_back(mv);
- meshlets.streams.push_back(mc);
-
- // generate bounds meshes, using a sphere per meshlet
- bounds.nodes = mesh.nodes;
-
- Stream bv = {cgltf_attribute_type_position};
- Stream bc = {cgltf_attribute_type_color};
-
- for (size_t i = 0; i < mr.size(); ++i)
- {
- const meshopt_Meshlet& ml = mr[i];
-
- meshopt_Bounds mb = meshopt_computeMeshletBounds(&ml, positions->data[0].f, positions->data.size(), sizeof(Attr));
-
- unsigned int h = unsigned(i);
- h ^= h >> 13;
- h *= 0x5bd1e995;
- h ^= h >> 15;
-
- Attr c = {{float(h & 0xff) / 255.f, float((h >> 8) & 0xff) / 255.f, float((h >> 16) & 0xff) / 255.f, 0.1f}};
-
- unsigned int offset = unsigned(bv.data.size());
-
- const int N = 10;
-
- for (int y = 0; y <= N; ++y)
- {
- float u = (y == N) ? 0 : float(y) / N * 2 * 3.1415926f;
- float sinu = sinf(u), cosu = cosf(u);
-
- for (int x = 0; x <= N; ++x)
- {
- float v = float(x) / N * 3.1415926f;
- float sinv = sinf(v), cosv = cosf(v);
-
- float fx = sinv * cosu;
- float fy = sinv * sinu;
- float fz = cosv;
-
- Attr p = {{mb.center[0] + mb.radius * fx, mb.center[1] + mb.radius * fy, mb.center[2] + mb.radius * fz, 1.f}};
-
- bv.data.push_back(p);
- bc.data.push_back(c);
- }
- }
-
- for (int y = 0; y < N; ++y)
- for (int x = 0; x < N; ++x)
- {
- bounds.indices.push_back(offset + (N + 1) * (y + 0) + (x + 0));
- bounds.indices.push_back(offset + (N + 1) * (y + 0) + (x + 1));
- bounds.indices.push_back(offset + (N + 1) * (y + 1) + (x + 0));
-
- bounds.indices.push_back(offset + (N + 1) * (y + 1) + (x + 0));
- bounds.indices.push_back(offset + (N + 1) * (y + 0) + (x + 1));
- bounds.indices.push_back(offset + (N + 1) * (y + 1) + (x + 1));
- }
- }
-
- bounds.type = cgltf_primitive_type_triangles;
- bounds.streams.push_back(bv);
- bounds.streams.push_back(bc);
-}
-#endif
diff --git a/src/simplifier.cpp b/src/simplifier.cpp
index 4080670..88e2652 100644
--- a/src/simplifier.cpp
+++ b/src/simplifier.cpp
@@ -1138,11 +1138,6 @@ static float interpolate(float y, float x0, float y0, float x1, float y1, float
} // namespace meshopt
-#ifndef NDEBUG
-unsigned char* meshopt_simplifyDebugKind = 0;
-unsigned int* meshopt_simplifyDebugLoop = 0;
-unsigned int* meshopt_simplifyDebugLoopBack = 0;
-#endif
size_t meshopt_simplify(unsigned int* destination, const unsigned int* indices, size_t index_count, const float* vertex_positions_data, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count, float target_error)
{
@@ -1285,16 +1280,6 @@ size_t meshopt_simplify(unsigned int* destination, const unsigned int* indices,
dumpLockedCollapses(result, result_count, vertex_kind);
#endif
-#ifndef NDEBUG
- if (meshopt_simplifyDebugKind)
- memcpy(meshopt_simplifyDebugKind, vertex_kind, vertex_count);
-
- if (meshopt_simplifyDebugLoop)
- memcpy(meshopt_simplifyDebugLoop, loop, vertex_count * sizeof(unsigned int));
-
- if (meshopt_simplifyDebugLoopBack)
- memcpy(meshopt_simplifyDebugLoopBack, loopback, vertex_count * sizeof(unsigned int));
-#endif
return result_count;
}
|