diff --git a/Cargo.lock b/Cargo.lock index 99a35d0..cf43310 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,6 +62,14 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +[[package]] +name = "leaf" +version = "0.1.0" +dependencies = [ + "nodarium_macros", + "nodarium_utils", +] + [[package]] name = "math" version = "0.1.0" diff --git a/app/src/lib/graph-interface/graph-state.svelte.ts b/app/src/lib/graph-interface/graph-state.svelte.ts index 4419cad..512fe39 100644 --- a/app/src/lib/graph-interface/graph-state.svelte.ts +++ b/app/src/lib/graph-interface/graph-state.svelte.ts @@ -194,7 +194,11 @@ export class GraphState { if (node?.inputs?.[key] === undefined) continue; if ('setting' in node.inputs[key]) continue; if (node.inputs[key].hidden) continue; - if (node.inputs[key].type === 'shape') { + if ( + node.inputs[key].type === 'shape' + && node.inputs[key].external !== true + && node.inputs[key].internal !== false + ) { height += 20; continue; } diff --git a/app/src/lib/graph-interface/node/NodeInput.svelte b/app/src/lib/graph-interface/node/NodeInput.svelte index af30b89..a4a5c24 100644 --- a/app/src/lib/graph-interface/node/NodeInput.svelte +++ b/app/src/lib/graph-interface/node/NodeInput.svelte @@ -31,11 +31,24 @@ return 0; } - let value = $state(getDefaultValue()); + let value = $state(structuredClone($state.snapshot(getDefaultValue()))); + + function diffArray(a: number[], b?: number[] | number) { + if (!Array.isArray(b)) return true; + if (Array.isArray(a) !== Array.isArray(b)) return true; + if (a.length !== b.length) return true; + for (let i = 0; i < a.length; i++) { + if (a[i] !== b[i]) return true; + } + return false; + } $effect(() => { - if (value !== undefined && node?.props?.[id] !== value) { - node.props = { ...node.props, [id]: value }; + const a = $state.snapshot(value); + const b = $state.snapshot(node?.props?.[id]); + const isDiff = Array.isArray(a) ? diffArray(a, b) : a !== b; + if (value !== undefined && isDiff) { + node.props = { ...node.props, [id]: a }; if (graph) { graph.save(); graph.execute(); diff --git a/app/src/lib/graph-interface/node/NodeParameter.svelte b/app/src/lib/graph-interface/node/NodeParameter.svelte index cf37541..0889c21 100644 --- a/app/src/lib/graph-interface/node/NodeParameter.svelte +++ b/app/src/lib/graph-interface/node/NodeParameter.svelte @@ -18,7 +18,8 @@ const inputType = $derived(node?.state?.type?.inputs?.[id]); const socketId = $derived(`${node.id}-${id}`); - const height = $derived(input.type === 'shape' ? 200 : 100); + const isShape = $derived(input.type === 'shape' && input.external !== true); + const height = $derived(isShape ? 200 : 100); const graphState = getGraphState(); const graphId = graph?.id; diff --git a/nodes/max/plantarium/leaf/.gitignore b/nodes/max/plantarium/leaf/.gitignore new file mode 100644 index 0000000..4e30131 --- /dev/null +++ b/nodes/max/plantarium/leaf/.gitignore @@ -0,0 +1,6 @@ +/target +**/*.rs.bk +Cargo.lock +bin/ +pkg/ +wasm-pack.log diff --git a/nodes/max/plantarium/leaf/Cargo.toml b/nodes/max/plantarium/leaf/Cargo.toml new file mode 100644 index 0000000..b582166 --- /dev/null +++ b/nodes/max/plantarium/leaf/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "leaf" +version = "0.1.0" +authors = ["Max Richter "] +edition = "2018" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } +nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } diff --git a/nodes/max/plantarium/leaf/src/input.json b/nodes/max/plantarium/leaf/src/input.json new file mode 100644 index 0000000..42ce391 --- /dev/null +++ b/nodes/max/plantarium/leaf/src/input.json @@ -0,0 +1,16 @@ +{ + "id": "max/plantarium/leaf", + "outputs": [ + "geometry" + ], + "inputs": { + "shape": { + "type": "shape", + "external": true + }, + "size": { + "type": "float", + "value": 1 + } + } +} diff --git a/nodes/max/plantarium/leaf/src/lib.rs b/nodes/max/plantarium/leaf/src/lib.rs new file mode 100644 index 0000000..4922f5e --- /dev/null +++ b/nodes/max/plantarium/leaf/src/lib.rs @@ -0,0 +1,13 @@ +use nodarium_macros::nodarium_definition_file; +use nodarium_macros::nodarium_execute; +use nodarium_utils::{concat_args, log, split_args}; + +nodarium_definition_file!("src/input.json"); + +#[nodarium_execute] +pub fn execute(input: &[i32]) -> Vec { + let args = split_args(input); + log!("leaf input: {:?}", input); + log!("leaf args: {:?}", args); + concat_args(args) +} diff --git a/nodes/max/plantarium/shape/src/lib.rs b/nodes/max/plantarium/shape/src/lib.rs index 118fd29..adf2178 100644 --- a/nodes/max/plantarium/shape/src/lib.rs +++ b/nodes/max/plantarium/shape/src/lib.rs @@ -1,13 +1,10 @@ use nodarium_macros::nodarium_definition_file; use nodarium_macros::nodarium_execute; -use nodarium_utils::{concat_args, log, split_args}; +use nodarium_utils::{concat_args, split_args}; nodarium_definition_file!("src/input.json"); #[nodarium_execute] pub fn execute(input: &[i32]) -> Vec { - let args = split_args(input); - log!("vec3 input: {:?}", input); - log!("vec3 args: {:?}", args); - concat_args(args) + concat_args(split_args(input)) } diff --git a/packages/utils/src/lib.rs b/packages/utils/src/lib.rs index 5809ecb..8d02ca7 100644 --- a/packages/utils/src/lib.rs +++ b/packages/utils/src/lib.rs @@ -11,7 +11,7 @@ extern "C" { pub fn host_log(ptr: *const u8, len: usize); } -#[cfg(debug_assertions)] +// #[cfg(debug_assertions)] #[macro_export] macro_rules! log { ($($t:tt)*) => {{ @@ -25,13 +25,13 @@ macro_rules! log { }} } -#[cfg(not(debug_assertions))] -#[macro_export] -macro_rules! log { - ($($arg:tt)*) => {{ - // This will expand to nothing in release builds - }}; -} +// #[cfg(not(debug_assertions))] +// #[macro_export] +// macro_rules! log { +// ($($arg:tt)*) => {{ +// // This will expand to nothing in release builds +// }}; +// } #[allow(dead_code)] #[rustfmt::skip]