3D Feature Development
When to Use
- Adding new rendering capabilities (post-processing, shadows, new material types)
- Adding or modifying dat.gui control panels
- Changing camera behavior or adding camera modes
- Adding new loaders or asset format support
- Modifying lighting, environment maps, or tone mapping
- Adding display toggles (wireframe, skeleton, grid, etc.)
- Animation playback features or morph target controls
Key File: src/viewer.js
The Viewer class manages all Three.js rendering. Key sections:
State Object
All GUI-controllable state lives in this.state (defined in constructor). To add a new toggle:
- Add default value to
this.state - Add GUI control in the appropriate
addGUI()subfolder - Add the handler method on the
Viewerclass
GUI Folders
dat.gui controls are organized into folders created in addGUI():
- Lights — Ambient/directional intensity, punctual lights, exposure, tone mapping
- Display — Wireframe, skeleton, grid, axes, auto-rotate, background
- Animation — Playback speed, individual clip controls, morph targets
- Cameras — Default + scene cameras
Loaders
| Loader | Purpose | CDN Path |
|---|---|---|
GLTFLoader |
glTF/GLB models | Built-in Three.js |
DRACOLoader |
Compressed geometry | unpkg.com/three@.../draco/gltf/ |
KTX2Loader |
Basis textures | unpkg.com/three@.../basis/ |
MeshoptDecoder |
Meshopt geometry | Built-in Three.js |
EXRLoader |
HDR environment maps | Built-in Three.js |
Environment Maps
Defined in src/environments.js as an array of { id, name, path, format } objects. To add a new environment:
- Add entry to the array in
environments.js - The viewer auto-discovers it via the
environmentsimport
Procedure
- Identify which section of
src/viewer.jsto modify - For new GUI controls: add state → add GUI control → add handler
- For new loaders: import from
three/addons/, configure in constructor - For new environments: add to
src/environments.js - Test with
npm run devathttp://localhost:3000 - Test with various glTF models (drag-and-drop or
?model=param)
Three.js Patterns Used
PMREMGeneratorfor environment map preprocessingAnimationMixerfor animation playback withclipAction()OrbitControlsfor camera interactionBox3for model bounding box / auto-framingtraverse()for material/mesh iterationLoadingManagerfor coordinated asset loading