feat: add slider element

This commit is contained in:
max_richter 2024-04-18 11:06:45 +02:00
parent c3691e7169
commit 815152d23c
7 changed files with 27 additions and 12 deletions

View File

@ -111,8 +111,6 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
// here we store the intermediate results of the nodes
const results: Record<string, string | boolean | number> = {};
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);
}

View File

@ -18,7 +18,7 @@ pub fn execute(input: Vec<i32>) -> Vec<i32> {
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());

View File

@ -9,6 +9,7 @@
},
"thickness": {
"type": "float",
"element": "slider",
"value": 2
},
"resolution": {

View File

@ -12,7 +12,7 @@ pub fn execute(input: &[i32]) -> Vec<i32> {
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<i32> = vec![0; resolution * 4 + 1];
path.resize(resolution * 4 + 1, 0);

View File

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

View File

@ -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 @@
</script>
{#if input.type === "float"}
<Float {id} bind:value />
{#if input?.element === "slider"}
<Slider {id} bind:value />
{:else}
<Float {id} bind:value />
{/if}
{:else if input.type === "integer"}
<Integer {id} bind:value />
{:else if input.type === "boolean"}

View File

@ -0,0 +1,9 @@
<script lang="ts">
export let value: number = 0;
export let min = 0;
export let max = 10;
export let step = 0.1;
export let id: string;
</script>
<input type="range" {id} bind:value {min} {max} {step} />