Rename several node graph structs/fields

This commit is contained in:
Keavon Chambers 2023-12-08 15:27:32 -08:00
parent d082b15abb
commit c5ed54cbd2
18 changed files with 379 additions and 380 deletions

View file

@ -9,7 +9,7 @@ use crate::{DocumentError, DocumentResponse, Operation};
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeNetwork, NodeOutput};
use graphene_core::renderer::ClickTarget;
use graphene_core::transform::Footprint;
use graphene_core::{concrete, generic, NodeIdentifier};
use graphene_core::{concrete, generic, ProtoNodeIdentifier};
use graphene_std::wasm_application_io::WasmEditorApi;
use glam::{DAffine2, DVec2};
@ -64,13 +64,13 @@ impl Default for Document {
DocumentNode {
name: "EditorApi".to_string(),
inputs: vec![NodeInput::Network(concrete!(WasmEditorApi))],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::IdentityNode")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
..Default::default()
},
DocumentNode {
name: "Create Canvas".to_string(),
inputs: vec![NodeInput::node(0, 0)],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_std::wasm_application_io::CreateSurfaceNode")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::CreateSurfaceNode")),
skip_deduplication: true,
..Default::default()
},
@ -78,7 +78,7 @@ impl Default for Document {
name: "Cache".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::node(1, 0)],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode<_, _>")),
..Default::default()
},
DocumentNode {
@ -88,7 +88,7 @@ impl Default for Document {
NodeInput::Network(graphene_core::Type::Fn(Box::new(concrete!(Footprint)), Box::new(generic!(T)))),
NodeInput::node(2, 0),
],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_std::wasm_application_io::RenderNode<_, _, _>")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::RenderNode<_, _, _>")),
..Default::default()
},
]

View file

@ -473,7 +473,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
// Set a random seed input
responses.add(NodeGraphMessage::SetInputValue {
node_id: *imaginate_node.last().unwrap(),
// Needs to match the index of the seed parameter in `pub const IMAGINATE_NODE: DocumentNodeBlueprint` in `document_node_type.rs`
// Needs to match the index of the seed parameter in `pub const IMAGINATE_NODE: DocumentNodeDefinition` in `document_node_type.rs`
input_index: 3,
value: graph_craft::document::value::TaggedValue::F64(random_value),
});

View file

@ -76,8 +76,8 @@ pub struct FrontendNode {
#[serde(rename = "isLayer")]
pub is_layer: bool,
pub id: graph_craft::document::NodeId,
pub alias: String,
pub name: String,
pub identifier: String,
#[serde(rename = "primaryInput")]
pub primary_input: Option<FrontendGraphInput>,
#[serde(rename = "exposedInputs")]
@ -297,8 +297,8 @@ impl NodeGraphMessageHandler {
nodes.push(FrontendNode {
is_layer: node.is_layer(),
id: *id,
name: node.alias.clone(),
identifier: node.name.clone(),
alias: node.alias.clone(),
name: node.name.clone(),
primary_input,
exposed_inputs,
primary_output,

View file

@ -741,7 +741,7 @@
</div>
<div class="details">
<!-- TODO: Allow the user to edit the name, just like in the Layers panel -->
<TextLabel tooltip={editor.instance.inDevelopmentMode() ? `Node ID: ${node.id}` : undefined} italic={!node.name}>{node.name || "Layer"}</TextLabel>
<TextLabel tooltip={editor.instance.inDevelopmentMode() ? `Node ID: ${node.id}` : undefined} italic={!node.alias}>{node.alias || "Layer"}</TextLabel>
</div>
<svg class="border-mask" width="0" height="0">
@ -771,9 +771,9 @@
>
<!-- Primary row -->
<div class="primary" class:no-parameter-section={exposedInputsOutputs.length === 0}>
<IconLabel icon={nodeIcon(node.identifier)} />
<IconLabel icon={nodeIcon(node.name)} />
<!-- TODO: Allow the user to edit the name, just like in the Layers panel -->
<TextLabel tooltip={editor.instance.inDevelopmentMode() ? `Node ID: ${node.id}` : undefined} italic={!node.name}>{node.name || node.identifier}</TextLabel>
<TextLabel tooltip={editor.instance.inDevelopmentMode() ? `Node ID: ${node.id}` : undefined} italic={!node.alias}>{node.alias || node.name}</TextLabel>
</div>
<!-- Parameter rows -->
{#if exposedInputsOutputs.length > 0}

View file

@ -87,7 +87,6 @@
</script>
<!-- TODO: Refactor this component to use `<svelte:component this={attributesObject} />` to avoid all the separate conditional components -->
<!-- TODO: Also rename this component, and probably move the `widget-${direction}` wrapper to be part of `WidgetLayout.svelte` as part of its refactor -->
<div class={`widget-span ${className} ${extraClasses}`.trim()} class:row={direction === "row"} class:column={direction === "column"}>
{#each widgetsAndNextSiblingIsSuffix as [component, nextIsSuffix], index}

View file

@ -101,9 +101,9 @@ export class FrontendNode {
readonly id!: bigint;
readonly name!: string;
readonly alias!: string;
readonly identifier!: string;
readonly name!: string;
readonly primaryInput!: FrontendGraphInput | undefined;

View file

@ -26,10 +26,10 @@ pub struct DocumentNode {
Each `DocumentNode` is of a particular type, for example the "Opacity" node type. You can define your own type of document node in `editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs`. A sample document node type definition for the opacity node is shown:
```rs
DocumentNodeBlueprint {
DocumentNodeDefinition {
name: "Opacity",
category: "Image Adjustments",
identifier: NodeImplementation::proto("graphene_core::raster::OpacityNode<_>"),
implementation: NodeImplementation::proto("graphene_core::raster::OpacityNode<_>"),
inputs: vec![
DocumentInputType::value("Image", TaggedValue::ImageFrame(ImageFrame::empty()), true),
DocumentInputType::value("Factor", TaggedValue::F32(100.), false),
@ -136,7 +136,7 @@ The definition for the constructor of a node that applies the opacity transforma
```rs
(
// Matches against the string defined in the document node.
NodeIdentifier::new("graphene_core::raster::OpacityNode<_>"),
ProtoNodeIdentifier::new("graphene_core::raster::OpacityNode<_>"),
// This function is run when converting the `ProtoNode` struct into the desired struct.
|args| {
Box::pin(async move {

View file

@ -66,7 +66,7 @@ macro_rules! fn_type {
#[derive(Clone, Debug, PartialEq, Eq, Hash, specta::Type)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct NodeIdentifier {
pub struct ProtoNodeIdentifier {
pub name: Cow<'static, str>,
}
@ -218,14 +218,14 @@ impl std::fmt::Display for Type {
}
}
impl From<&'static str> for NodeIdentifier {
impl From<&'static str> for ProtoNodeIdentifier {
fn from(s: &'static str) -> Self {
NodeIdentifier { name: Cow::Borrowed(s) }
ProtoNodeIdentifier { name: Cow::Borrowed(s) }
}
}
impl NodeIdentifier {
impl ProtoNodeIdentifier {
pub const fn new(name: &'static str) -> Self {
NodeIdentifier { name: Cow::Borrowed(name) }
ProtoNodeIdentifier { name: Cow::Borrowed(name) }
}
}

View file

@ -1,6 +1,6 @@
use crate::document::value::TaggedValue;
use crate::proto::{ConstructionArgs, ProtoNetwork, ProtoNode, ProtoNodeInput};
use graphene_core::{GraphicGroup, NodeIdentifier, Type};
use graphene_core::{GraphicGroup, ProtoNodeIdentifier, Type};
use dyn_any::{DynAny, StaticType};
use glam::IVec2;
@ -40,15 +40,17 @@ fn return_true() -> bool {
true
}
/// An instance of a [`DocumentNodeDefinition`] that has been instantiated in a [`NodeNetwork`].
/// Currently, when an instance is made, it lives all on its own without any lasting connection to the definition.
/// But we will want to change it in the future so it merely references its definition.
#[derive(Clone, Debug, PartialEq, Hash, DynAny)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DocumentNode {
// TODO: Rename to "name" (also rename the TODOs in the `DocumentNodeBlueprint` struct)
/// A name chosen by the user for this node. Empty indicates no given name, in which case the node's identifier is displayed to the user in italics.
/// A name chosen by the user for this instance of the node. Empty indicates no given name, in which case the node definition's name is displayed to the user in italics.
#[serde(default)]
pub alias: String,
// TODO: Rename to "identifier" (also rename the TODOs in the `DocumentNodeBlueprint` struct)
/// An identifier used to display in the UI and to display the appropriate properties.
// TODO: Replace this name with a reference to the [`DocumentNodeDefinition`] node definition to use the name from there instead.
/// The name of the node definition, as originally set by [`DocumentNodeDefinition`], used to display in the UI and to display the appropriate properties.
pub name: String,
/// The inputs to a node, which are either:
/// - From other nodes within this graph [`NodeInput::Node`],
@ -360,12 +362,12 @@ impl NodeInput {
#[derive(Clone, Debug, PartialEq, Hash, DynAny)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Represents the implementation of a node, which can be a nested [`NodeNetwork`], a proto [`NodeIdentifier`], or extract.
/// Represents the implementation of a node, which can be a nested [`NodeNetwork`], a proto [`ProtoNodeIdentifier`], or extract.
pub enum DocumentNodeImplementation {
/// A nested [`NodeNetwork`] that is flattened by the [`NodeNetwork::flatten`] function.
Network(NodeNetwork),
/// A protonode identifier which can be found in `node_registry.rs`.
Unresolved(NodeIdentifier),
Unresolved(ProtoNodeIdentifier),
/// `DocumentNode`s with a `DocumentNodeImplementation::Extract` are converted into a `ClonedNode` that returns the `DocumentNode` specified by the single `NodeInput::Node`.
/// The referenced node (specified by the single `NodeInput::Node`) is removed from the network, and any `NodeInput::Node`s used by the referenced node are replaced with a generically typed network input.
Extract,
@ -373,7 +375,7 @@ pub enum DocumentNodeImplementation {
impl Default for DocumentNodeImplementation {
fn default() -> Self {
Self::Unresolved(NodeIdentifier::new("graphene_core::ops::IdentityNode"))
Self::Unresolved(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode"))
}
}
@ -393,7 +395,7 @@ impl DocumentNodeImplementation {
}
pub const fn proto(name: &'static str) -> Self {
Self::Unresolved(NodeIdentifier::new(name))
Self::Unresolved(ProtoNodeIdentifier::new(name))
}
}
@ -527,7 +529,7 @@ impl NodeNetwork {
name: "MemoNode".to_string(),
manual_composition: Some(concrete!(())),
inputs: vec![NodeInput::Network(ty)],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::memo::MemoNode")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::MemoNode")),
..Default::default()
},
),
@ -536,7 +538,7 @@ impl NodeNetwork {
DocumentNode {
name: "CloneNode".to_string(),
inputs: vec![NodeInput::node(0, 0)],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::CloneNode<_>")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::ops::CloneNode<_>")),
..Default::default()
},
),
@ -983,7 +985,7 @@ impl NodeNetwork {
.nodes
.iter()
.filter(|(_, node)| {
matches!(&node.implementation, DocumentNodeImplementation::Unresolved(ident) if ident == &NodeIdentifier::new("graphene_core::ops::IdentityNode"))
matches!(&node.implementation, DocumentNodeImplementation::Unresolved(ident) if ident == &ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode"))
&& node.inputs.len() == 1
&& matches!(node.inputs[0], NodeInput::Node { .. })
})
@ -1115,7 +1117,7 @@ mod test {
use super::*;
use crate::proto::{ConstructionArgs, ProtoNetwork, ProtoNode, ProtoNodeInput};
use graphene_core::NodeIdentifier;
use graphene_core::ProtoNodeIdentifier;
fn gen_node_id() -> NodeId {
static NODE_ID: AtomicU64 = AtomicU64::new(4);
@ -1366,7 +1368,7 @@ mod test {
DocumentNode {
name: "Identity 1".into(),
inputs: vec![NodeInput::Network(concrete!(u32))],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::IdentityNode")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
..Default::default()
},
),
@ -1375,7 +1377,7 @@ mod test {
DocumentNode {
name: "Identity 2".into(),
inputs: vec![NodeInput::Network(concrete!(u32))],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::IdentityNode")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
..Default::default()
},
),
@ -1405,7 +1407,7 @@ mod test {
DocumentNode {
name: "Result".into(),
inputs: vec![result_node_input],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::IdentityNode")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
..Default::default()
},
),

View file

@ -3,7 +3,7 @@ extern crate log;
#[macro_use]
extern crate graphene_core;
pub use graphene_core::{concrete, generic, NodeIdentifier, Type, TypeDescriptor};
pub use graphene_core::{concrete, generic, ProtoNodeIdentifier, Type, TypeDescriptor};
pub mod document;
pub mod proto;

View file

@ -204,7 +204,7 @@ impl ConstructionArgs {
pub struct ProtoNode {
pub construction_args: ConstructionArgs,
pub input: ProtoNodeInput,
pub identifier: NodeIdentifier,
pub identifier: ProtoNodeIdentifier,
pub document_node_path: Vec<NodeId>,
pub skip_deduplication: bool,
/// Represents a global state on which the node depends. This is a hack, TODO: figure out a proper solution
@ -214,7 +214,7 @@ pub struct ProtoNode {
impl Default for ProtoNode {
fn default() -> Self {
Self {
identifier: NodeIdentifier::new("graphene_core::ops::IdentityNode"),
identifier: ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode"),
construction_args: ConstructionArgs::Value(value::TaggedValue::U32(0)),
input: ProtoNodeInput::None,
document_node_path: vec![],
@ -282,7 +282,7 @@ impl ProtoNode {
/// Construct a new [`ProtoNode`] with the specified construction args and a `ClonedNode` implementation.
pub fn value(value: ConstructionArgs, path: Vec<NodeId>) -> Self {
Self {
identifier: NodeIdentifier::new("graphene_core::value::ClonedNode"),
identifier: ProtoNodeIdentifier::new("graphene_core::value::ClonedNode"),
construction_args: value,
input: ProtoNodeInput::None,
document_node_path: path,
@ -395,7 +395,7 @@ impl ProtoNetwork {
self.nodes.push((
compose_node_id,
ProtoNode {
identifier: NodeIdentifier::new("graphene_core::structural::ComposeNode<_, _, _>"),
identifier: ProtoNodeIdentifier::new("graphene_core::structural::ComposeNode<_, _, _>"),
construction_args: ConstructionArgs::Nodes(vec![(input_node_id, false), (node_id, true)]),
input,
document_node_path: path,
@ -541,14 +541,14 @@ impl ProtoNetwork {
/// The `TypingContext` is used to store the types of the nodes indexed by their stable node id.
#[derive(Default, Clone)]
pub struct TypingContext {
lookup: Cow<'static, HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>>>,
lookup: Cow<'static, HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>>>,
inferred: HashMap<NodeId, NodeIOTypes>,
constructor: HashMap<NodeId, NodeConstructor>,
}
impl TypingContext {
/// Creates a new `TypingContext` with the given lookup table.
pub fn new(lookup: &'static HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>>) -> Self {
pub fn new(lookup: &'static HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>>) -> Self {
Self {
lookup: Cow::Borrowed(lookup),
..Default::default()

View file

@ -8,7 +8,7 @@ use graph_craft::{
document::*,
graphene_compiler::{Compiler, Executor},
imaginate_input::ImaginatePreferences,
NodeIdentifier,
ProtoNodeIdentifier,
};
use graphene_core::{
application_io::{ApplicationIo, NodeGraphUpdateSender},
@ -164,20 +164,20 @@ fn begin_scope() -> DocumentNode {
DocumentNode {
name: "SetNode".to_string(),
manual_composition: Some(concrete!(WasmEditorApi)),
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::SomeNode")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::ops::SomeNode")),
..Default::default()
},
DocumentNode {
name: "LetNode".to_string(),
inputs: vec![NodeInput::node(0, 0)],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::memo::LetNode<_>")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::LetNode<_>")),
..Default::default()
},
DocumentNode {
name: "RefNode".to_string(),
manual_composition: Some(concrete!(WasmEditorApi)),
inputs: vec![NodeInput::lambda(1, 0)],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::memo::RefNode<_, _>")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::memo::RefNode<_, _>")),
..Default::default()
},
]

View file

@ -381,9 +381,9 @@ pub struct MapGpuSingleImageNode<N> {
#[node_macro::node_fn(MapGpuSingleImageNode)]
fn map_gpu_single_image(input: Image<Color>, node: String) -> Image<Color> {
use graph_craft::document::*;
use graph_craft::NodeIdentifier;
use graph_craft::ProtoNodeIdentifier;
let identifier = NodeIdentifier { name: std::borrow::Cow::Owned(node) };
let identifier = ProtoNodeIdentifier { name: std::borrow::Cow::Owned(node) };
let network = NodeNetwork {
inputs: vec![0],

View file

@ -24,7 +24,7 @@ mod tests {
DocumentNode {
name: "Cons".into(),
inputs: vec![NodeInput::Network(concrete!(u32)), NodeInput::Network(concrete!(&u32))],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::structural::ConsNode<_, _>")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::structural::ConsNode<_, _>")),
..Default::default()
},
),
@ -33,7 +33,7 @@ mod tests {
DocumentNode {
name: "Add".into(),
inputs: vec![NodeInput::node(0, 0)],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::AddPairNode")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::ops::AddPairNode")),
..Default::default()
},
),
@ -95,7 +95,7 @@ mod tests {
DocumentNode {
name: "id".into(),
inputs: vec![NodeInput::Network(concrete!(u32))],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::IdentityNode")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode")),
..Default::default()
},
),
@ -105,7 +105,7 @@ mod tests {
DocumentNode {
name: "Add".into(),
inputs: vec![NodeInput::node(0, 0), NodeInput::node(0, 0)],
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::AddNode<_>")),
implementation: DocumentNodeImplementation::Unresolved(ProtoNodeIdentifier::new("graphene_core::ops::AddNode<_>")),
..Default::default()
},
),

View file

@ -13,7 +13,7 @@ use graphene_core::vector::VectorData;
use graphene_core::{application_io::SurfaceHandle, SurfaceFrame, WasmSurfaceHandleFrame};
use graphene_core::{concrete, generic, Artboard, GraphicGroup};
use graphene_core::{fn_type, raster::*};
use graphene_core::{Cow, NodeIdentifier, Type};
use graphene_core::{Cow, ProtoNodeIdentifier, Type};
use graphene_core::{Node, NodeIO, NodeIOTypes};
use graphene_std::any::{ComposeTypeErased, DowncastBothNode, DynAnyNode, FutureWrapperNode, IntoTypeErasedNode};
use graphene_std::wasm_application_io::*;
@ -55,7 +55,7 @@ macro_rules! register_node {
($path:ty, input: $input:ty, fn_params: [ $($arg:ty => $type:ty),*]) => {
vec![
(
NodeIdentifier::new(stringify!($path)),
ProtoNodeIdentifier::new(stringify!($path)),
|args| {
Box::pin(async move {
let node = construct_node!(args, $path, [$($arg => $type),*]).await;
@ -86,7 +86,7 @@ macro_rules! async_node {
($path:ty, input: $input:ty, output: $output:ty, fn_params: [ $($arg:ty => $type:ty),*]) => {
vec![
(
NodeIdentifier::new(stringify!($path)),
ProtoNodeIdentifier::new(stringify!($path)),
|mut args| {
Box::pin(async move {
args.reverse();
@ -122,10 +122,10 @@ macro_rules! raster_node {
// optimization purposes.
#[cfg_attr(debug_assertions, inline(never))]
#[cfg_attr(not(debug_assertions), inline)]
fn generate_triples() -> Vec<(NodeIdentifier, NodeConstructor, NodeIOTypes)> {
fn generate_triples() -> Vec<(ProtoNodeIdentifier, NodeConstructor, NodeIOTypes)> {
vec![
(
NodeIdentifier::new(stringify!($path)),
ProtoNodeIdentifier::new(stringify!($path)),
|args| {
Box::pin(async move {
let node = construct_node!(args, $path, [$(() => $type),*]).await;
@ -140,7 +140,7 @@ macro_rules! raster_node {
},
),
(
NodeIdentifier::new(stringify!($path)),
ProtoNodeIdentifier::new(stringify!($path)),
|args| {
Box::pin(async move {
let node = construct_node!(args, $path, [$(() => $type),*]).await;
@ -156,7 +156,7 @@ macro_rules! raster_node {
},
),
(
NodeIdentifier::new(stringify!($path)),
ProtoNodeIdentifier::new(stringify!($path)),
|args| {
Box::pin(async move {
let node = construct_node!(args, $path, [$(() => $type),*]).await;
@ -178,11 +178,11 @@ macro_rules! raster_node {
}
//TODO: turn into hashmap
fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>> {
let node_types: Vec<Vec<(NodeIdentifier, NodeConstructor, NodeIOTypes)>> = vec![
fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>> {
let node_types: Vec<Vec<(ProtoNodeIdentifier, NodeConstructor, NodeIOTypes)>> = vec![
//register_node!(graphene_core::ops::IdentityNode, input: Any<'_>, params: []),
vec![(
NodeIdentifier::new("graphene_core::ops::IdentityNode"),
ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode"),
|_| Box::pin(async move { FutureWrapperNode::new(IdentityNode::new()).into_type_erased() }),
NodeIOTypes::new(generic!(I), generic!(I), vec![]),
)],
@ -284,7 +284,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
register_node!(graphene_std::raster::InsertChannelNode<_, _, _, _>, input: ImageFrame<Color>, params: [ImageFrame<Color>, RedGreenBlue]),
register_node!(graphene_std::raster::InsertChannelNode<_, _, _, _>, input: ImageFrame<Color>, params: [ImageFrame<Luma>, RedGreenBlue]),
vec![(
NodeIdentifier::new("graphene_std::raster::CombineChannelsNode"),
ProtoNodeIdentifier::new("graphene_std::raster::CombineChannelsNode"),
|args| {
Box::pin(async move {
use graphene_core::raster::*;
@ -380,7 +380,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
),
#[cfg(feature = "gpu")]
vec![(
NodeIdentifier::new("graphene_std::executor::MapGpuSingleImageNode<_>"),
ProtoNodeIdentifier::new("graphene_std::executor::MapGpuSingleImageNode<_>"),
|args| {
Box::pin(async move {
let document_node: DowncastBothNode<(), graph_craft::document::DocumentNode> = DowncastBothNode::new(args[0].clone());
@ -399,7 +399,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
)],
#[cfg(feature = "gpu")]
vec![(
NodeIdentifier::new("graphene_std::executor::BlendGpuImageNode<_, _, _>"),
ProtoNodeIdentifier::new("graphene_std::executor::BlendGpuImageNode<_, _, _>"),
|args| {
Box::pin(async move {
let background: DowncastBothNode<(), ImageFrame<Color>> = DowncastBothNode::new(args[0].clone());
@ -418,7 +418,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
),
)],
vec![(
NodeIdentifier::new("graphene_core::structural::ComposeNode<_, _, _>"),
ProtoNodeIdentifier::new("graphene_core::structural::ComposeNode<_, _, _>"),
|args| {
Box::pin(async move {
let node = ComposeTypeErased::new(args[0].clone(), args[1].clone());
@ -446,7 +446,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
register_node!(graphene_core::raster::adjustments::ColorFillNode<_>, input: ImageFrame<Color>, params: [Color]),
register_node!(graphene_core::raster::adjustments::ColorOverlayNode<_, _, _>, input: ImageFrame<Color>, params: [Color, BlendMode, f32]),
vec![(
NodeIdentifier::new("graphene_core::raster::BlendNode<_, _, _, _>"),
ProtoNodeIdentifier::new("graphene_core::raster::BlendNode<_, _, _, _>"),
|args| {
Box::pin(async move {
let image: DowncastBothNode<(), ImageFrame<Color>> = DowncastBothNode::new(args[0].clone());
@ -478,7 +478,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
params: [RelativeAbsolute, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32]
),
vec![(
NodeIdentifier::new("graphene_core::raster::BrightnessContrastNode<_, _, _>"),
ProtoNodeIdentifier::new("graphene_core::raster::BrightnessContrastNode<_, _, _>"),
|args| {
Box::pin(async move {
use graphene_core::raster::brightness_contrast::*;
@ -508,7 +508,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
)],
vec![
(
NodeIdentifier::new("graphene_core::raster::CurvesNode<_>"),
ProtoNodeIdentifier::new("graphene_core::raster::CurvesNode<_>"),
|args| {
use graphene_core::raster::{curve::Curve, GenerateCurvesNode};
let curve: DowncastBothNode<(), Curve> = DowncastBothNode::new(args[0].clone());
@ -526,7 +526,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
),
// TODO: Use channel split and merge for this instead of using LuminanceMut for the whole color.
(
NodeIdentifier::new("graphene_core::raster::CurvesNode<_>"),
ProtoNodeIdentifier::new("graphene_core::raster::CurvesNode<_>"),
|args| {
use graphene_core::raster::{curve::Curve, GenerateCurvesNode};
let curve: DowncastBothNode<(), Curve> = DowncastBothNode::new(args[0].clone());
@ -584,7 +584,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
async_node!(graphene_core::memo::EndLetNode<_, _>, input: WasmEditorApi, output: SurfaceFrame, params: [SurfaceFrame]),
vec![
(
NodeIdentifier::new("graphene_core::memo::RefNode<_, _>"),
ProtoNodeIdentifier::new("graphene_core::memo::RefNode<_, _>"),
|args| {
Box::pin(async move {
let node: DowncastBothNode<Option<WasmEditorApi>, WasmEditorApi> = graphene_std::any::DowncastBothNode::new(args[0].clone());
@ -597,7 +597,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
NodeIOTypes::new(concrete!(()), concrete!(WasmEditorApi), vec![fn_type!(Option<WasmEditorApi>, WasmEditorApi)]),
),
(
NodeIdentifier::new("graphene_std::raster::ImaginateNode<_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _>"),
ProtoNodeIdentifier::new("graphene_std::raster::ImaginateNode<_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _>"),
|args: Vec<graph_craft::proto::SharedNodeContainer>| {
Box::pin(async move {
use graphene_std::raster::ImaginateNode;
@ -669,7 +669,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
//register_node!(graphene_core::transform::TranformNode<_, _, _, _, _, _>, input: , output: RenderOutput, fn_params: [Footprint => GraphicGroup, () => Arc<WasmSurfaceHandle>]),
vec![
(
NodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"),
ProtoNodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"),
|mut args| {
Box::pin(async move {
args.reverse();
@ -691,7 +691,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
},
),
(
NodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"),
ProtoNodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"),
|mut args| {
Box::pin(async move {
args.reverse();
@ -720,7 +720,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
},
),
(
NodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"),
ProtoNodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"),
|mut args| {
Box::pin(async move {
args.reverse();
@ -749,7 +749,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
},
),
(
NodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"),
ProtoNodeIdentifier::new("graphene_core::transform::TransformNode<_, _, _, _, _, _>"),
|mut args| {
Box::pin(async move {
const EXPECT_MESSAGE: &str = "Not enough arguments provided to construct node";
@ -785,7 +785,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
register_node!(graphene_core::vector::BoundingBoxNode, input: VectorData, params: []),
register_node!(graphene_core::vector::CircularRepeatNode<_, _, _>, input: VectorData, params: [f32, f32, u32]),
vec![(
NodeIdentifier::new("graphene_core::transform::CullNode<_>"),
ProtoNodeIdentifier::new("graphene_core::transform::CullNode<_>"),
|args| {
Box::pin(async move {
let mut args = args.clone();
@ -806,7 +806,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
register_node!(graphene_core::transform::CullNode<_>, input: Footprint, params: [Artboard]),
register_node!(graphene_core::transform::CullNode<_>, input: Footprint, params: [ImageFrame<Color>]),
vec![(
NodeIdentifier::new("graphene_core::transform::CullNode<_>"),
ProtoNodeIdentifier::new("graphene_core::transform::CullNode<_>"),
|args| {
Box::pin(async move {
let mut args = args.clone();
@ -850,19 +850,19 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
register_node!(graphene_core::ToGraphicElementData, input: Artboard, params: []),
async_node!(graphene_core::ConstructArtboardNode<_, _, _, _, _>, input: Footprint, output: Artboard, fn_params: [Footprint => GraphicGroup, () => glam::IVec2, () => glam::IVec2, () => Color, () => bool]),
];
let mut map: HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>> = HashMap::new();
let mut map: HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>> = HashMap::new();
for (id, c, types) in node_types.into_iter().flatten() {
// TODO: this is a hack to remove the newline from the node new_name
// This occurs for the ChannelMixerNode presumably because of the long name.
// This might be caused by the stringify! macro
let new_name = id.name.replace('\n', " ");
let nid = NodeIdentifier { name: Cow::Owned(new_name) };
let nid = ProtoNodeIdentifier { name: Cow::Owned(new_name) };
map.entry(nid).or_default().insert(types.clone(), c);
}
map
}
pub static NODE_REGISTRY: Lazy<HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>>> = Lazy::new(|| node_registry());
pub static NODE_REGISTRY: Lazy<HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>>> = Lazy::new(|| node_registry());
#[cfg(test)]
mod protograph_testing {

View file

@ -116,7 +116,7 @@ fn create_buffer<T: Pod + Send + Sync>(data: Vec<T>, alloc: &StandardMemoryAlloc
// TODO: Fix this test
// #[cfg(test)]
// mod test {
// use graph_craft::proto::{ConstructionArgs, NodeIdentifier, ProtoNetwork, ProtoNode, ProtoNodeInput, Type};
// use graph_craft::proto::{ConstructionArgs, ProtoNodeIdentifier, ProtoNetwork, ProtoNode, ProtoNodeInput, Type};
// use graph_craft::{concrete, generic};
// fn inc_network() -> ProtoNetwork {
@ -127,7 +127,7 @@ fn create_buffer<T: Pod + Send + Sync>(data: Vec<T>, alloc: &StandardMemoryAlloc
// (
// 1,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::ops::IdentityNode", &[generic!("u32")]),
// identifier: ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode", &[generic!("u32")]),
// input: ProtoNodeInput::Node(11),
// construction_args: ConstructionArgs::Nodes(vec![]),
// },
@ -135,7 +135,7 @@ fn create_buffer<T: Pod + Send + Sync>(data: Vec<T>, alloc: &StandardMemoryAlloc
// (
// 10,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::structural::ConsNode", &[generic!("&ValueNode<u32>"), generic!("()")]),
// identifier: ProtoNodeIdentifier::new("graphene_core::structural::ConsNode", &[generic!("&ValueNode<u32>"), generic!("()")]),
// input: ProtoNodeInput::Network,
// construction_args: ConstructionArgs::Nodes(vec![14]),
// },
@ -143,7 +143,7 @@ fn create_buffer<T: Pod + Send + Sync>(data: Vec<T>, alloc: &StandardMemoryAlloc
// (
// 11,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::ops::AddPairNode", &[generic!("u32"), generic!("u32")]),
// identifier: ProtoNodeIdentifier::new("graphene_core::ops::AddPairNode", &[generic!("u32"), generic!("u32")]),
// input: ProtoNodeInput::Node(10),
// construction_args: ConstructionArgs::Nodes(vec![]),
// },
@ -151,7 +151,7 @@ fn create_buffer<T: Pod + Send + Sync>(data: Vec<T>, alloc: &StandardMemoryAlloc
// (
// 14,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::value::ValueNode", &[concrete!("u32")]),
// identifier: ProtoNodeIdentifier::new("graphene_core::value::ValueNode", &[concrete!("u32")]),
// input: ProtoNodeInput::None,
// construction_args: ConstructionArgs::Value(Box::new(3_u32)),
// },

View file

@ -209,7 +209,7 @@ async fn execute_shader<I: Pod + Send + Sync, O: Pod + Send + Sync>(device: Arc<
// (
// 1,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::ops::IdentityNode", &[generic!("u32")]),
// identifier: ProtoNodeIdentifier::new("graphene_core::ops::IdentityNode", &[generic!("u32")]),
// input: ProtoNodeInput::Node(11),
// construction_args: ConstructionArgs::Nodes(vec![]),
// },
@ -217,7 +217,7 @@ async fn execute_shader<I: Pod + Send + Sync, O: Pod + Send + Sync>(device: Arc<
// (
// 10,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::structural::ConsNode", &[generic!("&ValueNode<u32>"), generic!("()")]),
// identifier: ProtoNodeIdentifier::new("graphene_core::structural::ConsNode", &[generic!("&ValueNode<u32>"), generic!("()")]),
// input: ProtoNodeInput::Network,
// construction_args: ConstructionArgs::Nodes(vec![14]),
// },
@ -225,7 +225,7 @@ async fn execute_shader<I: Pod + Send + Sync, O: Pod + Send + Sync>(device: Arc<
// (
// 11,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::ops::AddPairNode", &[generic!("u32"), generic!("u32")]),
// identifier: ProtoNodeIdentifier::new("graphene_core::ops::AddPairNode", &[generic!("u32"), generic!("u32")]),
// input: ProtoNodeInput::Node(10),
// construction_args: ConstructionArgs::Nodes(vec![]),
// },
@ -233,7 +233,7 @@ async fn execute_shader<I: Pod + Send + Sync, O: Pod + Send + Sync>(device: Arc<
// (
// 14,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::value::ValueNode", &[concrete!("u32")]),
// identifier: ProtoNodeIdentifier::new("graphene_core::value::ValueNode", &[concrete!("u32")]),
// input: ProtoNodeInput::None,
// construction_args: ConstructionArgs::Value(Box::new(3_u32)),
// },