mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-11 22:50:08 +00:00
moved more useful methods from editor to fyrox-graph
This commit is contained in:
@@ -141,8 +141,8 @@ impl MoveContext {
|
||||
frame_size,
|
||||
|plane_point, gizmo_inv_transform, gizmo_origin| {
|
||||
let graph = &scene.graph;
|
||||
selection
|
||||
.root_nodes(graph)
|
||||
graph
|
||||
.root_nodes(selection.nodes())
|
||||
.iter()
|
||||
.map(|&node_handle| {
|
||||
let node = &graph[node_handle];
|
||||
|
||||
@@ -25,6 +25,7 @@ use crate::fyrox::{
|
||||
};
|
||||
use crate::{scene::GraphSelection, Engine};
|
||||
use fyrox::core::blank_reflect_ref;
|
||||
use fyrox::graph::SceneGraph;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -94,7 +95,7 @@ impl Clipboard {
|
||||
|
||||
let scene = &engine.scenes[scene_handle];
|
||||
|
||||
let root_nodes = selection.root_nodes(&scene.graph);
|
||||
let root_nodes = scene.graph.root_nodes(selection.nodes());
|
||||
|
||||
deep_clone_nodes(&root_nodes, &scene.graph, &mut self.graph);
|
||||
|
||||
|
||||
+4
-22
@@ -440,34 +440,16 @@ impl GameScene {
|
||||
editor_selection: &Selection,
|
||||
graph: &Graph,
|
||||
) -> bool {
|
||||
if let Some(selection) = editor_selection.as_graph() {
|
||||
// Convert selection to the full list of descendant nodes first.
|
||||
let roots = selection.root_nodes(graph);
|
||||
let mut all_nodes = FxHashSet::default();
|
||||
for root in roots {
|
||||
for (descendant_handle, _) in graph.traverse_iter(root) {
|
||||
all_nodes.insert(descendant_handle);
|
||||
}
|
||||
}
|
||||
|
||||
for node in selection.nodes() {
|
||||
for (descendant_handle, _) in graph.traverse_iter(*node) {
|
||||
for reference in graph.find_references_to(descendant_handle) {
|
||||
if !all_nodes.contains(&reference) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
editor_selection
|
||||
.as_graph()
|
||||
.is_some_and(|s| !graph.external_refs(s.nodes()).is_empty())
|
||||
}
|
||||
|
||||
fn try_save_selection_as_prefab(&self, path: &Path, selection: &Selection, engine: &Engine) {
|
||||
let source_scene = &engine.scenes[self.scene];
|
||||
let mut dest_scene = Scene::new();
|
||||
if let Some(graph_selection) = selection.as_graph() {
|
||||
for root_node in graph_selection.root_nodes(&source_scene.graph) {
|
||||
for root_node in source_scene.graph.root_nodes(graph_selection.nodes()) {
|
||||
source_scene.graph.copy_node(
|
||||
root_node,
|
||||
&mut dest_scene.graph,
|
||||
|
||||
@@ -152,7 +152,7 @@ impl SelectionContainer for GraphSelection {
|
||||
// by engine's design when we delete a node, we also delete all its children. So we have to keep
|
||||
// this behaviour in editor too.
|
||||
|
||||
let root_nodes = selection.root_nodes(graph);
|
||||
let root_nodes = graph.root_nodes(selection.nodes());
|
||||
|
||||
for root_node in root_nodes {
|
||||
command_group.push(DeleteSubGraphCommand::new(root_node));
|
||||
@@ -207,38 +207,6 @@ impl GraphSelection {
|
||||
self.nodes.extend_from_slice(&other.nodes)
|
||||
}
|
||||
|
||||
pub fn root_nodes(&self, graph: &Graph) -> Vec<Handle<Node>> {
|
||||
// Helper function.
|
||||
fn is_descendant_of(handle: Handle<Node>, other: Handle<Node>, graph: &Graph) -> bool {
|
||||
for &child in graph[other].children() {
|
||||
if child == handle {
|
||||
return true;
|
||||
}
|
||||
|
||||
let inner = is_descendant_of(handle, child, graph);
|
||||
if inner {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
let mut root_nodes = Vec::new();
|
||||
for &node in self.nodes().iter() {
|
||||
let mut descendant = false;
|
||||
for &other_node in self.nodes().iter() {
|
||||
if is_descendant_of(node, other_node, graph) {
|
||||
descendant = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !descendant {
|
||||
root_nodes.push(node);
|
||||
}
|
||||
}
|
||||
root_nodes
|
||||
}
|
||||
|
||||
pub fn global_rotation_position(
|
||||
&self,
|
||||
graph: &Graph,
|
||||
|
||||
Reference in New Issue
Block a user