summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaracenOne <SaracenOne@gmail.com>2021-07-21 20:32:55 +0100
committerSaracenOne <SaracenOne@gmail.com>2021-07-26 17:38:48 +0100
commitfbda490d0f8e5e35c377a5afd5f00d956c1dd765 (patch)
tree32eaecdeb77a5d258b0c1b7d5074807d09b583d2
parentfef27e9b5b9b125ff535513c80b45953e8717f7d (diff)
Removing bounding box calculations from 3D scene drag and drop and collide against physics rather than visual geometry.
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp57
1 files changed, 5 insertions, 52 deletions
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index 6b6f5e7bc6..b7651c350c 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -3782,63 +3782,16 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const
Vector3 world_ray = _get_ray(p_pos);
Vector3 world_pos = _get_ray_pos(p_pos);
- Vector<ObjectID> instances = RenderingServer::get_singleton()->instances_cull_ray(world_pos, world_ray, get_tree()->get_root()->get_world_3d()->get_scenario());
- Set<Ref<EditorNode3DGizmo>> found_gizmos;
-
- float closest_dist = MAX_DISTANCE;
-
Vector3 point = world_pos + world_ray * MAX_DISTANCE;
- Vector3 normal = Vector3(0.0, 0.0, 0.0);
-
- for (int i = 0; i < instances.size(); i++) {
- MeshInstance3D *mesh_instance = Object::cast_to<MeshInstance3D>(ObjectDB::get_instance(instances[i]));
-
- if (!mesh_instance) {
- continue;
- }
-
- Vector<Ref<Node3DGizmo>> gizmos = mesh_instance->get_gizmos();
-
- for (int j = 0; j < gizmos.size(); j++) {
- Ref<EditorNode3DGizmo> seg = gizmos[j];
-
- if ((!seg.is_valid()) || found_gizmos.has(seg)) {
- continue;
- }
-
- found_gizmos.insert(seg);
- Vector3 hit_point;
- Vector3 hit_normal;
- bool inters = seg->intersect_ray(camera, p_pos, hit_point, hit_normal);
-
- if (!inters) {
- continue;
- }
-
- float dist = world_pos.distance_to(hit_point);
-
- if (dist < 0) {
- continue;
- }
+ PhysicsDirectSpaceState3D *ss = get_tree()->get_root()->get_world_3d()->get_direct_space_state();
+ PhysicsDirectSpaceState3D::RayResult result;
- if (dist < closest_dist) {
- closest_dist = dist;
- point = hit_point;
- normal = hit_normal;
- }
- }
+ if (ss->intersect_ray(world_pos, world_pos + world_ray * MAX_DISTANCE, result)) {
+ point = result.position;
}
- Vector3 offset = Vector3();
- for (int i = 0; i < 3; i++) {
- if (normal[i] > 0.0) {
- offset[i] = (preview_bounds->get_size()[i] - (preview_bounds->get_size()[i] + preview_bounds->get_position()[i]));
- } else if (normal[i] < 0.0) {
- offset[i] = -(preview_bounds->get_size()[i] + preview_bounds->get_position()[i]);
- }
- }
- return point + offset;
+ return point;
}
AABB Node3DEditorViewport::_calculate_spatial_bounds(const Node3D *p_parent, bool p_exclude_top_level_transform) {