diff options
Diffstat (limited to 'scene/resources/3d/world_boundary_shape_3d.cpp')
-rw-r--r-- | scene/resources/3d/world_boundary_shape_3d.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/scene/resources/3d/world_boundary_shape_3d.cpp b/scene/resources/3d/world_boundary_shape_3d.cpp index 7cff587a20..1957b2c99e 100644 --- a/scene/resources/3d/world_boundary_shape_3d.cpp +++ b/scene/resources/3d/world_boundary_shape_3d.cpp @@ -32,6 +32,7 @@ #include "world_boundary_shape_3d.h" +#include "scene/resources/mesh.h" #include "servers/physics_server_3d.h" Vector<Vector3> WorldBoundaryShape3D::get_debug_mesh_lines() const { @@ -63,6 +64,53 @@ Vector<Vector3> WorldBoundaryShape3D::get_debug_mesh_lines() const { return points; } +Ref<ArrayMesh> WorldBoundaryShape3D::get_debug_arraymesh_faces(const Color &p_modulate) const { + Plane p = get_plane(); + + Vector3 n1 = p.get_any_perpendicular_normal(); + Vector3 n2 = p.normal.cross(n1).normalized(); + + Vector3 pface[4] = { + p.normal * p.d + n1 * 10.0 + n2 * 10.0, + p.normal * p.d + n1 * 10.0 + n2 * -10.0, + p.normal * p.d + n1 * -10.0 + n2 * -10.0, + p.normal * p.d + n1 * -10.0 + n2 * 10.0, + }; + + Vector<Vector3> points = { + pface[0], + pface[1], + pface[2], + pface[3], + }; + + Vector<Color> colors = { + p_modulate, + p_modulate, + p_modulate, + p_modulate, + }; + + Vector<int> indices = { + 0, + 1, + 2, + 0, + 2, + 3, + }; + + Ref<ArrayMesh> mesh = memnew(ArrayMesh); + Array a; + a.resize(Mesh::ARRAY_MAX); + a[RS::ARRAY_VERTEX] = points; + a[RS::ARRAY_COLOR] = colors; + a[RS::ARRAY_INDEX] = indices; + mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, a); + + return mesh; +} + void WorldBoundaryShape3D::_update_shape() { PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), plane); Shape3D::_update_shape(); |