feat: testing on how to flatten tree structures

This commit is contained in:
max_richter 2024-04-05 16:45:57 +02:00
parent 473f696626
commit 68d1bac572
23 changed files with 348 additions and 307 deletions

2
Cargo.lock generated
View File

@ -2683,6 +2683,8 @@ version = "0.1.0"
dependencies = [ dependencies = [
"console_error_panic_hook", "console_error_panic_hook",
"plantarium", "plantarium",
"serde",
"serde-wasm-bindgen",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-test", "wasm-bindgen-test",
] ]

View File

@ -24,7 +24,7 @@
"input-elements": "link:../packages/input-elements", "input-elements": "link:../packages/input-elements",
"jsondiffpatch": "^0.6.0", "jsondiffpatch": "^0.6.0",
"meshline": "^3.2.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": "^0.159.0",
"three.meshline": "^1.4.0" "three.meshline": "^1.4.0"
}, },

View File

@ -53,7 +53,7 @@
<div class="wrapper" data-node-id={node.id}> <div class="wrapper" data-node-id={node.id}>
<div class="content"> <div class="content">
{node.type} / {node.id} {node.type.split("/").pop()}
</div> </div>
<div <div
class="click-target" class="click-target"

View File

@ -5,17 +5,17 @@
export let node: Node; export let node: Node;
export let input: NodeInput; export let input: NodeInput;
export let id: string; export let label: string;
const graph = getGraphManager(); const graph = getGraphManager();
let value = node?.props?.[id] ?? input.value; let value = node?.props?.[label] ?? input.value;
$: if (node?.props?.[id] !== value) { $: if (node?.props?.[label] !== value) {
node.props = { ...node.props, [id]: value }; node.props = { ...node.props, [label]: value };
graph.execute(); graph.execute();
} }
</script> </script>
<label for="asd">{id}</label> <label for="asd">{label}</label>
<Input {input} bind:value /> <Input {input} bind:value />

View File

@ -69,7 +69,7 @@
> >
{#key id && graphId} {#key id && graphId}
<div class="content" class:disabled={$inputSockets.has(socketId)}> <div class="content" class:disabled={$inputSockets.has(socketId)}>
<NodeInput {node} {input} {id} /> <NodeInput {node} {input} label={input?.title || id} />
</div> </div>
{#if node?.tmp?.type?.inputs?.[id]?.internal !== true} {#if node?.tmp?.type?.inputs?.[id]?.internal !== true}

View File

@ -145,6 +145,8 @@ export class GraphManager extends EventEmitter<{ "save": Graph }> {
this.status.set("loading"); this.status.set("loading");
this.id.set(graph.id); this.id.set(graph.id);
this.nodeRegistry.load();
for (const node of this.graph.nodes) { for (const node of this.graph.nodes) {
const nodeType = this.nodeRegistry.getNode(node.type); const nodeType = this.nodeRegistry.getNode(node.type);
if (!nodeType) { if (!nodeType) {
@ -165,6 +167,7 @@ export class GraphManager extends EventEmitter<{ "save": Graph }> {
this.loaded = true; this.loaded = true;
logger.log(`Graph loaded in ${performance.now() - a}ms`); logger.log(`Graph loaded in ${performance.now() - a}ms`);
setTimeout(() => this.execute(), 100);
} }

View File

@ -20,8 +20,8 @@ export function grid(width: number, height: number) {
visible: false, visible: false,
}, },
position: [x * 30, y * 40], position: [x * 30, y * 40],
props: i == 0 ? { value: 0 } : {}, props: i == 0 ? { value: 0 } : { op_type: 1, a: 2, b: i },
type: i == 0 ? "input/float" : "math", type: i == 0 ? "max/plantarium/input-float" : "max/plantarium/math",
}); });
graph.edges.push([i, 0, i + 1, i === amount - 1 ? "input" : "a",]); graph.edges.push([i, 0, i + 1, i === amount - 1 ? "input" : "a",]);

View File

@ -10,7 +10,7 @@ export function tree(depth: number): Graph {
}, },
{ {
id: 1, id: 1,
type: "math", type: "max/plantarium/math",
position: [-40, -10] position: [-40, -10]
} }
] ]
@ -33,13 +33,13 @@ export function tree(depth: number): Graph {
nodes.push({ nodes.push({
id: id0, id: id0,
type: "math", type: "max/plantarium/math",
position: [x, y], position: [x, y],
}); });
edges.push([id0, 0, parent, "a"]); edges.push([id0, 0, parent, "a"]);
nodes.push({ nodes.push({
id: id1, id: id1,
type: "math", type: "max/plantarium/math",
position: [x, y + 35], position: [x, y + 35],
}); });
edges.push([id1, 0, parent, "b"]); edges.push([id1, 0, parent, "b"]);

View File

@ -1,22 +1,58 @@
import type { NodeRegistry, NodeType } from "@nodes/types"; 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[] = [ const nodeTypes: NodeType[] = [
{ {
id: "input/float", id: "max/plantarium/input-float",
inputs: { inputs: {
"value": { type: "float", value: 0.1, internal: true }, "value": { type: "float", value: 0.1, internal: true },
}, },
outputs: ["float"], outputs: ["float"],
execute: ({ value }) => { return value } execute: ({ value }) => { return [0, 1, 0, value] }
}, },
{ {
id: d.get_id(), id: "max/plantarium/math",
inputs: JSON.parse(d.get_input_types()), inputs: {
outputs: d.get_outputs(), "op_type": { title: "type", type: "select", labels: ["add", "subtract", "multiply", "divide"], value: 0 },
execute: ({ op_type, a, b }) => { "a": { type: "float" },
return d.execute(op_type, a, b); "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<string, NodeType> = 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 { 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); return nodeTypes.find((nodeType) => nodeType.id === id);
} }
getAllNodes(): NodeType[] { getAllNodes() {
return [...nodeTypes]; return [...nodeTypes];
} }
} }

View File

@ -1,5 +1,93 @@
import type { Graph, NodeRegistry, NodeType, RuntimeExecutor } from "@nodes/types"; 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 { export class MemoryRuntimeExecutor implements RuntimeExecutor {
constructor(private registry: NodeRegistry) { } constructor(private registry: NodeRegistry) { }
@ -130,7 +218,12 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
} }
// return the result of the parent of the output node // 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;
} }

View File

@ -24,19 +24,13 @@ pub fn get_input_types() -> String {
} }
#[wasm_bindgen] #[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();
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 // Interpolate strings into JSON format
let json_string = format!( let json_string = format!(
r#"{{"parameter": "random", "min": {}, "max": {}, "seed": {}}}"#, r#"{{"parameter": "math", "op_type": {}, "a": {}, "b": {}}}"#,
min_str, max_str, seed_str var_op_type, var_a, var_b
); );
json_string json_string

View File

@ -18,6 +18,8 @@ wasm-bindgen = "0.2.84"
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying. # code size when deploying.
plantarium = { version = "0.1.0", path = "../../../../packages/plantarium" } 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 } console_error_panic_hook = { version = "0.1.7", optional = true }
[dev-dependencies] [dev-dependencies]

View File

@ -1,6 +1,4 @@
mod utils; mod utils;
use plantarium::*;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
#[wasm_bindgen] #[wasm_bindgen]
@ -25,19 +23,14 @@ pub fn get_input_types() -> String {
} }
#[wasm_bindgen] #[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(); 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 // Interpolate strings into JSON format
let json_string = format!( let json_string = format!(
r#"{{"parameter": "random", "min": {}, "max": {}, "seed": {}}}"#, r#"{{"parameter": "random", "min": {}, "max": {}, "seed": {}}}"#,
min_str, max_str, seed_str var_min, var_max, var_seed
); );
json_string json_string
} }

View File

@ -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<WebAssembly.Instance> {
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 }
}

View File

@ -2,13 +2,18 @@ import { json } from "@sveltejs/kit";
import type { RequestHandler } from "./$types"; import type { RequestHandler } from "./$types";
export const GET: RequestHandler = async function GET({ fetch, params }) { export const GET: RequestHandler = async function GET({ fetch, params }) {
const d = await fetch(`/${params.user}/${params.collection}/${params.node}/wasm`); const wasmResponse = await fetch(`/${params.user}/${params.collection}/${params.node}/wasm`);
const wrapWasm = await import("./wrap-wasm");
const module = new WebAssembly.Module(await d.arrayBuffer()); let wrapperCode = await (await fetch(`/${params.user}/${params.collection}/${params.node}/wrapper`)).text();
const instance = new WebAssembly.Instance(module, { ["./index_bg.js"]: wrapWasm }); wrapperCode = wrapperCode.replace("wasm = val;", `if(wasm) return;
wrapWasm.__wbg_set_wasm(instance.exports); wasm = val;`);
const id = wrapWasm.get_id(); const wasmWrapper = await import(`data:text/javascript;base64,${btoa(wrapperCode)}`);
const outputs = wrapWasm.get_outputs();
const inputTypes = JSON.parse(wrapWasm.get_input_types()); 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, }); return json({ id, outputs, inputs: inputTypes, });
} }

View File

@ -0,0 +1,27 @@
<script lang="ts">
import type { PageData } from './$types';
import { getNode, getNodeWasm } from '$lib/registry';
import { onMount } from 'svelte';
export let data: PageData;
const nodeId = `${data.params.user}/${data.params.collection}/${data.params.node}` as const;
let node;
let wasm;
onMount(async () => {
wasm = await getNodeWasm(nodeId);
window['wasm'] = wasm;
node = await getNode(nodeId);
});
</script>
<h1>{data.params.user}/{data.params.collection}/{data.params.node}</h1>
<h3>Node Definition</h3>
{#if !node}
<p>Loading Node</p>
{:else}
<pre>{JSON.stringify(node, null, 2)}</pre>
{/if}

View File

@ -0,0 +1,7 @@
import type { PageLoad } from "./$types";
export const load: PageLoad = ({ params }) => {
return {
params
}
};

View File

@ -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);
};

View File

@ -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" } });
}

View File

@ -45,7 +45,24 @@ export type Socket = {
export interface NodeRegistry { 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<void>;
/**
* 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; getNode: (id: string) => NodeType | undefined;
/**
* Get all nodes
* @returns An array of all nodes
*/
getAllNodes: () => NodeType[]; getAllNodes: () => NodeType[];
} }

View File

@ -26,6 +26,7 @@ type NodeInputSelect = {
type DefaultOptions = { type DefaultOptions = {
internal?: boolean; internal?: boolean;
title?: string;
} }
export type NodeInput = (NodeInputBoolean | NodeInputFloat | NodeInputInteger | NodeInputSelect) & DefaultOptions; export type NodeInput = (NodeInputBoolean | NodeInputFloat | NodeInputInteger | NodeInputSelect) & DefaultOptions;

View File

@ -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;

View File

@ -6,6 +6,8 @@ settings:
importers: importers:
.: {}
app: app:
dependencies: dependencies:
'@nodes/input-elements': '@nodes/input-elements':
@ -42,8 +44,8 @@ importers:
specifier: ^3.2.0 specifier: ^3.2.0
version: 3.2.0(three@0.159.0) version: 3.2.0(three@0.159.0)
plantarium-nodes-math: plantarium-nodes-math:
specifier: link:../nodes/math/pkg specifier: link:../nodes/max/plantarium/math/pkg
version: link:../nodes/math/pkg version: link:../nodes/max/plantarium/math/pkg
three: three:
specifier: ^0.159.0 specifier: ^0.159.0
version: 0.159.0 version: 0.159.0
@ -100,6 +102,16 @@ importers:
specifier: ^3.3.0 specifier: ^3.3.0
version: 3.3.0(vite@5.1.4) 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: packages/input-elements:
dependencies: dependencies:
'@nodes/types': '@nodes/types':