From 14d3a8dd83845e4ba3120d3b0671177cd0cf6cef Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Wed, 24 Mar 2021 17:51:27 -0700 Subject: [PATCH] Draw triangles for HeightMapShape debug collision Helps with ambiguous cases where it's not possible to tell which diagonal is used for collision in quads. --- scene/resources/height_map_shape.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scene/resources/height_map_shape.cpp b/scene/resources/height_map_shape.cpp index aef8345c08e..44664140aa6 100644 --- a/scene/resources/height_map_shape.cpp +++ b/scene/resources/height_map_shape.cpp @@ -45,7 +45,7 @@ Vector HeightMapShape::get_debug_mesh_lines() { PoolRealArray::Read r = map_data.read(); // reserve some memory for our points.. - points.resize(((map_width - 1) * map_depth * 2) + (map_width * (map_depth - 1) * 2)); + points.resize(((map_width - 1) * map_depth * 2) + (map_width * (map_depth - 1) * 2) + (map_width - 1) * (map_depth - 1) * 2); // now set our points int r_offset = 0; @@ -66,6 +66,11 @@ Vector HeightMapShape::get_debug_mesh_lines() { points.write[w_offset++] = Vector3(height.x, r[r_offset + map_width - 1], height.z + 1.0); } + if ((w != map_width - 1) && (d != map_depth - 1)) { + points.write[w_offset++] = Vector3(height.x + 1.0, r[r_offset], height.z); + points.write[w_offset++] = Vector3(height.x, r[r_offset + map_width - 1], height.z + 1.0); + } + height.x += 1.0; }