Generalize the 'Map Vector' node as 'Map' with support for all graphical types (#3793)
* Rename Map Vector to Map
* Fix compilation errors
* Move to the Graphic module and add Read {Graphic, Raster, Color} nodes
---------
Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
parent
bd1c54907d
commit
ba177c4c5d
|
|
@ -479,9 +479,9 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||||
// "true: bool" -> 1[6:Reset Transform]
|
// "true: bool" -> 1[6:Reset Transform]
|
||||||
// "false: bool" -> 2[6:Reset Transform]
|
// "false: bool" -> 2[6:Reset Transform]
|
||||||
// "false: bool" -> 3[6:Reset Transform]
|
// "false: bool" -> 3[6:Reset Transform]
|
||||||
// [12:Flatten Vector]0 -> 0[7:Map Vector]
|
// [12:Flatten Vector]0 -> 0[7:Map]
|
||||||
// [6:Reset Transform]0 -> 1[7:Map Vector]
|
// [6:Reset Transform]0 -> 1[7:Map]
|
||||||
// [7:Map Vector]0 -> 0[8:Morph]
|
// [7:Map]0 -> 0[8:Morph]
|
||||||
// [15:Multiply]0 -> 1[8:Morph]
|
// [15:Multiply]0 -> 1[8:Morph]
|
||||||
// [8:Morph]0 -> 0[9:Transform]
|
// [8:Morph]0 -> 0[9:Transform]
|
||||||
// [4:Position on Path]0 -> 1[9:Transform]
|
// [4:Position on Path]0 -> 1[9:Transform]
|
||||||
|
|
@ -563,9 +563,9 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||||
],
|
],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
// 7: Map Vector
|
// 7: Map
|
||||||
DocumentNode {
|
DocumentNode {
|
||||||
implementation: DocumentNodeImplementation::ProtoNode(vector_nodes::map_vector::IDENTIFIER),
|
implementation: DocumentNodeImplementation::ProtoNode(graphic::map::IDENTIFIER),
|
||||||
inputs: vec![NodeInput::node(NodeId(12), 0), NodeInput::node(NodeId(6), 0)],
|
inputs: vec![NodeInput::node(NodeId(12), 0), NodeInput::node(NodeId(6), 0)],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
@ -719,7 +719,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||||
},
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
// 7: Map Vector
|
// 7: Map
|
||||||
DocumentNodeMetadata {
|
DocumentNodeMetadata {
|
||||||
persistent_metadata: DocumentNodePersistentMetadata {
|
persistent_metadata: DocumentNodePersistentMetadata {
|
||||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(21, 1)),
|
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(21, 1)),
|
||||||
|
|
@ -838,9 +838,9 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||||
// [1:Extract Transform]0 -> 0[2:Decompose Translation]
|
// [1:Extract Transform]0 -> 0[2:Decompose Translation]
|
||||||
// [2:Decompose Translation]0 -> 0[3:Vec2 to Point]
|
// [2:Decompose Translation]0 -> 0[3:Vec2 to Point]
|
||||||
// [IMPORTS]0 -> 0[4:Flatten Vector]
|
// [IMPORTS]0 -> 0[4:Flatten Vector]
|
||||||
// [4:Flatten Vector]0 -> 0[5:Map Vector]
|
// [4:Flatten Vector]0 -> 0[5:Map]
|
||||||
// [3:Vec2 to Point]0 -> 1[5:Map Vector]
|
// [3:Vec2 to Point]0 -> 1[5:Map]
|
||||||
// [5:Map Vector]0 -> 0[6: Flatten Path]
|
// [5:Map]0 -> 0[6: Flatten Path]
|
||||||
// [6:Flatten Path]0 -> 0[7:Points to Polyline]
|
// [6:Flatten Path]0 -> 0[7:Points to Polyline]
|
||||||
// "false: bool" -> 1[7:Points to Polyline]
|
// "false: bool" -> 1[7:Points to Polyline]
|
||||||
// [7:Points to Polyline]0 -> 0[EXPORTS]
|
// [7:Points to Polyline]0 -> 0[EXPORTS]
|
||||||
|
|
@ -879,9 +879,9 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||||
inputs: vec![NodeInput::import(generic!(T), 0)],
|
inputs: vec![NodeInput::import(generic!(T), 0)],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
// 5: Map Vector
|
// 5: Map
|
||||||
DocumentNode {
|
DocumentNode {
|
||||||
implementation: DocumentNodeImplementation::ProtoNode(vector_nodes::map_vector::IDENTIFIER),
|
implementation: DocumentNodeImplementation::ProtoNode(graphic::map::IDENTIFIER),
|
||||||
inputs: vec![NodeInput::node(NodeId(4), 0), NodeInput::node(NodeId(3), 0)],
|
inputs: vec![NodeInput::node(NodeId(4), 0), NodeInput::node(NodeId(3), 0)],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
@ -954,7 +954,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||||
},
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
// 5: Map Vector
|
// 5: Map
|
||||||
DocumentNodeMetadata {
|
DocumentNodeMetadata {
|
||||||
persistent_metadata: DocumentNodePersistentMetadata {
|
persistent_metadata: DocumentNodePersistentMetadata {
|
||||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(28, 0)),
|
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(28, 0)),
|
||||||
|
|
|
||||||
|
|
@ -838,7 +838,7 @@ const NODE_REPLACEMENTS: &[NodeReplacement<'static>] = &[
|
||||||
aliases: &["graphene_core::vector::InstanceIndexNode", "core_types::vector::InstanceIndexNode"],
|
aliases: &["graphene_core::vector::InstanceIndexNode", "core_types::vector::InstanceIndexNode"],
|
||||||
},
|
},
|
||||||
NodeReplacement {
|
NodeReplacement {
|
||||||
node: graphene_std::vector::map_vector::IDENTIFIER,
|
node: graphene_std::graphic::map::IDENTIFIER,
|
||||||
aliases: &["graphene_core::vector::InstanceMapNode"],
|
aliases: &["graphene_core::vector::InstanceMapNode"],
|
||||||
},
|
},
|
||||||
NodeReplacement {
|
NodeReplacement {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,18 @@
|
||||||
use core_types::ExtractVarArgs;
|
|
||||||
use core_types::table::Table;
|
use core_types::table::Table;
|
||||||
|
use core_types::{Color, ExtractVarArgs};
|
||||||
use core_types::{Ctx, ExtractIndex, ExtractPosition};
|
use core_types::{Ctx, ExtractIndex, ExtractPosition};
|
||||||
use glam::DVec2;
|
use glam::DVec2;
|
||||||
use graphic_types::Vector;
|
use graphic_types::{Graphic, Vector};
|
||||||
|
use raster_types::{CPU, Raster};
|
||||||
|
|
||||||
|
#[node_macro::node(category("Context"), path(graphene_core::vector))]
|
||||||
|
fn read_graphic(ctx: impl Ctx + ExtractVarArgs) -> Table<Graphic> {
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Call this "Read Context" once it's fully generic
|
|
||||||
#[node_macro::node(category("Context"), path(graphene_core::vector))]
|
#[node_macro::node(category("Context"), path(graphene_core::vector))]
|
||||||
fn read_vector(ctx: impl Ctx + ExtractVarArgs) -> Table<Vector> {
|
fn read_vector(ctx: impl Ctx + ExtractVarArgs) -> Table<Vector> {
|
||||||
let Ok(var_arg) = ctx.vararg(0) else { return Default::default() };
|
let Ok(var_arg) = ctx.vararg(0) else { return Default::default() };
|
||||||
|
|
@ -13,6 +21,22 @@ fn read_vector(ctx: impl Ctx + ExtractVarArgs) -> Table<Vector> {
|
||||||
var_arg.downcast_ref().cloned().unwrap_or_default()
|
var_arg.downcast_ref().cloned().unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[node_macro::node(category("Context"), path(graphene_core::vector))]
|
||||||
|
fn read_raster(ctx: impl Ctx + ExtractVarArgs) -> Table<Raster<CPU>> {
|
||||||
|
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("Context"), path(graphene_core::vector))]
|
||||||
|
fn read_color(ctx: impl Ctx + ExtractVarArgs) -> Table<Color> {
|
||||||
|
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("Context"), path(core_types::vector))]
|
#[node_macro::node(category("Context"), path(core_types::vector))]
|
||||||
async fn read_position(
|
async fn read_position(
|
||||||
ctx: impl Ctx + ExtractPosition,
|
ctx: impl Ctx + ExtractPosition,
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,46 @@
|
||||||
use core_types::Color;
|
|
||||||
use core_types::Ctx;
|
|
||||||
use core_types::registry::types::SignedInteger;
|
use core_types::registry::types::SignedInteger;
|
||||||
use core_types::table::{Table, TableRow};
|
use core_types::table::{Table, TableRow};
|
||||||
use core_types::uuid::NodeId;
|
use core_types::uuid::NodeId;
|
||||||
|
use core_types::{AnyHash, CloneVarArgs, Color, Context, Ctx, ExtractAll, OwnedContextImpl};
|
||||||
use glam::{DAffine2, DVec2};
|
use glam::{DAffine2, DVec2};
|
||||||
use graphic_types::graphic::{Graphic, IntoGraphicTable};
|
use graphic_types::graphic::{Graphic, IntoGraphicTable};
|
||||||
use graphic_types::{Artboard, Vector};
|
use graphic_types::{Artboard, Vector};
|
||||||
use raster_types::{CPU, GPU, Raster};
|
use raster_types::{CPU, GPU, Raster};
|
||||||
use vector_types::GradientStops;
|
use vector_types::GradientStops;
|
||||||
|
|
||||||
|
#[node_macro::node(category("General"), path(graphene_core::vector))]
|
||||||
|
async fn map<Item: AnyHash + Send + Sync + std::hash::Hash>(
|
||||||
|
ctx: impl Ctx + CloneVarArgs + ExtractAll,
|
||||||
|
#[implementations(
|
||||||
|
Table<Graphic>,
|
||||||
|
Table<Vector>,
|
||||||
|
Table<Raster<CPU>>,
|
||||||
|
Table<Color>,
|
||||||
|
Table<GradientStops>,
|
||||||
|
)]
|
||||||
|
content: Table<Item>,
|
||||||
|
#[implementations(
|
||||||
|
Context -> Table<Graphic>,
|
||||||
|
Context -> Table<Vector>,
|
||||||
|
Context -> Table<Raster<CPU>>,
|
||||||
|
Context -> Table<Color>,
|
||||||
|
Context -> Table<GradientStops>,
|
||||||
|
)]
|
||||||
|
mapped: impl Node<Context<'static>, Output = Table<Item>>,
|
||||||
|
) -> Table<Item> {
|
||||||
|
let mut rows = Table::new();
|
||||||
|
|
||||||
|
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))).with_index(i);
|
||||||
|
let table = mapped.eval(owned_ctx.into_context()).await;
|
||||||
|
|
||||||
|
rows.extend(table);
|
||||||
|
}
|
||||||
|
|
||||||
|
rows
|
||||||
|
}
|
||||||
|
|
||||||
/// Performs internal editor record-keeping that enables tools to target this network's layer.
|
/// Performs internal editor record-keeping that enables tools to target this network's layer.
|
||||||
/// This node associates the ID of the network's parent layer to every element of output data.
|
/// This node associates the ID of the network's parent layer to every element of output data.
|
||||||
/// This technical detail may be ignored by users, and will be phased out in the future.
|
/// This technical detail may be ignored by users, and will be phased out in the future.
|
||||||
|
|
|
||||||
|
|
@ -1325,25 +1325,6 @@ async fn separate_subpaths(_: impl Ctx, content: Table<Vector>) -> Table<Vector>
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Call this "Map" once it's fully generic
|
|
||||||
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
|
|
||||||
async fn map_vector(ctx: impl Ctx + CloneVarArgs + ExtractAll, content: Table<Vector>, mapped: impl Node<Context<'static>, Output = Table<Vector>>) -> Table<Vector> {
|
|
||||||
let mut rows = Vec::new();
|
|
||||||
|
|
||||||
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))).with_index(i);
|
|
||||||
let table = mapped.eval(owned_ctx.into_context()).await;
|
|
||||||
|
|
||||||
for inner_row in table {
|
|
||||||
rows.push(inner_row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rows.into_iter().collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Call this "Map" once it's fully generic
|
|
||||||
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
|
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
|
||||||
async fn map_points(ctx: impl Ctx + CloneVarArgs + ExtractAll, content: Table<Vector>, mapped: impl Node<Context<'static>, Output = DVec2>) -> Table<Vector> {
|
async fn map_points(ctx: impl Ctx + CloneVarArgs + ExtractAll, content: Table<Vector>, mapped: impl Node<Context<'static>, Output = DVec2>) -> Table<Vector> {
|
||||||
let mut content = content;
|
let mut content = content;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue