From d9afec5bf6eaa2dad9a61901a8f90af529c64376 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Wed, 1 May 2024 23:05:04 +0200 Subject: [PATCH] feat: add benchmark settings panel --- app/package.json | 2 + .../lib/graph-interface/graph/Graph.svelte | 59 +++- app/src/lib/graph-templates/grid.ts | 2 +- app/src/lib/graph-templates/index.ts | 4 + app/src/lib/graph-templates/lotta-faces.json | 1 + .../lotta-nodes-and-faces.json | 1 + app/src/lib/graph-templates/lotta-nodes.json | 1 + app/src/lib/helpers/createKeyMap.ts | 5 + app/src/lib/performance/BarSplit.svelte | 48 +++ .../lib/performance/PerformanceViewer.svelte | 261 +++++++++------- app/src/lib/performance/store.ts | 37 ++- app/src/lib/result-viewer/Scene.svelte | 31 +- app/src/lib/result-viewer/Viewer.svelte | 195 ++---------- app/src/lib/result-viewer/updateGeometries.ts | 146 +++++++++ app/src/lib/runtime-executor.ts | 14 +- app/src/lib/settings/Settings.svelte | 2 + app/src/lib/settings/app-settings.ts | 24 ++ .../settings/panels/ActiveNodeSettings.svelte | 1 - .../lib/settings/panels/BenchmarkPanel.svelte | 88 ++++++ .../lib/settings/panels/ExportSettings.svelte | 53 ++++ app/src/lib/settings/panels/Keymap.svelte | 3 +- .../lib/worker-runtime-executor-backend.ts | 7 +- app/src/routes/+page.svelte | 112 +++++-- nodes/max/plantarium/gravity/src/input.json | 4 +- nodes/max/plantarium/gravity/src/lib.rs | 61 ++-- nodes/max/plantarium/noise/src/lib.rs | 11 +- packages/types/src/index.ts | 1 + packages/types/src/types.ts | 46 +-- packages/ui/src/lib/Input.svelte | 38 +-- packages/ui/src/lib/elements/Checkbox.svelte | 166 +++++----- packages/ui/src/lib/elements/Float.svelte | 69 ++--- packages/ui/src/lib/elements/Integer.svelte | 287 +++++++++--------- packages/ui/src/lib/elements/Select.svelte | 32 +- packages/ui/src/lib/elements/Vec3.svelte | 42 ++- packages/ui/src/routes/+page.svelte | 33 +- packages/utils/src/flatTree.ts | 44 +++ packages/utils/src/geometry/path_data.rs | 40 +++ packages/utils/src/tree.rs | 7 +- pnpm-lock.yaml | 16 + 39 files changed, 1253 insertions(+), 741 deletions(-) create mode 100644 app/src/lib/graph-templates/lotta-faces.json create mode 100644 app/src/lib/graph-templates/lotta-nodes-and-faces.json create mode 100644 app/src/lib/graph-templates/lotta-nodes.json create mode 100644 app/src/lib/performance/BarSplit.svelte create mode 100644 app/src/lib/result-viewer/updateGeometries.ts create mode 100644 app/src/lib/settings/panels/BenchmarkPanel.svelte create mode 100644 app/src/lib/settings/panels/ExportSettings.svelte diff --git a/app/package.json b/app/package.json index d0e8204..411975d 100644 --- a/app/package.json +++ b/app/package.json @@ -18,6 +18,7 @@ "@types/three": "^0.164.0", "@unocss/reset": "^0.59.4", "comlink": "^4.4.1", + "file-saver": "^2.0.5", "jsondiffpatch": "^0.6.0", "three": "^0.164.1" }, @@ -27,6 +28,7 @@ "@sveltejs/adapter-static": "^3.0.1", "@sveltejs/vite-plugin-svelte": "next", "@tsconfig/svelte": "^5.0.4", + "@types/file-saver": "^2.0.7", "@unocss/preset-icons": "^0.59.4", "svelte": "5.0.0-next.118", "svelte-check": "^3.7.0", diff --git a/app/src/lib/graph-interface/graph/Graph.svelte b/app/src/lib/graph-interface/graph/Graph.svelte index 9291036..643b299 100644 --- a/app/src/lib/graph-interface/graph/Graph.svelte +++ b/app/src/lib/graph-interface/graph/Graph.svelte @@ -12,7 +12,7 @@ import Camera from "../Camera.svelte"; import GraphView from "./GraphView.svelte"; import type { Node, NodeId, Node as NodeType, Socket } from "@nodes/types"; - import { NodeDefinitionSchema } from "@nodes/types"; + import { GraphSchema, NodeDefinitionSchema } from "@nodes/types"; import FloatingEdge from "../edges/FloatingEdge.svelte"; import { activeNodeId, @@ -28,6 +28,7 @@ import { createWasmWrapper } from "@nodes/utils"; import HelpView from "../HelpView.svelte"; + import FileSaver from "file-saver"; export let manager: GraphManager; @@ -612,6 +613,7 @@ keymap.addShortcut({ key: "a", ctrl: true, + preventDefault: true, description: "Select all nodes", callback: () => { if (!isBodyFocused()) return; @@ -637,7 +639,6 @@ ctrl: true, description: "Redo", callback: () => { - if (!isBodyFocused()) return; manager.redo(); for (const node of $nodes.values()) { updateNodePosition(node); @@ -645,6 +646,20 @@ }, }); + keymap.addShortcut({ + key: "s", + ctrl: true, + description: "Save", + preventDefault: true, + callback: () => { + const state = manager.serialize(); + const blob = new Blob([JSON.stringify(state)], { + type: "application/json;charset=utf-8", + }); + FileSaver.saveAs(blob, "nodarium-graph.json"); + }, + }); + keymap.addShortcut({ key: ["Delete", "Backspace", "x"], description: "Delete selected nodes", @@ -833,17 +848,31 @@ }); }); } else if (event.dataTransfer.files.length) { - const files = event.dataTransfer.files; - const reader = new FileReader(); - reader.onload = (e) => { - const buffer = e.target?.result as Buffer; - if (buffer) { - const wrapper = createWasmWrapper(buffer); - const definition = wrapper.get_definition(); - const res = NodeDefinitionSchema.parse(definition); - } - }; - reader.readAsArrayBuffer(files[0]); + const file = event.dataTransfer.files[0]; + + if (file.type === "application/wasm") { + const reader = new FileReader(); + reader.onload = (e) => { + const buffer = e.target?.result as Buffer; + if (buffer) { + const wrapper = createWasmWrapper(buffer); + const definition = wrapper.get_definition(); + const res = NodeDefinitionSchema.parse(definition); + console.log(res); + } + }; + reader.readAsArrayBuffer(file); + } else if (file.type === "application/json") { + const reader = new FileReader(); + reader.onload = (e) => { + const buffer = e.target?.result as Buffer; + if (buffer) { + const state = GraphSchema.parse(JSON.parse(buffer.toString())); + manager.load(state); + } + }; + reader.readAsText(file); + } } } @@ -893,13 +922,13 @@ > -