From e279537708fb511abf1d8f65325c145916a10918 Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 8 Feb 2026 07:21:29 +0100 Subject: feat(3d): Implement Mesh Wireframe rendering for Visual Debug --- src/3d/visual_debug.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/3d/visual_debug.cc') diff --git a/src/3d/visual_debug.cc b/src/3d/visual_debug.cc index 3f5778a..78c751b 100644 --- a/src/3d/visual_debug.cc +++ b/src/3d/visual_debug.cc @@ -225,6 +225,32 @@ void VisualDebug::add_mesh_normals(const mat4& transform, uint32_t num_vertices, } } +void VisualDebug::add_mesh_wireframe(const mat4& transform, uint32_t num_vertices, + const MeshVertex* vertices, uint32_t num_indices, + const uint32_t* indices, const vec3& color) { + if (!vertices || !indices || num_indices == 0) + return; + + for (uint32_t i = 0; i < num_indices; i += 3) { + if (i + 2 >= num_indices) break; + + uint32_t idx0 = indices[i]; + uint32_t idx1 = indices[i + 1]; + uint32_t idx2 = indices[i + 2]; + + if (idx0 >= num_vertices || idx1 >= num_vertices || idx2 >= num_vertices) + continue; + + vec4 p0_world = transform * vec4(vertices[idx0].p[0], vertices[idx0].p[1], vertices[idx0].p[2], 1.0f); + vec4 p1_world = transform * vec4(vertices[idx1].p[0], vertices[idx1].p[1], vertices[idx1].p[2], 1.0f); + vec4 p2_world = transform * vec4(vertices[idx2].p[0], vertices[idx2].p[1], vertices[idx2].p[2], 1.0f); + + add_line(p0_world.xyz(), p1_world.xyz(), color); + add_line(p1_world.xyz(), p2_world.xyz(), color); + add_line(p2_world.xyz(), p0_world.xyz(), color); + } +} + void VisualDebug::add_line(const vec3& start, const vec3& end, const vec3& color) { lines_.push_back({start, end, color}); } -- cgit v1.2.3