From 0e49388312edccbfe7215d22a1c624fe17306aa1 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sat, 30 Dec 2023 12:56:50 +0100 Subject: [PATCH] Make CopyToPoints node resolution aware (#1536) * Make CopyToPoints node resolution aware * Add unfinished code review as todo comment --------- Co-authored-by: Keavon Chambers --- .../document_node_types.rs | 3 +- node-graph/gcore/src/vector/vector_nodes.rs | 15 ++- .../interpreted-executor/src/node_registry.rs | 116 +----------------- 3 files changed, 21 insertions(+), 113 deletions(-) diff --git a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs index 62f2cbb6..3779d7c7 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs @@ -2281,7 +2281,8 @@ fn static_nodes() -> Vec { DocumentNodeDefinition { name: "Copy to Points", category: "Vector", - implementation: NodeImplementation::proto("graphene_core::vector::CopyToPoints<_>"), + implementation: NodeImplementation::proto("graphene_core::vector::CopyToPoints<_, _>"), + manual_composition: Some(concrete!(Footprint)), inputs: vec![ DocumentInputType::value("Points", TaggedValue::VectorData(graphene_core::vector::VectorData::empty()), true), DocumentInputType::value("Instance", TaggedValue::VectorData(graphene_core::vector::VectorData::empty()), true), diff --git a/node-graph/gcore/src/vector/vector_nodes.rs b/node-graph/gcore/src/vector/vector_nodes.rs index b1bf0d8b..7caa007a 100644 --- a/node-graph/gcore/src/vector/vector_nodes.rs +++ b/node-graph/gcore/src/vector/vector_nodes.rs @@ -1,6 +1,8 @@ use super::style::{Fill, FillType, Gradient, GradientType, Stroke}; use super::VectorData; +use crate::transform::Footprint; use crate::{Color, Node}; +use core::future::Future; use bezier_rs::{Subpath, SubpathTValue}; use glam::{DAffine2, DVec2}; @@ -144,12 +146,21 @@ fn generate_bounding_box(vector_data: VectorData) -> VectorData { } #[derive(Debug, Clone, Copy)] -pub struct CopyToPoints { +pub struct CopyToPoints { + points: Points, instance: Instance, } #[node_macro::node_fn(CopyToPoints)] -fn copy_to_points(points: VectorData, instance: VectorData) -> VectorData { +async fn copy_to_points, FI: Future>( + footprint: Footprint, + points: impl Node, + instance: impl Node, +) -> VectorData { + // TODO: https://github.com/GraphiteEditor/Graphite/pull/1536#discussion_r1436422419 + let points = self.points.eval(footprint).await; + let instance = self.instance.eval(footprint).await; + let points_list = points.subpaths.iter().flat_map(|s| s.anchors()); let instance_bounding_box = instance.bounding_box().unwrap_or_default(); diff --git a/node-graph/interpreted-executor/src/node_registry.rs b/node-graph/interpreted-executor/src/node_registry.rs index ec3d7ad2..9c616a55 100644 --- a/node-graph/interpreted-executor/src/node_registry.rs +++ b/node-graph/interpreted-executor/src/node_registry.rs @@ -676,115 +676,11 @@ fn node_registry() -> HashMap, input: WasmEditorApi, output: RenderOutput, fn_params: [Footprint => Option, () => Arc]), async_node!(graphene_std::wasm_application_io::RenderNode<_, _, _>, input: WasmEditorApi, output: RenderOutput, fn_params: [() => Vec, () => Arc]), async_node!(graphene_std::wasm_application_io::RenderNode<_, _, _>, input: WasmEditorApi, output: RenderOutput, fn_params: [Footprint => Vec, () => Arc]), - //register_node!(graphene_core::transform::TranformNode<_, _, _, _, _, _>, input: , output: RenderOutput, fn_params: [Footprint => GraphicGroup, () => Arc]), - vec![ - ( - ProtoNodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"), - |mut args| { - Box::pin(async move { - args.reverse(); - let node = >::new( - DowncastBothNode::::new(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - ); - let any: DynAnyNode = graphene_std::any::DynAnyNode::new(node); - Box::new(any) as TypeErasedBox - }) - }, - { - let params = vec![fn_type!(Footprint, VectorData), fn_type!(DVec2), fn_type!(f32), fn_type!(DVec2), fn_type!(DVec2), fn_type!(DVec2)]; - NodeIOTypes::new(concrete!(Footprint), concrete!(VectorData), params) - }, - ), - ( - ProtoNodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"), - |mut args| { - Box::pin(async move { - args.reverse(); - let node = >::new( - DowncastBothNode::::new(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - ); - let any: DynAnyNode = graphene_std::any::DynAnyNode::new(node); - Box::new(any) as TypeErasedBox - }) - }, - { - let params = vec![ - fn_type!(Footprint, WasmSurfaceHandleFrame), - fn_type!(DVec2), - fn_type!(f32), - fn_type!(DVec2), - fn_type!(DVec2), - fn_type!(DVec2), - ]; - NodeIOTypes::new(concrete!(Footprint), concrete!(WasmSurfaceHandleFrame), params) - }, - ), - ( - ProtoNodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"), - |mut args| { - Box::pin(async move { - args.reverse(); - let node = >::new( - DowncastBothNode::>::new(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - graphene_std::any::input_node::(args.pop().expect("Not enough arguments provided to construct node")), - ); - let any: DynAnyNode = graphene_std::any::DynAnyNode::new(node); - Box::new(any) as TypeErasedBox - }) - }, - { - let params = vec![ - fn_type!(Footprint, ImageFrame), - fn_type!(DVec2), - fn_type!(f32), - fn_type!(DVec2), - fn_type!(DVec2), - fn_type!(DVec2), - ]; - NodeIOTypes::new(concrete!(Footprint), concrete!(ImageFrame), params) - }, - ), - ( - ProtoNodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"), - |mut args| { - Box::pin(async move { - const EXPECT_MESSAGE: &str = "Not enough arguments provided to construct node"; - - args.reverse(); - - let node = >::new( - DowncastBothNode::::new(args.pop().expect(EXPECT_MESSAGE)), - graphene_std::any::input_node::(args.pop().expect(EXPECT_MESSAGE)), - graphene_std::any::input_node::(args.pop().expect(EXPECT_MESSAGE)), - graphene_std::any::input_node::(args.pop().expect(EXPECT_MESSAGE)), - graphene_std::any::input_node::(args.pop().expect(EXPECT_MESSAGE)), - graphene_std::any::input_node::(args.pop().expect(EXPECT_MESSAGE)), - ); - - let any: DynAnyNode = graphene_std::any::DynAnyNode::new(node); - Box::new(any) as TypeErasedBox - }) - }, - { - let params = vec![fn_type!(Footprint, GraphicGroup), fn_type!(DVec2), fn_type!(f32), fn_type!(DVec2), fn_type!(DVec2), fn_type!(DVec2)]; - NodeIOTypes::new(concrete!(Footprint), concrete!(GraphicGroup), params) - }, - ), - ], + async_node!(graphene_core::transform::TransformNode<_, _, _, _, _, _>, input: Footprint, output: VectorData, fn_params: [Footprint => VectorData, () => DVec2, () => f32, () => DVec2, () => DVec2, () => DVec2]), + async_node!(graphene_core::transform::TransformNode<_, _, _, _, _, _>, input: Footprint, output: WasmSurfaceHandleFrame, fn_params: [Footprint => WasmSurfaceHandleFrame, () => DVec2, () => f32, () => DVec2, () => DVec2, () => DVec2]), + async_node!(graphene_core::transform::TransformNode<_, _, _, _, _, _>, input: Footprint, output: WasmSurfaceHandleFrame, fn_params: [Footprint => WasmSurfaceHandleFrame, () => DVec2, () => f32, () => DVec2, () => DVec2, () => DVec2]), + async_node!(graphene_core::transform::TransformNode<_, _, _, _, _, _>, input: Footprint, output: ImageFrame, fn_params: [Footprint => ImageFrame, () => DVec2, () => f32, () => DVec2, () => DVec2, () => DVec2]), + async_node!(graphene_core::transform::TransformNode<_, _, _, _, _, _>, input: Footprint, output: GraphicGroup, fn_params: [Footprint => GraphicGroup, () => DVec2, () => f32, () => DVec2, () => DVec2, () => DVec2]), register_node!(graphene_core::transform::SetTransformNode<_>, input: VectorData, params: [VectorData]), register_node!(graphene_core::transform::SetTransformNode<_>, input: ImageFrame, params: [ImageFrame]), register_node!(graphene_core::transform::SetTransformNode<_>, input: VectorData, params: [DAffine2]), @@ -836,7 +732,7 @@ fn node_registry() -> HashMap, input: Footprint, params: [ImageFrame]), register_node!(graphene_std::raster::MandelbrotNode, input: Footprint, params: []), - register_node!(graphene_core::vector::CopyToPoints<_>, input: VectorData, params: [VectorData]), + async_node!(graphene_core::vector::CopyToPoints<_, _>, input: Footprint, output: VectorData, fn_params: [Footprint => VectorData, Footprint => VectorData]), register_node!(graphene_core::vector::ResamplePoints<_>, input: VectorData, params: [f64]), register_node!(graphene_core::vector::SplinesFromPointsNode, input: VectorData, params: []), register_node!(graphene_core::vector::generator_nodes::CircleGenerator<_>, input: (), params: [f32]),