diff options
Diffstat (limited to 'src/3d/visual_debug.cc')
| -rw-r--r-- | src/3d/visual_debug.cc | 27 |
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, |
