Skip to content

Commit 0e49388

Browse files
TrueDoctorKeavon
andauthored
Make CopyToPoints node resolution aware (#1536)
* Make CopyToPoints node resolution aware * Add unfinished code review as todo comment --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent 947a131 commit 0e49388

File tree

3 files changed

+21
-113
lines changed

3 files changed

+21
-113
lines changed

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
22812281
DocumentNodeDefinition {
22822282
name: "Copy to Points",
22832283
category: "Vector",
2284-
implementation: NodeImplementation::proto("graphene_core::vector::CopyToPoints<_>"),
2284+
implementation: NodeImplementation::proto("graphene_core::vector::CopyToPoints<_, _>"),
2285+
manual_composition: Some(concrete!(Footprint)),
22852286
inputs: vec![
22862287
DocumentInputType::value("Points", TaggedValue::VectorData(graphene_core::vector::VectorData::empty()), true),
22872288
DocumentInputType::value("Instance", TaggedValue::VectorData(graphene_core::vector::VectorData::empty()), true),

node-graph/gcore/src/vector/vector_nodes.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use super::style::{Fill, FillType, Gradient, GradientType, Stroke};
22
use super::VectorData;
3+
use crate::transform::Footprint;
34
use crate::{Color, Node};
5+
use core::future::Future;
46

57
use bezier_rs::{Subpath, SubpathTValue};
68
use glam::{DAffine2, DVec2};
@@ -144,12 +146,21 @@ fn generate_bounding_box(vector_data: VectorData) -> VectorData {
144146
}
145147

146148
#[derive(Debug, Clone, Copy)]
147-
pub struct CopyToPoints<Instance> {
149+
pub struct CopyToPoints<Points, Instance> {
150+
points: Points,
148151
instance: Instance,
149152
}
150153

151154
#[node_macro::node_fn(CopyToPoints)]
152-
fn copy_to_points(points: VectorData, instance: VectorData) -> VectorData {
155+
async fn copy_to_points<FP: Future<Output = VectorData>, FI: Future<Output = VectorData>>(
156+
footprint: Footprint,
157+
points: impl Node<Footprint, Output = FP>,
158+
instance: impl Node<Footprint, Output = FI>,
159+
) -> VectorData {
160+
// TODO: https://github.com/GraphiteEditor/Graphite/pull/1536#discussion_r1436422419
161+
let points = self.points.eval(footprint).await;
162+
let instance = self.instance.eval(footprint).await;
163+
153164
let points_list = points.subpaths.iter().flat_map(|s| s.anchors());
154165

155166
let instance_bounding_box = instance.bounding_box().unwrap_or_default();

node-graph/interpreted-executor/src/node_registry.rs

Lines changed: 6 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -676,115 +676,11 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
676676
async_node!(graphene_std::wasm_application_io::RenderNode<_, _, _>, input: WasmEditorApi, output: RenderOutput, fn_params: [Footprint => Option<Color>, () => Arc<WasmSurfaceHandle>]),
677677
async_node!(graphene_std::wasm_application_io::RenderNode<_, _, _>, input: WasmEditorApi, output: RenderOutput, fn_params: [() => Vec<Color>, () => Arc<WasmSurfaceHandle>]),
678678
async_node!(graphene_std::wasm_application_io::RenderNode<_, _, _>, input: WasmEditorApi, output: RenderOutput, fn_params: [Footprint => Vec<Color>, () => Arc<WasmSurfaceHandle>]),
679-
//register_node!(graphene_core::transform::TranformNode<_, _, _, _, _, _>, input: , output: RenderOutput, fn_params: [Footprint => GraphicGroup, () => Arc<WasmSurfaceHandle>]),
680-
vec![
681-
(
682-
ProtoNodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"),
683-
|mut args| {
684-
Box::pin(async move {
685-
args.reverse();
686-
let node = <graphene_core::transform::TransformNode<_, _, _, _, _, _>>::new(
687-
DowncastBothNode::<Footprint, VectorData>::new(args.pop().expect("Not enough arguments provided to construct node")),
688-
graphene_std::any::input_node::<DVec2>(args.pop().expect("Not enough arguments provided to construct node")),
689-
graphene_std::any::input_node::<f32>(args.pop().expect("Not enough arguments provided to construct node")),
690-
graphene_std::any::input_node::<DVec2>(args.pop().expect("Not enough arguments provided to construct node")),
691-
graphene_std::any::input_node::<DVec2>(args.pop().expect("Not enough arguments provided to construct node")),
692-
graphene_std::any::input_node::<DVec2>(args.pop().expect("Not enough arguments provided to construct node")),
693-
);
694-
let any: DynAnyNode<Footprint, _, _> = graphene_std::any::DynAnyNode::new(node);
695-
Box::new(any) as TypeErasedBox
696-
})
697-
},
698-
{
699-
let params = vec![fn_type!(Footprint, VectorData), fn_type!(DVec2), fn_type!(f32), fn_type!(DVec2), fn_type!(DVec2), fn_type!(DVec2)];
700-
NodeIOTypes::new(concrete!(Footprint), concrete!(VectorData), params)
701-
},
702-
),
703-
(
704-
ProtoNodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"),
705-
|mut args| {
706-
Box::pin(async move {
707-
args.reverse();
708-
let node = <graphene_core::transform::TransformNode<_, _, _, _, _, _>>::new(
709-
DowncastBothNode::<Footprint, WasmSurfaceHandleFrame>::new(args.pop().expect("Not enough arguments provided to construct node")),
710-
graphene_std::any::input_node::<DVec2>(args.pop().expect("Not enough arguments provided to construct node")),
711-
graphene_std::any::input_node::<f32>(args.pop().expect("Not enough arguments provided to construct node")),
712-
graphene_std::any::input_node::<DVec2>(args.pop().expect("Not enough arguments provided to construct node")),
713-
graphene_std::any::input_node::<DVec2>(args.pop().expect("Not enough arguments provided to construct node")),
714-
graphene_std::any::input_node::<DVec2>(args.pop().expect("Not enough arguments provided to construct node")),
715-
);
716-
let any: DynAnyNode<Footprint, _, _> = graphene_std::any::DynAnyNode::new(node);
717-
Box::new(any) as TypeErasedBox
718-
})
719-
},
720-
{
721-
let params = vec![
722-
fn_type!(Footprint, WasmSurfaceHandleFrame),
723-
fn_type!(DVec2),
724-
fn_type!(f32),
725-
fn_type!(DVec2),
726-
fn_type!(DVec2),
727-
fn_type!(DVec2),
728-
];
729-
NodeIOTypes::new(concrete!(Footprint), concrete!(WasmSurfaceHandleFrame), params)
730-
},
731-
),
732-
(
733-
ProtoNodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"),
734-
|mut args| {
735-
Box::pin(async move {
736-
args.reverse();
737-
let node = <graphene_core::transform::TransformNode<_, _, _, _, _, _>>::new(
738-
DowncastBothNode::<Footprint, ImageFrame<Color>>::new(args.pop().expect("Not enough arguments provided to construct node")),
739-
graphene_std::any::input_node::<DVec2>(args.pop().expect("Not enough arguments provided to construct node")),
740-
graphene_std::any::input_node::<f32>(args.pop().expect("Not enough arguments provided to construct node")),
741-
graphene_std::any::input_node::<DVec2>(args.pop().expect("Not enough arguments provided to construct node")),
742-
graphene_std::any::input_node::<DVec2>(args.pop().expect("Not enough arguments provided to construct node")),
743-
graphene_std::any::input_node::<DVec2>(args.pop().expect("Not enough arguments provided to construct node")),
744-
);
745-
let any: DynAnyNode<Footprint, _, _> = graphene_std::any::DynAnyNode::new(node);
746-
Box::new(any) as TypeErasedBox
747-
})
748-
},
749-
{
750-
let params = vec![
751-
fn_type!(Footprint, ImageFrame<Color>),
752-
fn_type!(DVec2),
753-
fn_type!(f32),
754-
fn_type!(DVec2),
755-
fn_type!(DVec2),
756-
fn_type!(DVec2),
757-
];
758-
NodeIOTypes::new(concrete!(Footprint), concrete!(ImageFrame<Color>), params)
759-
},
760-
),
761-
(
762-
ProtoNodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"),
763-
|mut args| {
764-
Box::pin(async move {
765-
const EXPECT_MESSAGE: &str = "Not enough arguments provided to construct node";
766-
767-
args.reverse();
768-
769-
let node = <graphene_core::transform::TransformNode<_, _, _, _, _, _>>::new(
770-
DowncastBothNode::<Footprint, GraphicGroup>::new(args.pop().expect(EXPECT_MESSAGE)),
771-
graphene_std::any::input_node::<DVec2>(args.pop().expect(EXPECT_MESSAGE)),
772-
graphene_std::any::input_node::<f32>(args.pop().expect(EXPECT_MESSAGE)),
773-
graphene_std::any::input_node::<DVec2>(args.pop().expect(EXPECT_MESSAGE)),
774-
graphene_std::any::input_node::<DVec2>(args.pop().expect(EXPECT_MESSAGE)),
775-
graphene_std::any::input_node::<DVec2>(args.pop().expect(EXPECT_MESSAGE)),
776-
);
777-
778-
let any: DynAnyNode<Footprint, _, _> = graphene_std::any::DynAnyNode::new(node);
779-
Box::new(any) as TypeErasedBox
780-
})
781-
},
782-
{
783-
let params = vec![fn_type!(Footprint, GraphicGroup), fn_type!(DVec2), fn_type!(f32), fn_type!(DVec2), fn_type!(DVec2), fn_type!(DVec2)];
784-
NodeIOTypes::new(concrete!(Footprint), concrete!(GraphicGroup), params)
785-
},
786-
),
787-
],
679+
async_node!(graphene_core::transform::TransformNode<_, _, _, _, _, _>, input: Footprint, output: VectorData, fn_params: [Footprint => VectorData, () => DVec2, () => f32, () => DVec2, () => DVec2, () => DVec2]),
680+
async_node!(graphene_core::transform::TransformNode<_, _, _, _, _, _>, input: Footprint, output: WasmSurfaceHandleFrame, fn_params: [Footprint => WasmSurfaceHandleFrame, () => DVec2, () => f32, () => DVec2, () => DVec2, () => DVec2]),
681+
async_node!(graphene_core::transform::TransformNode<_, _, _, _, _, _>, input: Footprint, output: WasmSurfaceHandleFrame, fn_params: [Footprint => WasmSurfaceHandleFrame, () => DVec2, () => f32, () => DVec2, () => DVec2, () => DVec2]),
682+
async_node!(graphene_core::transform::TransformNode<_, _, _, _, _, _>, input: Footprint, output: ImageFrame<Color>, fn_params: [Footprint => ImageFrame<Color>, () => DVec2, () => f32, () => DVec2, () => DVec2, () => DVec2]),
683+
async_node!(graphene_core::transform::TransformNode<_, _, _, _, _, _>, input: Footprint, output: GraphicGroup, fn_params: [Footprint => GraphicGroup, () => DVec2, () => f32, () => DVec2, () => DVec2, () => DVec2]),
788684
register_node!(graphene_core::transform::SetTransformNode<_>, input: VectorData, params: [VectorData]),
789685
register_node!(graphene_core::transform::SetTransformNode<_>, input: ImageFrame<Color>, params: [ImageFrame<Color>]),
790686
register_node!(graphene_core::transform::SetTransformNode<_>, input: VectorData, params: [DAffine2]),
@@ -836,7 +732,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
836732
)],
837733
register_node!(graphene_std::raster::SampleNode<_>, input: Footprint, params: [ImageFrame<Color>]),
838734
register_node!(graphene_std::raster::MandelbrotNode, input: Footprint, params: []),
839-
register_node!(graphene_core::vector::CopyToPoints<_>, input: VectorData, params: [VectorData]),
735+
async_node!(graphene_core::vector::CopyToPoints<_, _>, input: Footprint, output: VectorData, fn_params: [Footprint => VectorData, Footprint => VectorData]),
840736
register_node!(graphene_core::vector::ResamplePoints<_>, input: VectorData, params: [f64]),
841737
register_node!(graphene_core::vector::SplinesFromPointsNode, input: VectorData, params: []),
842738
register_node!(graphene_core::vector::generator_nodes::CircleGenerator<_>, input: (), params: [f32]),

0 commit comments

Comments
 (0)