|
|
@@ -47,6 +47,7 @@ User Interaction
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
**Event flow:**
|
|
|
|
**Event flow:**
|
|
|
|
|
|
|
|
|
|
|
|
1. User edits graph → GraphManager mutates state
|
|
|
|
1. User edits graph → GraphManager mutates state
|
|
|
|
2. GraphManager emits `save` → ProjectManager persists to IndexDB
|
|
|
|
2. GraphManager emits `save` → ProjectManager persists to IndexDB
|
|
|
|
3. GraphManager emits `result` → Runtime executes graph → Viewer updates
|
|
|
|
3. GraphManager emits `result` → Runtime executes graph → Viewer updates
|
|
|
@@ -56,7 +57,7 @@ User Interaction
|
|
|
|
## Critical Files
|
|
|
|
## Critical Files
|
|
|
|
|
|
|
|
|
|
|
|
| File | Role |
|
|
|
|
| File | Role |
|
|
|
|
|------|------|
|
|
|
|
| ------------------------------------------------------ | --------------------------------------------------------------------- |
|
|
|
|
| `app/src/routes/+page.svelte` | Wires all systems; creates GraphManager, runtime, registry |
|
|
|
|
| `app/src/routes/+page.svelte` | Wires all systems; creates GraphManager, runtime, registry |
|
|
|
|
| `app/src/lib/graph-interface/graph-manager.svelte.ts` | Central graph logic: createNode, createEdge, serialize, load, history |
|
|
|
|
| `app/src/lib/graph-interface/graph-manager.svelte.ts` | Central graph logic: createNode, createEdge, serialize, load, history |
|
|
|
|
| `app/src/lib/graph-interface/graph-state.svelte.ts` | UI state: camera, selection, mouse, clipboard, groupSelectedNodes |
|
|
|
|
| `app/src/lib/graph-interface/graph-state.svelte.ts` | UI state: camera, selection, mouse, clipboard, groupSelectedNodes |
|
|
|
@@ -83,54 +84,56 @@ User Interaction
|
|
|
|
```typescript
|
|
|
|
```typescript
|
|
|
|
// packages/types/src/types.ts
|
|
|
|
// packages/types/src/types.ts
|
|
|
|
|
|
|
|
|
|
|
|
type NodeId = `${string}/${string}/${string}` // e.g. "max/plantarium/stem"
|
|
|
|
type NodeId = `${string}/${string}/${string}`; // e.g. "max/plantarium/stem"
|
|
|
|
|
|
|
|
|
|
|
|
type NodeInstance = {
|
|
|
|
type NodeInstance = {
|
|
|
|
id: number
|
|
|
|
id: number;
|
|
|
|
type: NodeId
|
|
|
|
type: NodeId;
|
|
|
|
position: [number, number]
|
|
|
|
position: [number, number];
|
|
|
|
props?: Record<string, number | number[]> // current parameter values
|
|
|
|
props?: Record<string, number | number[]>; // current parameter values
|
|
|
|
meta?: { title?: string; lastModified?: string }
|
|
|
|
meta?: { title?: string; lastModified?: string };
|
|
|
|
state: NodeRuntimeState // runtime-only, NOT serialized
|
|
|
|
state: NodeRuntimeState; // runtime-only, NOT serialized
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
type NodeRuntimeState = {
|
|
|
|
type NodeRuntimeState = {
|
|
|
|
type?: NodeDefinition // resolved definition
|
|
|
|
type?: NodeDefinition; // resolved definition
|
|
|
|
parents?: NodeInstance[]
|
|
|
|
parents?: NodeInstance[];
|
|
|
|
children?: NodeInstance[]
|
|
|
|
children?: NodeInstance[];
|
|
|
|
x?: number; y?: number // interpolated position
|
|
|
|
x?: number;
|
|
|
|
mesh?: Mesh // Three.js mesh reference
|
|
|
|
y?: number; // interpolated position
|
|
|
|
ref?: HTMLElement
|
|
|
|
mesh?: Mesh; // Three.js mesh reference
|
|
|
|
}
|
|
|
|
ref?: HTMLElement;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
type NodeDefinition = {
|
|
|
|
type NodeDefinition = {
|
|
|
|
id: NodeId
|
|
|
|
id: NodeId;
|
|
|
|
inputs?: Record<string, NodeInput>
|
|
|
|
inputs?: Record<string, NodeInput>;
|
|
|
|
outputs?: string[] // output type names
|
|
|
|
outputs?: string[]; // output type names
|
|
|
|
meta?: { title?: string; description?: string }
|
|
|
|
meta?: { title?: string; description?: string };
|
|
|
|
execute(input: Int32Array): Int32Array // WASM function
|
|
|
|
execute(input: Int32Array): Int32Array; // WASM function
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Edge: [fromNode, outputIndex, toNode, inputSocketName]
|
|
|
|
// Edge: [fromNode, outputIndex, toNode, inputSocketName]
|
|
|
|
type Edge = [NodeInstance, number, NodeInstance, string]
|
|
|
|
type Edge = [NodeInstance, number, NodeInstance, string];
|
|
|
|
|
|
|
|
|
|
|
|
type Graph = {
|
|
|
|
type Graph = {
|
|
|
|
nodes: NodeInstance[]
|
|
|
|
nodes: NodeInstance[];
|
|
|
|
edges: [number, number, number, string][] // serialized (IDs, not refs)
|
|
|
|
edges: [number, number, number, string][]; // serialized (IDs, not refs)
|
|
|
|
settings: Record<string, unknown>
|
|
|
|
settings: Record<string, unknown>;
|
|
|
|
groups: GroupDefinition[]
|
|
|
|
groups: GroupDefinition[];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
type GroupDefinition = {
|
|
|
|
type GroupDefinition = {
|
|
|
|
id: number
|
|
|
|
id: number;
|
|
|
|
nodes: NodeInstance[]
|
|
|
|
nodes: NodeInstance[];
|
|
|
|
edges: Edge[]
|
|
|
|
edges: Edge[];
|
|
|
|
inputs?: Record<string, NodeInput>
|
|
|
|
inputs?: Record<string, NodeInput>;
|
|
|
|
outputs?: string[]
|
|
|
|
outputs?: string[];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### NodeInput socket types
|
|
|
|
### NodeInput socket types
|
|
|
|
|
|
|
|
|
|
|
|
`float` | `integer` | `boolean` | `select` | `seed` | `vec3` | `geometry` | `path` | `shape` | `color` | `*` (wildcard)
|
|
|
|
`float` | `integer` | `boolean` | `select` | `seed` | `vec3` | `geometry` | `path` | `shape` | `color` | `*` (wildcard)
|
|
|
|
|
|
|
|
|
|
|
|
Each input can have: `value` (default), `label`, `hidden`, `external`, `setting` (link to graph setting), `accepts` (extra compatible types).
|
|
|
|
Each input can have: `value` (default), `label`, `hidden`, `external`, `setting` (link to graph setting), `accepts` (extra compatible types).
|
|
|
@@ -140,34 +143,43 @@ Each input can have: `value` (default), `label`, `hidden`, `external`, `setting`
|
|
|
|
## Patterns & Conventions
|
|
|
|
## Patterns & Conventions
|
|
|
|
|
|
|
|
|
|
|
|
### Svelte 5 reactivity
|
|
|
|
### Svelte 5 reactivity
|
|
|
|
|
|
|
|
|
|
|
|
The codebase uses Svelte 5 runes throughout — `$state`, `$derived`, `$effect`. Collections use `SvelteMap<K,V>` and `SvelteSet<T>` (from `svelte/reactivity`) instead of plain Map/Set so that mutations trigger reactive updates.
|
|
|
|
The codebase uses Svelte 5 runes throughout — `$state`, `$derived`, `$effect`. Collections use `SvelteMap<K,V>` and `SvelteSet<T>` (from `svelte/reactivity`) instead of plain Map/Set so that mutations trigger reactive updates.
|
|
|
|
|
|
|
|
|
|
|
|
### Context API
|
|
|
|
### Context API
|
|
|
|
|
|
|
|
|
|
|
|
`GraphManager` and `GraphState` are provided via Svelte context (`setContext` / `getContext`) inside `GraphInterface`. All child components (Node, Edge, etc.) consume them via context rather than props.
|
|
|
|
`GraphManager` and `GraphState` are provided via Svelte context (`setContext` / `getContext`) inside `GraphInterface`. All child components (Node, Edge, etc.) consume them via context rather than props.
|
|
|
|
|
|
|
|
|
|
|
|
### Edge representation
|
|
|
|
### Edge representation
|
|
|
|
|
|
|
|
|
|
|
|
In memory, edges are `[NodeInstance, outputIndex, NodeInstance, inputSocketName]` — direct object references for fast traversal. On serialization (`Graph.edges`), they become `[nodeId, outputIndex, nodeId, inputSocketName]` (plain IDs).
|
|
|
|
In memory, edges are `[NodeInstance, outputIndex, NodeInstance, inputSocketName]` — direct object references for fast traversal. On serialization (`Graph.edges`), they become `[nodeId, outputIndex, nodeId, inputSocketName]` (plain IDs).
|
|
|
|
|
|
|
|
|
|
|
|
### Socket compatibility
|
|
|
|
### Socket compatibility
|
|
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
```typescript
|
|
|
|
areSocketsCompatible(outputType: string, inputType: string | string[]): boolean
|
|
|
|
areSocketsCompatible(outputType: string, inputType: string | string[]): boolean
|
|
|
|
// '*' wildcard matches any type; 'geometry' accepts ['geometry', 'instances']
|
|
|
|
// '*' wildcard matches any type; 'geometry' accepts ['geometry', 'instances']
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### WASM execution interface
|
|
|
|
### WASM execution interface
|
|
|
|
|
|
|
|
|
|
|
|
Every node exposes a single function: `execute(input: Int32Array): Int32Array`.
|
|
|
|
Every node exposes a single function: `execute(input: Int32Array): Int32Array`.
|
|
|
|
Data encoding (Plantarium):
|
|
|
|
Data encoding (Plantarium):
|
|
|
|
|
|
|
|
|
|
|
|
- `[0, stemDepth, ...x,y,z,thickness]` — path
|
|
|
|
- `[0, stemDepth, ...x,y,z,thickness]` — path
|
|
|
|
- `[1, vertexCount, faceCount, ...faces, ...vertices, ...normals]` — geometry
|
|
|
|
- `[1, vertexCount, faceCount, ...faces, ...vertices, ...normals]` — geometry
|
|
|
|
- `[2, vertexCount, faceCount, instanceCount, stemDepth, ...]` — instances
|
|
|
|
- `[2, vertexCount, faceCount, instanceCount, stemDepth, ...]` — instances
|
|
|
|
|
|
|
|
|
|
|
|
### Event emitter
|
|
|
|
### Event emitter
|
|
|
|
|
|
|
|
|
|
|
|
`GraphManager extends EventEmitter<{ save, result, settings }>`. Subscribe with `manager.on('result', cb)`. Used to decouple the editor UI from runtime execution and persistence.
|
|
|
|
`GraphManager extends EventEmitter<{ save, result, settings }>`. Subscribe with `manager.on('result', cb)`. Used to decouple the editor UI from runtime execution and persistence.
|
|
|
|
|
|
|
|
|
|
|
|
### History
|
|
|
|
### History
|
|
|
|
|
|
|
|
|
|
|
|
Every mutation goes through `HistoryManager`. Call `this.history.save(this.serialize())` before mutations; undo/redo replays jsondiffpatch deltas.
|
|
|
|
Every mutation goes through `HistoryManager`. Call `this.history.save(this.serialize())` before mutations; undo/redo replays jsondiffpatch deltas.
|
|
|
|
|
|
|
|
|
|
|
|
### Internal node IDs
|
|
|
|
### Internal node IDs
|
|
|
|
|
|
|
|
|
|
|
|
Built-in nodes use the `__internal/` namespace: `__internal/group/instance`, `__internal/node/debug`. Virtual boundary nodes use `__virtual/`: `__virtual/group/input`, `__virtual/group/output`.
|
|
|
|
Built-in nodes use the `__internal/` namespace: `__internal/group/instance`, `__internal/node/debug`. Virtual boundary nodes use `__virtual/`: `__virtual/group/input`, `__virtual/group/output`.
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
---
|
|
|
@@ -179,7 +191,7 @@ Group selected nodes with **Ctrl+G**. A `GroupDefinition` is stored in `Graph.gr
|
|
|
|
**Known gaps as of 2026-05-03:**
|
|
|
|
**Known gaps as of 2026-05-03:**
|
|
|
|
|
|
|
|
|
|
|
|
| Issue | Location |
|
|
|
|
| Issue | Location |
|
|
|
|
|-------|----------|
|
|
|
|
| ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
|
|
|
|
| `createGroupNode()` called but not defined | `graph-state.svelte.ts:334` → missing in `graph-manager.svelte.ts` |
|
|
|
|
| `createGroupNode()` called but not defined | `graph-state.svelte.ts:334` → missing in `graph-manager.svelte.ts` |
|
|
|
|
| Runtime expects `group.graph.nodes/edges`; schema has flat `nodes/edges` | `runtime-executor.ts` vs `types.ts` |
|
|
|
|
| Runtime expects `group.graph.nodes/edges`; schema has flat `nodes/edges` | `runtime-executor.ts` vs `types.ts` |
|
|
|
|
| Runtime expects `group.inputs` as array; schema defines it as `Record<string, NodeInput>` | Same mismatch |
|
|
|
|
| Runtime expects `group.inputs` as array; schema defines it as `Record<string, NodeInput>` | Same mismatch |
|
|
|
|