@@ -32,7 +32,7 @@ impl DocumentInputType {
32
32
Self { name, data_type, default }
33
33
}
34
34
35
- pub const fn _none ( ) -> Self {
35
+ pub const fn none ( ) -> Self {
36
36
Self {
37
37
name : "None" ,
38
38
data_type : FrontendGraphDataType :: General ,
@@ -589,59 +589,74 @@ fn static_nodes() -> Vec<DocumentNodeType> {
589
589
properties: node_properties:: add_properties,
590
590
} ,
591
591
( * IMAGINATE_NODE ) . clone( ) ,
592
- /*DocumentNodeType {
593
- name: "Unit Circle Generator",
594
- category: "Vector",
595
- identifier: NodeImplementation::proto("graphene_std::vector::generator_nodes::UnitCircleGenerator", &[]),
596
- inputs: vec![DocumentInputType::none()],
597
- outputs: vec![DocumentOutputType::new("Vector", FrontendGraphDataType::Subpath)],
598
- properties: node_properties::no_properties,
599
- },
600
592
DocumentNodeType {
601
- name: "Unit Square Generator",
593
+ name: "Unit Circle Generator" ,
602
594
category: "Vector" ,
603
- identifier: NodeImplementation::proto("graphene_std ::vector::generator_nodes::UnitSquareGenerator", &[] ),
595
+ identifier: NodeImplementation :: proto( "graphene_core ::vector::generator_nodes::UnitCircleGenerator" ) ,
604
596
inputs: vec![ DocumentInputType :: none( ) ] ,
605
597
outputs: vec![ DocumentOutputType :: new( "Vector" , FrontendGraphDataType :: Subpath ) ] ,
606
598
properties: node_properties:: no_properties,
607
599
} ,
608
600
DocumentNodeType {
609
601
name: "Path Generator" ,
610
602
category: "Vector" ,
611
- identifier: NodeImplementation::proto("graphene_core::ops::IdNode "),
603
+ identifier: NodeImplementation :: proto( "graphene_core::vector::generator_nodes::PathGenerator " ) ,
612
604
inputs: vec![ DocumentInputType {
613
605
name: "Path Data" ,
614
606
data_type: FrontendGraphDataType :: Subpath ,
615
- default: NodeInput::value(TaggedValue::Subpath(Subpath::new()), false),
607
+ default : NodeInput :: value( TaggedValue :: Subpath ( bezier_rs :: Subpath :: new( Vec :: new ( ) , false ) ) , false ) ,
616
608
} ] ,
617
609
outputs: vec![ DocumentOutputType :: new( "Vector" , FrontendGraphDataType :: Subpath ) ] ,
618
610
properties: node_properties:: no_properties,
619
611
} ,
620
612
DocumentNodeType {
621
- name: "Transform Subpath ",
613
+ name: "Transform" ,
622
614
category: "Vector" ,
623
- identifier: NodeImplementation::proto("graphene_std ::vector::generator_nodes::TransformSubpathNode", &[] ),
615
+ identifier: NodeImplementation :: proto( "graphene_core ::vector::TransformNode<_, _, _, _>" ) ,
624
616
inputs: vec![
625
- DocumentInputType::new("Subpath ", TaggedValue::Subpath(Subpath ::empty()), true),
626
- DocumentInputType::new ("Translation", TaggedValue::DVec2(DVec2::ZERO), false),
627
- DocumentInputType::new ("Rotation", TaggedValue::F64(0.), false),
628
- DocumentInputType::new ("Scale", TaggedValue::DVec2(DVec2::ONE), false),
629
- DocumentInputType::new ("Skew", TaggedValue::DVec2(DVec2::ZERO), false),
617
+ DocumentInputType :: value ( "Vector Data ", TaggedValue :: VectorData ( graphene_core :: vector :: VectorData :: empty( ) ) , true ) ,
618
+ DocumentInputType :: value ( "Translation" , TaggedValue :: DVec2 ( DVec2 :: ZERO ) , false ) ,
619
+ DocumentInputType :: value ( "Rotation" , TaggedValue :: F64 ( 0. ) , false ) ,
620
+ DocumentInputType :: value ( "Scale" , TaggedValue :: DVec2 ( DVec2 :: ONE ) , false ) ,
621
+ DocumentInputType :: value ( "Skew" , TaggedValue :: DVec2 ( DVec2 :: ZERO ) , false ) ,
630
622
] ,
631
623
outputs: vec![ DocumentOutputType :: new( "Vector" , FrontendGraphDataType :: Subpath ) ] ,
632
624
properties: node_properties:: transform_properties,
633
625
} ,
634
626
DocumentNodeType {
635
- name: "Blit Subpath",
627
+ name: "Fill" ,
628
+ category: "Vector" ,
629
+ identifier: NodeImplementation :: proto( "graphene_core::vector::SetFillNode<_, _, _, _, _, _, _>" ) ,
630
+ inputs: vec![
631
+ DocumentInputType :: value( "Vector Data" , TaggedValue :: VectorData ( graphene_core:: vector:: VectorData :: empty( ) ) , true ) ,
632
+ DocumentInputType :: value( "Fill Type" , TaggedValue :: FillType ( vector:: style:: FillType :: Solid ) , false ) ,
633
+ DocumentInputType :: value( "Solid Color" , TaggedValue :: Color ( Color :: BLACK ) , false ) ,
634
+ DocumentInputType :: value( "Gradient Type" , TaggedValue :: GradientType ( vector:: style:: GradientType :: Linear ) , false ) ,
635
+ DocumentInputType :: value( "Start" , TaggedValue :: DVec2 ( DVec2 :: new( 0. , 0.5 ) ) , false ) ,
636
+ DocumentInputType :: value( "End" , TaggedValue :: DVec2 ( DVec2 :: new( 1. , 0.5 ) ) , false ) ,
637
+ DocumentInputType :: value( "Transform" , TaggedValue :: DAffine2 ( DAffine2 :: IDENTITY ) , false ) ,
638
+ DocumentInputType :: value( "Positions" , TaggedValue :: GradientPositions ( vec![ ( 0. , Some ( Color :: BLACK ) ) , ( 1. , Some ( Color :: WHITE ) ) ] ) , false ) ,
639
+ ] ,
640
+ outputs: vec![ DocumentOutputType :: new( "Vector" , FrontendGraphDataType :: Subpath ) ] ,
641
+ properties: node_properties:: fill_properties,
642
+ } ,
643
+ DocumentNodeType {
644
+ name: "Stroke" ,
636
645
category: "Vector" ,
637
- identifier: NodeImplementation::proto("graphene_std ::vector::generator_nodes::BlitSubpath", &[] ),
646
+ identifier: NodeImplementation :: proto( "graphene_core ::vector::SetStrokeNode<_, _, _, _, _, _, _>" ) ,
638
647
inputs: vec![
639
- DocumentInputType::new("Image", TaggedValue::Image(Image::empty()), true),
640
- DocumentInputType::new("Subpath", TaggedValue::Subpath(Subpath::empty()), true),
648
+ DocumentInputType :: value( "Vector Data" , TaggedValue :: VectorData ( graphene_core:: vector:: VectorData :: empty( ) ) , true ) ,
649
+ DocumentInputType :: value( "Color" , TaggedValue :: Color ( Color :: BLACK ) , false ) ,
650
+ DocumentInputType :: value( "Weight" , TaggedValue :: F64 ( 0. ) , false ) ,
651
+ DocumentInputType :: value( "Dash Lengths" , TaggedValue :: VecF32 ( Vec :: new( ) ) , false ) ,
652
+ DocumentInputType :: value( "Dash Offset" , TaggedValue :: F64 ( 0. ) , false ) ,
653
+ DocumentInputType :: value( "Line Cap" , TaggedValue :: LineCap ( graphene_core:: vector:: style:: LineCap :: Butt ) , false ) ,
654
+ DocumentInputType :: value( "Line Join" , TaggedValue :: LineJoin ( graphene_core:: vector:: style:: LineJoin :: Miter ) , false ) ,
655
+ DocumentInputType :: value( "Miter Limit" , TaggedValue :: F64 ( 4. ) , false ) ,
641
656
] ,
642
- outputs: vec![DocumentOutputType::new("Vector", FrontendGraphDataType::Raster )],
643
- properties: node_properties::no_properties ,
644
- },*/
657
+ outputs: vec![ DocumentOutputType :: new( "Vector" , FrontendGraphDataType :: Subpath ) ] ,
658
+ properties: node_properties:: stroke_properties ,
659
+ } ,
645
660
]
646
661
}
647
662
@@ -718,14 +733,25 @@ impl DocumentNodeType {
718
733
DocumentNodeImplementation :: Network ( inner_network)
719
734
}
720
735
736
+ /// Converts the [DocumentNodeType] type to a [DocumentNode], based on the inputs from the graph (which must be the correct length) and the metadata
721
737
pub fn to_document_node ( & self , inputs : impl IntoIterator < Item = NodeInput > , metadata : graph_craft:: document:: DocumentNodeMetadata ) -> DocumentNode {
738
+ let inputs: Vec < _ > = inputs. into_iter ( ) . collect ( ) ;
739
+ assert_eq ! ( inputs. len( ) , self . inputs. len( ) , "Inputs passed from the graph must be equal to the number required" ) ;
722
740
DocumentNode {
723
741
name : self . name . to_string ( ) ,
724
- inputs : inputs . into_iter ( ) . collect ( ) ,
742
+ inputs,
725
743
implementation : self . generate_implementation ( ) ,
726
744
metadata,
727
745
}
728
746
}
747
+
748
+ /// Converts the [DocumentNodeType] type to a [DocumentNode], using the provided `input_override` and falling back to the default inputs.
749
+ /// `input_override` does not have to be the correct length.
750
+ pub fn to_document_node_default_inputs ( & self , input_override : impl IntoIterator < Item = Option < NodeInput > > , metadata : graph_craft:: document:: DocumentNodeMetadata ) -> DocumentNode {
751
+ let mut input_override = input_override. into_iter ( ) ;
752
+ let inputs = self . inputs . iter ( ) . map ( |default| input_override. next ( ) . unwrap_or_default ( ) . unwrap_or_else ( || default. default . clone ( ) ) ) ;
753
+ self . to_document_node ( inputs, metadata)
754
+ }
729
755
}
730
756
731
757
pub fn wrap_network_in_scope ( network : NodeNetwork ) -> NodeNetwork {
@@ -764,7 +790,7 @@ pub fn new_image_network(output_offset: i32, output_node_id: NodeId) -> NodeNetw
764
790
nodes : [
765
791
resolve_document_node_type ( "Input" )
766
792
. expect ( "Input node does not exist" )
767
- . to_document_node ( [ NodeInput :: Network ( concrete ! ( ImageFrame ) ) ] , DocumentNodeMetadata :: position ( ( 8 , 4 ) ) ) ,
793
+ . to_document_node_default_inputs ( [ ] , DocumentNodeMetadata :: position ( ( 8 , 4 ) ) ) ,
768
794
resolve_document_node_type ( "Output" )
769
795
. expect ( "Output node does not exist" )
770
796
. to_document_node ( [ NodeInput :: node ( output_node_id, 0 ) ] , DocumentNodeMetadata :: position ( ( output_offset + 8 , 4 ) ) ) ,
@@ -776,3 +802,37 @@ pub fn new_image_network(output_offset: i32, output_node_id: NodeId) -> NodeNetw
776
802
..Default :: default ( )
777
803
}
778
804
}
805
+
806
+ pub fn new_vector_network ( subpath : bezier_rs:: Subpath < uuid:: ManipulatorGroupId > ) -> NodeNetwork {
807
+ let input = resolve_document_node_type ( "Input" ) . expect ( "Input node does not exist" ) ;
808
+ let path_generator = resolve_document_node_type ( "Path Generator" ) . expect ( "Path Generator node does not exist" ) ;
809
+ let transform = resolve_document_node_type ( "Transform" ) . expect ( "Transform node does not exist" ) ;
810
+ let fill = resolve_document_node_type ( "Fill" ) . expect ( "Fill node does not exist" ) ;
811
+ let stroke = resolve_document_node_type ( "Stroke" ) . expect ( "Stroke node does not exist" ) ;
812
+ let output = resolve_document_node_type ( "Output" ) . expect ( "Output node does not exist" ) ;
813
+
814
+ let mut pos = 0 ;
815
+ let mut next_pos = || {
816
+ let node_pos = DocumentNodeMetadata :: position ( ( pos, 4 ) ) ;
817
+ pos += 8 ;
818
+ node_pos
819
+ } ;
820
+
821
+ NodeNetwork {
822
+ inputs : vec ! [ 0 ] ,
823
+ outputs : vec ! [ NodeOutput :: new( 5 , 0 ) ] ,
824
+ nodes : [
825
+ input. to_document_node_default_inputs ( [ ] , next_pos ( ) ) ,
826
+ path_generator. to_document_node_default_inputs ( [ Some ( NodeInput :: value ( TaggedValue :: Subpath ( subpath) , false ) ) ] , next_pos ( ) ) ,
827
+ transform. to_document_node_default_inputs ( [ Some ( NodeInput :: node ( 1 , 0 ) ) ] , next_pos ( ) ) ,
828
+ fill. to_document_node_default_inputs ( [ Some ( NodeInput :: node ( 2 , 0 ) ) ] , next_pos ( ) ) ,
829
+ stroke. to_document_node_default_inputs ( [ Some ( NodeInput :: node ( 3 , 0 ) ) ] , next_pos ( ) ) ,
830
+ output. to_document_node_default_inputs ( [ Some ( NodeInput :: node ( 4 , 0 ) ) ] , next_pos ( ) ) ,
831
+ ]
832
+ . into_iter ( )
833
+ . enumerate ( )
834
+ . map ( |( id, node) | ( id as NodeId , node) )
835
+ . collect ( ) ,
836
+ ..Default :: default ( )
837
+ }
838
+ }
0 commit comments