From 26d3f6a2f18d92a683a4aea5ae7b513270a3241d Mon Sep 17 00:00:00 2001 From: Max Richter Date: Thu, 2 May 2024 18:49:08 +0200 Subject: [PATCH] fix: gravity node --- app/package.json | 9 +- app/src/lib/graph-interface/graph-manager.ts | 11 +- .../lib/graph-interface/graph/Graph.svelte | 25 +- app/src/lib/node-registry-cache.ts | 38 + app/src/lib/node-registry-client.ts | 63 +- app/src/lib/result-viewer/Camera.svelte | 2 +- app/src/lib/result-viewer/Scene.svelte | 49 +- app/src/lib/result-viewer/Viewer.svelte | 16 +- app/src/lib/settings/app-settings.ts | 2 +- .../lib/worker-runtime-executor-backend.ts | 3 + app/src/routes/+page.svelte | 21 +- nodes/max/plantarium/box/src/lib.rs | 12 +- nodes/max/plantarium/gravity/src/lib.rs | 2 +- nodes/max/plantarium/output/src/lib.rs | 7 +- packages/types/src/components.ts | 16 +- packages/ui/histoire.config.ts | 12 + packages/ui/package.json | 56 +- packages/ui/src/lib/Input.svelte | 18 +- packages/ui/src/lib/elements/Checkbox.svelte | 1 + .../ui/src/lib/elements/Float.story.svelte | 17 + packages/ui/src/lib/elements/Float.svelte | 52 +- .../ui/src/lib/elements/Integer.story.svelte | 18 + packages/ui/src/lib/elements/Integer.svelte | 50 +- .../ui/src/lib/elements/Select.story.svelte | 18 + packages/ui/src/lib/elements/Select.svelte | 9 +- .../ui/src/lib/elements/Vec3.story.svelte | 18 + packages/ui/src/lib/elements/Vec3.svelte | 4 +- .../ui/src/lib/helpers/StoryContent.svelte | 24 + .../ui/src/lib/helpers/StorySettings.svelte | 23 + packages/ui/src/routes/+page.svelte | 6 +- pnpm-lock.yaml | 1491 +++++++++++++---- 31 files changed, 1557 insertions(+), 536 deletions(-) create mode 100644 app/src/lib/node-registry-cache.ts create mode 100644 packages/ui/histoire.config.ts create mode 100644 packages/ui/src/lib/elements/Float.story.svelte create mode 100644 packages/ui/src/lib/elements/Integer.story.svelte create mode 100644 packages/ui/src/lib/elements/Select.story.svelte create mode 100644 packages/ui/src/lib/elements/Vec3.story.svelte create mode 100644 packages/ui/src/lib/helpers/StoryContent.svelte create mode 100644 packages/ui/src/lib/helpers/StorySettings.svelte diff --git a/app/package.json b/app/package.json index 411975d..50c3b36 100644 --- a/app/package.json +++ b/app/package.json @@ -13,12 +13,13 @@ "@nodes/ui": "link:../packages/ui", "@nodes/utils": "link:../packages/utils", "@sveltejs/kit": "^2.5.7", - "@threlte/core": "next", - "@threlte/extras": "next", + "@threlte/core": "^7.3.0", + "@threlte/extras": "^8.11.2", "@types/three": "^0.164.0", "@unocss/reset": "^0.59.4", "comlink": "^4.4.1", "file-saver": "^2.0.5", + "idb": "^8.0.0", "jsondiffpatch": "^0.6.0", "three": "^0.164.1" }, @@ -26,11 +27,11 @@ "@iconify-json/tabler": "^1.1.110", "@nodes/types": "link:../packages/types", "@sveltejs/adapter-static": "^3.0.1", - "@sveltejs/vite-plugin-svelte": "next", + "@sveltejs/vite-plugin-svelte": "^3.1.0", "@tsconfig/svelte": "^5.0.4", "@types/file-saver": "^2.0.7", "@unocss/preset-icons": "^0.59.4", - "svelte": "5.0.0-next.118", + "svelte": "^4.2.15", "svelte-check": "^3.7.0", "tslib": "^2.6.2", "typescript": "^5.4.5", diff --git a/app/src/lib/graph-interface/graph-manager.ts b/app/src/lib/graph-interface/graph-manager.ts index 4f1da03..42a4bdb 100644 --- a/app/src/lib/graph-interface/graph-manager.ts +++ b/app/src/lib/graph-interface/graph-manager.ts @@ -407,7 +407,10 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any, " // check if socket types match const fromSocketType = from.tmp?.type?.outputs?.[fromSocket]; - const toSocketType = to.tmp?.type?.inputs?.[toSocket]?.type; + const toSocketType = [to.tmp?.type?.inputs?.[toSocket]?.type]; + if (to.tmp?.type?.inputs?.[toSocket]?.accepts) { + toSocketType.push(...(to?.tmp?.type?.inputs?.[toSocket]?.accepts || [])); + } if (!areSocketsCompatible(fromSocketType, toSocketType)) { logger.error(`Socket types do not match: ${fromSocketType} !== ${toSocketType}`); @@ -534,7 +537,11 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any, " const inputs = node?.tmp?.type?.inputs; if (!inputs) continue; for (const key in inputs) { - if (areSocketsCompatible(ownType, inputs[key].type) && edges.get(node.id) !== key) { + + const otherType = [inputs[key].type]; + otherType.push(...(inputs[key].accepts || [])); + + if (areSocketsCompatible(ownType, otherType) && edges.get(node.id) !== key) { sockets.push([node, key]); } } diff --git a/app/src/lib/graph-interface/graph/Graph.svelte b/app/src/lib/graph-interface/graph/Graph.svelte index 643b299..8c9e927 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 { GraphSchema, NodeDefinitionSchema } from "@nodes/types"; + import { GraphSchema } from "@nodes/types"; import FloatingEdge from "../edges/FloatingEdge.svelte"; import { activeNodeId, @@ -25,7 +25,6 @@ import { createKeyMap } from "../../helpers/createKeyMap"; import BoxSelection from "../BoxSelection.svelte"; import AddMenu from "../AddMenu.svelte"; - import { createWasmWrapper } from "@nodes/utils"; import HelpView from "../HelpView.svelte"; import FileSaver from "file-saver"; @@ -819,11 +818,10 @@ isDragging = false; if (!event.dataTransfer) return; const nodeId = event.dataTransfer.getData("data/node-id") as NodeId; + let mx = event.clientX - rect.x; + let my = event.clientY - rect.y; if (nodeId) { - let mx = event.clientX - rect.x; - let my = event.clientY - rect.y; - let nodeOffsetX = event.dataTransfer.getData("data/node-offset-x"); let nodeOffsetY = event.dataTransfer.getData("data/node-offset-y"); if (nodeOffsetX && nodeOffsetY) { @@ -852,13 +850,16 @@ 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.onload = async (e) => { + const buffer = e.target?.result; + if (buffer?.constructor === ArrayBuffer) { + const nodeType = await manager.registry.register(buffer); + + manager.createNode({ + type: nodeType.id, + props: {}, + position: projectScreenToWorld(mx, my), + }); } }; reader.readAsArrayBuffer(file); diff --git a/app/src/lib/node-registry-cache.ts b/app/src/lib/node-registry-cache.ts new file mode 100644 index 0000000..c36d2da --- /dev/null +++ b/app/src/lib/node-registry-cache.ts @@ -0,0 +1,38 @@ +import type { RuntimeCache } from '@nodes/types'; +import { openDB, type IDBPDatabase } from 'idb'; + +export class IndexDBCache implements RuntimeCache { + + size: number = 100; + + db: Promise>; + private _cache = new Map(); + + constructor(id: string) { + this.db = openDB('cache/' + id, 1, { + upgrade(db) { + db.createObjectStore('keyval'); + }, + }); + } + + async get(key: string) { + let res = this._cache.get(key); + if (!res) { + res = await (await this.db).get('keyval', key); + } + if (res) { + this._cache.set(key, res); + } + return res; + } + async set(key: string, value: ArrayBuffer) { + this._cache.set(key, value); + const db = await this.db; + await db.put('keyval', value, key); + } + clear() { + this.db.then(db => db.clear('keyval')); + } + +} diff --git a/app/src/lib/node-registry-client.ts b/app/src/lib/node-registry-client.ts index 2d49c93..9dacb54 100644 --- a/app/src/lib/node-registry-client.ts +++ b/app/src/lib/node-registry-client.ts @@ -1,4 +1,4 @@ -import type { NodeRegistry, NodeDefinition } from "@nodes/types"; +import { type NodeRegistry, type NodeDefinition, NodeDefinitionSchema, type RuntimeCache } from "@nodes/types"; import { createWasmWrapper } from "@nodes/utils"; import { createLogger } from "./helpers"; @@ -10,6 +10,8 @@ export class RemoteNodeRegistry implements NodeRegistry { status: "loading" | "ready" | "error" = "loading"; private nodes: Map = new Map(); + cache?: RuntimeCache; + fetch: typeof fetch = globalThis.fetch.bind(globalThis); constructor(private url: string) { } @@ -46,6 +48,22 @@ export class RemoteNodeRegistry implements NodeRegistry { return response.json() } + private async fetchNodeWasm(nodeId: `${string}/${string}/${string}`) { + + const response = await this.fetch(`${this.url}/nodes/${nodeId}.wasm`); + if (!response.ok) { + if (this.cache) { + let value = await this.cache.get(nodeId); + if (value) { + return value; + } + } + throw new Error(`Failed to load node wasm ${nodeId}`); + } + + return response.arrayBuffer(); + } + async load(nodeIds: `${string}/${string}/${string}`[]) { const a = performance.now(); @@ -55,26 +73,12 @@ export class RemoteNodeRegistry implements NodeRegistry { return this.nodes.get(id)!; } - const response = await this.fetch(`${this.url}/nodes/${id}.wasm`); - if (!response.ok) { - throw new Error(`Failed to load node wasm ${id}`); - } + const wasmBuffer = await this.fetchNodeWasm(id); - const wasmBuffer = await response.arrayBuffer(); + return this.register(wasmBuffer); - const wrapper = createWasmWrapper(wasmBuffer); - - const definition = wrapper.get_definition(); - - return { - ...definition, - execute: wrapper.execute - }; })); - for (const node of nodes) { - this.nodes.set(node.id, node); - } const duration = performance.now() - a; @@ -87,6 +91,31 @@ export class RemoteNodeRegistry implements NodeRegistry { return nodes } + async register(wasmBuffer: ArrayBuffer) { + + const wrapper = createWasmWrapper(wasmBuffer); + + const definition = NodeDefinitionSchema.safeParse(wrapper.get_definition()); + + if (definition.error) { + console.error(definition.error); + throw definition.error; + } + + if (this.cache) { + await this.cache.set(definition.data.id, wasmBuffer); + } + + let node = { + ...definition.data, + execute: wrapper.execute + } + + this.nodes.set(definition.data.id, node); + + return node; + } + getNode(id: string) { return this.nodes.get(id); } diff --git a/app/src/lib/result-viewer/Camera.svelte b/app/src/lib/result-viewer/Camera.svelte index df15539..36a8878 100644 --- a/app/src/lib/result-viewer/Camera.svelte +++ b/app/src/lib/result-viewer/Camera.svelte @@ -17,7 +17,7 @@ camera: Vector3Tuple; target: Vector3Tuple; }>("nodes.camera.transform", { - camera: [0, 0, 10], + camera: [10, 10, 10], target: [0, 0, 0], }); diff --git a/app/src/lib/result-viewer/Scene.svelte b/app/src/lib/result-viewer/Scene.svelte index 9e5108b..14a6b8a 100644 --- a/app/src/lib/result-viewer/Scene.svelte +++ b/app/src/lib/result-viewer/Scene.svelte @@ -11,20 +11,43 @@ import { AppSettings } from "../settings/app-settings"; import Camera from "./Camera.svelte"; - const d = useThrelte(); + const threlte = useThrelte(); - export const invalidate = d.invalidate; + export const invalidate = function () { + if (scene) { + geometries = scene.children + .filter( + (child) => "geometry" in child && child.isObject3D && child.geometry, + ) + .map((child) => { + return child.geometry; + }); + } - export let geometries: BufferGeometry[]; + if (geometries && scene && centerCamera) { + const aabb = new Box3().setFromObject(scene); + center = aabb + .getCenter(new Vector3()) + .max(new Vector3(-4, -4, -4)) + .min(new Vector3(4, 4, 4)); + } + threlte.invalidate(); + }; + + let geometries: BufferGeometry[] = []; export let lines: Vector3[][]; - export let scene; - let geos: Group; - $: scene = geos; - export let geoGroup: Group; + export let scene: Group; export let centerCamera: boolean = true; let center = new Vector3(0, 4, 0); + $: if ($AppSettings && scene) { + scene.children.forEach((child) => { + child.material.wireframe = $AppSettings.wireframe; + threlte.invalidate(); + }); + } + function getPosition(geo: BufferGeometry, i: number) { return [ geo.attributes.position.array[i], @@ -32,14 +55,6 @@ geo.attributes.position.array[i + 2], ] as Vector3Tuple; } - - $: if (geometries && geos && centerCamera) { - const aabb = new Box3().setFromObject(geos); - center = aabb - .getCenter(new Vector3()) - .max(new Vector3(-4, -4, -4)) - .min(new Vector3(4, 4, 4)); - } @@ -48,7 +63,7 @@ {/if} - + {#each geometries as geo} {#if $AppSettings.showIndices} {#each geo.attributes.position.array as _, i} @@ -66,7 +81,7 @@ {/if} {/each} - + {#if $AppSettings.showStemLines && lines} diff --git a/app/src/lib/result-viewer/Viewer.svelte b/app/src/lib/result-viewer/Viewer.svelte index ec5e288..e94bae1 100644 --- a/app/src/lib/result-viewer/Viewer.svelte +++ b/app/src/lib/result-viewer/Viewer.svelte @@ -1,7 +1,7 @@ - + diff --git a/app/src/lib/settings/app-settings.ts b/app/src/lib/settings/app-settings.ts index 3fb3c8e..56a957a 100644 --- a/app/src/lib/settings/app-settings.ts +++ b/app/src/lib/settings/app-settings.ts @@ -1,6 +1,6 @@ import localStore from "$lib/helpers/localStore"; -export const AppSettings = localStore("node-settings", { +export const AppSettings = localStore("node.settings", { theme: 0, showGrid: true, showNodeGrid: true, diff --git a/app/src/lib/worker-runtime-executor-backend.ts b/app/src/lib/worker-runtime-executor-backend.ts index 55550d7..53b8535 100644 --- a/app/src/lib/worker-runtime-executor-backend.ts +++ b/app/src/lib/worker-runtime-executor-backend.ts @@ -2,9 +2,12 @@ import { MemoryRuntimeExecutor, MemoryRuntimeCache } from "./runtime-executor"; import { RemoteNodeRegistry } from "./node-registry-client"; import type { Graph } from "@nodes/types"; import { createPerformanceStore } from "./performance/store"; +import { IndexDBCache } from "./node-registry-cache"; const cache = new MemoryRuntimeCache(); +const indexDbCache = new IndexDBCache("node-registry"); const nodeRegistry = new RemoteNodeRegistry(""); +nodeRegistry.cache = indexDbCache; const executor = new MemoryRuntimeExecutor(nodeRegistry, cache); const performanceStore = createPerformanceStore("worker"); diff --git a/app/src/routes/+page.svelte b/app/src/routes/+page.svelte index c5131b1..932d312 100644 --- a/app/src/routes/+page.svelte +++ b/app/src/routes/+page.svelte @@ -13,7 +13,6 @@ import { createKeyMap } from "$lib/helpers/createKeyMap"; import NodeStore from "$lib/node-store/NodeStore.svelte"; import type { GraphManager } from "$lib/graph-interface/graph-manager"; - import { setContext } from "svelte"; import ActiveNodeSettings from "$lib/settings/panels/ActiveNodeSettings.svelte"; import PerformanceViewer from "$lib/performance/PerformanceViewer.svelte"; import Panel from "$lib/settings/Panel.svelte"; @@ -26,12 +25,15 @@ MemoryRuntimeCache, MemoryRuntimeExecutor, } from "$lib/runtime-executor"; + import { IndexDBCache } from "$lib/node-registry-cache"; import { decodeNestedArray, fastHashString } from "@nodes/utils"; import BenchmarkPanel from "$lib/settings/panels/BenchmarkPanel.svelte"; let performanceStore = createPerformanceStore("page"); + const registryCache = new IndexDBCache("node-registry"); const nodeRegistry = new RemoteNodeRegistry(""); + nodeRegistry.cache = registryCache; const workerRuntime = new WorkerRuntimeExecutor(); const runtimeCache = new MemoryRuntimeCache(); const memoryRuntime = new MemoryRuntimeExecutor(nodeRegistry, runtimeCache); @@ -39,6 +41,15 @@ globalThis.decode = decodeNestedArray; + globalThis.clearCache = () => { + registryCache.clear(); + runtimeCache.clear(); + localStorage.clear(); + setTimeout(() => { + window.location.reload(); + }, 500); + }; + $: runtime = $AppSettings.useWorker ? workerRuntime : memoryRuntime; let activeNode: Node | undefined; @@ -51,6 +62,9 @@ let manager: GraphManager; let managerStatus: Writable<"loading" | "error" | "idle">; + $: if (manager) { + managerStatus = manager.status; + } async function randomGenerate() { const g = manager.serialize(); @@ -82,6 +96,7 @@ async function handleResult(_graph: Graph, _settings: Record) { if (!_settings) return; + if ($managerStatus !== "idle") return; const inputHash = fastHashString( JSON.stringify(_graph) + JSON.stringify(_settings), ); @@ -131,6 +146,10 @@ return true; } + $: if ($managerStatus === "idle") { + handleResult(manager.serialize(), $graphSettings); + } + $: if (AppSettings) { //@ts-ignore AppSettingTypes.debug.stressTest.loadGrid.callback = () => { diff --git a/nodes/max/plantarium/box/src/lib.rs b/nodes/max/plantarium/box/src/lib.rs index bad2031..0e0dcd3 100644 --- a/nodes/max/plantarium/box/src/lib.rs +++ b/nodes/max/plantarium/box/src/lib.rs @@ -1,9 +1,9 @@ use nodarium_macros::include_definition_file; use nodarium_utils::{ - encode_float, evaluate_float, geometry::calculate_normals, set_panic_hook, split_args, wrap_arg, + encode_float, evaluate_float, geometry::calculate_normals, log, set_panic_hook, split_args, + wrap_arg, }; use wasm_bindgen::prelude::*; -use web_sys::console; include_definition_file!("src/input.json"); @@ -15,7 +15,7 @@ pub fn execute(input: &[i32]) -> Vec { let args = split_args(input); - console::log_1(&format!("WASM(cube): input: {:?} -> {:?}", input, args ).into()); + log!("WASM(cube): input: {:?} -> {:?}", input, args); let size = evaluate_float(args[0]); @@ -79,6 +79,10 @@ pub fn execute(input: &[i32]) -> Vec { calculate_normals(&mut cube_geometry); - wrap_arg(&cube_geometry) + let res = wrap_arg(&cube_geometry); + + log!("WASM(cube): output: {:?}", res); + + res } diff --git a/nodes/max/plantarium/gravity/src/lib.rs b/nodes/max/plantarium/gravity/src/lib.rs index c779c4e..331806a 100644 --- a/nodes/max/plantarium/gravity/src/lib.rs +++ b/nodes/max/plantarium/gravity/src/lib.rs @@ -80,7 +80,7 @@ pub fn execute(input: &[i32]) -> Vec { } // Correct midpoint length - mid_point *= mid_point.length() / length; + mid_point *= length / mid_point.length(); let final_end_point = start_point + mid_point; let offset_end_point = end_point + offset_vec; diff --git a/nodes/max/plantarium/output/src/lib.rs b/nodes/max/plantarium/output/src/lib.rs index 978b908..0dd49ef 100644 --- a/nodes/max/plantarium/output/src/lib.rs +++ b/nodes/max/plantarium/output/src/lib.rs @@ -2,7 +2,7 @@ use nodarium_macros::include_definition_file; use nodarium_utils::{ concat_args, evaluate_int, geometry::{extrude_path, wrap_path}, - log, split_args, + log, set_panic_hook, split_args, }; use wasm_bindgen::prelude::*; @@ -10,16 +10,17 @@ include_definition_file!("src/inputs.json"); #[wasm_bindgen] pub fn execute(input: &[i32]) -> Vec { - utils::set_panic_hook(); + set_panic_hook(); let args = split_args(input); + log!("WASM(output) args: {:?}", args); + assert_eq!(args.len(), 2, "Expected 2 arguments, got {}", args.len()); let inputs = split_args(args[0]); let resolution = evaluate_int(args[1]) as usize; - log!("output inputs: {:?}", inputs); log!("inputs: {}, resolution: {}", inputs.len(), resolution); let mut output: Vec> = Vec::new(); diff --git a/packages/types/src/components.ts b/packages/types/src/components.ts index bc02296..9b8a8d3 100644 --- a/packages/types/src/components.ts +++ b/packages/types/src/components.ts @@ -1,6 +1,8 @@ import { Graph, NodeDefinition, NodeId } from "./types"; export interface NodeRegistry { + + /** * The status of the node registry * @remarks The status should be "loading" when the registry is loading, "ready" when the registry is ready, and "error" if an error occurred while loading the registry @@ -25,6 +27,16 @@ export interface NodeRegistry { * @returns An array of all nodes */ getAllNodes: () => NodeDefinition[]; + + /** + * Register a new node + * @param wasmBuffer - The WebAssembly buffer for the node + * @returns The node definition + */ + register: (wasmBuffer: ArrayBuffer) => Promise; + + + cache?: RuntimeCache; } export interface RuntimeExecutor { @@ -49,13 +61,13 @@ export interface RuntimeCache { * @param key - The key to get the value for * @returns The value for the given key, or undefined if no such value exists */ - get: (key: string) => T | undefined; + get: (key: string) => T | Promise | undefined; /** * Set the value for the given key * @param key - The key to set the value for * @param value - The value to set */ - set: (key: string, value: T) => void; + set: (key: string, value: T) => void | Promise; /** * Clear the cache */ diff --git a/packages/ui/histoire.config.ts b/packages/ui/histoire.config.ts new file mode 100644 index 0000000..bb2292a --- /dev/null +++ b/packages/ui/histoire.config.ts @@ -0,0 +1,12 @@ +import { defineConfig } from 'histoire' +import { HstSvelte } from '@histoire/plugin-svelte' + +export default defineConfig({ + setupFile: '/src/histoire.setup.ts', + storyMatch: [ + './src/lib/**/*.story.svelte', + ], + plugins: [ + HstSvelte(), + ], +}) diff --git a/packages/ui/package.json b/packages/ui/package.json index c94f613..7354b5f 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -9,8 +9,11 @@ "prepublishOnly": "npm run package", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", - "lint": "prettier --check . && eslint .", - "format": "prettier --write ." + "test": "vitest", + "lint": "eslint .", + "story:dev": "histoire dev", + "story:build": "histoire build", + "story:preview": "histoire preview" }, "exports": { ".": { @@ -24,35 +27,36 @@ "!dist/**/*.test.*", "!dist/**/*.spec.*" ], - "dependencies": { - "@nodes/types": "link:../types" - }, "peerDependencies": { - "svelte": "^5.0.0-next.1" + "svelte": "^4.0.0" }, "devDependencies": { - "@sveltejs/adapter-auto": "^3.0.0", + "@histoire/plugin-svelte": "^0.17.17", + "@sveltejs/adapter-auto": "^3.2.0", "@sveltejs/adapter-static": "^3.0.1", - "@sveltejs/kit": "^2.0.0", - "@sveltejs/package": "^2.0.0", - "@sveltejs/vite-plugin-svelte": "^3.0.0", - "@types/eslint": "^8.56.0", - "@typescript-eslint/eslint-plugin": "^7.0.0", - "@typescript-eslint/parser": "^7.0.0", - "eslint": "^8.56.0", - "eslint-config-prettier": "^9.1.0", - "eslint-plugin-svelte": "^2.36.0-next.4", - "prettier": "^3.1.1", - "prettier-plugin-svelte": "^3.1.2", - "publint": "^0.1.9", - "svelte": "^5.0.0-next.1", - "svelte-check": "^3.6.0", - "tslib": "^2.4.1", - "typescript": "^5.0.0", - "vite": "^5.0.11", - "vitest": "^1.5.3" + "@sveltejs/kit": "^2.5.7", + "@sveltejs/package": "^2.3.1", + "@sveltejs/vite-plugin-svelte": "^3.1.0", + "@types/eslint": "^8.56.10", + "@typescript-eslint/eslint-plugin": "^7.7.1", + "@typescript-eslint/parser": "^7.7.1", + "eslint": "^9.1.1", + "eslint-plugin-svelte": "^2.38.0", + "histoire": "^0.17.17", + "publint": "^0.2.7", + "svelte": "^4.2.15", + "svelte-check": "^3.7.0", + "tslib": "^2.6.2", + "typescript": "^5.4.5", + "vite": "^5.2.10", + "vitest": "^1.5.2" }, "svelte": "./dist/index.js", "types": "./dist/index.d.ts", - "type": "module" + "type": "module", + "dependencies": { + "@nodes/types": "link:../types", + "@threlte/core": "^7.3.0", + "@threlte/extras": "^8.11.2" + } } diff --git a/packages/ui/src/lib/Input.svelte b/packages/ui/src/lib/Input.svelte index 56e603f..30e1019 100644 --- a/packages/ui/src/lib/Input.svelte +++ b/packages/ui/src/lib/Input.svelte @@ -10,21 +10,6 @@ export let input: NodeInput; export let value: any; export let id: string; - - $: if (value === undefined || value === null) { - switch (input.type) { - case 'float': - value = 0; - case 'integer': - value = 0; - case 'boolean': - value = false; - case 'select': - value = 0; - case 'vec3': - value = [0, 0, 0]; - } - } {#if input.type === 'float'} @@ -34,7 +19,8 @@ {:else if input.type === 'boolean'} {:else if input.type === 'select'} - {:else if input.type === 'vec3'} {/if} + diff --git a/packages/ui/src/lib/elements/Checkbox.svelte b/packages/ui/src/lib/elements/Checkbox.svelte index 20eded7..a01e0cf 100644 --- a/packages/ui/src/lib/elements/Checkbox.svelte +++ b/packages/ui/src/lib/elements/Checkbox.svelte @@ -94,3 +94,4 @@ display: block; } + diff --git a/packages/ui/src/lib/elements/Float.story.svelte b/packages/ui/src/lib/elements/Float.story.svelte new file mode 100644 index 0000000..49cfe3f --- /dev/null +++ b/packages/ui/src/lib/elements/Float.story.svelte @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/packages/ui/src/lib/elements/Float.svelte b/packages/ui/src/lib/elements/Float.svelte index 628ddca..a1d5d78 100644 --- a/packages/ui/src/lib/elements/Float.svelte +++ b/packages/ui/src/lib/elements/Float.svelte @@ -1,19 +1,9 @@ + + + + + + + + + diff --git a/packages/ui/src/lib/elements/Integer.svelte b/packages/ui/src/lib/elements/Integer.svelte index 6d86eb8..16b1138 100644 --- a/packages/ui/src/lib/elements/Integer.svelte +++ b/packages/ui/src/lib/elements/Integer.svelte @@ -1,19 +1,13 @@ + + + + @@ -23,3 +21,4 @@ border: none; } + diff --git a/packages/ui/src/lib/elements/Vec3.story.svelte b/packages/ui/src/lib/elements/Vec3.story.svelte new file mode 100644 index 0000000..5f6d499 --- /dev/null +++ b/packages/ui/src/lib/elements/Vec3.story.svelte @@ -0,0 +1,18 @@ + + + + + + + + + + diff --git a/packages/ui/src/lib/elements/Vec3.svelte b/packages/ui/src/lib/elements/Vec3.svelte index b01c884..196aa8c 100644 --- a/packages/ui/src/lib/elements/Vec3.svelte +++ b/packages/ui/src/lib/elements/Vec3.svelte @@ -1,7 +1,9 @@
diff --git a/packages/ui/src/lib/helpers/StoryContent.svelte b/packages/ui/src/lib/helpers/StoryContent.svelte new file mode 100644 index 0000000..262df79 --- /dev/null +++ b/packages/ui/src/lib/helpers/StoryContent.svelte @@ -0,0 +1,24 @@ + + +
+ +
+ + diff --git a/packages/ui/src/lib/helpers/StorySettings.svelte b/packages/ui/src/lib/helpers/StorySettings.svelte new file mode 100644 index 0000000..c76f2a2 --- /dev/null +++ b/packages/ui/src/lib/helpers/StorySettings.svelte @@ -0,0 +1,23 @@ + + +
+ +