From 4348dba61835b644957835731c780cdc289d7099 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Fri, 26 Sep 2025 22:08:12 +0200 Subject: [PATCH 1/3] Add map instance and extract vector nodes --- node-graph/gcore/src/vector/vector_nodes.rs | 28 ++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/node-graph/gcore/src/vector/vector_nodes.rs b/node-graph/gcore/src/vector/vector_nodes.rs index ef649f0d12..2e3a7a535e 100644 --- a/node-graph/gcore/src/vector/vector_nodes.rs +++ b/node-graph/gcore/src/vector/vector_nodes.rs @@ -17,7 +17,7 @@ use crate::vector::misc::{MergeByDistanceAlgorithm, PointSpacingType, is_linear} use crate::vector::misc::{handles_to_segment, segment_to_handles}; use crate::vector::style::{PaintOrder, StrokeAlign, StrokeCap, StrokeJoin}; use crate::vector::{FillId, RegionId}; -use crate::{CloneVarArgs, Color, Context, Ctx, ExtractAll, Graphic, OwnedContextImpl}; +use crate::{CloneVarArgs, Color, Context, Ctx, ExtractAll, ExtractVarArgs, Graphic, OwnedContextImpl}; use core::f64::consts::PI; use core::hash::{Hash, Hasher}; use glam::{DAffine2, DVec2}; @@ -969,6 +969,32 @@ async fn separate_subpaths(_: impl Ctx, content: Table) -> Table }) .collect() } +#[node_macro::node(category("Vector: Modifier"), path(graphene_core::vector))] +fn extract_vector(ctx: impl Ctx + ExtractVarArgs) -> Table { + let Ok(var_arg) = ctx.vararg(0) else { return Default::default() }; + let var_arg = var_arg as &dyn std::any::Any; + var_arg.downcast_ref().cloned().unwrap_or_default() +} + +#[node_macro::node(category("Vector: Modifier"), path(graphene_core::vector))] +async fn map_instance(ctx: impl Ctx + CloneVarArgs + ExtractAll, content: Table, map_fn: impl Node, Output = Table>) -> Table { + let mut rows = Vec::new(); + // log::debug!("content: {content:?}"); + for row in content { + let transform = row.transform; + let alpha_blending = row.alpha_blending; + let source_node_id = row.source_node_id; + + let owned_ctx = OwnedContextImpl::from(ctx.clone()); + let owned_ctx = owned_ctx.with_vararg(Box::new(Table::new_from_row(row))); + let table = map_fn.eval(owned_ctx.into_context()).await; + // log::debug!("content: {content:?}"); + for inner_row in table { + rows.push(inner_row); + } + } + rows.into_iter().collect() +} #[node_macro::node(category("Vector"), path(graphene_core::vector))] async fn flatten_path(_: impl Ctx, #[implementations(Table, Table)] content: Table) -> Table From 1cb9ea25f2295023a91a636b8136cb88cac29633 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Fri, 26 Sep 2025 22:10:03 +0200 Subject: [PATCH 2/3] Cleanup --- node-graph/gcore/src/vector/vector_nodes.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/node-graph/gcore/src/vector/vector_nodes.rs b/node-graph/gcore/src/vector/vector_nodes.rs index 2e3a7a535e..5348985b78 100644 --- a/node-graph/gcore/src/vector/vector_nodes.rs +++ b/node-graph/gcore/src/vector/vector_nodes.rs @@ -979,16 +979,10 @@ fn extract_vector(ctx: impl Ctx + ExtractVarArgs) -> Table { #[node_macro::node(category("Vector: Modifier"), path(graphene_core::vector))] async fn map_instance(ctx: impl Ctx + CloneVarArgs + ExtractAll, content: Table, map_fn: impl Node, Output = Table>) -> Table { let mut rows = Vec::new(); - // log::debug!("content: {content:?}"); for row in content { - let transform = row.transform; - let alpha_blending = row.alpha_blending; - let source_node_id = row.source_node_id; - let owned_ctx = OwnedContextImpl::from(ctx.clone()); let owned_ctx = owned_ctx.with_vararg(Box::new(Table::new_from_row(row))); let table = map_fn.eval(owned_ctx.into_context()).await; - // log::debug!("content: {content:?}"); for inner_row in table { rows.push(inner_row); } From 8a602a3b913a4be490ec848811b359f544b7ef46 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Fri, 3 Oct 2025 11:40:08 +0200 Subject: [PATCH 3/3] Inject index in map node --- node-graph/gcore/src/vector/vector_nodes.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/node-graph/gcore/src/vector/vector_nodes.rs b/node-graph/gcore/src/vector/vector_nodes.rs index 5348985b78..89b4d4dffe 100644 --- a/node-graph/gcore/src/vector/vector_nodes.rs +++ b/node-graph/gcore/src/vector/vector_nodes.rs @@ -977,11 +977,11 @@ fn extract_vector(ctx: impl Ctx + ExtractVarArgs) -> Table { } #[node_macro::node(category("Vector: Modifier"), path(graphene_core::vector))] -async fn map_instance(ctx: impl Ctx + CloneVarArgs + ExtractAll, content: Table, map_fn: impl Node, Output = Table>) -> Table { +async fn map(ctx: impl Ctx + CloneVarArgs + ExtractAll, content: Table, map_fn: impl Node, Output = Table>) -> Table { let mut rows = Vec::new(); - for row in content { + for (i, row) in content.into_iter().enumerate() { let owned_ctx = OwnedContextImpl::from(ctx.clone()); - let owned_ctx = owned_ctx.with_vararg(Box::new(Table::new_from_row(row))); + let owned_ctx = owned_ctx.with_vararg(Box::new(Table::new_from_row(row))).with_index(i); let table = map_fn.eval(owned_ctx.into_context()).await; for inner_row in table { rows.push(inner_row);