diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-08-11 10:39:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-11 10:39:59 +0200 |
commit | 30e33f0c8496fe4cdbb4b6e628bd7eebc186735a (patch) | |
tree | 930d5af250471cf2c818ea54075ea898b0f120f8 | |
parent | b47e6c0dba0fb89aabedae204c247c747f99b87b (diff) | |
parent | d2d62122e26afa66ff69d17a2c3b87ec6ed7e885 (diff) |
Merge pull request #10209 from kubecz3k/click-spatial-select
ability to click on spatial subscene to select it
-rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 0dba1f12a2..a549f09cb1 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -266,6 +266,8 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, float closest_dist = 1e20; int selected_handle = -1; + Vector<Spatial *> subscenes = Vector<Spatial *>(); + for (int i = 0; i < instances.size(); i++) { Object *obj = ObjectDB::get_instance(instances[i]); @@ -279,11 +281,19 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, Ref<SpatialEditorGizmo> seg = spat->get_gizmo(); - if (!seg.is_valid()) - continue; + if ((!seg.is_valid()) || found_gizmos.has(seg)) { + + Node *subscene_candidate = spat; + + while (subscene_candidate->get_owner() != editor->get_edited_scene()) + subscene_candidate = subscene_candidate->get_owner(); + + spat = subscene_candidate->cast_to<Spatial>(); + if (spat && (spat->get_filename() != "")) + subscenes.push_back(spat); - if (found_gizmos.has(seg)) continue; + } found_gizmos.insert(seg); Vector3 point; @@ -311,6 +321,22 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, // r_includes_current=true; } + for (int idx_subscene = 0; idx_subscene < subscenes.size(); idx_subscene++) { + + Spatial *subscene = subscenes.get(idx_subscene); + float dist = ray.cross(subscene->get_global_transform().origin - pos).length(); + + if ((dist < 0) || (dist > 1.2)) + continue; + + if (dist < closest_dist) { + closest = subscene->get_instance_id(); + closest_dist = dist; + item = subscene; + selected_handle = -1; + } + } + if (!item) return 0; |