Skip to content

Commit 7764da4

Browse files
committed
Implement new node_fn macro
1 parent 5043799 commit 7764da4

File tree

13 files changed

+946
-126
lines changed

13 files changed

+946
-126
lines changed

Cargo.lock

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
154154
category: "Value",
155155
node_template: NodeTemplate {
156156
document_node: DocumentNode {
157-
implementation: DocumentNodeImplementation::proto("graphene_core::ops::ConstructVector2<_, _>"),
157+
implementation: DocumentNodeImplementation::proto("graphene_core::ops::construct_vector2::ConstructVector2"),
158158
inputs: vec![
159159
NodeInput::value(TaggedValue::None, false),
160160
NodeInput::value(TaggedValue::F64(0.), false),

frontend/src/wasm-communication/editor.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ export async function initWasm() {
1919

2020
// Import the WASM module JS bindings and wrap them in the panic proxy
2121
// eslint-disable-next-line import/no-cycle
22-
await init();
22+
let wasm = await init();
23+
// console.log(wasm);
24+
for (const [name, f] of Object.entries(wasm)) {
25+
if (name.startsWith("__node_registry")) {
26+
console.log(f);
27+
f();
28+
}
29+
}
30+
2331
wasmImport = await wasmMemory();
2432
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2533
(window as any).imageCanvases = {};

frontend/wasm/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub mod editor_api;
88
pub mod helpers;
99

1010
use editor::messages::prelude::*;
11+
use js_sys::{Array, Function, Object, Reflect};
1112

1213
use std::panic;
1314
use std::sync::atomic::{AtomicBool, Ordering};

node-graph/gcore/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ std = [
3030
]
3131
reflections = [
3232
"alloc",
33-
"ctor"
33+
"ctor",
3434
]
3535
serde = [
3636
"dep:serde",

node-graph/gcore/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub mod vector;
4040
#[cfg(feature = "alloc")]
4141
pub mod application_io;
4242

43-
#[cfg(feature = "alloc")]
43+
#[cfg(feature = "reflections")]
4444
pub mod registry;
4545

4646
pub mod quantization;

node-graph/gcore/src/ops.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,8 @@ where
192192
first % second
193193
}
194194

195-
pub struct ConstructVector2<X, Y> {
196-
x: X,
197-
y: Y,
198-
}
199-
#[node_macro::node_fn(ConstructVector2)]
200-
fn construct_vector2(_primary: (), x: f64, y: f64) -> glam::DVec2 {
195+
#[node_macro::new_node_fn]
196+
fn construct_vector2(_: (), x: f64, y: f64) -> glam::DVec2 {
201197
glam::DVec2::new(x, y)
202198
}
203199

node-graph/gcore/src/registry.rs

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -233,116 +233,3 @@ where
233233
}
234234
}
235235
}
236-
237-
async fn construct_vector2<'n, IY: Into<f64> + Send + 'n, IC: Into<u64> + Send + 'n>(_: (), x: f64, y: IY, c: impl Node<'n, (), Output: core::future::Future<Output = IC>>) -> glam::DVec2 {
238-
glam::DVec2::new(x, y.into())
239-
}
240-
mod construct_vector2 {
241-
use super::*;
242-
use crate as gcore;
243-
use ctor::ctor;
244-
use gcore::ops::TypeNode;
245-
use gcore::registry::{DowncastBothNode, DynAnyNode, DynFuture, FieldMetadata, NodeMetadata, TypeErasedBox, NODE_METADATA, NODE_REGISTRY};
246-
use gcore::value::ClonedNode;
247-
use gcore::{concrete, fn_type, Node, NodeIOTypes, ProtoNodeIdentifier, WasmNotSync};
248-
pub struct ConstructVector2<Node0, Node1, Node2> {
249-
x: Node0,
250-
y: Node1,
251-
c: Node2,
252-
}
253-
#[automatically_derived]
254-
impl<'n, IY: Into<f64> + Send + 'n, IC: Into<u64> + Send + 'n, Node0, Node1, Node2> Node<'n, ()> for ConstructVector2<Node0, Node1, Node2>
255-
where
256-
Node0: Node<'n, (), Output = f64>,
257-
Node1: Node<'n, (), Output = IY>,
258-
Node2: Node<'n, (), Output: core::future::Future<Output = IC>> + WasmNotSync + 'n,
259-
{
260-
type Output = DynFuture<'n, glam::DVec2>;
261-
fn eval(&'n self, input: ()) -> Self::Output {
262-
let x = self.x.eval(());
263-
let y = self.y.eval(());
264-
let c = &self.c;
265-
Box::pin(construct_vector2(input, x, y, c))
266-
}
267-
}
268-
#[automatically_derived]
269-
impl<'n, Node0, Node1, Node2> ConstructVector2<Node0, Node1, Node2> {
270-
pub fn new(x: Node0, y: Node1, c: Node2) -> Self {
271-
Self { x, y, c }
272-
}
273-
}
274-
#[ctor]
275-
fn register_node() {
276-
let mut registry = NODE_REGISTRY.lock().unwrap();
277-
registry.insert(
278-
ProtoNodeIdentifier::new(concat![std::module_path!(), "::", stringify!(ConstructVector2)]),
279-
vec![
280-
(
281-
|args| {
282-
Box::pin(async move {
283-
let x: DowncastBothNode<(), f64> = DowncastBothNode::new(args[0usize].clone());
284-
let value = x.eval(()).await;
285-
let x = ClonedNode::new(value);
286-
let x: TypeNode<_, (), f64> = TypeNode::new(x);
287-
let y: DowncastBothNode<(), f32> = DowncastBothNode::new(args[1usize].clone());
288-
let value = y.eval(()).await;
289-
let y = ClonedNode::new(value);
290-
let y: TypeNode<_, (), f32> = TypeNode::new(y);
291-
let c: DowncastBothNode<(), u32> = DowncastBothNode::new(args[2usize].clone());
292-
let node = ConstructVector2::new(x, y, c);
293-
let any: DynAnyNode<(), _, _> = DynAnyNode::new(node);
294-
Box::new(any) as TypeErasedBox<'_>
295-
})
296-
},
297-
NodeIOTypes::new(concrete!(()), concrete!(glam::DVec2), vec![fn_type!((), f64), fn_type!((), f32), fn_type!((), u32)]),
298-
),
299-
(
300-
|args| {
301-
Box::pin(async move {
302-
let x: DowncastBothNode<(), f64> = DowncastBothNode::new(args[0usize].clone());
303-
let value = x.eval(()).await;
304-
let x = ClonedNode::new(value);
305-
let x: TypeNode<_, (), f64> = TypeNode::new(x);
306-
let y: DowncastBothNode<(), f64> = DowncastBothNode::new(args[1usize].clone());
307-
let value = y.eval(()).await;
308-
let y = ClonedNode::new(value);
309-
let y: TypeNode<_, (), f64> = TypeNode::new(y);
310-
let c: DowncastBothNode<(), u64> = DowncastBothNode::new(args[2usize].clone());
311-
let node = ConstructVector2::new(x, y, c);
312-
let any: DynAnyNode<(), _, _> = DynAnyNode::new(node);
313-
Box::new(any) as TypeErasedBox<'_>
314-
})
315-
},
316-
NodeIOTypes::new(concrete!(()), concrete!(glam::DVec2), vec![fn_type!((), f64), fn_type!((), f64), fn_type!((), u64)]),
317-
),
318-
],
319-
);
320-
}
321-
#[ctor]
322-
fn register_metadata() {
323-
let metadata = NodeMetadata {
324-
identifier: ProtoNodeIdentifier::new(concat![std::module_path!(), "::", stringify!(ConstructVector2)]),
325-
category: Some("Value"),
326-
input_type: concrete!(()),
327-
output_type: concrete!(glam::DVec2),
328-
fields: vec![
329-
FieldMetadata {
330-
name: stringify!(x).to_string(),
331-
default_value: Some(stringify!(1.3)),
332-
},
333-
FieldMetadata {
334-
name: stringify!(y).to_string(),
335-
default_value: None,
336-
},
337-
FieldMetadata {
338-
name: stringify!(c).to_string(),
339-
default_value: None,
340-
},
341-
],
342-
};
343-
NODE_METADATA
344-
.lock()
345-
.unwrap()
346-
.insert(ProtoNodeIdentifier::new(concat![std::module_path!(), "::", stringify!(ConstructVector2)]), metadata);
347-
}
348-
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
286286
register_node!(graphene_core::ops::ModuloNode<_>, input: &f64, params: [f64]),
287287
register_node!(graphene_core::ops::ModuloNode<_>, input: f64, params: [&f64]),
288288
register_node!(graphene_core::ops::ModuloNode<_>, input: &f64, params: [&f64]),
289-
register_node!(graphene_core::ops::ConstructVector2<_, _>, input: (), params: [f64, f64]),
290289
register_node!(graphene_core::ops::SomeNode, input: &WasmEditorApi, params: []),
291290
register_node!(graphene_core::ops::UnwrapNode, input: Option<Color>, params: []),
292291
register_node!(graphene_core::logic::LogToConsoleNode, input: bool, params: []),
@@ -806,6 +805,12 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
806805
async_node!(graphene_core::AddArtboardNode<_, _>, input: Footprint, output: ArtboardGroup, fn_params: [Footprint => ArtboardGroup, Footprint => Artboard]),
807806
];
808807
let mut map: HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>> = HashMap::new();
808+
for (id, entry) in graphene_core::registry::NODE_REGISTRY.lock().unwrap().drain() {
809+
log::debug!("id: {id:?}");
810+
for (constructor, types) in entry.into_iter() {
811+
map.entry(id.clone()).or_default().insert(types, constructor);
812+
}
813+
}
809814
for (id, c, types) in node_types.into_iter().flatten() {
810815
// TODO: this is a hack to remove the newline from the node new_name
811816
// This occurs for the ChannelMixerNode presumably because of the long name.

node-graph/node-macro/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ proc-macro = true
1515

1616
[dependencies]
1717
# Workspace dependencies
18-
syn = { workspace = true }
18+
syn = { workspace = true, features = ["extra-traits", "full"] }
1919
proc-macro2 = { workspace = true }
2020
quote = { workspace = true }
21+
22+
convert_case = "0.6.0"
23+
indoc = "2.0.5"
24+
proc-macro-crate = "3.1.0"
25+

0 commit comments

Comments
 (0)