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, 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 }),
  b3dGround({ width: 20, height: 20 }),
)
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