#obsidian #architecture #visualization #plugins

Visualizing Thought: Architecting the 3D Graph

A dissection of the Obsidian 3D Graph plugin—transitioning from 2D maps to a spatial UI, resolving CSS color architecture, and engineering a live physics engine.

The standard Obsidian graph is a flat projection. It is a fantastic map for early note-making, but as a vault expands into thousands of interconnected nodes, the two-dimensional plane becomes a limitation. The network requires a Z-axis.

This necessity led to the architecture of the 3D Graph plugin—an instrument designed to transform a static database into a living, navigable space.

The Instrument

At its core, the 3D Graph plugin forces the Obsidian vault out of its flat constraints. It renders documents and their links as nodes in a dynamic, force-directed universe. The observer can rotate, pan, and zoom through the architecture of their own thought.

The objective was not just visual flair, but functional high-level oversight: discovering unexpected constellations of data, identifying dense clusters, and isolating orphaned notes.

Key Mechanics:

  • Spatial Rendering: Live, interactive exploration of the network.
  • Granular Filtering: Real-time isolation by search syntax, tags, paths, and link status.
  • Parametric Styling: Custom node sizing and rule-based chromatic assignments.
  • The Control Panel: A floating interface to manipulate the graph's physical laws (gravity, repulsion, link distance) without breaking visual contact with the render.

Engineering the Physics

Building this instrument introduced immediate friction between standard web technologies and the Obsidian rendering engine. Two distinct architectural challenges required novel solutions.

Challenge I: The Chromatic Conundrum

The Friction: The plugin initially relied on getComputedStyle to extract colors from the user's active Obsidian theme. However, modern CSS themes utilize complex color spaces and mixed variables (e.g., color-mix(in srgb, blue 40%, white) or lab(64 0.01 -0.0008)). Three.js, the underlying WebGL engine, requires absolute, predictable hex or RGB values. It cannot interpret CSS equations.

The Solution: The extraction of pigment from the void required a secondary rendering pass. I engineered an invisible <canvas> to force the browser to compute the final absolute color.

// Extracting absolute RGB from complex CSS variables
function getCssColor(variable, fallback) {
    const tempEl = document.createElement('div');
    tempEl.style.color = `var(${variable})`;
    document.body.appendChild(tempEl);
    const computedColor = getComputedStyle(tempEl).color;
    document.body.removeChild(tempEl);

    const canvas = document.createElement('canvas');
    canvas.width = 1;
    canvas.height = 1;
    const ctx = canvas.getContext('2d');
    
    ctx.fillStyle = computedColor; 
    ctx.fillRect(0, 0, 1, 1);

    const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data;
    return `rgb(${r}, ${g}, ${b})`;
}

The browser's native engine resolves the math, paints a single pixel, and we extract the absolute RGB data. Clean, dependency-free, and universally compatible.

Challenge II: The Live Control UI

The Friction: Initially, parameters were adjusted in Obsidian's global settings menu. Modifying a physics slider required navigating away from the graph, adjusting a blind variable, and returning to observe the result. It was a disjointed loop.

The Solution: The architecture demanded a localized, heads-up display.

  • Dynamic Construction: Using Obsidian's internal UI API (Setting, addSlider), a floating panel is instantiated at runtime directly above the canvas.
  • Immediate Binding: Adjusting a variable (like repulsion force) fires an update directly to the d3Force engine, recalculating node positions without tearing down the renderer.
  • Caching: To maintain high framerates during live manipulation, expensive operations—like the canvas color extraction—are cached after the initial frame.

The Open Vault

The 3D Graph remains a living instrument. It is currently being utilized and modified by the broader Obsidian community, proving that the tools we use to think should be as malleable as the thoughts themselves.

The Repository Archive

A.G.