From 87ba4daf4bd627af033b4fbd784f783d9c58988b Mon Sep 17 00:00:00 2001 From: Kiri Jolly Date: Tue, 28 Apr 2020 17:14:06 -0700 Subject: Fixed false positives in the culling system. This fixes numerous false positives coming out of the culling system. AABB checks are now a full separating-axis check against the frustum, with the points of the frustum being compared to the planes of the box just as the points of the box were being compared to the planes of the frustum. This fixes large objects behind the camera not being culled correctly. Some systems that used frustums that were (sometimes mistakenly?) unbounded on one or more side have been modified to be fully enclosed. --- editor/node_3d_editor_gizmos.cpp | 5 +++-- editor/plugins/node_3d_editor_plugin.cpp | 16 ++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'editor') diff --git a/editor/node_3d_editor_gizmos.cpp b/editor/node_3d_editor_gizmos.cpp index 9a5df3e58f..5fcc783644 100644 --- a/editor/node_3d_editor_gizmos.cpp +++ b/editor/node_3d_editor_gizmos.cpp @@ -486,11 +486,12 @@ bool EditorNode3DGizmo::intersect_frustum(const Camera3D *p_camera, const Vector Vector transformed_frustum; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < p_frustum.size(); i++) { transformed_frustum.push_back(it.xform(p_frustum[i])); } - if (collision_mesh->inside_convex_shape(transformed_frustum.ptr(), transformed_frustum.size(), mesh_scale)) { + Vector convex_points = Geometry::compute_convex_mesh_points(p_frustum.ptr(), p_frustum.size()); + if (collision_mesh->inside_convex_shape(transformed_frustum.ptr(), transformed_frustum.size(), convex_points.ptr(), convex_points.size(), mesh_scale)) { return true; } } diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 17eaa06d57..723898ba6a 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -674,17 +674,13 @@ void Node3DEditorViewport::_select_region() { } } - if (!orthogonal) { - Plane near(cam_pos, -_get_camera_normal()); - near.d -= get_znear(); + Plane near(cam_pos, -_get_camera_normal()); + near.d -= get_znear(); + frustum.push_back(near); - frustum.push_back(near); - - Plane far = -near; - far.d += get_zfar(); - - frustum.push_back(far); - } + Plane far = -near; + far.d += get_zfar(); + frustum.push_back(far); Vector instances = RenderingServer::get_singleton()->instances_cull_convex(frustum, get_tree()->get_root()->get_world()->get_scenario()); Vector selected; -- cgit v1.2.3