import { AppBase, EventHandler } from 'playcanvas'; /** * Asset urls an embedder supplies. Shared by the two ways of instantiating the viewer — as * fields of {@link CreateViewerOptions} in a page, and serialised into a generated document by * `renderViewerHtml` — so the two surfaces cannot drift. */ type ViewerAssets = { /** Splat url. May be a `data:` uri, for a document with no sibling files. */ contentUrl: string; /** * Filename describing {@link ViewerAssets.contentUrl}, e.g. `scene.sog`. The splat format * is chosen by the name's extension, so this is required when the url itself has no usable * name — a `data:` uri. */ contentFilename?: string; /** Poster image shown, blurred, while the splat loads. */ posterUrl?: string; /** Equirectangular skybox texture url. */ skyboxUrl?: string; /** Collision data url, for walk mode. A `.glb` is treated as a mesh, otherwise voxels. */ collisionUrl?: string; /** * The gsaf decoder's wasm, fetched only when the content is a `.gsaf` file. Defaults to the * `gsaf-decoder.wasm` shipped beside the viewer's bundle. A document with no sibling files * (an inlined bundle) sets it to the `data:` url the `@playcanvas/supersplat-viewer/gsaf-decoder` * export provides. */ gsafDecoderUrl?: string; /** * The ZSTD decoder's wasm, fetched only when a version 4 `.spz` file loads, on its own or as * a chunk of an `.lcc2` scene. Defaults to the `zstd-decoder.wasm` shipped beside the viewer's * bundle. A document with no sibling files (an inlined bundle) sets it to a `data:` url. */ zstdDecoderUrl?: string; }; /** Per-instance switches. Every one is optional and off unless stated. */ type ViewerFlags = { /** * Requested renderer; the engine falls back to WebGL when WebGPU is unavailable. Default * `webgpu`. */ renderer?: 'webgl' | 'webgpu'; /** * Build the viewer's ui: the controls, panels, poster, loading bar, annotation hotspots * and their navigator. Defaults to `true`. `false` is the headless level: the canvas and * the api, with no overlay markup. Core camera input, browser integration and preference * persistence remain active. The host renders controls against the public handle; * `setMoveInput` supports a replacement joystick. Note that the touch joystick and the AR/VR * fallback prompt live in that ui, so a headless host owns those affordances too. */ ui?: boolean; /** Show the centre reticle in desktop fly/walk mode with gaming controls. Defaults to `false`. */ reticle?: boolean; /** Start with the camera animation paused. */ noanim?: boolean; /** Disable post effects. */ nofx?: boolean; /** Override the settings' `highPrecisionRendering`. */ hpr?: boolean; /** Show the engine's MiniStats panel. */ ministats?: boolean; /** Render with LOD colorisation. */ colorize?: boolean; /** Load all streaming LOD data before the first frame. */ fullload?: boolean; /** * Offer VR at once: where VR can start, a prompt shows over the viewer while it loads, and a * tap on it starts a VR session as soon as the scene is placed, the rest of the scene streaming * in during the session; a tap elsewhere dismisses it. A session needs a tap: browsers start * none without one. The camera animation starts paused, as with `noanim`. Needs the ui. * Defaults to `false`. */ vr?: boolean; /** * Override the anti-aliasing compensation that splats trained with anti-aliasing need: `true` * renders every splat with it, `false` without. When not set, the engine follows the training * mode each splat file records (PlayCanvas Engine 2.24 and later). */ aa?: boolean; /** * Developer override of the Performance Mode setting: `true` forces the stochastic splat * renderer (unsorted, depth-tested splats whose depth buffer also serves picking) in its * per-pixel mode, `'mobile'` in its interleaved-pixel-sets mode, and `'off'` keeps the * engine's sorted renderer; each hides the setting. Without it the user's Performance Mode * toggle decides, and the device class picks the mode. WebGPU only; ignored on WebGL. The * renderer draws WebGPU XR sessions too, one view per eye (Safari on Apple Vision Pro); where * only WebGL could host a session, the viewer offers a reload into WebGL. */ stochastic?: boolean | 'mobile' | 'off'; /** * Developer knob for the stochastic renderer: the data path that feeds it. Default * `direct`, the resident files read in place; `workbuffer` reads the engine's work buffer. */ splatSource?: 'workbuffer' | 'direct'; /** * Developer knob for the stochastic renderer: comma-separated `key:value` experiment * switches applied over the chosen mode's, e.g. `coverage:interleaved,jitter:2`. */ variant?: string; /** Splat budget in millions, overriding the Quality slider's ladder (every position then gives it). */ budget?: number; /** * Developer knob: while the viewer renders on demand, the most rendered frames the gpu may * have unfinished before the next continuous render (the camera moving, the stochastic * renderer accumulating) waits for one to finish; `0` lets them queue. Defaults to `2`. */ framesInFlight?: number; /** Render the collision heatmap debug overlay (WebGPU only). */ heatmap?: boolean; /** Open the developer debug panel on load; Ctrl+Shift+D toggles it either way. */ debug?: boolean; /** Ui language. Default: detected from the browser. */ lang?: string; /** * Publish `window.app`, `scrubTo`, `captureFrame`, `animationDuration` and the debug panel's * camera-state hooks. The standalone document turns this on for the thumbnail pipeline; an * embedded instance leaves it off, since two viewers would overwrite each other's. */ exposeGlobals?: boolean; }; /** Options for `createViewer`. */ type CreateViewerOptions = ViewerAssets & ViewerFlags & { /** The element the viewer builds its subtree in. The host sizes it; the viewer fills it. */ container: HTMLElement; /** * Experience settings: an object in any version the viewer reads, a promise of that * object, or a url to fetch them from, resolved against the document. The poster is * shown while settings are pending. */ settings: object | Promise | string; /** * An already-created poster image, instead of {@link ViewerAssets.posterUrl}. Lets a * page start loading it before this bundle arrives. */ poster?: HTMLImageElement; /** A fetch of {@link ViewerAssets.contentUrl} already in flight, for the same reason. */ contents?: Promise; }; type CaptureResult = { width: number; height: number; data: string; }; /** A camera position, look-at target and vertical field of view in degrees. */ type CameraPose = { position: [number, number, number]; target: [number, number, number]; fov: number; }; /** A camera. Only the first camera in a settings file is used. */ type Camera = { initial: CameraPose; }; /** A point of interest in the scene, with the camera framing used to view it. */ type Annotation = { position: [number, number, number]; title: string; text: string; extras?: unknown; camera: Camera; }; type CameraMode = 'orbit' | 'anim' | 'fly' | 'walk'; type InputMode = 'desktop' | 'touch'; /** Immersive session kind accepted by {@link ViewerHandle.startXR}. */ type XrMode = 'ar' | 'vr'; /** * A position of the Quality slider, left to right. Each picks the splat budget from the device * class's ladder (desktop 2 / 4 / 8 / 16 million, phones and tablets 1 / 2 / 4 / 8), and on the * sorted renderer `performance` also renders at half resolution (the stochastic renderer keeps * full resolution). Positions the device cannot hold are listed out of * {@link ViewerState.qualityAvailable}. */ type QualityLevel = 'performance' | 'default' | 'high' | 'max'; type State = { /** True once the first complete frame has rendered. */ loaded: boolean; /** * The Quality slider's position: the splat budget, and at `performance` half resolution on the * sorted renderer. * Persisted in local storage; defaults to `performance` on phones and tablets, `default` * elsewhere. A position the device cannot hold falls back to the nearest available below it. * An XR session that cannot hold it draws at the nearest it can below, and leaves it unchanged. */ quality: QualityLevel; /** * The positions the device can hold, in slider order. Read-only: decided from the gpu's * storage-binding limit and a memory estimate per position, for both renderers where the * stochastic setting can switch between them, so switching never changes the budget. */ qualityAvailable: QualityLevel[]; /** * Performance Mode: draw with the stochastic splat renderer (unsorted, depth-tested splats, * temporally accumulated) instead of the engine's sorted one. WebGPU only, and not offered in * Quest or Pico browsers, where the toggle has no effect. Persisted; off by default. Switches * at runtime. */ performanceMode: boolean; /** Content loading progress, 0 to 100. */ progress: number; /** What the user last interacted with, which decides the ui's affordances. */ inputMode: InputMode; /** The active camera controller. `anim` is the authored camera animation. */ cameraMode: CameraMode; /** * Whether there is an animation for the timeline to play: the authored camera animation, or * the frames of an animated splat sequence ({@link ViewerState.hasSequence}). */ hasAnimation: boolean; /** * Whether the content is an animated splat sequence (a gsaf file). The timeline plays its * frames in every camera mode, and the camera has no animation of its own. */ hasSequence: boolean; /** Length of that animation in seconds, or 0. */ animationDuration: number; /** Playhead position in seconds. Read-only: the animation cursor or the sequence owns it. */ animationTime: number; /** Whether the animation is paused. */ animationPaused: boolean; /** Whether an AR session can start, or could after reloading into WebGL. */ hasAR: boolean; /** Whether a VR session can start, or could after reloading into WebGL. */ hasVR: boolean; /** Whether AR can start on the current renderer, without a WebGL reload. */ canStartAR: boolean; /** Whether VR can start on the current renderer, without a WebGL reload. */ canStartVR: boolean; /** Active immersive session kind, or null. Read-only: use `startXR` / `endXR`. */ xrMode: XrMode | null; /** Whether the experience ships collision data, which walk mode needs. */ hasCollision: boolean; /** Whether that collision data can be drawn as a debug overlay. */ hasCollisionOverlay: boolean; /** Whether walk mode is offered: collision data, and a scene big enough to walk in. */ walkAllowed: boolean; /** Draws the collision debug overlay. */ collisionOverlayEnabled: boolean; /** Native fullscreen ownership, or the requested state of the legacy iframe parent bridge. */ isFullscreen: boolean; /** Fades the controls out. The viewer also sets this on an idle timer. */ controlsHidden: boolean; /** Shows the annotation hotspots. Persisted in local storage. */ showAnnotations: boolean; /** Selected annotation's zero-based index in `annotations`, or null. Read-only: use `selectAnnotation`. */ selectedAnnotation: number | null; /** Mouse-look and joystick movement rather than click-to-navigate. Persisted. */ gamingControls: boolean; /** * In XR with tracked hands, a left fist held upright for two seconds, the right hand open, * puts the scene or object in miniature on top of the fist, like an ice cream in its cone, * until the hand opens; with controllers, the left grip squeezed does the same on the * controller's top face. Persisted; on by default. The XR menu offers it as Ice Cream. */ iceCream: boolean; /** * Gates the inputs the dom cannot route by hit-testing, because their listeners sit on * `window`: the keyboard (both the engine's source and the viewer's own shortcuts) and the * gamepad. Pointer input on the canvas is unaffected. Clear it while your own controls have * focus or a modal is open, and to choose which of several viewers the keyboard drives. */ inputEnabled: boolean; }; type WritableStateKey = 'cameraMode' | 'quality' | 'performanceMode' | 'showAnnotations' | 'gamingControls' | 'iceCream' | 'animationPaused' | 'collisionOverlayEnabled' | 'controlsHidden' | 'inputEnabled'; /** * The viewer's state as a host sees it: one observable object, with the keys the viewer owns * marked read-only. Writing a read-only key is ignored, and the viewer overwrites it. */ type ViewerState = Pick & Readonly>; /** Options for {@link ViewerHandle.captureFrame}. */ type CaptureOptions = { /** Animation time to capture at, in seconds. The animation is paused there. */ time?: number; /** Output width in pixels. Defaults to 480. */ width?: number; /** Output height in pixels. Defaults to the width. */ height?: number; /** Supersampling factor, capped at 8. Defaults to 2. */ supersample?: number; }; /** What `createViewer` resolves to: one viewer instance. */ type ViewerHandle = { /** The engine application, for a host that needs to reach past this api. */ readonly app: AppBase; /** Observable state. Writes to its writable keys take effect at once. */ readonly state: ViewerState; /** Fires `:changed` with `(value, previous)` for every key of {@link ViewerState}. */ readonly events: EventHandler; /** Annotation data in settings order, available on creation. Editing entries is unsupported. */ readonly annotations: readonly Readonly[]; /** * Render the scene, with post effects, into an offscreen supersampled target and return it * downsampled to the requested size, as base64. Waits for the first frame, and rejects if * the viewer is destroyed before the capture completes. Concurrent calls are serialised, * since they share the one camera. */ captureFrame(options?: CaptureOptions): Promise; /** * Seek the animation in seconds, selecting the animation camera without changing its pause * state. Repeat tracks wrap; once and ping-pong tracks clamp to their duration. Requires * `state.loaded` and `state.hasAnimation`; throws before readiness, after destruction or for * non-finite time. Requests a frame but does not wait for rendering to complete. */ seek(time: number): void; /** * Frame the whole scene, switching to orbit mode. Requires `state.loaded` and throws * before readiness or after destruction. Starts a transition without waiting for it. */ frameScene(): void; /** * Reset the active camera: restore the entry spawn in fly/walk mode, or switch to orbit * and restore the authored initial view (scene framing if absent). Requires `state.loaded` * and throws before readiness or after destruction. Starts a transition without waiting. */ resetCamera(): void; /** * Enter walk mode, or return to the mode active before entering it. Does nothing when * `state.walkAllowed` is false. Requires `state.loaded` and throws before readiness or * after destruction. Pointer lock for gaming controls still requires a user gesture. */ toggleWalk(): void; /** * Select an annotation by its zero-based index and transition to its camera in orbit mode. * Pass null to clear selection without moving the camera. Selecting the same index again * navigates again. Works without the built-in UI and preserves annotation visibility and * animation pause state. Requires `state.loaded`; throws before readiness, after destruction * or for an index that is not an integer in range. Returns without waiting for rendering. */ selectAnnotation(index: number | null): void; /** * Hold camera-relative movement in fly/walk: x is right, z is forward. Finite axes are * clamped to -1..1; (0, 0) stops. Input persists until replaced, a camera/XR mode change, * window blur, document visibility change or destruction. Ignored in other modes and XR. * Requires `state.loaded`; throws before readiness, after destruction or for non-finite * axes. Independent of `gamingControls`, `inputMode` and the keyboard/gamepad input gate. */ setMoveInput(x: number, z: number): void; /** * Request fullscreen for this viewer's root. Call from a user gesture; rejects on browser * refusal or destruction. Available before scene loading finishes. Without native support, * an iframe sends the legacy parent message and resolves without acknowledgement. */ requestFullscreen(): Promise; /** Leave this viewer's fullscreen, leaving other fullscreen elements alone. Rejects after destruction. */ exitFullscreen(): Promise; /** * Start AR or VR from a user gesture after `state.loaded`. Requires `canStartAR` / `canStartVR` * on the current renderer; the host owns any reload UI. Resolves on session start and rejects * on refusal, unavailable XR, an existing/pending session or destruction. */ startXR(mode: XrMode): Promise; /** End the active XR session. Idle is a no-op; rejects during startup or after destruction. */ endXR(): Promise; /** * Release everything: the engine application, the graphics context, every listener, and the * subtree built inside the container. Idempotent, and safe before loading finishes. */ destroy(): void; }; declare const createViewer: (options: CreateViewerOptions) => Promise; export { createViewer }; export type { CaptureOptions, CaptureResult, CreateViewerOptions, QualityLevel, ViewerAssets, ViewerFlags, ViewerHandle, ViewerState, XrMode };