feat(node): initial leaf / shape nodes
All checks were successful
🚀 Lint & Test & Deploy / release (pull_request) Successful in 4m1s
All checks were successful
🚀 Lint & Test & Deploy / release (pull_request) Successful in 4m1s
This commit is contained in:
8
Cargo.lock
generated
8
Cargo.lock
generated
@@ -62,6 +62,14 @@ version = "1.0.17"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
|
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "leaf"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"nodarium_macros",
|
||||||
|
"nodarium_utils",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "math"
|
name = "math"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|||||||
@@ -194,7 +194,11 @@ export class GraphState {
|
|||||||
if (node?.inputs?.[key] === undefined) continue;
|
if (node?.inputs?.[key] === undefined) continue;
|
||||||
if ('setting' in node.inputs[key]) continue;
|
if ('setting' in node.inputs[key]) continue;
|
||||||
if (node.inputs[key].hidden) 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;
|
height += 20;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,24 @@
|
|||||||
return 0;
|
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(() => {
|
$effect(() => {
|
||||||
if (value !== undefined && node?.props?.[id] !== value) {
|
const a = $state.snapshot(value);
|
||||||
node.props = { ...node.props, [id]: 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) {
|
if (graph) {
|
||||||
graph.save();
|
graph.save();
|
||||||
graph.execute();
|
graph.execute();
|
||||||
|
|||||||
@@ -18,7 +18,8 @@
|
|||||||
const inputType = $derived(node?.state?.type?.inputs?.[id]);
|
const inputType = $derived(node?.state?.type?.inputs?.[id]);
|
||||||
|
|
||||||
const socketId = $derived(`${node.id}-${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 graphState = getGraphState();
|
||||||
const graphId = graph?.id;
|
const graphId = graph?.id;
|
||||||
|
|||||||
6
nodes/max/plantarium/leaf/.gitignore
vendored
Normal file
6
nodes/max/plantarium/leaf/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/target
|
||||||
|
**/*.rs.bk
|
||||||
|
Cargo.lock
|
||||||
|
bin/
|
||||||
|
pkg/
|
||||||
|
wasm-pack.log
|
||||||
12
nodes/max/plantarium/leaf/Cargo.toml
Normal file
12
nodes/max/plantarium/leaf/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "leaf"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Max Richter <jim-x@web.de>"]
|
||||||
|
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" }
|
||||||
16
nodes/max/plantarium/leaf/src/input.json
Normal file
16
nodes/max/plantarium/leaf/src/input.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"id": "max/plantarium/leaf",
|
||||||
|
"outputs": [
|
||||||
|
"geometry"
|
||||||
|
],
|
||||||
|
"inputs": {
|
||||||
|
"shape": {
|
||||||
|
"type": "shape",
|
||||||
|
"external": true
|
||||||
|
},
|
||||||
|
"size": {
|
||||||
|
"type": "float",
|
||||||
|
"value": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
nodes/max/plantarium/leaf/src/lib.rs
Normal file
13
nodes/max/plantarium/leaf/src/lib.rs
Normal file
@@ -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<i32> {
|
||||||
|
let args = split_args(input);
|
||||||
|
log!("leaf input: {:?}", input);
|
||||||
|
log!("leaf args: {:?}", args);
|
||||||
|
concat_args(args)
|
||||||
|
}
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
use nodarium_macros::nodarium_definition_file;
|
use nodarium_macros::nodarium_definition_file;
|
||||||
use nodarium_macros::nodarium_execute;
|
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_definition_file!("src/input.json");
|
||||||
|
|
||||||
#[nodarium_execute]
|
#[nodarium_execute]
|
||||||
pub fn execute(input: &[i32]) -> Vec<i32> {
|
pub fn execute(input: &[i32]) -> Vec<i32> {
|
||||||
let args = split_args(input);
|
concat_args(split_args(input))
|
||||||
log!("vec3 input: {:?}", input);
|
|
||||||
log!("vec3 args: {:?}", args);
|
|
||||||
concat_args(args)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ extern "C" {
|
|||||||
pub fn host_log(ptr: *const u8, len: usize);
|
pub fn host_log(ptr: *const u8, len: usize);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
// #[cfg(debug_assertions)]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! log {
|
macro_rules! log {
|
||||||
($($t:tt)*) => {{
|
($($t:tt)*) => {{
|
||||||
@@ -25,13 +25,13 @@ macro_rules! log {
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
// #[cfg(not(debug_assertions))]
|
||||||
#[macro_export]
|
// #[macro_export]
|
||||||
macro_rules! log {
|
// macro_rules! log {
|
||||||
($($arg:tt)*) => {{
|
// ($($arg:tt)*) => {{
|
||||||
// This will expand to nothing in release builds
|
// // This will expand to nothing in release builds
|
||||||
}};
|
// }};
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
|||||||
Reference in New Issue
Block a user