diff --git a/app/e2e/main.test.ts-snapshots/test-1-linux.png b/app/e2e/main.test.ts-snapshots/test-1-linux.png index 7be9fee..2ba5305 100644 Binary files a/app/e2e/main.test.ts-snapshots/test-1-linux.png and b/app/e2e/main.test.ts-snapshots/test-1-linux.png differ diff --git a/app/src/lib/graph-interface/edges/Edge.svelte b/app/src/lib/graph-interface/edges/Edge.svelte index fe58df3..4f5a9e3 100644 --- a/app/src/lib/graph-interface/edges/Edge.svelte +++ b/app/src/lib/graph-interface/edges/Edge.svelte @@ -6,15 +6,12 @@ toneMapped: false }); - let lineColor = $state(colors.outline.clone().convertSRGBToLinear()); - $effect.root(() => { $effect(() => { if (appSettings.value.theme === undefined) { return; } circleMaterial.color = colors.outline.clone().convertSRGBToLinear(); - lineColor = colors.outline.clone().convertSRGBToLinear(); }); }); @@ -35,6 +32,7 @@ import { CubicBezierCurve } from 'three/src/extras/curves/CubicBezierCurve.js'; import { Vector2 } from 'three/src/math/Vector2.js'; import { getGraphState } from '../graph-state.svelte'; + import MeshGradientLineMaterial from './MeshGradientLine/MeshGradientLineMaterial.svelte'; const graphState = getGraphState(); @@ -45,12 +43,17 @@ y2: number; z: number; id?: string; + inputType?: string; + outputType?: string; }; - const { x1, y1, x2, y2, z, id }: Props = $props(); + const { x1, y1, x2, y2, z, inputType = 'unknown', outputType = 'unknown', id }: Props = $props(); const thickness = $derived(Math.max(0.001, 0.00082 * Math.exp(0.055 * z))); + const inputColor = $derived(graphState.colors.getColor(inputType)); + const outputColor = $derived(graphState.colors.getColor(outputType)); + let points = $state([]); let lastId: string | null = null; @@ -106,9 +109,9 @@ position.z={y1} position.y={0.8} rotation.x={-Math.PI / 2} - material={circleMaterial} > + + {#if graphState.hoveredEdgeId === id} @@ -126,7 +130,8 @@ @@ -135,5 +140,10 @@ - + diff --git a/app/src/lib/graph-interface/edges/MeshGradientLine/MeshGradientLineMaterial.svelte b/app/src/lib/graph-interface/edges/MeshGradientLine/MeshGradientLineMaterial.svelte index d30a38a..8b212da 100644 --- a/app/src/lib/graph-interface/edges/MeshGradientLine/MeshGradientLineMaterial.svelte +++ b/app/src/lib/graph-interface/edges/MeshGradientLine/MeshGradientLineMaterial.svelte @@ -23,6 +23,7 @@ let { invalidate, size } = useThrelte(); + // svelte-ignore state_referenced_locally const uniforms = { lineWidth: { value: width }, colorStart: { value: new Color(colorStart) }, diff --git a/app/src/lib/graph-interface/graph-state.svelte.ts b/app/src/lib/graph-interface/graph-state.svelte.ts index a62fac5..50018d0 100644 --- a/app/src/lib/graph-interface/graph-state.svelte.ts +++ b/app/src/lib/graph-interface/graph-state.svelte.ts @@ -3,6 +3,7 @@ import { getContext, setContext } from 'svelte'; import { SvelteMap, SvelteSet } from 'svelte/reactivity'; import type { OrthographicCamera, Vector3 } from 'three'; import type { GraphManager } from './graph-manager.svelte'; +import { ColorGenerator } from './graph/colors'; import { getNodeHeight, getSocketPosition } from './helpers/nodeHelpers'; const graphStateKey = Symbol('graph-state'); @@ -28,7 +29,32 @@ type EdgeData = { points: Vector3[]; }; +const predefinedColors = { + path: { + hue: 80, + lightness: 20, + saturation: 80 + }, + float: { + hue: 70, + lightness: 10, + saturation: 0 + }, + geometry: { + hue: 0, + lightness: 50, + saturation: 70 + }, + '*': { + hue: 200, + lightness: 20, + saturation: 100 + } +} as const; + export class GraphState { + colors = new ColorGenerator(predefinedColors); + constructor(private graph: GraphManager) { $effect.root(() => { $effect(() => { diff --git a/app/src/lib/graph-interface/graph/Graph.svelte b/app/src/lib/graph-interface/graph/Graph.svelte index 48a9304..2ecaea5 100644 --- a/app/src/lib/graph-interface/graph/Graph.svelte +++ b/app/src/lib/graph-interface/graph/Graph.svelte @@ -95,6 +95,13 @@ graphState.activeSocket = null; graphState.addMenuPosition = null; } + + function getSocketType(node: NodeInstance, index: number | string): string { + if (typeof index === 'string') { + return node.state.type?.inputs?.[index].type || 'unknown'; + } + return node.state.type?.outputs?.[index] || 'unknown'; + } = new Map(); + private lightnessLevels = [10, 60]; + + constructor(predefined: Record) { + for (const [id, colorStr] of Object.entries(predefined)) { + this.colors.set(id, colorStr); + } + } + + public getColor(id: string): string { + if (this.colors.has(id)) { + return this.colorToHsl(this.colors.get(id)!); + } + + const newColor = this.generateNewColor(); + this.colors.set(id, newColor); + console.log(id, newColor); + return this.colorToHsl(newColor); + } + + private generateNewColor(): Color { + const existingHues = Array.from(this.colors.values()).map(c => c.hue).sort(); + let hue = existingHues[0]; + let attempts = 0; + + while ( + existingHues.some(h => Math.abs(h - hue) < 30 || Math.abs(h - hue) > 330) + && attempts < 360 + ) { + hue = (hue + 30) % 360; + attempts++; + } + + const lightness = 60; + + return { hue, lightness, saturation: 100 }; + } + + private colorToHsl(c: Color): string { + return `hsl(${c.hue}, ${c.saturation}%, ${c.lightness}%)`; + } +} diff --git a/app/src/lib/graph-interface/node/NodeHeader.svelte b/app/src/lib/graph-interface/node/NodeHeader.svelte index 5532b17..c82fa59 100644 --- a/app/src/lib/graph-interface/node/NodeHeader.svelte +++ b/app/src/lib/graph-interface/node/NodeHeader.svelte @@ -1,6 +1,6 @@
@@ -96,10 +107,10 @@ width: 30px; height: 30px; border-radius: 100%; - box-shadow: 0px 0px 10px var(--color-layer-3); - background-color: var(--color-layer-3); - outline: solid thin white; - opacity: 0.2; + box-shadow: 0px 0px 10px var(--socket-color); + background-color: var(--socket-color); + outline: solid thin var(--socket-color); + opacity: 0.7; z-index: -10; } diff --git a/app/src/lib/graph-interface/node/NodeParameter.svelte b/app/src/lib/graph-interface/node/NodeParameter.svelte index 6cd890b..8d3d8a7 100644 --- a/app/src/lib/graph-interface/node/NodeParameter.svelte +++ b/app/src/lib/graph-interface/node/NodeParameter.svelte @@ -1,5 +1,5 @@
{#key id && graphId} @@ -95,10 +107,8 @@ xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="none" - style={` - --path: path("${path}"); - --hover-path: path("${pathHover}"); - `} + style:--path={`path("${path}")`} + style:--hover-path={`path("${pathHover}")`} > @@ -126,10 +136,10 @@ width: 30px; height: 30px; border-radius: 100%; - box-shadow: 0px 0px 10px var(--color-layer-3); - background-color: var(--color-layer-3); - outline: solid thin white; - opacity: 0.2; + box-shadow: 0px 0px 10px var(--socket-color); + background-color: var(--socket-color); + outline: solid thin var(--socket-color); + opacity: 0.5; z-index: -10; }