From 0fc082e1ee3af5bb6a4b52f85756d24dc02b230f Mon Sep 17 00:00:00 2001 From: Jamie Greunbaum Date: Tue, 2 Apr 2024 03:26:10 -0400 Subject: Add CollisionShape3D custom debug colours This allows changing the display colour of a CollisionShape3D node on a per-shape basis. It also adds the ability to display a solid coloured preview of a CollisionShape3D. Closes https://github.com/godotengine/godot-proposals/issues/906 --- scene/resources/3d/sphere_shape_3d.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'scene/resources/3d/sphere_shape_3d.cpp') diff --git a/scene/resources/3d/sphere_shape_3d.cpp b/scene/resources/3d/sphere_shape_3d.cpp index 56b78471ec..bdce41c16f 100644 --- a/scene/resources/3d/sphere_shape_3d.cpp +++ b/scene/resources/3d/sphere_shape_3d.cpp @@ -30,6 +30,8 @@ #include "sphere_shape_3d.h" +#include "scene/resources/3d/primitive_meshes.h" +#include "scene/resources/material.h" #include "servers/physics_server_3d.h" Vector SphereShape3D::get_debug_mesh_lines() const { @@ -54,6 +56,24 @@ Vector SphereShape3D::get_debug_mesh_lines() const { return points; } +Ref SphereShape3D::get_debug_arraymesh_faces(const Color &p_modulate) const { + Array sphere_array; + sphere_array.resize(RS::ARRAY_MAX); + SphereMesh::create_mesh_array(sphere_array, radius, radius * 2, 32); + + Vector colors; + const PackedVector3Array &verts = sphere_array[RS::ARRAY_VERTEX]; + const int32_t verts_size = verts.size(); + for (int i = 0; i < verts_size; i++) { + colors.append(p_modulate); + } + + Ref sphere_mesh = memnew(ArrayMesh); + sphere_array[RS::ARRAY_COLOR] = colors; + sphere_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, sphere_array); + return sphere_mesh; +} + real_t SphereShape3D::get_enclosing_radius() const { return radius; } -- cgit v1.2.3