diff --git a/Cargo.lock b/Cargo.lock index d1fad7e..ba0a0bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2683,6 +2683,8 @@ version = "0.1.0" dependencies = [ "console_error_panic_hook", "plantarium", + "serde", + "serde-wasm-bindgen", "wasm-bindgen", "wasm-bindgen-test", ] diff --git a/app/package.json b/app/package.json index ea8c821..32ffc4f 100644 --- a/app/package.json +++ b/app/package.json @@ -24,7 +24,7 @@ "input-elements": "link:../packages/input-elements", "jsondiffpatch": "^0.6.0", "meshline": "^3.2.0", - "plantarium-nodes-math": "link:../nodes/math/pkg", + "plantarium-nodes-math": "link:../nodes/max/plantarium/math/pkg", "three": "^0.159.0", "three.meshline": "^1.4.0" }, diff --git a/app/src/lib/components/node/NodeHeader.svelte b/app/src/lib/components/node/NodeHeader.svelte index 69726de..b32d1f5 100644 --- a/app/src/lib/components/node/NodeHeader.svelte +++ b/app/src/lib/components/node/NodeHeader.svelte @@ -53,7 +53,7 @@
- {node.type} / {node.id} + {node.type.split("/").pop()}
- + diff --git a/app/src/lib/components/node/NodeParameter.svelte b/app/src/lib/components/node/NodeParameter.svelte index 170e2f4..6580130 100644 --- a/app/src/lib/components/node/NodeParameter.svelte +++ b/app/src/lib/components/node/NodeParameter.svelte @@ -69,7 +69,7 @@ > {#key id && graphId}
- +
{#if node?.tmp?.type?.inputs?.[id]?.internal !== true} diff --git a/app/src/lib/graph-manager.ts b/app/src/lib/graph-manager.ts index fe584dc..ae53d4a 100644 --- a/app/src/lib/graph-manager.ts +++ b/app/src/lib/graph-manager.ts @@ -1,5 +1,5 @@ import { writable, type Writable } from "svelte/store"; -import type { Graph, Node, Edge, Socket, NodeRegistry, RuntimeExecutor, } from "@nodes/s"; +import type { Graph, Node, Edge, Socket, NodeRegistry, RuntimeExecutor, } from "@nodes/s"; import { HistoryManager } from "./history-manager"; import * as templates from "./graphs"; import EventEmitter from "./helpers/EventEmitter"; @@ -145,6 +145,8 @@ export class GraphManager extends EventEmitter<{ "save": Graph }> { this.status.set("loading"); this.id.set(graph.id); + this.nodeRegistry.load(); + for (const node of this.graph.nodes) { const nodeType = this.nodeRegistry.getNode(node.type); if (!nodeType) { @@ -165,6 +167,7 @@ export class GraphManager extends EventEmitter<{ "save": Graph }> { this.loaded = true; logger.log(`Graph loaded in ${performance.now() - a}ms`); + setTimeout(() => this.execute(), 100); } diff --git a/app/src/lib/graphs/grid.ts b/app/src/lib/graphs/grid.ts index d74c5d9..8e2f4b6 100644 --- a/app/src/lib/graphs/grid.ts +++ b/app/src/lib/graphs/grid.ts @@ -20,8 +20,8 @@ export function grid(width: number, height: number) { visible: false, }, position: [x * 30, y * 40], - props: i == 0 ? { value: 0 } : {}, - type: i == 0 ? "input/float" : "math", + props: i == 0 ? { value: 0 } : { op_type: 1, a: 2, b: i }, + type: i == 0 ? "max/plantarium/input-float" : "max/plantarium/math", }); graph.edges.push([i, 0, i + 1, i === amount - 1 ? "input" : "a",]); diff --git a/app/src/lib/graphs/tree.ts b/app/src/lib/graphs/tree.ts index 533f207..31efae8 100644 --- a/app/src/lib/graphs/tree.ts +++ b/app/src/lib/graphs/tree.ts @@ -10,7 +10,7 @@ export function tree(depth: number): Graph { }, { id: 1, - type: "math", + type: "max/plantarium/math", position: [-40, -10] } ] @@ -33,13 +33,13 @@ export function tree(depth: number): Graph { nodes.push({ id: id0, - type: "math", + type: "max/plantarium/math", position: [x, y], }); edges.push([id0, 0, parent, "a"]); nodes.push({ id: id1, - type: "math", + type: "max/plantarium/math", position: [x, y + 35], }); edges.push([id1, 0, parent, "b"]); diff --git a/app/src/lib/node-registry.ts b/app/src/lib/node-registry.ts index 0054657..0b9f4be 100644 --- a/app/src/lib/node-registry.ts +++ b/app/src/lib/node-registry.ts @@ -1,22 +1,58 @@ import type { NodeRegistry, NodeType } from "@nodes/types"; -import * as d from "plantarium-nodes-math"; +function binaryArrayToNumber(binaryArray: number[]): number { + let result = 0; + for (let i = 0; i < binaryArray.length; i++) { + result = (result << 1) + binaryArray[i]; + } + return result; +} const nodeTypes: NodeType[] = [ { - id: "input/float", + id: "max/plantarium/input-float", inputs: { "value": { type: "float", value: 0.1, internal: true }, }, outputs: ["float"], - execute: ({ value }) => { return value } + execute: ({ value }) => { return [0, 1, 0, value] } }, { - id: d.get_id(), - inputs: JSON.parse(d.get_input_types()), - outputs: d.get_outputs(), - execute: ({ op_type, a, b }) => { - return d.execute(op_type, a, b); + id: "max/plantarium/math", + inputs: { + "op_type": { title: "type", type: "select", labels: ["add", "subtract", "multiply", "divide"], value: 0 }, + "a": { type: "float" }, + "b": { type: "float" }, + }, + outputs: ["float"], + execute: ({ op_type, a, b }: { op_type: number, a: number, b: number }) => { + + const res = [1, 3, -1, op_type, 0, 0]; + + const bitmask = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + + console.log({ a, b }); + + if (Array.isArray(a)) { + res[4] = res.length; + res.push(...a); + bitmask[1] = 1; + console.log("A", res.length, a.length); + } else { + res[4] = a; + } + + if (Array.isArray(b)) { + res[5] = res.length; + res.push(...b); + bitmask[2] = 1; + } else { + res[5] = b; + } + + res[2] = binaryArrayToNumber(bitmask); + + return res } }, { @@ -28,11 +64,41 @@ const nodeTypes: NodeType[] = [ } ] +export class RemoteNodeRegistry implements NodeRegistry { + + private nodes: Map = new Map(); + + constructor(private url: string) { } + + async load(nodeIds: string[]) { + for (const id of nodeIds) { + const response = await fetch(`${this.url}/nodes/${id}`); + const node = this.getNode(id); + if (node) { + this.nodes.set(id, node); + } + } + } + + getNode(id: string) { + return this.nodes.get(id); + } + + getAllNodes() { + return [...this.nodes.values()]; + } +} + export class MemoryNodeRegistry implements NodeRegistry { - getNode(id: string): NodeType | undefined { + + async load(nodeIds: string[]) { + // Do nothing + } + + getNode(id: string) { return nodeTypes.find((nodeType) => nodeType.id === id); } - getAllNodes(): NodeType[] { + getAllNodes() { return [...nodeTypes]; } } diff --git a/app/src/lib/runtime-executor.ts b/app/src/lib/runtime-executor.ts index 4d431ea..1aad0f4 100644 --- a/app/src/lib/runtime-executor.ts +++ b/app/src/lib/runtime-executor.ts @@ -1,5 +1,93 @@ import type { Graph, NodeRegistry, NodeType, RuntimeExecutor } from "@nodes/types"; + +function numberToBinaryArray(number: number): number[] { + const binaryArray: number[] = []; + for (let i = 31; i >= 0; i--) { + const bit = (number >> i) & 1; + binaryArray.push(bit); + } + return binaryArray; +} + +function evaluate_node([node_type, ...args]: number[]) { + + // Float node + if (node_type === 0) { + return args[0]; + } + + console.log(args); + + // Math node + if (node_type === 1) { + if (args[0] === 0) { + return args[1] + args[2]; + } else if (args[0] === 1) { + return args[1] - args[2]; + } else if (args[0] === 2) { + return args[1] * args[1]; + } else { + return args[1] / args[2]; + } + } +} + + +function read_node(index: number, params: number[], depth = 0) { + if (depth > 20) { + throw new Error("Max depth reached"); + } + + const node_type = params[index]; + const amount_of_args = params[index + 1]; + const bitmask = params[index + 2]; + console.log("READ_NODE", index, { node_type, bitmask, amount_of_args }); + + const mask = numberToBinaryArray(bitmask); + + // there are not nodes connected to this node, lets evaluate + if (bitmask === 0) { + console.log("EVALUATE", index, params); + } + + const args = []; + + for (let i = 0; i < amount_of_args; i++) { + const isNode = mask[i] === 1; + if (isNode) { + console.log("NODE", index + 3 + i, params.slice(index + 3 + i, index + 3 + i + 5)); + args[i] = read_node(params[index + 3 + i], params, depth + 1); + } else { + args[i] = params[index + 3 + i]; + } + } + + console.log({ node_type, amount_of_args, args, bitmask }); + return evaluate_node([node_type, ...args]); + +} + +function split_params(params: number[]) { + const result = []; + let index = 0; + while (index < params.length) { + const amount_of_args = params[index + 1]; + const node_size = 3 + amount_of_args; + result.push(params.slice(index, index + node_size)); + index += node_size; + } + return result; +} + +function evaluate(params: number[]) { + console.log("PARAMS", split_params(params)); + const node = read_node(0, params); + + console.log("RESULT: ", node); + +} + export class MemoryRuntimeExecutor implements RuntimeExecutor { constructor(private registry: NodeRegistry) { } @@ -130,7 +218,12 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { } // return the result of the parent of the output node - return results[outputNode.tmp?.parents?.[0].id as number] as string + const res = results[outputNode.tmp?.parents?.[0].id as number] as string + + evaluate(res); + + + return res; } diff --git a/nodes/max/plantarium/math/src/lib.rs b/nodes/max/plantarium/math/src/lib.rs index bf4a5f6..12e5f89 100644 --- a/nodes/max/plantarium/math/src/lib.rs +++ b/nodes/max/plantarium/math/src/lib.rs @@ -24,19 +24,13 @@ pub fn get_input_types() -> String { } #[wasm_bindgen] -pub fn execute(var_op_type: JsValue, var_a: JsValue, var_b: JsValue) -> String { +pub fn execute(var_op_type: u8, var_a: String, var_b: String) -> String { utils::set_panic_hook(); - utils::set_panic_hook(); - // Convert JsValues to strings - let min_str = unwrap_string(var_min); - let max_str = unwrap_string(var_max); - let seed_str = unwrap_string(var_seed); - // Interpolate strings into JSON format let json_string = format!( - r#"{{"parameter": "random", "min": {}, "max": {}, "seed": {}}}"#, - min_str, max_str, seed_str + r#"{{"parameter": "math", "op_type": {}, "a": {}, "b": {}}}"#, + var_op_type, var_a, var_b ); json_string diff --git a/nodes/max/plantarium/random/Cargo.toml b/nodes/max/plantarium/random/Cargo.toml index 0f01b1e..8eac533 100644 --- a/nodes/max/plantarium/random/Cargo.toml +++ b/nodes/max/plantarium/random/Cargo.toml @@ -18,6 +18,8 @@ wasm-bindgen = "0.2.84" # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for # code size when deploying. plantarium = { version = "0.1.0", path = "../../../../packages/plantarium" } +serde = { version = "1.0", features = ["derive"] } +serde-wasm-bindgen = "0.4" console_error_panic_hook = { version = "0.1.7", optional = true } [dev-dependencies] diff --git a/nodes/max/plantarium/random/src/lib.rs b/nodes/max/plantarium/random/src/lib.rs index acad4e2..06889ae 100644 --- a/nodes/max/plantarium/random/src/lib.rs +++ b/nodes/max/plantarium/random/src/lib.rs @@ -1,6 +1,4 @@ mod utils; - -use plantarium::*; use wasm_bindgen::prelude::*; #[wasm_bindgen] @@ -25,19 +23,14 @@ pub fn get_input_types() -> String { } #[wasm_bindgen] -pub fn execute(var_min: JsValue, var_max: JsValue, var_seed: JsValue) -> String { +pub fn execute(var_min: String, var_max: String, var_seed: i32) -> String { utils::set_panic_hook(); - // Convert JsValues to strings - let min_str = unwrap_string(var_min); - let max_str = unwrap_string(var_max); - let seed_str = unwrap_string(var_seed); // Interpolate strings into JSON format let json_string = format!( r#"{{"parameter": "random", "min": {}, "max": {}, "seed": {}}}"#, - min_str, max_str, seed_str + var_min, var_max, var_seed ); json_string } - diff --git a/packages/node-registry/src/lib/registry.ts b/packages/node-registry/src/lib/registry.ts new file mode 100644 index 0000000..d216872 --- /dev/null +++ b/packages/node-registry/src/lib/registry.ts @@ -0,0 +1,35 @@ +export async function getNodeWrapper(id: `${string}/${string}/${string}`) { + + let wrapperCode = await (await fetch(`/${id}/wrapper`)).text(); + wrapperCode = wrapperCode.replace("wasm = val;", `if(wasm) return; +wasm = val;`); + const wasmWrapper = await import(/*vite-ignore*/`data:text/javascript;base64,${btoa(wrapperCode)}`); + + return wasmWrapper; +} + +export async function getNodeWasm(id: `${string}/${string}/${string}`): Promise { + + const wasmResponse = await fetch(`/${id}/wasm`); + + const wasmWrapper = await getNodeWrapper(id); + + const module = new WebAssembly.Module(await wasmResponse.arrayBuffer()); + const instance = new WebAssembly.Instance(module, { ["./index_bg.js"]: wasmWrapper }); + wasmWrapper.__wbg_set_wasm(instance.exports); + + return wasmWrapper; +} + + +export async function getNode(id: `${string}/${string}/${string}`) { + + const wrapper = await getNodeWasm(id); + + const node_id = wrapper.get_id(); + const outputs = wrapper.get_outputs(); + const inputTypes = JSON.parse(wrapper.get_input_types()); + + return { id: node_id, outputs, inputs: inputTypes } + +} diff --git a/packages/node-registry/src/routes/[user]/[collection]/[node]/+server.ts b/packages/node-registry/src/routes/[user]/[collection]/[node]/+server.ts index c45865e..030c369 100644 --- a/packages/node-registry/src/routes/[user]/[collection]/[node]/+server.ts +++ b/packages/node-registry/src/routes/[user]/[collection]/[node]/+server.ts @@ -2,13 +2,18 @@ import { json } from "@sveltejs/kit"; import type { RequestHandler } from "./$types"; export const GET: RequestHandler = async function GET({ fetch, params }) { - const d = await fetch(`/${params.user}/${params.collection}/${params.node}/wasm`); - const wrapWasm = await import("./wrap-wasm"); - const module = new WebAssembly.Module(await d.arrayBuffer()); - const instance = new WebAssembly.Instance(module, { ["./index_bg.js"]: wrapWasm }); - wrapWasm.__wbg_set_wasm(instance.exports); - const id = wrapWasm.get_id(); - const outputs = wrapWasm.get_outputs(); - const inputTypes = JSON.parse(wrapWasm.get_input_types()); + const wasmResponse = await fetch(`/${params.user}/${params.collection}/${params.node}/wasm`); + + let wrapperCode = await (await fetch(`/${params.user}/${params.collection}/${params.node}/wrapper`)).text(); + wrapperCode = wrapperCode.replace("wasm = val;", `if(wasm) return; +wasm = val;`); + const wasmWrapper = await import(`data:text/javascript;base64,${btoa(wrapperCode)}`); + + const module = new WebAssembly.Module(await wasmResponse.arrayBuffer()); + const instance = new WebAssembly.Instance(module, { ["./index_bg.js"]: wasmWrapper }); + wasmWrapper.__wbg_set_wasm(instance.exports); + const id = wasmWrapper.get_id(); + const outputs = wasmWrapper.get_outputs(); + const inputTypes = JSON.parse(wasmWrapper.get_input_types()); return json({ id, outputs, inputs: inputTypes, }); } diff --git a/packages/node-registry/src/routes/[user]/[collection]/[node]/test/+page.svelte b/packages/node-registry/src/routes/[user]/[collection]/[node]/test/+page.svelte new file mode 100644 index 0000000..f4741ad --- /dev/null +++ b/packages/node-registry/src/routes/[user]/[collection]/[node]/test/+page.svelte @@ -0,0 +1,27 @@ + + +

{data.params.user}/{data.params.collection}/{data.params.node}

+ +

Node Definition

+{#if !node} +

Loading Node

+{:else} +
{JSON.stringify(node, null, 2)}
+{/if} diff --git a/packages/node-registry/src/routes/[user]/[collection]/[node]/test/+page.ts b/packages/node-registry/src/routes/[user]/[collection]/[node]/test/+page.ts new file mode 100644 index 0000000..3146b1d --- /dev/null +++ b/packages/node-registry/src/routes/[user]/[collection]/[node]/test/+page.ts @@ -0,0 +1,7 @@ +import type { PageLoad } from "./$types"; + +export const load: PageLoad = ({ params }) => { + return { + params + } +}; diff --git a/packages/node-registry/src/routes/[user]/[collection]/[node]/wrap-wasm.ts b/packages/node-registry/src/routes/[user]/[collection]/[node]/wrap-wasm.ts deleted file mode 100644 index 1c68fda..0000000 --- a/packages/node-registry/src/routes/[user]/[collection]/[node]/wrap-wasm.ts +++ /dev/null @@ -1,254 +0,0 @@ -let wasm; -export function __wbg_set_wasm(val) { - wasm = val; -} - - -const heap = new Array(128).fill(undefined); - -heap.push(undefined, null, true, false); - -function getObject(idx) { return heap[idx]; } - -let heap_next = heap.length; - -function dropObject(idx) { - if (idx < 132) return; - heap[idx] = heap_next; - heap_next = idx; -} - -function takeObject(idx) { - const ret = getObject(idx); - dropObject(idx); - return ret; -} - -let WASM_VECTOR_LEN = 0; - -let cachedUint8Memory0 = null; - -function getUint8Memory0() { - if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { - cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); - } - return cachedUint8Memory0; -} - -const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder; - -let cachedTextEncoder = new lTextEncoder('utf-8'); - -const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' - ? function (arg, view) { - return cachedTextEncoder.encodeInto(arg, view); - } - : function (arg, view) { - const buf = cachedTextEncoder.encode(arg); - view.set(buf); - return { - read: arg.length, - written: buf.length - }; - }); - -function passStringToWasm0(arg, malloc, realloc) { - - if (realloc === undefined) { - const buf = cachedTextEncoder.encode(arg); - const ptr = malloc(buf.length, 1) >>> 0; - getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); - WASM_VECTOR_LEN = buf.length; - return ptr; - } - - let len = arg.length; - let ptr = malloc(len, 1) >>> 0; - - const mem = getUint8Memory0(); - - let offset = 0; - - for (; offset < len; offset++) { - const code = arg.charCodeAt(offset); - if (code > 0x7F) break; - mem[ptr + offset] = code; - } - - if (offset !== len) { - if (offset !== 0) { - arg = arg.slice(offset); - } - ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; - const view = getUint8Memory0().subarray(ptr + offset, ptr + len); - const ret = encodeString(arg, view); - - offset += ret.written; - ptr = realloc(ptr, len, offset, 1) >>> 0; - } - - WASM_VECTOR_LEN = offset; - return ptr; -} - -function isLikeNone(x) { - return x === undefined || x === null; -} - -let cachedInt32Memory0 = null; - -function getInt32Memory0() { - if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { - cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); - } - return cachedInt32Memory0; -} - -const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; - -let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); - -cachedTextDecoder.decode(); - -function getStringFromWasm0(ptr, len) { - ptr = ptr >>> 0; - return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); -} - -function addHeapObject(obj) { - if (heap_next === heap.length) heap.push(heap.length + 1); - const idx = heap_next; - heap_next = heap[idx]; - - heap[idx] = obj; - return idx; -} - -let cachedUint32Memory0 = null; - -function getUint32Memory0() { - if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) { - cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer); - } - return cachedUint32Memory0; -} - -function getArrayJsValueFromWasm0(ptr, len) { - ptr = ptr >>> 0; - const mem = getUint32Memory0(); - const slice = mem.subarray(ptr / 4, ptr / 4 + len); - const result = []; - for (let i = 0; i < slice.length; i++) { - result.push(takeObject(slice[i])); - } - return result; -} -/** -* @returns {(string)[]} -*/ -export function get_outputs() { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.get_outputs(retptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var v1 = getArrayJsValueFromWasm0(r0, r1).slice(); - wasm.__wbindgen_free(r0, r1 * 4, 4); - return v1; - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -} - -/** -* @returns {string} -*/ -export function get_id() { - let deferred1_0; - let deferred1_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.get_id(retptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred1_0 = r0; - deferred1_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); - } -} - -/** -* @returns {string} -*/ -export function get_input_types() { - let deferred1_0; - let deferred1_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.get_input_types(retptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred1_0 = r0; - deferred1_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); - } -} - -/** -* @param {any} var_min -* @param {any} var_max -* @param {any} var_seed -* @returns {string} -*/ -export function execute(var_min, var_max, var_seed) { - let deferred1_0; - let deferred1_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.execute(retptr, addHeapObject(var_min), addHeapObject(var_max), addHeapObject(var_seed)); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred1_0 = r0; - deferred1_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); - } -} - -export function __wbindgen_is_undefined(arg0) { - const ret = getObject(arg0) === undefined; - return ret; -}; - -export function __wbindgen_is_null(arg0) { - const ret = getObject(arg0) === null; - return ret; -}; - -export function __wbindgen_object_drop_ref(arg0) { - takeObject(arg0); -}; - -export function __wbindgen_string_get(arg0, arg1) { - const obj = getObject(arg1); - const ret = typeof (obj) === 'string' ? obj : undefined; - var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; -}; - -export function __wbindgen_string_new(arg0, arg1) { - const ret = getStringFromWasm0(arg0, arg1); - return addHeapObject(ret); -}; - - diff --git a/packages/node-registry/src/routes/[user]/[collection]/[node]/wrapper/+server.ts b/packages/node-registry/src/routes/[user]/[collection]/[node]/wrapper/+server.ts new file mode 100644 index 0000000..1dd106f --- /dev/null +++ b/packages/node-registry/src/routes/[user]/[collection]/[node]/wrapper/+server.ts @@ -0,0 +1,12 @@ +import type { RequestHandler } from "./$types"; +import fs from "fs/promises"; +import path from "path"; + +export const GET: RequestHandler = async function GET({ params }) { + + const filePath = path.resolve(`../../nodes/${params.user}/${params.collection}/${params.node}/pkg/index_bg.js`); + + const file = await fs.readFile(filePath); + + return new Response(file, { status: 200, headers: { "Content-Type": "text/javascript" } }); +} diff --git a/packages/types/index.ts b/packages/types/index.ts index 3233762..230f4a7 100644 --- a/packages/types/index.ts +++ b/packages/types/index.ts @@ -45,7 +45,24 @@ export type Socket = { export interface NodeRegistry { + /** + * Load the nodes with the given ids + * @param nodeIds - The ids of the nodes to load + * @returns A promise that resolves when the nodes are loaded + * @throws An error if the nodes could not be loaded + * @remarks This method should be called before calling getNode or getAllNodes + */ + load: (nodeIds: string[]) => Promise; + /** + * Get a node by id + * @param id - The id of the node to get + * @returns The node with the given id, or undefined if no such node exists + */ getNode: (id: string) => NodeType | undefined; + /** + * Get all nodes + * @returns An array of all nodes + */ getAllNodes: () => NodeType[]; } diff --git a/packages/types/inputs.ts b/packages/types/inputs.ts index 1cad437..9e6ace7 100644 --- a/packages/types/inputs.ts +++ b/packages/types/inputs.ts @@ -26,6 +26,7 @@ type NodeInputSelect = { type DefaultOptions = { internal?: boolean; + title?: string; } export type NodeInput = (NodeInputBoolean | NodeInputFloat | NodeInputInteger | NodeInputSelect) & DefaultOptions; diff --git a/packages/types/parameters.ts b/packages/types/parameters.ts new file mode 100644 index 0000000..b0cb153 --- /dev/null +++ b/packages/types/parameters.ts @@ -0,0 +1,26 @@ +type RandomParameter = { + type: "random"; + min: Parameter; + max: Parameter; + seed: number; +} + + +type MathParameter = { + type: "math"; + op_type: number; + a: Parameter; + b: Parameter; +} + + +type NoiseParameter = { + type: "noise"; + frequency: Parameter; + amplitude: Parameter; + seed: number; +} + + +type Parameter = number | RandomParameter | MathParameter | NoiseParameter; + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2e55bee..7a2fd8d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,8 @@ settings: importers: + .: {} + app: dependencies: '@nodes/input-elements': @@ -42,8 +44,8 @@ importers: specifier: ^3.2.0 version: 3.2.0(three@0.159.0) plantarium-nodes-math: - specifier: link:../nodes/math/pkg - version: link:../nodes/math/pkg + specifier: link:../nodes/max/plantarium/math/pkg + version: link:../nodes/max/plantarium/math/pkg three: specifier: ^0.159.0 version: 0.159.0 @@ -100,6 +102,16 @@ importers: specifier: ^3.3.0 version: 3.3.0(vite@5.1.4) + nodes/max/plantarium/math: {} + + nodes/max/plantarium/math/pkg: {} + + nodes/max/plantarium/random: {} + + nodes/max/plantarium/random/old-pkg: {} + + nodes/max/plantarium/random/pkg: {} + packages/input-elements: dependencies: '@nodes/types':