From 93ab82536da201ffb154d4441d994ee7772b0529 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Fri, 25 Nov 2022 11:43:06 -0600 Subject: [PATCH] Use a more specific type for Mesh create_(convex|trimesh)_shape --- doc/classes/Mesh.xml | 4 ++-- editor/import/resource_importer_scene.cpp | 2 +- editor/plugins/mesh_instance_3d_editor_plugin.cpp | 10 ++++++---- scene/3d/collision_object_3d.cpp | 1 + scene/3d/mesh_instance_3d.cpp | 6 ++++-- scene/3d/spring_arm_3d.cpp | 1 + scene/resources/importer_mesh.cpp | 4 ++-- scene/resources/importer_mesh.h | 2 +- scene/resources/mesh.cpp | 6 +++--- scene/resources/mesh.h | 9 ++++++--- 10 files changed, 27 insertions(+), 18 deletions(-) diff --git a/doc/classes/Mesh.xml b/doc/classes/Mesh.xml index 640fa9efec8..4d3fb7ed5c5 100644 --- a/doc/classes/Mesh.xml +++ b/doc/classes/Mesh.xml @@ -97,7 +97,7 @@ - + @@ -115,7 +115,7 @@ - + Calculate a [ConcavePolygonShape3D] from the mesh. diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index f7a3ce26799..ffe69544840 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -355,7 +355,7 @@ static void _pre_gen_shape_list(Ref &mesh, Vector> &r ERR_FAIL_NULL_MSG(mesh, "Cannot generate shape list with null mesh value"); ERR_FAIL_NULL_MSG(mesh->get_mesh(), "Cannot generate shape list with null mesh value"); if (!p_convex) { - Ref shape = mesh->create_trimesh_shape(); + Ref shape = mesh->create_trimesh_shape(); r_shape_list.push_back(shape); } else { Vector> cd; diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.cpp b/editor/plugins/mesh_instance_3d_editor_plugin.cpp index 68fbce771aa..420c8dfde0c 100644 --- a/editor/plugins/mesh_instance_3d_editor_plugin.cpp +++ b/editor/plugins/mesh_instance_3d_editor_plugin.cpp @@ -38,6 +38,8 @@ #include "scene/3d/navigation_region_3d.h" #include "scene/3d/physics_body_3d.h" #include "scene/gui/box_container.h" +#include "scene/resources/concave_polygon_shape_3d.h" +#include "scene/resources/convex_polygon_shape_3d.h" void MeshInstance3DEditor::_node_removed(Node *p_node) { if (p_node == node) { @@ -66,7 +68,7 @@ void MeshInstance3DEditor::_menu_option(int p_option) { List selection = editor_selection->get_selected_node_list(); if (selection.is_empty()) { - Ref shape = mesh->create_trimesh_shape(); + Ref shape = mesh->create_trimesh_shape(); if (shape.is_null()) { err_dialog->set_text(TTR("Couldn't create a Trimesh collision shape.")); err_dialog->popup_centered(); @@ -105,7 +107,7 @@ void MeshInstance3DEditor::_menu_option(int p_option) { continue; } - Ref shape = m->create_trimesh_shape(); + Ref shape = m->create_trimesh_shape(); if (shape.is_null()) { continue; } @@ -137,7 +139,7 @@ void MeshInstance3DEditor::_menu_option(int p_option) { return; } - Ref shape = mesh->create_trimesh_shape(); + Ref shape = mesh->create_trimesh_shape(); if (shape.is_null()) { return; } @@ -171,7 +173,7 @@ void MeshInstance3DEditor::_menu_option(int p_option) { bool simplify = (p_option == MENU_OPTION_CREATE_SIMPLIFIED_CONVEX_COLLISION_SHAPE); - Ref shape = mesh->create_convex_shape(true, simplify); + Ref shape = mesh->create_convex_shape(true, simplify); if (shape.is_null()) { err_dialog->set_text(TTR("Couldn't create a single convex collision shape.")); diff --git a/scene/3d/collision_object_3d.cpp b/scene/3d/collision_object_3d.cpp index ca23fe03a24..66546092f24 100644 --- a/scene/3d/collision_object_3d.cpp +++ b/scene/3d/collision_object_3d.cpp @@ -30,6 +30,7 @@ #include "collision_object_3d.h" +#include "scene/resources/shape_3d.h" #include "scene/scene_string_names.h" void CollisionObject3D::_notification(int p_what) { diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp index d4f60503c22..04d164ba88b 100644 --- a/scene/3d/mesh_instance_3d.cpp +++ b/scene/3d/mesh_instance_3d.cpp @@ -33,6 +33,8 @@ #include "collision_shape_3d.h" #include "core/core_string_names.h" #include "physics_body_3d.h" +#include "scene/resources/concave_polygon_shape_3d.h" +#include "scene/resources/convex_polygon_shape_3d.h" bool MeshInstance3D::_set(const StringName &p_name, const Variant &p_value) { //this is not _too_ bad performance wise, really. it only arrives here if the property was not set anywhere else. @@ -224,7 +226,7 @@ Node *MeshInstance3D::create_trimesh_collision_node() { return nullptr; } - Ref shape = mesh->create_trimesh_shape(); + Ref shape = mesh->create_trimesh_shape(); if (shape.is_null()) { return nullptr; } @@ -254,7 +256,7 @@ Node *MeshInstance3D::create_convex_collision_node(bool p_clean, bool p_simplify return nullptr; } - Ref shape = mesh->create_convex_shape(p_clean, p_simplify); + Ref shape = mesh->create_convex_shape(p_clean, p_simplify); if (shape.is_null()) { return nullptr; } diff --git a/scene/3d/spring_arm_3d.cpp b/scene/3d/spring_arm_3d.cpp index f855fce318e..6d8ce065240 100644 --- a/scene/3d/spring_arm_3d.cpp +++ b/scene/3d/spring_arm_3d.cpp @@ -31,6 +31,7 @@ #include "spring_arm_3d.h" #include "scene/3d/camera_3d.h" +#include "scene/resources/shape_3d.h" void SpringArm3D::_notification(int p_what) { switch (p_what) { diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp index cec55693450..d1278f9340f 100644 --- a/scene/resources/importer_mesh.cpp +++ b/scene/resources/importer_mesh.cpp @@ -971,10 +971,10 @@ Vector> ImporterMesh::convex_decompose(const Mesh::ConvexDecomposit return ret; } -Ref ImporterMesh::create_trimesh_shape() const { +Ref ImporterMesh::create_trimesh_shape() const { Vector faces = get_faces(); if (faces.size() == 0) { - return Ref(); + return Ref(); } Vector face_points; diff --git a/scene/resources/importer_mesh.h b/scene/resources/importer_mesh.h index 088a77edd10..bbd6498fcf1 100644 --- a/scene/resources/importer_mesh.h +++ b/scene/resources/importer_mesh.h @@ -119,7 +119,7 @@ public: Vector get_faces() const; Vector> convex_decompose(const Mesh::ConvexDecompositionSettings &p_settings) const; - Ref create_trimesh_shape() const; + Ref create_trimesh_shape() const; Ref create_navigation_mesh(); Error lightmap_unwrap_cached(const Transform3D &p_base_transform, float p_texel_size, const Vector &p_src_cache, Vector &r_dst_cache); diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index d1e300e057d..4f68a6f69ba 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -388,7 +388,7 @@ Vector Mesh::get_surface_faces(int p_surface) const { return Vector(); } -Ref Mesh::create_convex_shape(bool p_clean, bool p_simplify) const { +Ref Mesh::create_convex_shape(bool p_clean, bool p_simplify) const { if (p_simplify) { ConvexDecompositionSettings settings; settings.max_convex_hulls = 1; @@ -425,10 +425,10 @@ Ref Mesh::create_convex_shape(bool p_clean, bool p_simplify) const { return shape; } -Ref Mesh::create_trimesh_shape() const { +Ref Mesh::create_trimesh_shape() const { Vector faces = get_faces(); if (faces.size() == 0) { - return Ref(); + return Ref(); } Vector face_points; diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index 5ed41641176..6f995280e8a 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -35,9 +35,12 @@ #include "core/math/face3.h" #include "core/math/triangle_mesh.h" #include "scene/resources/material.h" -#include "scene/resources/shape_3d.h" #include "servers/rendering_server.h" +class ConcavePolygonShape3D; +class ConvexPolygonShape3D; +class Shape3D; + class Mesh : public Resource { GDCLASS(Mesh, Resource); @@ -211,8 +214,8 @@ public: static ConvexDecompositionFunc convex_decomposition_function; Vector> convex_decompose(const ConvexDecompositionSettings &p_settings) const; - Ref create_convex_shape(bool p_clean = true, bool p_simplify = false) const; - Ref create_trimesh_shape() const; + Ref create_convex_shape(bool p_clean = true, bool p_simplify = false) const; + Ref create_trimesh_shape() const; virtual int get_builtin_bind_pose_count() const; virtual Transform3D get_builtin_bind_pose(int p_index) const;