@@ -2689,13 +2689,19 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
2689
2689
let Some ( implementations) = & node_registry. get ( & id) else { continue } ;
2690
2690
let valid_inputs: HashSet < _ > = implementations. iter ( ) . map ( |( _, node_io) | node_io. call_argument . clone ( ) ) . collect ( ) ;
2691
2691
let first_node_io = implementations. first ( ) . map ( |( _, node_io) | node_io) . unwrap_or ( const { & NodeIOTypes :: empty ( ) } ) ;
2692
+ let mut node_io_types = vec ! [ HashSet :: new( ) ; fields. len( ) ] ;
2693
+ for ( _, node_io) in implementations. iter ( ) {
2694
+ for ( i, ty) in node_io. inputs . iter ( ) . enumerate ( ) {
2695
+ node_io_types[ i] . insert ( ty. clone ( ) ) ;
2696
+ }
2697
+ }
2692
2698
let mut input_type = & first_node_io. call_argument ;
2693
2699
if valid_inputs. len ( ) > 1 {
2694
2700
input_type = & const { generic ! ( D ) } ;
2695
2701
}
2696
2702
let output_type = & first_node_io. return_value ;
2697
2703
2698
- let inputs = fields
2704
+ let inputs: Vec < _ > = fields
2699
2705
. iter ( )
2700
2706
. zip ( first_node_io. inputs . iter ( ) )
2701
2707
. enumerate ( )
@@ -2715,14 +2721,89 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
2715
2721
NodeInput :: value ( TaggedValue :: None , true )
2716
2722
} )
2717
2723
. collect ( ) ;
2724
+ let input_count = inputs. len ( ) ;
2725
+ let network_inputs = ( 0 ..input_count) . map ( |i| NodeInput :: node ( NodeId ( i as u64 ) , 0 ) ) . collect ( ) ;
2726
+ let identity_node = ProtoNodeIdentifier :: new ( "graphene_core::ops::IdentityNode" ) ;
2727
+ let into_node_registry = & interpreted_executor:: node_registry:: NODE_REGISTRY ;
2728
+ let mut nodes: HashMap < _ , _ , _ > = node_io_types
2729
+ . iter ( )
2730
+ . enumerate ( )
2731
+ . map ( |( i, inputs) | {
2732
+ (
2733
+ NodeId ( i as u64 ) ,
2734
+ match inputs. len ( ) {
2735
+ 1 => {
2736
+ let input = inputs. iter ( ) . next ( ) . unwrap ( ) ;
2737
+ let input_ty = input. nested_type ( ) ;
2738
+ let into_node_identifier = ProtoNodeIdentifier {
2739
+ name : format ! ( "graphene_core::ops::IntoNode<{}>" , input_ty. clone( ) ) . into ( ) ,
2740
+ } ;
2741
+ let proto_node = if into_node_registry. iter ( ) . any ( |( ident, _) | {
2742
+ let ident = ident. name . as_ref ( ) ;
2743
+ // log::debug!("checking: {} against {}", ident, into_node_identifier.name.as_ref());
2744
+ ident == into_node_identifier. name . as_ref ( )
2745
+ } ) {
2746
+ // log::debug!("placing {}", into_node_identifier.name.as_ref());
2747
+ into_node_identifier
2748
+ } else {
2749
+ identity_node. clone ( )
2750
+ } ;
2751
+ DocumentNode {
2752
+ inputs : vec ! [ NodeInput :: network( input. clone( ) , i) ] ,
2753
+ // manual_composition: Some(fn_input.clone()),
2754
+ implementation : DocumentNodeImplementation :: ProtoNode ( proto_node) ,
2755
+ visible : true ,
2756
+ ..Default :: default ( )
2757
+ }
2758
+ }
2759
+ _ => DocumentNode {
2760
+ inputs : vec ! [ NodeInput :: network( generic!( X ) , i) ] ,
2761
+ implementation : DocumentNodeImplementation :: ProtoNode ( identity_node. clone ( ) ) ,
2762
+ visible : true ,
2763
+ ..Default :: default ( )
2764
+ } ,
2765
+ } ,
2766
+ )
2767
+ } )
2768
+ . collect ( ) ;
2769
+
2770
+ let document_node = DocumentNode {
2771
+ inputs : network_inputs,
2772
+ manual_composition : Some ( input_type. clone ( ) ) ,
2773
+ implementation : DocumentNodeImplementation :: ProtoNode ( id. clone ( ) . into ( ) ) ,
2774
+ visible : true ,
2775
+ skip_deduplication : false ,
2776
+ ..Default :: default ( )
2777
+ } ;
2778
+ let mut node_names: HashMap < NodeId , String > = nodes
2779
+ . iter ( )
2780
+ . map ( |( id, node) | ( * id, node. implementation . get_proto_node ( ) . unwrap ( ) . name . rsplit_once ( "::" ) . unwrap ( ) . 1 . to_string ( ) ) )
2781
+ . collect ( ) ;
2782
+ nodes. insert ( NodeId ( input_count as u64 ) , document_node) ;
2783
+ node_names. insert ( NodeId ( input_count as u64 ) , display_name. to_string ( ) ) ;
2784
+ let node_type_metadata = |id : NodeId | {
2785
+ NodeTypePersistentMetadata :: Node ( NodePersistentMetadata :: new ( NodePosition :: Absolute ( if id. 0 == input_count as u64 {
2786
+ IVec2 :: default ( )
2787
+ } else {
2788
+ IVec2 { x : -10 , y : id. 0 as i32 }
2789
+ } ) ) )
2790
+ } ;
2718
2791
2719
2792
let node = DocumentNodeDefinition {
2720
2793
identifier : display_name,
2721
2794
node_template : NodeTemplate {
2722
2795
document_node : DocumentNode {
2723
2796
inputs,
2724
2797
manual_composition : Some ( input_type. clone ( ) ) ,
2725
- implementation : DocumentNodeImplementation :: ProtoNode ( id. clone ( ) . into ( ) ) ,
2798
+ implementation : DocumentNodeImplementation :: Network ( NodeNetwork {
2799
+ exports : vec ! [ NodeInput :: Node {
2800
+ node_id: NodeId ( input_count as u64 ) ,
2801
+ output_index: 0 ,
2802
+ lambda: false ,
2803
+ } ] ,
2804
+ nodes,
2805
+ scope_injections : Default :: default ( ) ,
2806
+ } ) ,
2726
2807
visible : true ,
2727
2808
skip_deduplication : false ,
2728
2809
..Default :: default ( )
@@ -2742,6 +2823,30 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
2742
2823
has_primary_output : true ,
2743
2824
locked : false ,
2744
2825
2826
+ network_metadata : Some ( NodeNetworkMetadata {
2827
+ persistent_metadata : NodeNetworkPersistentMetadata {
2828
+ node_metadata : node_names
2829
+ . into_iter ( )
2830
+ . map ( |( id, display_name) | {
2831
+ let node_type_metadata = node_type_metadata ( id) ;
2832
+ (
2833
+ id,
2834
+ DocumentNodeMetadata {
2835
+ persistent_metadata : DocumentNodePersistentMetadata {
2836
+ display_name,
2837
+ node_type_metadata,
2838
+ ..Default :: default ( )
2839
+ } ,
2840
+ ..Default :: default ( )
2841
+ } ,
2842
+ )
2843
+ } )
2844
+ . collect ( ) ,
2845
+ ..Default :: default ( )
2846
+ } ,
2847
+ ..Default :: default ( )
2848
+ } ) ,
2849
+
2745
2850
..Default :: default ( )
2746
2851
} ,
2747
2852
} ,
0 commit comments