@playcanvas/supersplat-viewer 1.31.2 → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -171
- package/dist/index.d.ts +28 -18
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/viewer.css +761 -0
- package/dist/viewer.d.ts +274 -0
- package/dist/viewer.js +11202 -0
- package/dist/viewer.js.map +1 -0
- package/docs/api.md +356 -0
- package/package.json +20 -6
- package/public/index.css +221 -211
- package/public/index.html +32 -617
- package/public/index.js +2369 -1551
- package/public/index.js.map +1 -1
package/dist/viewer.d.ts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { AppBase, EventHandler } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Asset urls an embedder supplies. Shared by the two ways of instantiating the viewer — as
|
|
5
|
+
* fields of {@link CreateViewerOptions} in a page, and serialised into a generated document by
|
|
6
|
+
* `renderViewerHtml` — so the two surfaces cannot drift.
|
|
7
|
+
*/
|
|
8
|
+
type ViewerAssets = {
|
|
9
|
+
/** Splat url. May be a `data:` uri, for a document with no sibling files. */
|
|
10
|
+
contentUrl: string;
|
|
11
|
+
/**
|
|
12
|
+
* Filename describing {@link ViewerAssets.contentUrl}, e.g. `scene.sog`. The splat format
|
|
13
|
+
* is chosen by the name's extension, so this is required when the url itself has no usable
|
|
14
|
+
* name — a `data:` uri.
|
|
15
|
+
*/
|
|
16
|
+
contentFilename?: string;
|
|
17
|
+
/** Poster image shown, blurred, while the splat loads. */
|
|
18
|
+
posterUrl?: string;
|
|
19
|
+
/** Equirectangular skybox texture url. */
|
|
20
|
+
skyboxUrl?: string;
|
|
21
|
+
/** Collision data url, for walk mode. A `.glb` is treated as a mesh, otherwise voxels. */
|
|
22
|
+
collisionUrl?: string;
|
|
23
|
+
};
|
|
24
|
+
/** Per-instance switches. Every one is optional and off unless stated. */
|
|
25
|
+
type ViewerFlags = {
|
|
26
|
+
/**
|
|
27
|
+
* Requested renderer; the engine falls back to WebGL when WebGPU is unavailable. Default
|
|
28
|
+
* `webgpu`.
|
|
29
|
+
*/
|
|
30
|
+
renderer?: 'webgl' | 'webgpu';
|
|
31
|
+
/**
|
|
32
|
+
* Build the viewer's ui: the controls, panels, poster, loading bar, annotation hotspots
|
|
33
|
+
* and their navigator. Defaults to `true`. `false` is the headless level: the canvas and
|
|
34
|
+
* the api, with no overlay markup. Core camera input, browser integration and preference
|
|
35
|
+
* persistence remain active. The host renders controls against the public handle;
|
|
36
|
+
* `setMoveInput` supports a replacement joystick. Note that the touch joystick and the AR/VR
|
|
37
|
+
* fallback prompt live in that ui, so a headless host owns those affordances too.
|
|
38
|
+
*/
|
|
39
|
+
ui?: boolean;
|
|
40
|
+
/** Show the centre reticle in desktop fly/walk mode with gaming controls. Defaults to `false`. */
|
|
41
|
+
reticle?: boolean;
|
|
42
|
+
/** Start with the camera animation paused. */
|
|
43
|
+
noanim?: boolean;
|
|
44
|
+
/** Disable post effects. */
|
|
45
|
+
nofx?: boolean;
|
|
46
|
+
/** Override the settings' `highPrecisionRendering`. */
|
|
47
|
+
hpr?: boolean;
|
|
48
|
+
/** Show the engine's MiniStats panel. */
|
|
49
|
+
ministats?: boolean;
|
|
50
|
+
/** Render with LOD colorisation. */
|
|
51
|
+
colorize?: boolean;
|
|
52
|
+
/** Load all streaming LOD data before the first frame. */
|
|
53
|
+
fullload?: boolean;
|
|
54
|
+
/** Render with antialiasing. */
|
|
55
|
+
aa?: boolean;
|
|
56
|
+
/** Splat budget in millions, overriding the platform and performance-mode table. */
|
|
57
|
+
budget?: number;
|
|
58
|
+
/** Render the collision heatmap debug overlay (WebGPU only). */
|
|
59
|
+
heatmap?: boolean;
|
|
60
|
+
/** Open the developer debug panel on load; Ctrl+Shift+D toggles it either way. */
|
|
61
|
+
debug?: boolean;
|
|
62
|
+
/** Ui language. Default: detected from the browser. */
|
|
63
|
+
lang?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Publish `window.app`, `scrubTo`, `captureFrame`, `animationDuration` and the debug panel's
|
|
66
|
+
* camera-state hooks. The standalone document turns this on for the thumbnail pipeline; an
|
|
67
|
+
* embedded instance leaves it off, since two viewers would overwrite each other's.
|
|
68
|
+
*/
|
|
69
|
+
exposeGlobals?: boolean;
|
|
70
|
+
};
|
|
71
|
+
/** Options for `createViewer`. */
|
|
72
|
+
type CreateViewerOptions = ViewerAssets & ViewerFlags & {
|
|
73
|
+
/** The element the viewer builds its subtree in. The host sizes it; the viewer fills it. */
|
|
74
|
+
container: HTMLElement;
|
|
75
|
+
/**
|
|
76
|
+
* Experience settings: an object in any version the viewer reads, a promise of that
|
|
77
|
+
* object, or a url to fetch them from, resolved against the document. The poster is
|
|
78
|
+
* shown while settings are pending.
|
|
79
|
+
*/
|
|
80
|
+
settings: object | Promise<object> | string;
|
|
81
|
+
/**
|
|
82
|
+
* An already-created poster image, instead of {@link ViewerAssets.posterUrl}. Lets a
|
|
83
|
+
* page start loading it before this bundle arrives.
|
|
84
|
+
*/
|
|
85
|
+
poster?: HTMLImageElement;
|
|
86
|
+
/** A fetch of {@link ViewerAssets.contentUrl} already in flight, for the same reason. */
|
|
87
|
+
contents?: Promise<Response>;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
type CaptureResult = {
|
|
91
|
+
width: number;
|
|
92
|
+
height: number;
|
|
93
|
+
data: string;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** A camera position, look-at target and vertical field of view in degrees. */
|
|
97
|
+
type CameraPose = {
|
|
98
|
+
position: [number, number, number];
|
|
99
|
+
target: [number, number, number];
|
|
100
|
+
fov: number;
|
|
101
|
+
};
|
|
102
|
+
/** A camera. Only the first camera in a settings file is used. */
|
|
103
|
+
type Camera = {
|
|
104
|
+
initial: CameraPose;
|
|
105
|
+
};
|
|
106
|
+
/** A point of interest in the scene, with the camera framing used to view it. */
|
|
107
|
+
type Annotation = {
|
|
108
|
+
position: [number, number, number];
|
|
109
|
+
title: string;
|
|
110
|
+
text: string;
|
|
111
|
+
extras?: unknown;
|
|
112
|
+
camera: Camera;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
type CameraMode = 'orbit' | 'anim' | 'fly' | 'walk';
|
|
116
|
+
type InputMode = 'desktop' | 'touch';
|
|
117
|
+
/** Immersive session kind accepted by {@link ViewerHandle.startXR}. */
|
|
118
|
+
type XrMode = 'ar' | 'vr';
|
|
119
|
+
type State = {
|
|
120
|
+
/** True once the first complete frame has rendered. */
|
|
121
|
+
loaded: boolean;
|
|
122
|
+
/** Halves the render resolution. Persisted in local storage; defaults on for mobile. */
|
|
123
|
+
performanceMode: boolean;
|
|
124
|
+
/** Content loading progress, 0 to 100. */
|
|
125
|
+
progress: number;
|
|
126
|
+
/** What the user last interacted with, which decides the ui's affordances. */
|
|
127
|
+
inputMode: InputMode;
|
|
128
|
+
/** The active camera controller. `anim` is the authored camera animation. */
|
|
129
|
+
cameraMode: CameraMode;
|
|
130
|
+
/** Whether the experience has an authored camera animation. */
|
|
131
|
+
hasAnimation: boolean;
|
|
132
|
+
/** Length of that animation in seconds, or 0. */
|
|
133
|
+
animationDuration: number;
|
|
134
|
+
/** Playhead position in seconds. Read-only: the animation cursor owns it. */
|
|
135
|
+
animationTime: number;
|
|
136
|
+
/** Whether the animation is paused. */
|
|
137
|
+
animationPaused: boolean;
|
|
138
|
+
/** Whether an AR session can start, or could after reloading into WebGL. */
|
|
139
|
+
hasAR: boolean;
|
|
140
|
+
/** Whether a VR session can start, or could after reloading into WebGL. */
|
|
141
|
+
hasVR: boolean;
|
|
142
|
+
/** Whether AR can start on the current renderer, without a WebGL reload. */
|
|
143
|
+
canStartAR: boolean;
|
|
144
|
+
/** Whether VR can start on the current renderer, without a WebGL reload. */
|
|
145
|
+
canStartVR: boolean;
|
|
146
|
+
/** Active immersive session kind, or null. Read-only: use `startXR` / `endXR`. */
|
|
147
|
+
xrMode: XrMode | null;
|
|
148
|
+
/** Whether the experience ships collision data, which walk mode needs. */
|
|
149
|
+
hasCollision: boolean;
|
|
150
|
+
/** Whether that collision data can be drawn as a debug overlay. */
|
|
151
|
+
hasCollisionOverlay: boolean;
|
|
152
|
+
/** Whether walk mode is offered: collision data, and a scene big enough to walk in. */
|
|
153
|
+
walkAllowed: boolean;
|
|
154
|
+
/** Draws the collision debug overlay. */
|
|
155
|
+
collisionOverlayEnabled: boolean;
|
|
156
|
+
/** Native fullscreen ownership, or the requested state of the legacy iframe parent bridge. */
|
|
157
|
+
isFullscreen: boolean;
|
|
158
|
+
/** Fades the controls out. The viewer also sets this on an idle timer. */
|
|
159
|
+
controlsHidden: boolean;
|
|
160
|
+
/** Shows the annotation hotspots. Persisted in local storage. */
|
|
161
|
+
showAnnotations: boolean;
|
|
162
|
+
/** Selected annotation's zero-based index in `annotations`, or null. Read-only: use `selectAnnotation`. */
|
|
163
|
+
selectedAnnotation: number | null;
|
|
164
|
+
/** Mouse-look and joystick movement rather than click-to-navigate. Persisted. */
|
|
165
|
+
gamingControls: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Gates the inputs the dom cannot route by hit-testing, because their listeners sit on
|
|
168
|
+
* `window`: the keyboard (both the engine's source and the viewer's own shortcuts) and the
|
|
169
|
+
* gamepad. Pointer input on the canvas is unaffected. Clear it while your own controls have
|
|
170
|
+
* focus or a modal is open, and to choose which of several viewers the keyboard drives.
|
|
171
|
+
*/
|
|
172
|
+
inputEnabled: boolean;
|
|
173
|
+
};
|
|
174
|
+
type WritableStateKey = 'cameraMode' | 'performanceMode' | 'showAnnotations' | 'gamingControls' | 'animationPaused' | 'collisionOverlayEnabled' | 'controlsHidden' | 'inputEnabled';
|
|
175
|
+
/**
|
|
176
|
+
* The viewer's state as a host sees it: one observable object, with the keys the viewer owns
|
|
177
|
+
* marked read-only. Writing a read-only key is ignored, and the viewer overwrites it.
|
|
178
|
+
*/
|
|
179
|
+
type ViewerState = Pick<State, WritableStateKey> & Readonly<Omit<State, WritableStateKey>>;
|
|
180
|
+
/** Options for {@link ViewerHandle.captureFrame}. */
|
|
181
|
+
type CaptureOptions = {
|
|
182
|
+
/** Animation time to capture at, in seconds. The animation is paused there. */
|
|
183
|
+
time?: number;
|
|
184
|
+
/** Output width in pixels. Defaults to 480. */
|
|
185
|
+
width?: number;
|
|
186
|
+
/** Output height in pixels. Defaults to the width. */
|
|
187
|
+
height?: number;
|
|
188
|
+
/** Supersampling factor, capped at 8. Defaults to 2. */
|
|
189
|
+
supersample?: number;
|
|
190
|
+
};
|
|
191
|
+
/** What `createViewer` resolves to: one viewer instance. */
|
|
192
|
+
type ViewerHandle = {
|
|
193
|
+
/** The engine application, for a host that needs to reach past this api. */
|
|
194
|
+
readonly app: AppBase;
|
|
195
|
+
/** Observable state. Writes to its writable keys take effect at once. */
|
|
196
|
+
readonly state: ViewerState;
|
|
197
|
+
/** Fires `<key>:changed` with `(value, previous)` for every key of {@link ViewerState}. */
|
|
198
|
+
readonly events: EventHandler;
|
|
199
|
+
/** Annotation data in settings order, available on creation. Editing entries is unsupported. */
|
|
200
|
+
readonly annotations: readonly Readonly<Annotation>[];
|
|
201
|
+
/**
|
|
202
|
+
* Render the scene, with post effects, into an offscreen supersampled target and return it
|
|
203
|
+
* downsampled to the requested size, as base64. Waits for the first frame, and rejects if
|
|
204
|
+
* the viewer is destroyed before the capture completes. Concurrent calls are serialised,
|
|
205
|
+
* since they share the one camera.
|
|
206
|
+
*/
|
|
207
|
+
captureFrame(options?: CaptureOptions): Promise<CaptureResult>;
|
|
208
|
+
/**
|
|
209
|
+
* Seek the animation in seconds, selecting the animation camera without changing its pause
|
|
210
|
+
* state. Repeat tracks wrap; once and ping-pong tracks clamp to their duration. Requires
|
|
211
|
+
* `state.loaded` and `state.hasAnimation`; throws before readiness, after destruction or for
|
|
212
|
+
* non-finite time. Requests a frame but does not wait for rendering to complete.
|
|
213
|
+
*/
|
|
214
|
+
seek(time: number): void;
|
|
215
|
+
/**
|
|
216
|
+
* Frame the whole scene, switching to orbit mode. Requires `state.loaded` and throws
|
|
217
|
+
* before readiness or after destruction. Starts a transition without waiting for it.
|
|
218
|
+
*/
|
|
219
|
+
frameScene(): void;
|
|
220
|
+
/**
|
|
221
|
+
* Reset the active camera: restore the entry spawn in fly/walk mode, or switch to orbit
|
|
222
|
+
* and restore the authored initial view (scene framing if absent). Requires `state.loaded`
|
|
223
|
+
* and throws before readiness or after destruction. Starts a transition without waiting.
|
|
224
|
+
*/
|
|
225
|
+
resetCamera(): void;
|
|
226
|
+
/**
|
|
227
|
+
* Enter walk mode, or return to the mode active before entering it. Does nothing when
|
|
228
|
+
* `state.walkAllowed` is false. Requires `state.loaded` and throws before readiness or
|
|
229
|
+
* after destruction. Pointer lock for gaming controls still requires a user gesture.
|
|
230
|
+
*/
|
|
231
|
+
toggleWalk(): void;
|
|
232
|
+
/**
|
|
233
|
+
* Select an annotation by its zero-based index and transition to its camera in orbit mode.
|
|
234
|
+
* Pass null to clear selection without moving the camera. Selecting the same index again
|
|
235
|
+
* navigates again. Works without the built-in UI and preserves annotation visibility and
|
|
236
|
+
* animation pause state. Requires `state.loaded`; throws before readiness, after destruction
|
|
237
|
+
* or for an index that is not an integer in range. Returns without waiting for rendering.
|
|
238
|
+
*/
|
|
239
|
+
selectAnnotation(index: number | null): void;
|
|
240
|
+
/**
|
|
241
|
+
* Hold camera-relative movement in fly/walk: x is right, z is forward. Finite axes are
|
|
242
|
+
* clamped to -1..1; (0, 0) stops. Input persists until replaced, a camera/XR mode change,
|
|
243
|
+
* window blur, document visibility change or destruction. Ignored in other modes and XR.
|
|
244
|
+
* Requires `state.loaded`; throws before readiness, after destruction or for non-finite
|
|
245
|
+
* axes. Independent of `gamingControls`, `inputMode` and the keyboard/gamepad input gate.
|
|
246
|
+
*/
|
|
247
|
+
setMoveInput(x: number, z: number): void;
|
|
248
|
+
/**
|
|
249
|
+
* Request fullscreen for this viewer's root. Call from a user gesture; rejects on browser
|
|
250
|
+
* refusal or destruction. Available before scene loading finishes. Without native support,
|
|
251
|
+
* an iframe sends the legacy parent message and resolves without acknowledgement.
|
|
252
|
+
*/
|
|
253
|
+
requestFullscreen(): Promise<void>;
|
|
254
|
+
/** Leave this viewer's fullscreen, leaving other fullscreen elements alone. Rejects after destruction. */
|
|
255
|
+
exitFullscreen(): Promise<void>;
|
|
256
|
+
/**
|
|
257
|
+
* Start AR or VR from a user gesture after `state.loaded`. Requires `canStartAR` / `canStartVR`
|
|
258
|
+
* on the current renderer; the host owns any reload UI. Resolves on session start and rejects
|
|
259
|
+
* on refusal, unavailable XR, an existing/pending session or destruction.
|
|
260
|
+
*/
|
|
261
|
+
startXR(mode: XrMode): Promise<void>;
|
|
262
|
+
/** End the active XR session. Idle is a no-op; rejects during startup or after destruction. */
|
|
263
|
+
endXR(): Promise<void>;
|
|
264
|
+
/**
|
|
265
|
+
* Release everything: the engine application, the graphics context, every listener, and the
|
|
266
|
+
* subtree built inside the container. Idempotent, and safe before loading finishes.
|
|
267
|
+
*/
|
|
268
|
+
destroy(): void;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
declare const createViewer: (options: CreateViewerOptions) => Promise<ViewerHandle>;
|
|
272
|
+
|
|
273
|
+
export { createViewer };
|
|
274
|
+
export type { CaptureOptions, CaptureResult, CreateViewerOptions, ViewerAssets, ViewerFlags, ViewerHandle, ViewerState, XrMode };
|