From 244c8ad10ad79c9ca4fcdb21260c5d5dc60b3a21 Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Tue, 7 May 2024 16:41:44 -0700 Subject: [PATCH] Enable Merge nodes to take vector data inputs from the bottom, not just left Known bug: click targets aren't calculated for bottom input vector data. --- .../node_graph/document_node_types.rs | 25 ++++++++++++------- node-graph/gcore/src/graphic_element.rs | 7 ++++++ .../interpreted-executor/src/node_registry.rs | 6 ++++- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/editor/src/messages/portfolio/document/node_graph/document_node_types.rs b/editor/src/messages/portfolio/document/node_graph/document_node_types.rs index 59deee95..00c646fe 100644 --- a/editor/src/messages/portfolio/document/node_graph/document_node_types.rs +++ b/editor/src/messages/portfolio/document/node_graph/document_node_types.rs @@ -197,9 +197,10 @@ fn static_nodes() -> Vec { category: "General", is_layer: true, implementation: DocumentNodeImplementation::Network(NodeNetwork { - imports: vec![NodeId(2), NodeId(0)], - exports: vec![NodeOutput::new(NodeId(2), 0)], + imports: vec![NodeId(1), NodeId(0)], + exports: vec![NodeOutput::new(NodeId(3), 0)], nodes: [ + // Secondary (left) input type coercion ( NodeId(0), DocumentNode { @@ -209,24 +210,30 @@ fn static_nodes() -> Vec { ..Default::default() }, ), - // The monitor node is used to display a thumbnail in the UI. - // TODO: Check if thumbnail is reversed + // Primary (bottom) input type coercion ( NodeId(1), + DocumentNode { + name: "To Graphic Group".to_string(), + inputs: vec![NodeInput::Network(generic!(T))], + implementation: DocumentNodeImplementation::proto("graphene_core::ToGraphicGroupNode"), + ..Default::default() + }, + ), + // The monitor node is used to display a thumbnail in the UI + ( + NodeId(2), DocumentNode { inputs: vec![NodeInput::node(NodeId(0), 0)], ..monitor_node() }, ), ( - NodeId(2), + NodeId(3), DocumentNode { name: "ConstructLayer".to_string(), manual_composition: Some(concrete!(Footprint)), - inputs: vec![ - NodeInput::node(NodeId(1), 0), - NodeInput::Network(graphene_core::Type::Fn(Box::new(concrete!(Footprint)), Box::new(concrete!(graphene_core::GraphicGroup)))), - ], + inputs: vec![NodeInput::node(NodeId(2), 0), NodeInput::node(NodeId(1), 0)], implementation: DocumentNodeImplementation::proto("graphene_core::ConstructLayerNode<_, _>"), ..Default::default() }, diff --git a/node-graph/gcore/src/graphic_element.rs b/node-graph/gcore/src/graphic_element.rs index 9e85f305..e607e740 100644 --- a/node-graph/gcore/src/graphic_element.rs +++ b/node-graph/gcore/src/graphic_element.rs @@ -158,6 +158,13 @@ fn to_graphic_element>(data: Data) -> GraphicElement data.into() } +pub struct ToGraphicGroupNode {} + +#[node_fn(ToGraphicGroupNode)] +fn to_graphic_group>(data: Data) -> GraphicGroup { + data.into() +} + pub struct ConstructArtboardNode { contents: Contents, location: Location, diff --git a/node-graph/interpreted-executor/src/node_registry.rs b/node-graph/interpreted-executor/src/node_registry.rs index 1c529969..c546c186 100644 --- a/node-graph/interpreted-executor/src/node_registry.rs +++ b/node-graph/interpreted-executor/src/node_registry.rs @@ -796,8 +796,12 @@ fn node_registry() -> HashMap, params: []), register_node!(graphene_core::ToGraphicElementNode, input: GraphicGroup, params: []), register_node!(graphene_core::ToGraphicElementNode, input: Artboard, params: []), + register_node!(graphene_core::ToGraphicGroupNode, input: graphene_core::vector::VectorData, params: []), + register_node!(graphene_core::ToGraphicGroupNode, input: ImageFrame, params: []), + register_node!(graphene_core::ToGraphicGroupNode, input: GraphicGroup, params: []), + register_node!(graphene_core::ToGraphicGroupNode, input: Artboard, params: []), async_node!(graphene_core::ConstructArtboardNode<_, _, _, _, _>, input: Footprint, output: Artboard, fn_params: [Footprint => GraphicGroup, () => glam::IVec2, () => glam::IVec2, () => Color, () => bool]), - async_node!(graphene_core::AddArtboardNode<_, _>, input: Footprint, output: ArtboardGroup, fn_params: [Footprint => Artboard, Footprint => ArtboardGroup]), + async_node!(graphene_core::AddArtboardNode<_, _>, input: Footprint, output: ArtboardGroup, fn_params: [Footprint => Artboard, Footprint => ArtboardGroup]), ]; let mut map: HashMap> = HashMap::new(); for (id, c, types) in node_types.into_iter().flatten() {