summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-09-13 11:22:08 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-09-13 11:22:08 +0200
commitd5d6c730bf39327b1f4eb2f1cbc280f102959592 (patch)
tree577d92f1231998710244c37ed734611aaf4d002b
parent84f1fe781c7ef92f28b6e0a6f020fd9294dee8dc (diff)
parentb8de7b72c69c410d27aedb3f0845e9adcd3b976f (diff)
downloadredot-engine-d5d6c730bf39327b1f4eb2f1cbc280f102959592.tar.gz
Merge pull request #96934 from smix8/planemesh_gizmo
Fix `MeshInstance3D` gizmo redraw performance for `PlaneMesh` with larger subdiv value
-rw-r--r--editor/plugins/gizmos/mesh_instance_3d_gizmo_plugin.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/editor/plugins/gizmos/mesh_instance_3d_gizmo_plugin.cpp b/editor/plugins/gizmos/mesh_instance_3d_gizmo_plugin.cpp
index e54f429b8d..251fb6892e 100644
--- a/editor/plugins/gizmos/mesh_instance_3d_gizmo_plugin.cpp
+++ b/editor/plugins/gizmos/mesh_instance_3d_gizmo_plugin.cpp
@@ -33,6 +33,7 @@
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/soft_body_3d.h"
+#include "scene/resources/3d/primitive_meshes.h"
MeshInstance3DGizmoPlugin::MeshInstance3DGizmoPlugin() {
}
@@ -64,7 +65,22 @@ void MeshInstance3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
return; //none
}
- Ref<TriangleMesh> tm = m->generate_triangle_mesh();
+ Ref<TriangleMesh> tm;
+
+ Ref<PlaneMesh> plane_mesh = mesh->get_mesh();
+ if (plane_mesh.is_valid() && (plane_mesh->get_subdivide_depth() > 0 || plane_mesh->get_subdivide_width() > 0)) {
+ // PlaneMesh subdiv makes gizmo redraw very slow due to TriangleMesh BVH calculation for every face.
+ // For gizmo collision this is very much unnecessary since a PlaneMesh is always flat, 2 faces is enough.
+ Ref<PlaneMesh> simple_plane_mesh;
+ simple_plane_mesh.instantiate();
+ simple_plane_mesh->set_orientation(plane_mesh->get_orientation());
+ simple_plane_mesh->set_size(plane_mesh->get_size());
+ simple_plane_mesh->set_center_offset(plane_mesh->get_center_offset());
+ tm = simple_plane_mesh->generate_triangle_mesh();
+ } else {
+ tm = m->generate_triangle_mesh();
+ }
+
if (tm.is_valid()) {
p_gizmo->add_collision_triangles(tm);
}