UI / Decor
3D Room
A cosy 3D bedroom studio in three.js: drag to look around, day and night from the visitor's clock, a light switch, curtains, two desks, a bed, plushies and little figures to find.
Installation
npx shadcn@latest add https://jiaweing.com/r/room.jsonWith the @jiaweing namespace set up, use @jiaweing/room in place of the URL.
Usage
tsx
import { Room } from "@/components/room/room";tsx
<div className="h-[480px] w-full">
<Room time="auto" />
</div>- Drag to turn the room, pinch or scroll to zoom, and press things to set them off. Escape puts down whatever is picked up.
- three.js is only fetched in the browser, once the room is on the page. Nothing is drawn while it is scrolled out of sight.
- For visitors who ask for reduced motion, nothing moves on its own and the camera cuts instead of gliding.
- The room keeps its WebGL context only while it is mounted, and lets it go on unmount.
Props
Room
| Prop | Type | Default | Description |
|---|---|---|---|
| time | "auto" | "day" | "night" | "auto" | auto follows the visitor's clock: dawn 6 to 8, day 8 to 18, dusk 18 to 20, night after that. |
| lights | boolean | - | Every light in the room, on or off. Set it to control the lights yourself. |
| defaultLights | boolean | true | Where the lights start when lights is not set. |
| onLightsChange | (on: boolean) => void | - | The light switch by the door was pressed. |
| name | string | "MY ROOM" | The name on the sign over the door. |
| festive | boolean | false | Dresses the room up: a tree, lights, Santa hats and snow outside. |
| onHover | (id: string | null) => void | - | The thing under the pointer, by id, such as bed. |
| onSelect | (id: string) => void | - | A thing in the room was pressed, by id. |
| label | string | - | What screen readers say for the room. |
| className | string | - | Classes on the wrapper. It fills its parent, so give the parent a height. |
MIT licensed. Copy it, change it, ship it.