The 3D feature system enables users to embed live, interactive Three.js viewports directly into the 2D design canvas. Each 3D shape behaves like any other canvas element — it can be repositioned, resized, layered, have its opacity adjusted, and participate in the animation timeline — but internally it contains a fully independent Three.js scene where users can place, transform, and material-paint 3D primitives or imported models.
The core architectural idea is called the snapshot-bridge. Every 3D shape on the 2D canvas is a live Three.js renderer embedded as an HTML <canvas> element inside a <div> that is absolutely positioned within the 2D canvas artboard. The 2D canvas system controls where the 3D viewport sits (position, size, rotation, opacity), while the Three.js renderer controls what is drawn inside it.
This approach was chosen over two alternatives:
┌─────────────────────────────────────────────────┐
│ 2D Canvas (Artboard) │
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ <div> host │ │ <div> host │ │
│ │ ┌──────────────┐ │ │ ┌──────────────┐ │ │
│ │ │ WebGLRenderer │ │ │ │ WebGLRenderer │ │ │
│ │ │ <canvas> │ │ │ │ <canvas> │ │ │
│ │ │ │ │ │ │ │ │ │
│ │ │ Scene │ │ │ │ Scene │ │ │
│ │ │ Camera │ │ │ │ Camera │ │ │
│ │ │ OrbitCtrl │ │ │ │ OrbitCtrl │ │ │
│ │ └──────────────┘ │ │ └──────────────┘ │ │
│ │ ThreeDShapeElem │ │ ThreeDShapeElem │ │
│ └──────────────────┘ └──────────────────┘ │
│ │
│ CSS transform on artboard handles zoom/pan │
└─────────────────────────────────────────────────┘The bridge between the 2D world and the 3D world is the DesignElement type. Every 2D element with type === 'threed-shape' stores three optional 3D fields:
| Field | Type | Purpose |
|---|---|---|
| threeDMetadata | ThreeDMetadata | Serialized scene snapshot metadata for project save/load |
| threeDGeometryType | GeometryType | The primitive type the shape was created with (e.g. 'box') |
| threeDSceneState | SceneStateSnapshot | Live scene state used for persistence and restoration |
These fields are defined in src/types/design.ts (lines 200-205).