This page documents the core public surface of @realsee/five β the classes, enums, interfaces, and events you'll touch in every integration. It's organized as a class reference, not an alphabetic dump: methods you call together are listed together.
Curated reference
The page below is hand-curated against the SDK's public TypeScript declarations and focuses on the integration surface used by production embeds.
class Five
Five is the only class you instantiate. One instance owns one <canvas> and renders one work at a time.
import { Five, parseWork } from '@realsee/five'
const five = new Five(args: FiveInitArgs)new Five(args)
| Argument | Type | Description |
|---|---|---|
args | FiveInitArgs | Initialization options. See FiveInitArgs. |
Constructs a renderer. Side effects: none until you call load or appendTo. Safe to construct off the main render path.
.load(work)
five.load(work: Work): Promise<void>Loads a parsed Realsee Work and prepares it for rendering. Parse JSON with parseWork(workJSON) before calling load. You can call load again later to swap the loaded work.
| Argument | Type | Description |
|---|---|---|
work | Work | A Work returned by parseWork(workJSON). The JSON may come from @realsee/open-works or your server-side OpenAPI integration. |
.appendTo(container)
five.appendTo(container: HTMLElement): voidMounts the renderer's <canvas> as a child of container. The container must have a non-zero size at call time β Five SDK reads clientWidth / clientHeight to size the canvas.
.refresh()
five.refresh(): voidRe-measures the container and updates the canvas, projection matrix, and renderer viewport. Call this whenever the container's size changes (window resize, sidebar open, orientation change).
.changeMode(mode, config?)
five.changeMode(mode: Five.Mode, config?: { transition?: boolean }): voidTransitions the camera to the requested mode. By default the SDK animates between modes; pass { transition: false } to jump instantly.
| Argument | Type | Description |
|---|---|---|
mode | Five.Mode | Target mode. See Five.Mode. |
config | object | Optional transition options. |
.getCurrentState()
five.getCurrentState(): {
mode: Five.Mode
panoIndex: number
// β¦additional camera and pose fields
}Returns a snapshot of the renderer's current state. The shape is stable across mode transitions β fields not relevant to the active mode are still defined, just with sentinel values.
.on(event, handler) / .off(event, handler)
five.on<E extends FiveEvent>(event: E, handler: FiveEventHandler<E>): void
five.off<E extends FiveEvent>(event: E, handler: FiveEventHandler<E>): voidSubscribe / unsubscribe to renderer events. See Events for the full list and payload shapes. Handlers are called synchronously on the event's source frame.
.dispose()
five.dispose(): voidReleases GPU resources, removes the <canvas> from the DOM, detaches global event listeners, and stops the render loop. Call this from your framework's teardown hook (React's useEffect cleanup, Vue's onBeforeUnmount) when navigating away in an SPA β otherwise you will leak WebGL contexts. After dispose, the instance is unusable; construct a new one to render again.
enum Five.Mode
The three viewing modes. Pass these to changeMode and read them out of getCurrentState().mode.
| Value | Description |
|---|---|
Five.Mode.Panorama | First-person panorama view at a captured point. Default mode after load. |
Five.Mode.Floorplan | Top-down floorplan view of the captured space. |
Five.Mode.Modeling | Orbit camera around the textured 3D mesh. Useful for surveying the whole space at once. |
interface FiveInitArgs
Initialization options passed to new Five(args). Every field is optional; the defaults below are tuned for the typical web embed.
interface FiveInitArgs {
imageOptions?: ImageOptions
textureOptions?: TextureOptions
backgroundAlpha?: number
initWithTransition?: boolean
onlyRenderIfNeeds?: boolean
initialBasisLoader?: boolean
floorplan?: ModeViewOptions
panorama?: ModeViewOptions
plugins?: FivePlugin[]
}| Field | Type | Default | Description |
|---|---|---|---|
imageOptions | ImageOptions | { size: 512 } | Panorama image loader settings. size: 512 enables tile-based progressive loading. |
textureOptions | TextureOptions | { autoResize: true } | Mesh-texture loader settings. Set autoResize: false for crisp meshes on high-end devices. |
backgroundAlpha | number | 1 | Canvas clear-alpha. 0 makes the canvas transparent β useful when overlaying UI behind the renderer. |
initWithTransition | boolean | true | Animate the initial camera into place. Set to false to start instantly on the first panorama. |
onlyRenderIfNeeds | boolean | true | Render frames only when the scene actually changed. Leave on unless you're driving an external animation that needs every frame. |
initialBasisLoader | boolean | false | Pre-load the Basis texture transcoder. Only needed if your works use Basis-compressed textures; defaults to off to save bandwidth. |
floorplan | ModeViewOptions | {} | Per-mode camera bounds such as latitude limits and default field of view. |
panorama | ModeViewOptions | {} | Per-mode camera bounds for panorama view. |
plugins | FivePlugin[] | [] | Optional Five SDK plugins (tag layers, floorplan overlays, custom hot-zones). Plugins are owned by their respective Realsee packages. |
ImageOptions
interface ImageOptions {
size?: 512 | 1024 | 2048 | 4096 | 8192
quality?: number // 0β100
format?: 'jpg' | 'png' | 'webp' | 'avif' | 'heif'
transform?: (source: string, opts: TransformOptions) => string
}The transform hook lets you proxy panorama URLs through an image-CDN (Alibaba Cloud OSS, Tencent COS, your own service). Five SDK calls it for every tile fetch.
TextureOptions
interface TextureOptions {
size?: number | null
autoResize?: boolean
}size: null plus autoResize: false loads the full-resolution mesh texture β the crispest result, but expensive on memory.
Events
Subscribe with five.on(event, handler). The table covers the events you'll use most often; package typings remain the source of truth for less-common renderer events.
| Event | Payload | When it fires | |
|---|---|---|---|
modeChange | (mode: Five.Mode) | After a changeMode transition completes. The argument is the new mode. | |
cameraUpdate | (camera: { position, target, fov }) | On every frame where the camera changed. High-frequency β debounce if needed. | |
tap | (event: { x, y, intersect }) | User tapped / clicked inside the canvas. intersect contains the 3D hit info, or null if the tap missed the scene. | |
dragStart | () | The user started a drag gesture on the canvas. | |
dragEnd | () | The user released a drag gesture. | |
wantsTapGesture | `(intent: 'panorama' \ | 'floorplan')` | The user tapped in a way that suggests they want to enter another mode. Useful for "tap floor to walk there" interactions. |
panoIndexChange | (index: number) | The active panorama point changed (the user walked to a new capture point). |
Unsubscribe with five.off(event, handler) using the same handler reference you registered. Anonymous handlers cannot be removed individually; pass a named function if you need to detach.
See also
- Quickstart β a working integration in five minutes.
- Playground β render the bundled Demo scene or a VR from an accessible Viewing Team.
