summaryrefslogtreecommitdiff
path: root/src/3d/visual_debug.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-06 08:05:20 +0100
committerskal <pascal.massimino@gmail.com>2026-02-06 08:05:20 +0100
commit8ded2005d441f8aab44c833fc658d9622c788ebd (patch)
treeefaf714b636788148db583903bfbff3b015f3f58 /src/3d/visual_debug.cc
parent1ec5d1ae48d1dd3290992ba63a8ec581af02b9dd (diff)
feat(tests): Add test_mesh tool for OBJ loading and normal visualization
Implemented a new standalone test tool 'test_mesh' to: - Load a .obj file specified via command line. - Display the mesh with rotation and basic lighting on a tiled floor. - Provide a '--debug' option to visualize vertex normals as cyan lines. - Updated asset_packer to auto-generate smooth normals for OBJs if missing. - Fixed various WGPU API usage inconsistencies and build issues on macOS. - Exposed Renderer3D::GetVisualDebug() for test access. - Added custom Vec3 struct and math utilities for OBJ parsing. This tool helps verify mesh ingestion and normal computation independently of the main demo logic.
Diffstat (limited to 'src/3d/visual_debug.cc')
-rw-r--r--src/3d/visual_debug.cc27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/3d/visual_debug.cc b/src/3d/visual_debug.cc
index 86f12b4..009a1e1 100644
--- a/src/3d/visual_debug.cc
+++ b/src/3d/visual_debug.cc
@@ -107,7 +107,7 @@ void VisualDebug::create_pipeline(WGPUTextureFormat format) {
#if defined(DEMO_CROSS_COMPILE_WIN32)
pipeline_desc.vertex.entryPoint = "vs_main";
#else
- pipeline_desc.vertex.entryPoint = {"vs_main", 7};
+ pipeline_desc.vertex.entryPoint = str_view("vs_main");
#endif
pipeline_desc.vertex.bufferCount = 1;
pipeline_desc.vertex.buffers = &vertex_layout;
@@ -117,7 +117,7 @@ void VisualDebug::create_pipeline(WGPUTextureFormat format) {
#if defined(DEMO_CROSS_COMPILE_WIN32)
fragment_state.entryPoint = "fs_main";
#else
- fragment_state.entryPoint = {"fs_main", 7};
+ fragment_state.entryPoint = str_view("fs_main");
#endif
fragment_state.targetCount = 1;
@@ -203,6 +203,29 @@ void VisualDebug::add_aabb(const vec3& min, const vec3& max,
}
}
+void VisualDebug::add_mesh_normals(const mat4& transform, uint32_t num_vertices,
+ const MeshVertex* vertices) {
+ if (!vertices || num_vertices == 0)
+ return;
+
+ mat4 normal_matrix = mat4::transpose(transform.inverse());
+
+ for (uint32_t i = 0; i < num_vertices; ++i) {
+ const auto& v = vertices[i];
+
+ vec4 p_world = transform * vec4(v.p[0], v.p[1], v.p[2], 1.0f);
+ vec3 n_object = vec3(v.n[0], v.n[1], v.n[2]);
+ vec4 n_world_h = normal_matrix * vec4(n_object.x, n_object.y, n_object.z, 0.0f);
+ vec3 n_world = n_world_h.xyz().normalize();
+
+ lines_.push_back(
+ {p_world.xyz(), p_world.xyz() + n_world * 0.1f, // 0.1 is the length
+ {0.0f, 1.0f, 1.0f} // Cyan color
+ });
+ }
+}
+
+
void VisualDebug::update_buffers(const mat4& view_proj) {
// Update Uniforms
wgpuQueueWriteBuffer(wgpuDeviceGetQueue(device_), uniform_buffer_, 0,