b3d-skybox
Procedural sky with sun/moon cycle driven by time of day. Automatically controls
a b3dSun sibling's direction, intensity, and color.
Demo
import { b3d, b3dSun, b3dSkybox, b3dGround, b3dBox, b3dSphere, label3d, slider3d } from 'tosijs-3d'
import { tosi } from 'tosijs'
const { sky } = tosi({ sky: { timeOfDay: 17 } })
const scene = b3d(
{
scenePanel: () => [
label3d({ text: 'Sky' }),
slider3d({ label: 'time of day', value: sky.timeOfDay, min: 0, max: 24, step: 0.5 }),
],
sceneCreated(el, BABYLON) {
const camera = new BABYLON.ArcRotateCamera(
'cam', -Math.PI / 2, Math.PI / 3, 15,
new BABYLON.Vector3(0, 0, 0), el.scene
)
camera.attachControl(el.querySelector('canvas'), true)
el.setActiveCamera(camera)
},
},
b3dSun(),
b3dSkybox({ timeOfDay: sky.timeOfDay, realtimeScale: 0, latitude: 40 }),
// A checkered ground (receives shadows) + a few casters — scrub the time of
// day and watch the shadows swing long at dawn/dusk and short at noon.
b3dGround({ width: 20, height: 20, texture: 'checker', textureTiles: 10 }),
b3dBox({ meshName: 'pillar', size: 1.5, x: -3, y: 0.75, z: 1, color: '#c85a3a' }),
b3dBox({ meshName: 'crate', size: 1, x: 2, y: 0.5, z: 3, color: '#5aa0c8' }),
b3dSphere({ meshName: 'ball', diameter: 2, x: 3, y: 1, z: -2, color: '#c8a83a' }),
)
preview.append(scene)
Attributes
| Attribute | Default | Description |
|---|---|---|
timeOfDay |
6.5 |
0-24 hours |
realtimeScale |
10 |
Realtime speed multiplier |
latitude |
40 |
Geographic latitude (affects sun arc) |
turbidity |
10 |
Atmospheric haze |
rayleigh |
2 |
Rayleigh scattering |
sunColor |
'#eeeeff' |
Midday sun color |
duskColor |
'#ffaa22' |
Dawn/dusk sun color |
moonColor |
'#6688cc' |
Night light color |
moonIntensity |
0.15 |
Night light intensity |
applyFog |
false |
Whether scene fog affects the skybox |