Documentation is work in progress and not completeEditor
3D System

File Structure

The 3D system lives in src/3d/. Core logic is plain TypeScript classes and pure functions; the React layer is a thin shell that mounts them. This page maps every file to its responsibility and exports.

Core 3D Files

FileResponsibility
types.tsCentral type definitions and default constants for the entire 3D system. Defines every interface and enum, plus all DEFAULT_* config objects.
ThreeDShapeElement.tsTop-level facade. Each instance owns one ThreeDEngine and provides the public API consumed by ThreeDShapeRenderer.
ThreeDEngine.tsCreates and manages the WebGLRenderer, Scene, Camera, OrbitControls, lights and render loop. Delegates shape management to SceneManager and gizmo management to GizmoController.
SceneManager.tsMaintains the registry of 3D objects in a scene. Handles add, remove, select, raycast, transform, material and geometry updates.
GizmoController.tsWraps Three.js TransformControls. Manages attach/detach, mode switching and the OrbitControls conflict.
GeometryFactory.tsPure functions that create BufferGeometry instances from a GeometryConfig. Supports all six primitives plus SVG extrusion.
MaterialSystem.tsCreates and updates Three.js materials from a MaterialConfig. Handles texture loading, caching and disposal.
ModelLoader.tsLoads external 3D model files. Handles format detection, loader instantiation, normalization and object-URL lifecycle.
SceneSerializer.tsSerializes engine scene state to a JSON-safe snapshot and restores it on load.

React UI Components

FileResponsibility
ThreeDShapeRenderer.tsxMounts a ThreeDShapeElement into a DOM container. Manages element lifecycle, resize syncing, interaction mode and visibility-based pause/resume.
ThreeDPropertiesPanel.tsxThe properties panel shown when a 3D shape is selected. Controls canvas position, gizmo mode, 3D transform, geometry, material type, material properties and texture maps.
ThreeDShapePicker.tsxModal for choosing a primitive or importing a model. Shows a grid of six shape cards with a live 3D preview.
ThreeDShapePreview.tsxSelf-contained auto-rotating preview renderer used inside the picker. Creates a temporary engine, adds the primitive and orbits the camera.

Integration Points Outside src/3d/

File3D Relevance
src/types/design.tsDefines the threeDMetadata, threeDGeometryType and threeDSceneState fields on DesignElement (lines 200-205).
src/components/design-tool/Canvas.tsxRenders ThreeDShapeRenderer for every threed-shape element. Controls pointer-event routing via activeThreeDElementId.
public/draco/gltf/Draco decoder WASM files required by DRACOLoader.

Dependency Graph

types.ts  <-----------------------------------------------+
  ^                                                      |
  +-- GeometryFactory.ts <- MaterialSystem.ts            |
  |         ^                     ^                      |
  |         +------ SceneManager.ts ------------+        |
  |                       ^                     |        |
  |              ThreeDEngine.ts <- GizmoController.ts   |
  |                       ^                              |
  |              SceneSerializer.ts ---------------------+
  |                       ^
  |              ThreeDShapeElement.ts
  |                       ^
  |         +-------------+--------------+
  |         |             |              |
  |  ThreeDShapeRenderer  |  ThreeDPropertiesPanel
  |         |             |
  |         |    ThreeDShapePicker
  |         |             |
  |         |    ThreeDShapePreview
  |         |
  |    Canvas.tsx (design-tool)
  |
  +-- design.ts (types)