Skip to content

Commit ce05901

Browse files
committed
Migrate pass through and value node to identity implementation
1 parent 3419955 commit ce05901

File tree

11 files changed

+86
-71
lines changed

11 files changed

+86
-71
lines changed

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,17 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
8585
let custom = vec![
8686
// TODO: Auto-generate this from its proto node macro
8787
DocumentNodeDefinition {
88-
identifier: "Identity",
88+
identifier: "Pass Through",
8989
category: "General",
9090
node_template: NodeTemplate {
9191
document_node: DocumentNode {
92+
<<<<<<< HEAD
9293
implementation: DocumentNodeImplementation::ProtoNode(ops::identity::IDENTIFIER),
94+
||||||| parent of 8e045313 (Migrate pass through and value node to identity implementation)
95+
implementation: DocumentNodeImplementation::proto("graphene_core::ops::IdentityNode"),
96+
=======
97+
implementation: DocumentNodeImplementation::proto("graphene_std::any::IdentityNode"),
98+
>>>>>>> 8e045313 (Migrate pass through and value node to identity implementation)
9399
inputs: vec![NodeInput::value(TaggedValue::None, true)],
94100
..Default::default()
95101
},
@@ -100,14 +106,14 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
100106
},
101107
},
102108
description: Cow::Borrowed("Passes-through the input value without changing it. This is useful for rerouting wires for organization purposes."),
103-
properties: Some("identity_properties"),
109+
properties: Some("pass_through_properties"),
104110
},
105111
DocumentNodeDefinition {
106112
identifier: "Value",
107113
category: "General",
108114
node_template: NodeTemplate {
109115
document_node: DocumentNode {
110-
implementation: DocumentNodeImplementation::proto("graphene_core::any::ValueNode"),
116+
implementation: DocumentNodeImplementation::proto("graphene_std::any::IdentityNode"),
111117
manual_composition: Some(generic!(T)),
112118
inputs: vec![NodeInput::value(TaggedValue::None, false)],
113119
..Default::default()
@@ -1835,8 +1841,8 @@ fn static_node_properties() -> NodeProperties {
18351841
map.insert("grid_properties".to_string(), Box::new(node_properties::grid_properties));
18361842
map.insert("sample_polyline_properties".to_string(), Box::new(node_properties::sample_polyline_properties));
18371843
map.insert(
1838-
"identity_properties".to_string(),
1839-
Box::new(|_node_id, _context| node_properties::string_properties("The identity node passes its data through.")),
1844+
"pass_through_properties".to_string(),
1845+
Box::new(|_node_id, _context| node_properties::string_properties("The Pass Through node can be used to organize wires.")),
18401846
);
18411847
map.insert(
18421848
"monitor_properties".to_string(),

editor/src/messages/portfolio/document_migration.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -959,32 +959,13 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId],
959959
document.network_interface.set_input(&InputConnector::node(*node_id, 3), old_inputs[4].clone(), network_path);
960960
document.network_interface.set_input(&InputConnector::node(*node_id, 4), old_inputs[5].clone(), network_path);
961961
document.network_interface.set_input(&InputConnector::node(*node_id, 5), old_inputs[3].clone(), network_path);
962-
963-
upgraded = true;
962+
} else {
963+
// Swap it back if we're not changing anything
964+
let _ = document.network_interface.replace_inputs(node_id, network_path, &mut current_node_template);
964965
}
965966
}
966-
967-
if !upgraded {
968-
let _ = document.network_interface.replace_inputs(node_id, network_path, &mut current_node_template);
969-
}
970967
}
971968

972-
// Add the "Depth" parameter to the "Instance Index" node
973-
if reference == "Instance Index" && inputs_count == 0 {
974-
let mut node_template = resolve_document_node_type(reference)?.default_node_template();
975-
document.network_interface.replace_implementation(node_id, network_path, &mut node_template);
976-
977-
let mut node_path = network_path.to_vec();
978-
node_path.push(*node_id);
979-
980-
document.network_interface.add_import(TaggedValue::None, false, 0, "Primary", "", &node_path);
981-
document.network_interface.add_import(TaggedValue::U32(0), false, 1, "Loop Level", "TODO", &node_path);
982-
}
983-
984-
// ==================================
985-
// PUT ALL MIGRATIONS ABOVE THIS LINE
986-
// ==================================
987-
988969
// Ensure layers are positioned as stacks if they are upstream siblings of another layer
989970
document.network_interface.load_structure();
990971
let all_layers = LayerNodeIdentifier::ROOT_PARENT.descendants(document.network_interface.document_metadata()).collect::<Vec<_>>();

node-graph/gcore/src/ops.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
use crate::Node;
22
use std::marker::PhantomData;
33

4-
// TODO: Rename to "Passthrough"
5-
/// Passes-through the input value without changing it. This is useful for rerouting wires for organization purposes.
6-
#[node_macro::node(skip_impl)]
7-
fn identity<'i, T: 'i + Send>(value: T) -> T {
8-
value
9-
}
10-
114
// Type
125
// TODO: Document this
136
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]

node-graph/gcore/src/value.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@ impl<'i, const N: u32, I> Node<'i, I> for IntNode<N> {
1313
}
1414
}
1515

16-
// #[derive(Default, Debug, Clone, Copy)]
17-
// pub struct ValueNode<T>(pub T);
18-
19-
// impl<'i, T: 'i, I> Node<'i, I> for ValueNode<T> {
20-
// type Output = &'i T;
21-
// #[inline(always)]
22-
// fn eval(&'i self, _input: I) -> Self::Output {
23-
// &self.0
24-
// }
25-
// }
26-
27-
// impl<T> ValueNode<T> {
28-
// pub const fn new(value: T) -> ValueNode<T> {
29-
// ValueNode(value)
30-
// }
31-
// }
32-
33-
// impl<T> From<T> for ValueNode<T> {
34-
// fn from(value: T) -> Self {
35-
// ValueNode::new(value)
36-
// }
37-
// }
16+
#[derive(Default, Debug, Clone, Copy)]
17+
pub struct ValueNode<T>(pub T);
18+
19+
impl<'i, T: 'i, I> Node<'i, I> for ValueNode<T> {
20+
type Output = &'i T;
21+
#[inline(always)]
22+
fn eval(&'i self, _input: I) -> Self::Output {
23+
&self.0
24+
}
25+
}
26+
27+
impl<T> ValueNode<T> {
28+
pub const fn new(value: T) -> ValueNode<T> {
29+
ValueNode(value)
30+
}
31+
}
32+
33+
impl<T> From<T> for ValueNode<T> {
34+
fn from(value: T) -> Self {
35+
ValueNode::new(value)
36+
}
37+
}
3838

3939
#[derive(Default, Debug, Clone, Copy)]
4040
pub struct AsRefNode<T: AsRef<U>, U>(pub T, PhantomData<U>);

node-graph/graph-craft/src/document.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ pub enum DocumentNodeImplementation {
460460

461461
impl Default for DocumentNodeImplementation {
462462
fn default() -> Self {
463-
Self::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode"))
463+
Self::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode"))
464464
}
465465
}
466466

@@ -916,7 +916,7 @@ impl NodeNetwork {
916916
return;
917917
};
918918
// If the node is hidden, replace it with an identity node
919-
let identity_node = DocumentNodeImplementation::ProtoNode("graphene_core::ops::IdentityNode".into());
919+
let identity_node = DocumentNodeImplementation::ProtoNode("graphene_std::any::IdentityNode".into());
920920
if !node.visible && node.implementation != identity_node {
921921
node.implementation = identity_node;
922922

@@ -1092,7 +1092,7 @@ impl NodeNetwork {
10921092
fn remove_id_node(&mut self, id: NodeId) -> Result<(), String> {
10931093
let node = self.nodes.get(&id).ok_or_else(|| format!("Node with id {id} does not exist"))?.clone();
10941094
if let DocumentNodeImplementation::ProtoNode(ident) = &node.implementation {
1095-
if ident.name == "graphene_core::ops::IdentityNode" {
1095+
if ident.name == "graphene_std::any::IdentityNode" {
10961096
assert_eq!(node.inputs.len(), 1, "Id node has more than one input");
10971097
if let NodeInput::Node { node_id, output_index, .. } = node.inputs[0] {
10981098
let node_input_output_index = output_index;
@@ -1139,13 +1139,13 @@ impl NodeNetwork {
11391139
Ok(())
11401140
}
11411141

1142-
/// Strips out any [`graphene_core::ops::IdentityNode`]s that are unnecessary.
1142+
/// Strips out any [`graphene_std::any::IdentityNode`]s that are unnecessary.
11431143
pub fn remove_redundant_id_nodes(&mut self) {
11441144
let id_nodes = self
11451145
.nodes
11461146
.iter()
11471147
.filter(|(_, node)| {
1148-
matches!(&node.implementation, DocumentNodeImplementation::ProtoNode(ident) if ident == &ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode"))
1148+
matches!(&node.implementation, DocumentNodeImplementation::ProtoNode(ident) if ident == &ProtoNodeIdentifier::new("graphene_std::any::IdentityNode"))
11491149
&& node.inputs.len() == 1
11501150
&& matches!(node.inputs[0], NodeInput::Node { .. })
11511151
})
@@ -1333,7 +1333,7 @@ mod test {
13331333
fn extract_node() {
13341334
let id_node = DocumentNode {
13351335
inputs: vec![],
1336-
implementation: DocumentNodeImplementation::ProtoNode("graphene_core::ops::IdentityNode".into()),
1336+
implementation: DocumentNodeImplementation::ProtoNode("graphene_std::any::IdentityNode".into()),
13371337
..Default::default()
13381338
};
13391339
// TODO: Extend test cases to test nested network
@@ -1535,15 +1535,27 @@ mod test {
15351535
NodeId(1),
15361536
DocumentNode {
15371537
inputs: vec![NodeInput::network(concrete!(u32), 0)],
1538+
<<<<<<< HEAD
15381539
implementation: DocumentNodeImplementation::ProtoNode(graphene_core::ops::identity::IDENTIFIER),
1540+
||||||| parent of 8e045313 (Migrate pass through and value node to identity implementation)
1541+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
1542+
=======
1543+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode")),
1544+
>>>>>>> 8e045313 (Migrate pass through and value node to identity implementation)
15391545
..Default::default()
15401546
},
15411547
),
15421548
(
15431549
NodeId(2),
15441550
DocumentNode {
15451551
inputs: vec![NodeInput::network(concrete!(u32), 1)],
1552+
<<<<<<< HEAD
15461553
implementation: DocumentNodeImplementation::ProtoNode(graphene_core::ops::identity::IDENTIFIER),
1554+
||||||| parent of 8e045313 (Migrate pass through and value node to identity implementation)
1555+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
1556+
=======
1557+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode")),
1558+
>>>>>>> 8e045313 (Migrate pass through and value node to identity implementation)
15471559
..Default::default()
15481560
},
15491561
),
@@ -1570,7 +1582,13 @@ mod test {
15701582
NodeId(2),
15711583
DocumentNode {
15721584
inputs: vec![result_node_input],
1585+
<<<<<<< HEAD
15731586
implementation: DocumentNodeImplementation::ProtoNode(graphene_core::ops::identity::IDENTIFIER),
1587+
||||||| parent of 8e045313 (Migrate pass through and value node to identity implementation)
1588+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
1589+
=======
1590+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode")),
1591+
>>>>>>> 8e045313 (Migrate pass through and value node to identity implementation)
15741592
..Default::default()
15751593
},
15761594
),

node-graph/graph-craft/src/proto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub struct ProtoNode {
143143
impl Default for ProtoNode {
144144
fn default() -> Self {
145145
Self {
146-
identifier: ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode"),
146+
identifier: ProtoNodeIdentifier::new("graphene_std::any::IdentityNode"),
147147
construction_args: ConstructionArgs::Value(value::TaggedValue::U32(0).into()),
148148
input: ProtoNodeInput::None,
149149
original_location: OriginalLocation::default(),

node-graph/gstd/src/any.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,19 @@ pub fn downcast_node<I: StaticType, O: StaticType>(n: SharedNodeContainer) -> Do
4747
DowncastBothNode::new(n)
4848
}
4949

50-
// Same idea as the identity node, but with a hidden primary input in order to have an auto generated properties widget for the value
51-
pub struct Value {
50+
pub struct IdentityNode {
5251
value: SharedNodeContainer,
5352
}
5453

55-
impl<'i> Node<'i, Any<'i>> for Value {
54+
impl<'i> Node<'i, Any<'i>> for IdentityNode {
5655
type Output = DynFuture<'i, Any<'i>>;
5756
fn eval(&'i self, input: Any<'i>) -> Self::Output {
5857
Box::pin(async move { self.value.eval(input).await })
5958
}
6059
}
6160

62-
impl Value {
61+
impl IdentityNode {
6362
pub const fn new(value: SharedNodeContainer) -> Self {
64-
Value { value }
63+
IdentityNode { value }
6564
}
6665
}

node-graph/interpreted-executor/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ mod tests {
2020
NodeId(0),
2121
DocumentNode {
2222
inputs: vec![NodeInput::network(concrete!(u32), 0)],
23+
<<<<<<< HEAD
2324
implementation: DocumentNodeImplementation::ProtoNode(ops::identity::IDENTIFIER),
25+
||||||| parent of 8e045313 (Migrate pass through and value node to identity implementation)
26+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
27+
=======
28+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode")),
29+
>>>>>>> 8e045313 (Migrate pass through and value node to identity implementation)
2430
..Default::default()
2531
},
2632
),

node-graph/interpreted-executor/src/node_registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use graphene_std::Context;
1414
use graphene_std::GraphicElement;
1515
#[cfg(feature = "gpu")]
1616
use graphene_std::any::DowncastBothNode;
17-
use graphene_std::any::{ComposeTypeErased, DynAnyNode, IntoTypeErasedNode, Value};
17+
use graphene_std::any::{ComposeTypeErased, DynAnyNode, IdentityNode, IntoTypeErasedNode};
1818
use graphene_std::application_io::{ImageTexture, SurfaceFrame};
1919
#[cfg(feature = "gpu")]
2020
use graphene_std::wasm_application_io::{WasmEditorApi, WasmSurfaceHandle};
@@ -114,10 +114,10 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
114114
),
115115
),
116116
(
117-
ProtoNodeIdentifier::new("graphene_core::any::ValueNode"),
117+
ProtoNodeIdentifier::new("graphene_std::any::IdentityNode"),
118118
|args| {
119119
Box::pin(async move {
120-
let node = Value::new(args[0].clone());
120+
let node = IdentityNode::new(args[0].clone());
121121
node.into_type_erased()
122122
})
123123
},

node-graph/interpreted-executor/src/util.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ pub fn wrap_network_in_scope(mut network: NodeNetwork, editor_api: Arc<WasmEdito
6868
inner_network,
6969
render_node,
7070
DocumentNode {
71+
<<<<<<< HEAD
7172
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::ops::identity::IDENTIFIER),
73+
||||||| parent of 8e045313 (Migrate pass through and value node to identity implementation)
74+
implementation: DocumentNodeImplementation::proto("graphene_core::ops::IdentityNode"),
75+
=======
76+
implementation: DocumentNodeImplementation::proto("graphene_std::any::IdentityNode"),
77+
>>>>>>> 8e045313 (Migrate pass through and value node to identity implementation)
7278
inputs: vec![NodeInput::value(TaggedValue::EditorApi(editor_api), false)],
7379
..Default::default()
7480
},

0 commit comments

Comments
 (0)