diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-08 07:21:29 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-08 07:21:29 +0100 |
| commit | e279537708fb511abf1d8f65325c145916a10918 (patch) | |
| tree | be0a6ed193b3369b3014c4aa605c5cf983c142ad /src/3d/visual_debug.cc | |
| parent | 438ed437022eca66e84401563b280dc137d2f3c9 (diff) | |
feat(3d): Implement Mesh Wireframe rendering for Visual Debug
Diffstat (limited to 'src/3d/visual_debug.cc')
| -rw-r--r-- | src/3d/visual_debug.cc | 26 |
1 files changed, 26 insertions, 0 deletions
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}); } |
