From 7579c6c00be9cfb052cea5f5cb9b835f55b141ee Mon Sep 17 00:00:00 2001 From: Max Richter Date: Wed, 17 Apr 2024 15:34:28 +0200 Subject: [PATCH] feat: add box node --- Cargo.lock | 16 ++++ app/src/lib/graph-interface/graph-manager.ts | 14 +++- app/src/lib/node-registry.ts | 3 + app/src/lib/viewer/Scene.svelte | 22 +++++- app/src/lib/viewer/Viewer.svelte | 45 +++++------ app/src/routes/test/+page.svelte | 18 +++++ nodes/max/plantarium/array/src/lib.rs | 14 ++-- nodes/max/plantarium/box/.gitignore | 6 ++ nodes/max/plantarium/box/Cargo.toml | 28 +++++++ nodes/max/plantarium/box/package.json | 6 ++ nodes/max/plantarium/box/src/input.json | 11 +++ nodes/max/plantarium/box/src/lib.rs | 83 ++++++++++++++++++++ nodes/max/plantarium/box/tests/web.rs | 13 +++ nodes/max/plantarium/math/src/lib.rs | 6 +- nodes/max/plantarium/output/src/inputs.json | 5 +- nodes/max/plantarium/output/src/lib.rs | 53 +++++-------- nodes/max/plantarium/stem/src/lib.rs | 4 +- nodes/max/plantarium/sum/src/lib.rs | 6 +- nodes/max/plantarium/triangle/Cargo.toml | 2 + nodes/max/plantarium/triangle/src/input.json | 11 +++ nodes/max/plantarium/triangle/src/lib.rs | 54 +++++++++---- packages/types/index.ts | 2 +- packages/types/inputs.ts | 6 +- packages/utils/src/tree.rs | 35 +++++++-- 24 files changed, 364 insertions(+), 99 deletions(-) create mode 100644 nodes/max/plantarium/box/.gitignore create mode 100644 nodes/max/plantarium/box/Cargo.toml create mode 100644 nodes/max/plantarium/box/package.json create mode 100644 nodes/max/plantarium/box/src/input.json create mode 100644 nodes/max/plantarium/box/src/lib.rs create mode 100644 nodes/max/plantarium/box/tests/web.rs create mode 100644 nodes/max/plantarium/triangle/src/input.json diff --git a/Cargo.lock b/Cargo.lock index 1f819b0..adf7ed0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,6 +16,20 @@ dependencies = [ "web-sys", ] +[[package]] +name = "box" +version = "0.1.0" +dependencies = [ + "console_error_panic_hook", + "macros", + "serde", + "serde-wasm-bindgen", + "utils", + "wasm-bindgen", + "wasm-bindgen-test", + "web-sys", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -329,11 +343,13 @@ name = "triangle" version = "0.1.0" dependencies = [ "console_error_panic_hook", + "macros", "serde", "serde-wasm-bindgen", "utils", "wasm-bindgen", "wasm-bindgen-test", + "web-sys", ] [[package]] diff --git a/app/src/lib/graph-interface/graph-manager.ts b/app/src/lib/graph-interface/graph-manager.ts index 5bfb41c..e098f92 100644 --- a/app/src/lib/graph-interface/graph-manager.ts +++ b/app/src/lib/graph-interface/graph-manager.ts @@ -8,6 +8,13 @@ import type { NodeInput } from "@nodes/types"; const logger = createLogger("graph-manager"); +function areSocketsCompatible(output: string | undefined, inputs: string | string[] | undefined) { + if (Array.isArray(inputs) && output) { + return inputs.includes(output); + } + return inputs === output; +} + export class GraphManager extends EventEmitter<{ "save": Graph, "result": any }> { status: Writable<"loading" | "idle" | "error"> = writable("loading"); @@ -177,7 +184,6 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any }> } } } - console.log(settings); this.history.reset(); this._init(this.graph); @@ -353,7 +359,7 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any }> const fromSocketType = from.tmp?.type?.outputs?.[fromSocket]; const toSocketType = to.tmp?.type?.inputs?.[toSocket]?.type; - if (fromSocketType !== toSocketType) { + if (!areSocketsCompatible(fromSocketType, toSocketType)) { logger.error(`Socket types do not match: ${fromSocketType} !== ${toSocketType}`); return; } @@ -441,8 +447,8 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any }> const nodeType = node?.tmp?.type; if (!nodeType) return []; - const sockets: [Node, string | number][] = [] + // if index is a string, we are an input looking for outputs if (typeof index === "string") { @@ -479,7 +485,7 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any }> const inputs = node?.tmp?.type?.inputs; if (!inputs) continue; for (const key in inputs) { - if (inputs[key].type === ownType && edges.get(node.id) !== key) { + if (areSocketsCompatible(ownType, inputs[key].type) && edges.get(node.id) !== key) { sockets.push([node, key]); } } diff --git a/app/src/lib/node-registry.ts b/app/src/lib/node-registry.ts index c979ff6..9d259a5 100644 --- a/app/src/lib/node-registry.ts +++ b/app/src/lib/node-registry.ts @@ -72,10 +72,13 @@ export class RemoteNodeRegistry implements NodeRegistry { nodeIds.push("max/plantarium/random"); nodeIds.push("max/plantarium/float"); + nodeIds.push("max/plantarium/triangle"); nodeIds.push("max/plantarium/output"); nodeIds.push("max/plantarium/array"); nodeIds.push("max/plantarium/sum"); nodeIds.push("max/plantarium/stem"); + nodeIds.push("max/plantarium/box"); + nodeIds.push("max/plantarium/math"); const nodes = await Promise.all(nodeIds.map(id => this.loadNode(id))); diff --git a/app/src/lib/viewer/Scene.svelte b/app/src/lib/viewer/Scene.svelte index 83950c6..ed66fc0 100644 --- a/app/src/lib/viewer/Scene.svelte +++ b/app/src/lib/viewer/Scene.svelte @@ -1,18 +1,38 @@ - + {#each geometry as geo} + {#each geo.attributes.position.array as attr, i} + {#if i % 3 === 0} + + {/if} + {/each} + + + + + diff --git a/app/src/lib/viewer/Viewer.svelte b/app/src/lib/viewer/Viewer.svelte index ddeda81..c950ed3 100644 --- a/app/src/lib/viewer/Viewer.svelte +++ b/app/src/lib/viewer/Viewer.svelte @@ -1,7 +1,11 @@