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;
 }
