Skip to content

Commit 8e04531

Browse files
committed
Migrate pass through and value node to identity implementation
1 parent 4075003 commit 8e04531

File tree

11 files changed

+50
-58
lines changed

11 files changed

+50
-58
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
8484
let custom = vec![
8585
// TODO: Auto-generate this from its proto node macro
8686
DocumentNodeDefinition {
87-
identifier: "Identity",
87+
identifier: "Pass Through",
8888
category: "General",
8989
node_template: NodeTemplate {
9090
document_node: DocumentNode {
91-
implementation: DocumentNodeImplementation::proto("graphene_core::ops::IdentityNode"),
91+
implementation: DocumentNodeImplementation::proto("graphene_std::any::IdentityNode"),
9292
inputs: vec![NodeInput::value(TaggedValue::None, true)],
9393
..Default::default()
9494
},
@@ -99,14 +99,14 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
9999
},
100100
},
101101
description: Cow::Borrowed("Passes-through the input value without changing it. This is useful for rerouting wires for organization purposes."),
102-
properties: Some("identity_properties"),
102+
properties: Some("pass_through_properties"),
103103
},
104104
DocumentNodeDefinition {
105105
identifier: "Value",
106106
category: "General",
107107
node_template: NodeTemplate {
108108
document_node: DocumentNode {
109-
implementation: DocumentNodeImplementation::proto("graphene_core::any::ValueNode"),
109+
implementation: DocumentNodeImplementation::proto("graphene_std::any::IdentityNode"),
110110
manual_composition: Some(generic!(T)),
111111
inputs: vec![NodeInput::value(TaggedValue::None, false)],
112112
..Default::default()
@@ -2161,8 +2161,8 @@ fn static_node_properties() -> NodeProperties {
21612161
map.insert("grid_properties".to_string(), Box::new(node_properties::grid_properties));
21622162
map.insert("sample_polyline_properties".to_string(), Box::new(node_properties::sample_polyline_properties));
21632163
map.insert(
2164-
"identity_properties".to_string(),
2165-
Box::new(|_node_id, _context| node_properties::string_properties("The identity node passes its data through.")),
2164+
"pass_through_properties".to_string(),
2165+
Box::new(|_node_id, _context| node_properties::string_properties("The Pass Through node can be used to organize wires.")),
21662166
);
21672167
map.insert(
21682168
"monitor_properties".to_string(),

editor/src/messages/portfolio/document_migration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const REPLACEMENTS: &[(&str, &str)] = &[
139139
("graphene_std::raster::NoisePatternNode", "graphene_raster_nodes::std_nodes::NoisePatternNode"),
140140
("graphene_std::raster::MandelbrotNode", "graphene_raster_nodes::std_nodes::MandelbrotNode"),
141141
// text
142-
("graphene_core::text::TextGeneratorNode", "graphene_core::text::TextNode"),
142+
("graphene_core::text::TextGeneratorNode", "graphene_std::text::TextNode"),
143143
// transform
144144
("graphene_core::transform::SetTransformNode", "graphene_core::transform_nodes::ReplaceTransformNode"),
145145
("graphene_core::transform::ReplaceTransformNode", "graphene_core::transform_nodes::ReplaceTransformNode"),
@@ -158,7 +158,7 @@ const REPLACEMENTS: &[(&str, &str)] = &[
158158
("graphene_core::vector::generator_nodes::StarGenerator", "graphene_core::vector::generator_nodes::StarNode"),
159159
("graphene_std::executor::BlendGpuImageNode", "graphene_std::gpu_nodes::BlendGpuImageNode"),
160160
("graphene_std::raster::SampleNode", "graphene_std::raster::SampleImageNode"),
161-
("graphene_core::transform::CullNode", "graphene_core::ops::IdentityNode"),
161+
("graphene_core::transform::CullNode", "graphene_std::any::IdentityNode"),
162162
("graphene_std::raster::MaskImageNode", "graphene_std::raster::MaskNode"),
163163
("graphene_core::vector::FlattenVectorElementsNode", "graphene_core::vector::FlattenPathNode"),
164164
("graphene_std::vector::BooleanOperationNode", "graphene_path_bool::BooleanOperationNode"),

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: 9 additions & 9 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

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

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

1146-
/// Strips out any [`graphene_core::ops::IdentityNode`]s that are unnecessary.
1146+
/// Strips out any [`graphene_std::any::IdentityNode`]s that are unnecessary.
11471147
pub fn remove_redundant_id_nodes(&mut self) {
11481148
let id_nodes = self
11491149
.nodes
11501150
.iter()
11511151
.filter(|(_, node)| {
1152-
matches!(&node.implementation, DocumentNodeImplementation::ProtoNode(ident) if ident == &ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode"))
1152+
matches!(&node.implementation, DocumentNodeImplementation::ProtoNode(ident) if ident == &ProtoNodeIdentifier::new("graphene_std::any::IdentityNode"))
11531153
&& node.inputs.len() == 1
11541154
&& matches!(node.inputs[0], NodeInput::Node { .. })
11551155
})
@@ -1338,7 +1338,7 @@ mod test {
13381338
fn extract_node() {
13391339
let id_node = DocumentNode {
13401340
inputs: vec![],
1341-
implementation: DocumentNodeImplementation::ProtoNode("graphene_core::ops::IdentityNode".into()),
1341+
implementation: DocumentNodeImplementation::ProtoNode("graphene_std::any::IdentityNode".into()),
13421342
..Default::default()
13431343
};
13441344
// TODO: Extend test cases to test nested network
@@ -1540,15 +1540,15 @@ mod test {
15401540
NodeId(1),
15411541
DocumentNode {
15421542
inputs: vec![NodeInput::network(concrete!(u32), 0)],
1543-
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
1543+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode")),
15441544
..Default::default()
15451545
},
15461546
),
15471547
(
15481548
NodeId(2),
15491549
DocumentNode {
15501550
inputs: vec![NodeInput::network(concrete!(u32), 1)],
1551-
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
1551+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode")),
15521552
..Default::default()
15531553
},
15541554
),
@@ -1575,7 +1575,7 @@ mod test {
15751575
NodeId(2),
15761576
DocumentNode {
15771577
inputs: vec![result_node_input],
1578-
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
1578+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode")),
15791579
..Default::default()
15801580
},
15811581
),

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod tests {
2020
NodeId(0),
2121
DocumentNode {
2222
inputs: vec![NodeInput::network(concrete!(u32), 0)],
23-
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
23+
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::any::IdentityNode")),
2424
..Default::default()
2525
},
2626
),

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn wrap_network_in_scope(mut network: NodeNetwork, editor_api: Arc<WasmEdito
6868
inner_network,
6969
render_node,
7070
DocumentNode {
71-
implementation: DocumentNodeImplementation::proto("graphene_core::ops::IdentityNode"),
71+
implementation: DocumentNodeImplementation::proto("graphene_std::any::IdentityNode"),
7272
inputs: vec![NodeInput::value(TaggedValue::EditorApi(editor_api), false)],
7373
..Default::default()
7474
},

0 commit comments

Comments
 (0)