ability to click on spatial subscene to select it

This commit is contained in:
Jakub Grzesik 2017-08-09 18:40:02 +02:00
parent 1536cc4381
commit d2d62122e2
1 changed files with 29 additions and 3 deletions

View File

@ -266,6 +266,8 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
float closest_dist = 1e20; float closest_dist = 1e20;
int selected_handle = -1; int selected_handle = -1;
Vector<Spatial *> subscenes = Vector<Spatial *>();
for (int i = 0; i < instances.size(); i++) { for (int i = 0; i < instances.size(); i++) {
Object *obj = ObjectDB::get_instance(instances[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(); Ref<SpatialEditorGizmo> seg = spat->get_gizmo();
if (!seg.is_valid()) if ((!seg.is_valid()) || found_gizmos.has(seg)) {
continue;
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; continue;
}
found_gizmos.insert(seg); found_gizmos.insert(seg);
Vector3 point; Vector3 point;
@ -311,6 +321,22 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
// r_includes_current=true; // 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) if (!item)
return 0; return 0;