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     | 143 ------------------------------------------------------
 2 files changed, 180 deletions(-)

diff --git a/gltf/gltfpack.cpp b/gltf/gltfpack.cpp
index d45a42b..a75ecf6 100644
--- a/gltf/gltfpack.cpp
+++ b/gltf/gltfpack.cpp
@@ -402,30 +402,6 @@ static void process(cgltf_data* data, const char* input_path, const char* output
 	markNeededNodes(data, nodes, meshes, animations, settings);
 	markNeededMaterials(data, materials, meshes, settings);
 
-#ifndef NDEBUG
-	std::vector<Mesh> debug_meshes;
-
-	for (size_t i = 0; i < meshes.size(); ++i)
-	{
-		const Mesh& mesh = meshes[i];
-
-		if (settings.simplify_debug > 0)
-		{
-			Mesh kinds = {};
-			Mesh loops = {};
-			debugSimplify(mesh, kinds, loops, settings.simplify_debug, settings.simplify_error, settings.simplify_attributes, settings.quantize && !settings.nrm_float);
-			debug_meshes.push_back(kinds);
-			debug_meshes.push_back(loops);
-		}
-
-		if (settings.meshlet_debug > 0)
-		{
-			Mesh meshlets = {};
-			debugMeshlets(mesh, meshlets, settings.meshlet_debug, /* scan= */ false);
-			debug_meshes.push_back(meshlets);
-		}
-	}
-#endif
 
 	for (size_t i = 0; i < meshes.size(); ++i)
 	{
@@ -436,9 +412,6 @@ static void process(cgltf_data* data, const char* input_path, const char* output
 			hashMesh(mesh);
 	}
 
-#ifndef NDEBUG
-	meshes.insert(meshes.end(), debug_meshes.begin(), debug_meshes.end());
-#endif
 
 	filterEmptyMeshes(meshes); // some meshes may become empty after processing
 
@@ -1369,16 +1342,6 @@ int main(int argc, char** argv)
 		{
 			settings.simplify_attributes = true;
 		}
-#ifndef NDEBUG
-		else if (strcmp(arg, "-sd") == 0 && i + 1 < argc && isdigit(argv[i + 1][0]))
-		{
-			settings.simplify_debug = clamp(float(atof(argv[++i])), 0.f, 1.f);
-		}
-		else if (strcmp(arg, "-md") == 0 && i + 1 < argc && isdigit(argv[i + 1][0]))
-		{
-			settings.meshlet_debug = clamp(atoi(argv[++i]), 3, 255);
-		}
-#endif
 		else if (strcmp(arg, "-tu") == 0)
 		{
 			settings.texture_ktx2 = true;
diff --git a/gltf/mesh.cpp b/gltf/mesh.cpp
index c4899dc..009fc2d 100644
--- a/gltf/mesh.cpp
+++ b/gltf/mesh.cpp
@@ -1036,146 +1036,3 @@ void processMesh(Mesh& mesh, const Settings& settings)
 	}
 }
 
-#ifndef NDEBUG
-void debugSimplify(const Mesh& source, Mesh& kinds, Mesh& loops, float ratio, float error, bool attributes, bool quantize_tbn)
-{
-	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
-	filterBones(mesh);
-	reindexMesh(mesh, quantize_tbn);
-	filterTriangles(mesh);
-
-	size_t vertex_count = mesh.streams[0].data.size();
-
-	simplifyMesh(mesh, ratio, error, attributes, /* aggressive= */ false, /* lock_borders= */ false, /* debug= */ 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, kPalette[0]);
-
-	kinds.type = cgltf_primitive_type_points;
-	loops.type = cgltf_primitive_type_lines;
-
-	for (size_t i = 0; i < mesh.indices.size(); i += 3)
-	{
-		for (int k = 0; k < 3; ++k)
-		{
-			const unsigned int mask = (1 << 28) - 1;
-			unsigned int v = mesh.indices[i + k];
-			unsigned int next = mesh.indices[i + (k + 1) % 3];
-			unsigned int vk = (v >> 28) & 7;
-			unsigned int vl = v >> 31;
-
-			if (vk)
-			{
-				colors.data[v & mask] = kPalette[vk];
-				kinds.indices.push_back(v & mask);
-			}
-
-			if (vl)
-			{
-				loops.indices.push_back(v & mask);
-				loops.indices.push_back(next & mask);
-			}
-		}
-	}
-
-	kinds.streams.push_back(colors);
-	loops.streams.push_back(colors);
-}
-
-void debugMeshlets(const Mesh& source, Mesh& meshlets, int max_vertices, bool scan)
-{
-	Mesh mesh = source;
-	assert(mesh.type == cgltf_primitive_type_triangles);
-
-	reindexMesh(mesh, /* quantize_tbn= */ true);
-
-	if (scan)
-		optimizeMesh(mesh, false);
-
-	const Stream* positions = getStream(mesh, cgltf_attribute_type_position);
-	assert(positions);
-
-	const float cone_weight = 0.f;
-
-	size_t max_triangles = (max_vertices * 2 + 3) & ~3;
-	size_t max_meshlets = meshopt_buildMeshletsBound(mesh.indices.size(), max_vertices, max_triangles);
-
-	std::vector<meshopt_Meshlet> ml(max_meshlets);
-	std::vector<unsigned int> mlv(max_meshlets * max_vertices);
-	std::vector<unsigned char> mlt(max_meshlets * max_triangles * 3);
-
-	if (scan)
-		ml.resize(meshopt_buildMeshletsScan(&ml[0], &mlv[0], &mlt[0], &mesh.indices[0], mesh.indices.size(), positions->data.size(), max_vertices, max_triangles));
-	else
-		ml.resize(meshopt_buildMeshlets(&ml[0], &mlv[0], &mlt[0], &mesh.indices[0], mesh.indices.size(), positions->data[0].f, positions->data.size(), sizeof(Attr), max_vertices, max_triangles, cone_weight));
-
-	// 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 < ml.size(); ++i)
-	{
-		const meshopt_Meshlet& m = ml[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 < m.vertex_count; ++j)
-		{
-			mv.data.push_back(positions->data[mlv[m.vertex_offset + j]]);
-			mc.data.push_back(c);
-		}
-
-		for (size_t j = 0; j < m.triangle_count; ++j)
-		{
-			meshlets.indices.push_back(offset + mlt[m.triangle_offset + j * 3 + 0]);
-			meshlets.indices.push_back(offset + mlt[m.triangle_offset + j * 3 + 1]);
-			meshlets.indices.push_back(offset + mlt[m.triangle_offset + j * 3 + 2]);
-		}
-	}
-
-	meshlets.type = cgltf_primitive_type_triangles;
-	meshlets.streams.push_back(mv);
-	meshlets.streams.push_back(mc);
-}
-#endif
