Skip to content

Commit dda1f00

Browse files
committed
node spec editor code working
1 parent 4854f11 commit dda1f00

51 files changed

Lines changed: 1481 additions & 557 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(
2+
nodes: [],
3+
edges_inverted: {
4+
OutputData("test"): InputData(Default("f")),
5+
},
6+
io_spec: (
7+
input_times: [
8+
Default("some time ago"),
9+
],
10+
input_data: {
11+
Default("test"): Quat,
12+
Default("other_test"): RagdollConfig,
13+
Default("f"): F32,
14+
},
15+
output_time: true,
16+
output_data: {
17+
"test": F32,
18+
},
19+
input_order: {
20+
Data(Default("other_test")): 0,
21+
Data(Default("test")): 1,
22+
Data(Default("f")): 2,
23+
Time(Default("some time ago")): 3,
24+
},
25+
output_order: {
26+
Time: 0,
27+
Data("test"): 1,
28+
},
29+
),
30+
default_data: {},
31+
editor_metadata: (
32+
node_positions: {},
33+
input_position: (14.8515625, 58.16797),
34+
output_position: (372.15234, 99.671875),
35+
input_param_order: {},
36+
input_time_order: {},
37+
output_data_order: {},
38+
output_pose_order: {},
39+
),
40+
)

crates/bevy_animation_graph_builtin_nodes/src/graph_node.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use bevy_animation_graph_core::{
66
graph_context::QueryOutputTime,
77
io_env::GraphIoEnv,
88
new_context::{GraphContext, NodeContext},
9-
spec_context::SpecContext,
9+
spec_context::{NodeInput, NodeOutput, SpecContext},
1010
},
1111
duration_data::DurationData,
1212
edge_data::DataValue,
@@ -44,7 +44,7 @@ impl NodeLike for GraphNode {
4444
.create_child_context(self.graph.id(), None)
4545
.with_io(&sub_ctx_io);
4646

47-
if graph.node_spec.has_output_time() {
47+
if graph.io_spec.has_output_time() {
4848
let target_pin = TargetPin::OutputTime;
4949
let duration = graph.get_duration(target_pin, sub_ctx)?;
5050
ctx.set_duration_fwd(duration);
@@ -73,7 +73,7 @@ impl NodeLike for GraphNode {
7373
.create_child_context(self.graph.id(), None)
7474
.with_io(&sub_ctx_io);
7575

76-
if graph.node_spec.has_output_time() {
76+
if graph.io_spec.has_output_time() {
7777
let input = ctx.time_update_fwd();
7878
if let Ok(time_update) = input {
7979
let key = sub_ctx.state_key;
@@ -82,7 +82,7 @@ impl NodeLike for GraphNode {
8282
}
8383
}
8484

85-
for (id, _) in graph.node_spec.iter_output_data() {
85+
for (id, _) in graph.io_spec.iter_output_data() {
8686
let target_pin = TargetPin::OutputData(id.clone());
8787
let value = graph.get_data(target_pin, sub_ctx.clone())?;
8888
ctx.set_data_fwd(id, value);
@@ -97,7 +97,28 @@ impl NodeLike for GraphNode {
9797
.graph_assets
9898
.get(&self.graph)
9999
.ok_or(GraphError::GraphAssetMissing)?;
100-
ctx.set_from_node_spec(&graph.node_spec);
100+
for input in graph.io_spec.sorted_inputs() {
101+
match input {
102+
NodeInput::Time(GraphInputPin::Default(pin_id)) => {
103+
ctx.add_input_time(pin_id);
104+
}
105+
NodeInput::Data(GraphInputPin::Default(pin_id), data_spec) => {
106+
ctx.add_input_data(pin_id, data_spec);
107+
}
108+
_ => {}
109+
}
110+
}
111+
112+
for output in graph.io_spec.sorted_outputs() {
113+
match output {
114+
NodeOutput::Time => {
115+
ctx.add_output_time();
116+
}
117+
NodeOutput::Data(pin_id, data_spec) => {
118+
ctx.add_output_data(pin_id, data_spec);
119+
}
120+
}
121+
}
101122

102123
Ok(())
103124
}

crates/bevy_animation_graph_core/src/animation_graph/loader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ impl AssetLoader for AnimationGraphLoader {
4747
// Set up editor metadata
4848
// Needs to be done before adding nodes in case data is missing, so that it
4949
// gets properly initialized.
50-
graph.extra = serial.extra;
50+
graph.editor_metadata = serial.editor_metadata;
5151

5252
// Add nodes
5353
for node_ron in serial.nodes {
5454
let node = node_ron.finish_deserialize(&self.type_registry.read(), load_context)?;
5555
graph.add_node(node);
5656
}
5757

58-
graph.node_spec = serial.node_spec;
58+
graph.io_spec = serial.io_spec;
5959

6060
// Set default data values
6161
for (param_name, param_value) in serial.default_data {

crates/bevy_animation_graph_core/src/animation_graph/mod.rs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{
1919
graph_context_arena::GraphContextArena,
2020
io_env::{EmptyIoEnv, GraphIoEnv},
2121
new_context::GraphContext,
22-
spec_context::{NodeSpec, SpecResources},
22+
spec_context::{GraphSpec, SpecResources},
2323
system_resources::SystemResources,
2424
},
2525
duration_data::DurationData,
@@ -47,6 +47,12 @@ pub enum GraphInputPin {
4747
FsmBuiltin(FsmBuiltinPin),
4848
}
4949

50+
impl Default for GraphInputPin {
51+
fn default() -> Self {
52+
Self::Default("".into())
53+
}
54+
}
55+
5056
impl From<FsmBuiltinPin> for GraphInputPin {
5157
fn from(value: FsmBuiltinPin) -> Self {
5258
Self::FsmBuiltin(value)
@@ -229,12 +235,12 @@ pub struct AnimationGraph {
229235
pub edges_inverted: HashMap<TargetPin, SourcePin>,
230236

231237
/// Defines inputs and outputs for this graph.
232-
pub node_spec: NodeSpec,
238+
pub io_spec: GraphSpec,
233239

234240
pub default_data: HashMap<PinId, DataValue>,
235241

236242
#[reflect(ignore)]
237-
pub extra: EditorMetadata,
243+
pub editor_metadata: EditorMetadata,
238244
}
239245

240246
impl Default for AnimationGraph {
@@ -253,27 +259,27 @@ impl AnimationGraph {
253259
edges_inverted: HashMap::new(),
254260
edges: HashMap::new(),
255261

256-
node_spec: NodeSpec::default(),
262+
io_spec: GraphSpec::default(),
257263

258264
default_data: HashMap::new(),
259265

260-
extra: EditorMetadata::default(),
266+
editor_metadata: EditorMetadata::default(),
261267
}
262268
}
263269

264270
// --- Core graph interface: add nodes and edges
265271
// ----------------------------------------------------------------------------------------
266272
/// Add a new node to the graph
267273
pub fn add_node(&mut self, node: AnimationNode) {
268-
self.extra.node_added(node.id);
274+
self.editor_metadata.node_added(node.id);
269275
self.nodes.insert(node.id, node);
270276
}
271277

272278
/// Add a new node to the graph
273279
pub fn remove_node(&mut self, node_id: impl Into<NodeId>) {
274280
let node_id = node_id.into();
275281
self.nodes.remove(&node_id);
276-
self.extra.node_positions.remove(&node_id);
282+
self.editor_metadata.node_positions.remove(&node_id);
277283
}
278284

279285
/// Add a new edge to the graph
@@ -309,23 +315,23 @@ impl AnimationGraph {
309315
}
310316

311317
/// Register an input pose pin for the graph
312-
pub fn add_input_data(&mut self, pin_id: PinId, data_spec: DataSpec) {
313-
self.node_spec.add_input_data(pin_id, data_spec);
318+
pub fn add_input_data(&mut self, input: GraphInputPin, data_spec: DataSpec) {
319+
self.io_spec.add_input_data(input, data_spec);
314320
}
315321

316322
/// Register an input pose pin for the graph
317-
pub fn add_input_time(&mut self, pin_id: PinId) {
318-
self.node_spec.add_input_time(pin_id);
323+
pub fn add_input_time(&mut self, input: GraphInputPin) {
324+
self.io_spec.add_input_time(input);
319325
}
320326

321327
/// Register an output parameter for the graph
322328
pub fn add_output_data(&mut self, pin_id: PinId, spec: DataSpec) {
323-
self.node_spec.add_output_data(pin_id, spec);
329+
self.io_spec.add_output_data(pin_id, spec);
324330
}
325331

326332
/// Enables time "output" for this graph
327333
pub fn add_output_time(&mut self) {
328-
self.node_spec.add_output_time();
334+
self.io_spec.add_output_time();
329335
}
330336
// ----------------------------------------------------------------------------------------
331337

@@ -500,12 +506,12 @@ impl AnimationGraph {
500506
}
501507
}
502508

503-
pub fn contains_node<T: NodeLike>(&self) -> Option<NodeId> {
509+
pub fn contains_node_that<T: NodeLike>(&self, f: impl Fn(&T) -> bool) -> Option<NodeId> {
504510
self.nodes
505511
.values()
506512
.filter_map(|node| {
507-
node.inner.as_any().downcast_ref::<T>()?;
508-
Some(node.id)
513+
let inner = node.inner.as_any().downcast_ref::<T>()?;
514+
if f(inner) { Some(node.id) } else { None }
509515
})
510516
.next()
511517
}
@@ -522,7 +528,7 @@ impl AnimationGraph {
522528
.ok()
523529
.and_then(|spec| spec.get_input_data(pin_id))
524530
}
525-
TargetPin::OutputData(op) => self.node_spec.get_output_data(op),
531+
TargetPin::OutputData(op) => self.io_spec.get_output_data(op),
526532
_ => None,
527533
}
528534
}
@@ -539,7 +545,7 @@ impl AnimationGraph {
539545
.ok()
540546
.and_then(|spec| spec.get_output_data(pin_id))
541547
}
542-
SourcePin::InputData(GraphInputPin::Default(ip)) => self.node_spec.get_input_data(ip),
548+
SourcePin::InputData(ip) => self.io_spec.get_input_data(ip),
543549
_ => None,
544550
}
545551
}
@@ -556,9 +562,7 @@ impl AnimationGraph {
556562
.ok()
557563
.and_then(|spec| spec.has_output_time().then_some(()))
558564
}
559-
SourcePin::InputTime(GraphInputPin::Default(ip)) => {
560-
self.node_spec.has_input_time(ip).then_some(())
561-
}
565+
SourcePin::InputTime(ip) => self.io_spec.has_input_time(ip).then_some(()),
562566
_ => None,
563567
}
564568
}
@@ -575,7 +579,7 @@ impl AnimationGraph {
575579
.ok()
576580
.and_then(|spec| spec.has_input_time(pin_id).then_some(()))
577581
}
578-
TargetPin::OutputTime => self.node_spec.has_output_time().then_some(()),
582+
TargetPin::OutputTime => self.io_spec.has_output_time().then_some(()),
579583
_ => None,
580584
}
581585
}
@@ -852,7 +856,7 @@ impl AnimationGraph {
852856
);
853857
ctx.context_mut().query_output_time = QueryOutputTime::Forced(time_update);
854858
let mut outputs = HashMap::new();
855-
for (k, _) in self.node_spec.iter_output_data() {
859+
for (k, _) in self.io_spec.iter_output_data() {
856860
let out = self.get_data(TargetPin::OutputData(k.clone()), ctx.clone())?;
857861
outputs.insert(k.clone(), out);
858862
}

crates/bevy_animation_graph_core/src/animation_graph/serial.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};
1616
use crate::{
1717
animation_graph::{AnimationGraph, EditorMetadata, PinId, SourcePin, TargetPin},
1818
animation_node::serial::{AnimationNodeDeserializer, AnimationNodeSerializer},
19-
context::spec_context::NodeSpec,
19+
context::spec_context::GraphSpec,
2020
edge_data::DataValue,
2121
};
2222

@@ -25,23 +25,23 @@ pub struct AnimationGraphDeserializer {
2525
pub nodes: Vec<AnimationNodeDeserializer>,
2626
pub edges_inverted: HashMap<TargetPin, SourcePin>,
2727

28-
pub node_spec: NodeSpec,
28+
pub io_spec: GraphSpec,
2929

3030
pub default_data: HashMap<PinId, DataValue>,
3131

32-
pub extra: EditorMetadata,
32+
pub editor_metadata: EditorMetadata,
3333
}
3434

3535
#[derive(Serialize)]
3636
pub struct AnimationGraphSerializer<'a> {
3737
pub nodes: Vec<AnimationNodeSerializer<'a>>,
3838
pub edges_inverted: HashMap<TargetPin, SourcePin>,
3939

40-
pub node_spec: NodeSpec,
40+
pub io_spec: GraphSpec,
4141

4242
pub default_data: HashMap<PinId, DataValue>,
4343

44-
pub extra: EditorMetadata,
44+
pub editor_metadata: EditorMetadata,
4545
}
4646

4747
impl AnimationGraphSerializer<'_> {
@@ -52,9 +52,9 @@ impl AnimationGraphSerializer<'_> {
5252
let mut serial = AnimationGraphSerializer {
5353
nodes: Vec::new(),
5454
edges_inverted: graph.edges_inverted.clone(),
55-
node_spec: graph.node_spec.clone(),
55+
io_spec: graph.io_spec.clone(),
5656
default_data: graph.default_data.clone(),
57-
extra: graph.extra.clone(),
57+
editor_metadata: graph.editor_metadata.clone(),
5858
};
5959

6060
for node in graph.nodes.values() {

0 commit comments

Comments
 (0)