Skip to content

Commit d5d6c73

Browse files
committed
Merge pull request #96934 from smix8/planemesh_gizmo
Fix `MeshInstance3D` gizmo redraw performance for `PlaneMesh` with larger subdiv value
2 parents 84f1fe7 + b8de7b7 commit d5d6c73

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

editor/plugins/gizmos/mesh_instance_3d_gizmo_plugin.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "editor/plugins/node_3d_editor_plugin.h"
3434
#include "scene/3d/mesh_instance_3d.h"
3535
#include "scene/3d/soft_body_3d.h"
36+
#include "scene/resources/3d/primitive_meshes.h"
3637

3738
MeshInstance3DGizmoPlugin::MeshInstance3DGizmoPlugin() {
3839
}
@@ -64,7 +65,22 @@ void MeshInstance3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
6465
return; //none
6566
}
6667

67-
Ref<TriangleMesh> tm = m->generate_triangle_mesh();
68+
Ref<TriangleMesh> tm;
69+
70+
Ref<PlaneMesh> plane_mesh = mesh->get_mesh();
71+
if (plane_mesh.is_valid() && (plane_mesh->get_subdivide_depth() > 0 || plane_mesh->get_subdivide_width() > 0)) {
72+
// PlaneMesh subdiv makes gizmo redraw very slow due to TriangleMesh BVH calculation for every face.
73+
// For gizmo collision this is very much unnecessary since a PlaneMesh is always flat, 2 faces is enough.
74+
Ref<PlaneMesh> simple_plane_mesh;
75+
simple_plane_mesh.instantiate();
76+
simple_plane_mesh->set_orientation(plane_mesh->get_orientation());
77+
simple_plane_mesh->set_size(plane_mesh->get_size());
78+
simple_plane_mesh->set_center_offset(plane_mesh->get_center_offset());
79+
tm = simple_plane_mesh->generate_triangle_mesh();
80+
} else {
81+
tm = m->generate_triangle_mesh();
82+
}
83+
6884
if (tm.is_valid()) {
6985
p_gizmo->add_collision_triangles(tm);
7086
}

0 commit comments

Comments
 (0)