From 815152d23c6f9eda33a09dc09f7e780eb0230a8e Mon Sep 17 00:00:00 2001 From: Max Richter Date: Thu, 18 Apr 2024 11:06:45 +0200 Subject: [PATCH] feat: add slider element --- app/src/lib/runtime-executor.ts | 16 +++++++--------- nodes/max/plantarium/output/src/lib.rs | 2 +- nodes/max/plantarium/stem/src/input.json | 1 + nodes/max/plantarium/stem/src/lib.rs | 2 +- packages/types/inputs.ts | 2 ++ packages/ui/src/lib/Input.svelte | 7 ++++++- packages/ui/src/lib/elements/Slider.svelte | 9 +++++++++ 7 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 packages/ui/src/lib/elements/Slider.svelte diff --git a/app/src/lib/runtime-executor.ts b/app/src/lib/runtime-executor.ts index 4c4ed0d..8d2dbc1 100644 --- a/app/src/lib/runtime-executor.ts +++ b/app/src/lib/runtime-executor.ts @@ -111,8 +111,6 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { // here we store the intermediate results of the nodes const results: Record = {}; - console.log(this.cache); - for (const node of sortedNodes) { const node_type = this.typeMap.get(node.type)!; @@ -142,8 +140,8 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { } - console.log(" "); - console.log("--> EXECUTING NODE " + node_type.id, node.id); + // console.log(" "); + // console.log("--> EXECUTING NODE " + node_type.id, node.id); // execute the node and store the result @@ -156,7 +154,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { }))}`; const a1 = performance.now(); - console.log(`${a1 - a0}ms hashed inputs: ${node.id} -> ${cacheKey}`); + // console.log(`${a1 - a0}ms hashed inputs: ${node.id} -> ${cacheKey}`); if (false && this.cache[cacheKey] && this.cache[cacheKey].eol > Date.now()) { results[node.id] = this.cache[cacheKey].value; @@ -183,7 +181,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { const a2 = performance.now(); - console.log(`${a2 - a1}ms TRANSFORMED_INPUTS`); + // console.log(`${a2 - a1}ms TRANSFORMED_INPUTS`); const _inputs = concat_encoded(transformed_inputs); const a3 = performance.now(); @@ -191,11 +189,11 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { const duration = performance.now() - a3; if (duration > 5) { this.cache[cacheKey] = { eol: Date.now() + 10_000, value: results[node.id] }; - console.log(`Caching for 10 seconds`); + // console.log(`Caching for 10 seconds`); } - console.log(`${duration}ms Executed`); + // console.log(`${duration}ms Executed`); const a4 = performance.now(); - console.log(`${a4 - a0}ms e2e duration`); + // console.log(`${a4 - a0}ms e2e duration`); } catch (e) { console.error(`Error executing node ${node_type.id || node.id}`, e); } diff --git a/nodes/max/plantarium/output/src/lib.rs b/nodes/max/plantarium/output/src/lib.rs index 87c1ff8..7278977 100644 --- a/nodes/max/plantarium/output/src/lib.rs +++ b/nodes/max/plantarium/output/src/lib.rs @@ -18,7 +18,7 @@ pub fn execute(input: Vec) -> Vec { if arg[2] == 0 { let _arg = &arg[3..]; - let geometry = extrude_path(_arg, 8); + let geometry = extrude_path(_arg, 16); output.push(geometry); }else if arg[2] == 1 { output.push(arg.to_vec()); diff --git a/nodes/max/plantarium/stem/src/input.json b/nodes/max/plantarium/stem/src/input.json index 48227e5..5d6a7d1 100644 --- a/nodes/max/plantarium/stem/src/input.json +++ b/nodes/max/plantarium/stem/src/input.json @@ -9,6 +9,7 @@ }, "thickness": { "type": "float", + "element": "slider", "value": 2 }, "resolution": { diff --git a/nodes/max/plantarium/stem/src/lib.rs b/nodes/max/plantarium/stem/src/lib.rs index 9448582..ff37ad0 100644 --- a/nodes/max/plantarium/stem/src/lib.rs +++ b/nodes/max/plantarium/stem/src/lib.rs @@ -12,7 +12,7 @@ pub fn execute(input: &[i32]) -> Vec { let length = decode_float(evaluate_args(args[0])[0]); let thickness = decode_float(evaluate_args(args[1])[0]); - let resolution = 64; //evaluate_args(args[2]); + let resolution = 512; //evaluate_args(args[2]); let mut path: Vec = vec![0; resolution * 4 + 1]; path.resize(resolution * 4 + 1, 0); diff --git a/packages/types/inputs.ts b/packages/types/inputs.ts index 9fcb168..01c3cc3 100644 --- a/packages/types/inputs.ts +++ b/packages/types/inputs.ts @@ -1,5 +1,6 @@ type NodeInputFloat = { type: "float"; + element?: "slider"; value?: number; min?: number; max?: number; @@ -8,6 +9,7 @@ type NodeInputFloat = { type NodeInputInteger = { type: "integer"; + element?: "slider"; value?: number; min?: number; max?: number; diff --git a/packages/ui/src/lib/Input.svelte b/packages/ui/src/lib/Input.svelte index 27788c2..d0f1994 100644 --- a/packages/ui/src/lib/Input.svelte +++ b/packages/ui/src/lib/Input.svelte @@ -5,6 +5,7 @@ import Select from "$lib/elements/Select.svelte"; import type { NodeInput } from "@nodes/types"; + import Slider from "./elements/Slider.svelte"; export let input: NodeInput; export let value: any; @@ -12,7 +13,11 @@ {#if input.type === "float"} - + {#if input?.element === "slider"} + + {:else} + + {/if} {:else if input.type === "integer"} {:else if input.type === "boolean"} diff --git a/packages/ui/src/lib/elements/Slider.svelte b/packages/ui/src/lib/elements/Slider.svelte new file mode 100644 index 0000000..a17ee8c --- /dev/null +++ b/packages/ui/src/lib/elements/Slider.svelte @@ -0,0 +1,9 @@ + + +