@@ -3,108 +3,133 @@ use graph_craft::{
3
3
document:: { DocumentNode , DocumentNodeImplementation , NodeInput , NodeNetwork , value:: TaggedValue } ,
4
4
} ;
5
5
use graphene_std:: {
6
- Context , graphic , memo ,
7
- node_graph_overlay :: { self , types :: NodeGraphOverlayData } ,
6
+ node_graph_overlay :: { types :: NodeGraphOverlayData , ui_context :: UIContext } ,
7
+ table :: Table ,
8
8
uuid:: NodeId ,
9
9
} ;
10
10
11
+ /// https://excalidraw.com/#json=LgKS6I4lQvGPmke06ZJyp,D9aON9vVZJAjNnZWfwy_SQ
11
12
pub fn generate_node_graph_overlay ( node_graph_overlay_data : NodeGraphOverlayData , opacity : f64 ) -> DocumentNode {
12
- // TODO: Implement as Network and implement finer grained caching for the background, nodes, and exports
13
+ let generate_nodes_id = NodeId :: new ( ) ;
14
+ let cache_nodes_id = NodeId :: new ( ) ;
15
+ let transform_nodes_id = NodeId :: new ( ) ;
16
+
17
+ let generate_node_graph_bg = NodeId :: new ( ) ;
18
+ let cache_node_graph_bg = NodeId :: new ( ) ;
19
+
20
+ let merge_nodes_and_bg_id = NodeId :: new ( ) ;
21
+ let render_overlay_id = NodeId :: new ( ) ;
22
+ let send_overlay_id = NodeId :: new ( ) ;
23
+ let _cache_output_id = NodeId :: new ( ) ;
24
+ // TODO: Replace with new cache node
25
+ let memo_implementation = DocumentNodeImplementation :: ProtoNode ( graphene_std:: ops:: identity:: IDENTIFIER ) ;
26
+
13
27
DocumentNode {
14
28
inputs : vec ! [
15
- NodeInput :: value( TaggedValue :: None , true ) ,
29
+ NodeInput :: value( TaggedValue :: Vector ( Table :: new ( ) ) , true ) ,
16
30
NodeInput :: value( TaggedValue :: NodeGraphOverlayData ( node_graph_overlay_data) , true ) ,
17
31
NodeInput :: value( TaggedValue :: F64 ( opacity) , true ) ,
18
32
] ,
33
+
19
34
implementation : DocumentNodeImplementation :: Network ( NodeNetwork {
20
- exports : vec ! [ NodeInput :: node( NodeId ( 0 ) , 0 ) ] ,
35
+ exports : vec ! [ NodeInput :: node( send_overlay_id , 0 ) ] ,
21
36
nodes : vec ! [
22
- // Merge the overlay on top of the artwork
37
+ // Create the nodes
23
38
(
24
- NodeId ( 0 ) ,
39
+ generate_nodes_id ,
25
40
DocumentNode {
26
- call_argument: concrete!( Context ) ,
27
- inputs: vec![ NodeInput :: node ( NodeId ( 2 ) , 0 ) , NodeInput :: node ( NodeId ( 1 ) , 0 ) ] ,
28
- implementation: DocumentNodeImplementation :: ProtoNode ( graphic :: extend :: IDENTIFIER ) ,
41
+ call_argument: concrete!( UIContext ) ,
42
+ inputs: vec![ NodeInput :: network ( concrete! ( UIContext ) , 1 ) ] ,
43
+ implementation: DocumentNodeImplementation :: ProtoNode ( "graphene_core::node_graph_overlay::GenerateNodesNode" . into ( ) ) ,
29
44
..Default :: default ( )
30
45
} ,
31
46
) ,
32
- //Wrap Artwork in a table
47
+ // Cache the nodes
33
48
(
34
- NodeId ( 1 ) ,
49
+ cache_nodes_id ,
35
50
DocumentNode {
36
- inputs : vec! [ NodeInput :: network ( concrete!( Context ) , 0 ) ] ,
37
- implementation : DocumentNodeImplementation :: ProtoNode ( graphic :: wrap_graphic :: IDENTIFIER ) ,
38
- call_argument : concrete! ( Context ) ,
51
+ call_argument : concrete!( UIContext ) ,
52
+ inputs : vec! [ NodeInput :: node ( generate_nodes_id , 0 ) ] ,
53
+ implementation : memo_implementation . clone ( ) ,
39
54
..Default :: default ( )
40
55
} ,
41
56
) ,
42
- // Cache the full node graph so its not rerendered when the artwork changes
57
+ // Transform the nodes based on the Context
43
58
(
44
- NodeId ( 2 ) ,
59
+ transform_nodes_id ,
45
60
DocumentNode {
46
- call_argument: concrete!( Context ) ,
47
- inputs: vec![ NodeInput :: node( NodeId ( 3 ) , 0 ) ] ,
48
- implementation: DocumentNodeImplementation :: ProtoNode ( memo :: memo :: IDENTIFIER ) ,
61
+ call_argument: concrete!( UIContext ) ,
62
+ inputs: vec![ NodeInput :: node( cache_nodes_id , 0 ) ] ,
63
+ implementation: DocumentNodeImplementation :: ProtoNode ( "graphene_core::node_graph_overlay::TransformNodesNode" . into ( ) ) ,
49
64
..Default :: default ( )
50
65
} ,
51
66
) ,
52
- // Merge the nodes on top of the dot grid background
67
+ // Generate the dot grid background
53
68
(
54
- NodeId ( 3 ) ,
69
+ generate_node_graph_bg ,
55
70
DocumentNode {
56
- call_argument : concrete!( Context ) ,
57
- inputs : vec! [ NodeInput :: node ( NodeId ( 5 ) , 0 ) , NodeInput :: node ( NodeId ( 4 ) , 0 ) ] ,
58
- implementation : DocumentNodeImplementation :: ProtoNode ( graphic :: extend :: IDENTIFIER ) ,
71
+ inputs : vec! [ NodeInput :: network ( concrete!( UIContext ) , 2 ) ] ,
72
+ implementation : DocumentNodeImplementation :: ProtoNode ( "graphene_core::node_graph_overlay::DotGridBackgroundNode" . into ( ) ) ,
73
+ call_argument : concrete! ( UIContext ) ,
59
74
..Default :: default ( )
60
75
} ,
61
76
) ,
62
- // Generate the dot grid background
77
+ // Cache the dot grid background
63
78
(
64
- NodeId ( 4 ) ,
79
+ cache_node_graph_bg ,
65
80
DocumentNode {
66
- inputs : vec! [ NodeInput :: network ( concrete!( Context ) , 2 ) ] ,
67
- implementation : DocumentNodeImplementation :: ProtoNode ( node_graph_overlay :: dot_grid_background :: IDENTIFIER ) ,
68
- call_argument : concrete! ( Context ) ,
81
+ call_argument : concrete!( UIContext ) ,
82
+ inputs : vec! [ NodeInput :: node ( generate_node_graph_bg , 0 ) ] ,
83
+ implementation : memo_implementation . clone ( ) ,
69
84
..Default :: default ( )
70
85
} ,
71
86
) ,
72
- // Transform the nodes based on the Context
87
+ // Merge the nodes on top of the dot grid background
73
88
(
74
- NodeId ( 5 ) ,
89
+ merge_nodes_and_bg_id ,
75
90
DocumentNode {
76
- call_argument: concrete!( Context ) ,
77
- inputs: vec![ NodeInput :: node( NodeId ( 6 ) , 0 ) ] ,
78
- implementation: DocumentNodeImplementation :: ProtoNode ( node_graph_overlay :: transform_nodes :: IDENTIFIER ) ,
91
+ call_argument: concrete!( UIContext ) ,
92
+ inputs: vec![ NodeInput :: node( transform_nodes_id , 0 ) , NodeInput :: node ( cache_node_graph_bg , 0 ) ] ,
93
+ implementation: DocumentNodeImplementation :: ProtoNode ( "graphene_core::node_graph_overlay::NodeGraphUiExtendNode" . into ( ) ) ,
79
94
..Default :: default ( )
80
95
} ,
81
96
) ,
82
- // Cache the nodes
97
+ // Render the node graph UI graphic to an SVG
83
98
(
84
- NodeId ( 6 ) ,
99
+ render_overlay_id ,
85
100
DocumentNode {
86
- call_argument: concrete!( Context ) ,
87
- inputs: vec![ NodeInput :: node( NodeId ( 7 ) , 0 ) ] ,
88
- implementation: DocumentNodeImplementation :: ProtoNode ( memo :: memo :: IDENTIFIER ) ,
101
+ call_argument: concrete!( UIContext ) ,
102
+ inputs: vec![ NodeInput :: node( merge_nodes_and_bg_id , 0 ) ] ,
103
+ implementation: DocumentNodeImplementation :: ProtoNode ( "graphene_std::wasm_application_io::RenderNodeGraphUiNode" . into ( ) ) ,
89
104
..Default :: default ( )
90
105
} ,
91
106
) ,
92
- // Create the nodes
107
+ // Send the overlay to the frontend
93
108
(
94
- NodeId ( 7 ) ,
109
+ send_overlay_id ,
95
110
DocumentNode {
96
- call_argument: concrete!( Context ) ,
97
- inputs: vec![ NodeInput :: network ( concrete! ( Context ) , 1 ) ] ,
98
- implementation: DocumentNodeImplementation :: ProtoNode ( node_graph_overlay :: generate_nodes :: IDENTIFIER ) ,
111
+ call_argument: concrete!( UIContext ) ,
112
+ inputs: vec![ NodeInput :: node ( render_overlay_id , 0 ) ] ,
113
+ implementation: DocumentNodeImplementation :: ProtoNode ( "graphene_core::node_graph_overlay::SendRenderNode" . into ( ) ) ,
99
114
..Default :: default ( )
100
115
} ,
101
116
) ,
117
+ // Cache the full node graph so its not rerendered when the artwork changes
118
+ // (
119
+ // cache_nodes_id,
120
+ // DocumentNode {
121
+ // call_argument: concrete!(UIContext),
122
+ // inputs: vec![NodeInput::node(send_overlay_id, 0)],
123
+ // implementation: memo_implementation.clone(),
124
+ // ..Default::default()
125
+ // },
126
+ // ),
102
127
]
103
128
. into_iter ( )
104
129
. collect ( ) ,
105
130
..Default :: default ( )
106
131
} ) ,
107
- call_argument : concrete ! ( Context ) ,
132
+ call_argument : concrete ! ( UIContext ) ,
108
133
..Default :: default ( )
109
134
}
110
135
}
0 commit comments