ソースを参照

ability to click on spatial subscene to select it

(cherry-picked from d2d62122e26afa66ff69d17a2c3b87ec6ed7e885)
vipsbpig 8 年 前
コミット
a04bb88e46
1 ファイル変更29 行追加3 行削除
  1. 29 3
      editor/plugins/spatial_editor_plugin.cpp

+ 29 - 3
editor/plugins/spatial_editor_plugin.cpp

@@ -260,6 +260,7 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
 	r_includes_current = false;
 
 	List<_RayResult> results;
+	Vector<Spatial *> subscenes = Vector<Spatial *>();
 
 	for (int i = 0; i < instances.size(); i++) {
 
@@ -275,11 +276,18 @@ 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;
@@ -305,6 +313,24 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
 		res.handle = handle;
 		results.push_back(res);
 	}
+	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 (editor_selection->is_selected(subscene))
+			r_includes_current = true;
+
+		_RayResult res;
+		res.item = subscene;
+		res.depth = dist;
+		res.handle = -1;
+		results.push_back(res);
+	}
+
 
 	if (results.empty())
 		return 0;