Overview
Threadbox integrates with Mapbox GL JS’s sky and terrain layers to create immersive 3D environments. The sky layer simulates atmospheric perspective and sun position, while terrain adds elevation data for realistic landscapes.Sky Layer
Basic Sky Setup
Enable the atmospheric sky layer:- Shows atmospheric gradient
- Positions sun based on time and location
- Automatically updates with
realSunlight
Manual Sky Creation
Sky Configuration
Threadbox uses Mapbox’s sky layer with automatic sun positioning:Update Sky Position
Manually update sky with sun position:Get Sun Sky Position
Sky Layer Properties
Access the sky layer:Toggle Sky Layer
Terrain Layer
Basic Terrain Setup
Enable 3D terrain with elevation:Manual Terrain Creation
Terrain Configuration
Threadbox uses Mapbox’s terrain with automatic source creation:Custom Terrain Source
Add custom DEM (Digital Elevation Model) source:Update Terrain Lighting
Adjust terrain brightness based on sun:Toggle Terrain
Combined Sky & Terrain
Complete Setup
Time-of-Day Animation
Animate sun, sky, and terrain through the day:Location-Based Sky
Update sky when map moves:Advanced Configuration
Custom Sky Properties
Modify Mapbox sky layer directly:Terrain Exaggeration
Increase elevation for dramatic effect:Sky Gradient
Customize atmospheric gradient:Performance Optimization
Conditional Loading
Only enable sky/terrain when map pitch > 30° to save resources on 2D views
Update Frequency
Update sun position every 1-5 minutes, not every frame
Terrain LOD
Terrain automatically uses level-of-detail. Adjust maxzoom for performance.
Disable When Hidden
Set
sky: false and terrain: false when not visibleComplete Example
Troubleshooting
Sky not visible
Sky not visible
- Ensure map pitch is > 0 (sky only visible in 3D view)
- Check
tb.sky === true - Verify sky layer exists:
map.getLayer(tb.skyLayerName) - Make sure Mapbox GL JS version supports sky (v2.0+)
Terrain not loading
Terrain not loading
- Verify terrain source is added before setting terrain
- Check Mapbox GL JS version supports terrain (v2.0+)
- Ensure
tb.terrain === true - Verify you have a valid Mapbox access token
Sky/terrain not syncing with sun
Sky/terrain not syncing with sun
- Enable
realSunlight: truein Threebox options - Manually call
tb.updateSunSky()andtb.updateSunGround() - Verify date/coordinates are valid
See Also
- Shadows & Lighting - Sun simulation and shadows
- Threebox Instance - Threebox initialization
- Mapbox Terrain - Mapbox terrain documentation
- Mapbox Sky - Mapbox sky layer documentation