Overview
The 3D scene uses image-based lighting (IBL) that automatically reflects the time of day on the visitor’s device. When the page loads, the current hour is read fromnew Date() and mapped to one of five @react-three/drei Environment presets. Visitors can also manually change the time period via a dropdown in the UI overlay.
The getPeriodOfDay function
The mapping from hour to preset is defined in Home.jsx:
src/pages/Home.jsx
<Environment preset={...} />.
Hour-to-preset mapping
| Hour range | Environment preset | Display label |
|---|---|---|
| 5:00 – 6:59 | sunset | Dawn |
| 7:00 – 11:59 | park | Morning |
| 12:00 – 16:59 | warehouse | Evening |
| 17:00 – 18:59 | dawn | Dusk |
| 0:00 – 4:59 and 19:00 – 23:59 | night | Night |
The display labels shown in the UI overlay differ from the underlying preset names. For example, the
sunset preset is labelled “Dawn” in the interface because it produces soft, low-angle warm light appropriate for early morning.State initialization and the real-time clock
BothperiodOfDay and the displayed clock are initialized from new Date() and updated every second with setInterval:
src/pages/Home.jsx
currentTime, while periodOfDay is only recalculated when the user manually selects a different time period or when the page first loads.
Changing the time period
When the user selects a different time period from the dropdown, the scene does not switch immediately. Instead, a brief transition plays first:changingTimestate is set totrue.- The
<Canvas>is unmounted and replaced by<ChangingTimeOverlay />. - The overlay displays a clock GIF (
clock.gif) on a black background for approximately 2 seconds. - After the timeout,
changingTimeis set tofalseandperiodOfDayis updated to the new value. - The
<Canvas>remounts with the new environment preset.
src/pages/Home.jsx
Applying the preset
InsideComputer.jsx, the periodOfDay prop is forwarded directly to the <Environment> component:
src/models/Computer.jsx
@react-three/drei’s Environment component loads the corresponding HDRI from its built-in set and applies it as the scene’s background and lighting source. No additional configuration is required — swapping the preset string is sufficient to change the entire scene’s look and feel.
Available presets reference
sunset
sunset
Warm orange and pink tones. Used for the 5–7 AM “Dawn” period. Low-angle directional light simulating a sun just above the horizon.
park
park
Bright, neutral daylight with green ambient fill from foliage. Used for the 7 AM–12 PM “Morning” period.
warehouse
warehouse
Cool industrial lighting with high contrast. Used for the 12–5 PM “Evening” period.
dawn
dawn
Soft blue-purple twilight. Used for the 5–7 PM “Dusk” period.
night
night
Dark environment with minimal ambient light. Used for all hours outside the four named periods (7 PM–5 AM).