summaryrefslogtreecommitdiff
path: root/src/3d
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-08 07:21:29 +0100
committerskal <pascal.massimino@gmail.com>2026-02-08 07:21:29 +0100
commite279537708fb511abf1d8f65325c145916a10918 (patch)
treebe0a6ed193b3369b3014c4aa605c5cf983c142ad /src/3d
parent438ed437022eca66e84401563b280dc137d2f3c9 (diff)
feat(3d): Implement Mesh Wireframe rendering for Visual Debug
Diffstat (limited to 'src/3d')
-rw-r--r--src/3d/renderer.cc14
-rw-r--r--src/3d/visual_debug.cc26
-rw-r--r--src/3d/visual_debug.h3
3 files changed, 40 insertions, 3 deletions
diff --git a/src/3d/renderer.cc b/src/3d/renderer.cc
index eea3ff0..6e8f38a 100644
--- a/src/3d/renderer.cc
+++ b/src/3d/renderer.cc
@@ -306,11 +306,19 @@ void Renderer3D::draw(WGPURenderPassEncoder pass, const Scene& scene,
vec3 extent = obj.local_extent;
if (obj.type == ObjectType::TORUS) {
extent = vec3(1.5f, 0.5f, 1.5f);
- } else if (obj.type != ObjectType::MESH) {
+ } else if (obj.type == ObjectType::MESH) {
+ MeshAsset mesh = GetMeshAsset(obj.mesh_asset_id);
+ if (mesh.num_indices > 0) {
+ visual_debug_.add_mesh_wireframe(obj.get_model_matrix(), mesh.num_vertices, mesh.vertices, mesh.num_indices, mesh.indices, vec3(0.0f, 1.0f, 1.0f)); // Cyan wireframe
+ }
+ } else {
extent = vec3(1.0f, 1.0f, 1.0f);
}
- visual_debug_.add_box(obj.get_model_matrix(), extent,
- vec3(1.0f, 1.0f, 0.0f)); // Yellow boxes
+
+ if (obj.type != ObjectType::MESH) {
+ visual_debug_.add_box(obj.get_model_matrix(), extent,
+ vec3(1.0f, 1.0f, 0.0f)); // Yellow boxes
+ }
}
// Calculate ViewProj matrix for the debug renderer
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});
}
diff --git a/src/3d/visual_debug.h b/src/3d/visual_debug.h
index 7f1aa8b..c8069e1 100644
--- a/src/3d/visual_debug.h
+++ b/src/3d/visual_debug.h
@@ -30,6 +30,9 @@ class VisualDebug {
void add_aabb(const vec3& min, const vec3& max, const vec3& color);
void add_mesh_normals(const mat4& transform, uint32_t num_vertices, const MeshVertex* vertices);
+ void add_mesh_wireframe(const mat4& transform, uint32_t num_vertices,
+ const MeshVertex* vertices, uint32_t num_indices,
+ const uint32_t* indices, const vec3& color);
void add_line(const vec3& start, const vec3& end, const vec3& color);
void add_cross(const vec3& center, float size, const vec3& color);