@playcanvas/supersplat-viewer 1.29.2 → 1.30.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 CHANGED
@@ -56,40 +56,80 @@ By default the viewer uses WebGPU when available (falling back automatically whe
56
56
 
57
57
  ## NPM Package
58
58
 
59
- The web app source files are available as strings for templating when you import the package from npm:
59
+ ### Embedding the viewer
60
+
61
+ If you generate a page around the viewer, use `renderViewerHtml`. It returns a complete
62
+ document, with your asset URLs and settings supplied through a single JSON block:
60
63
 
61
64
  ```ts
62
- import { html, css, js } from '@playcanvas/supersplat-viewer';
65
+ import { renderViewerHtml } from '@playcanvas/supersplat-viewer';
63
66
 
64
- // logs the source of index.html
65
- console.log(html);
67
+ const document = renderViewerHtml({
68
+ bootstrap: {
69
+ settings, // an object, or omit and set settingsUrl
70
+ contentUrl: 'scene.sog',
71
+ posterUrl: 'poster.jpg'
72
+ },
73
+ baseHref: '/viewer/', // serving from a sub-path
74
+ backgroundColor: [0, 0, 0], // components are 0..1, not 0..255
75
+ headExtras: '<script src="analytics.js"></script>',
76
+ inlineCss: true // no sibling index.css needed
77
+ });
78
+ ```
66
79
 
67
- // logs the source of index.css
68
- console.log(css);
80
+ Called with no options it returns the document the package ships, unmodified. URL parameters
81
+ on the served page override the bootstrap's asset URLs, so an embed stays overridable per
82
+ instance — except an inline `settings` object, which takes precedence over `?settings=`.
69
83
 
70
- // logs the source of index.js
71
- console.log(js);
72
- ```
84
+ Set both `inlineCss` and `inlineJs` for a single self-contained file, with the splat passed as
85
+ a `data:` URI in `contentUrl` and the settings supplied inline through the bootstrap's
86
+ `settings` object — without an inline settings object the page still fetches `./settings.json`
87
+ from a sibling file. The flags are independent, so a server that serves the bundle from its
88
+ own route can inline only the stylesheet.
89
+
90
+ `html`, `css` and `js` are still exported as raw strings, but are **deprecated**: their
91
+ formatting is not part of this package's API and changes between releases, so pattern-matching
92
+ them is unsupported. `js` remains useful for serving the bundle yourself.
73
93
 
74
- The package also exports the settings schema types and helpers via the `/settings` subpath, which is useful for generating, validating or migrating a `settings.json` file:
94
+ ### Settings
95
+
96
+ The `/settings` subpath exports the schema types plus helpers for generating, validating and
97
+ migrating a `settings.json` file:
75
98
 
76
99
  ```ts
77
100
  import {
101
+ defaultSettings,
78
102
  importSettings,
79
103
  validateSettings,
104
+ POST_EFFECT_RANGES,
80
105
  type ExperienceSettings
81
106
  } from '@playcanvas/supersplat-viewer/settings';
82
107
 
83
- // throws on invalid input
108
+ // a complete settings object every tool agrees on; pass 'object' to frame a subject
109
+ // from outside rather than a captured space from within
110
+ const settings: ExperienceSettings = defaultSettings();
111
+
112
+ // throws on invalid input, naming the offending field
84
113
  validateSettings(json);
85
114
 
86
- // migrates a v1 settings object to the latest schema
87
- const settings: ExperienceSettings = importSettings(json);
115
+ // additionally check the authoring bounds — stricter than what the viewer will render,
116
+ // so existing files may fail. Producers writing new settings should enable it
117
+ validateSettings(json, { limits: true });
118
+
119
+ // migrates older versions forward; does not mutate its argument
120
+ const migrated = importSettings(json);
121
+
122
+ // the bounds are data, so an editor UI can drive a slider from the same numbers
123
+ const { min, max, step } = POST_EFFECT_RANGES.bloom.intensity;
88
124
  ```
89
125
 
126
+ `CAMERA_FOV_RANGE`, `POST_EFFECT_RANGES`, `ANIM_TRACK_LIMITS` and `ANNOTATION_LIMITS` are
127
+ exported as data, so an editor UI can drive sliders from the same bounds the validator uses.
128
+ They are frozen at runtime.
129
+
90
130
  ## Local Development
91
131
 
92
- To initialize a local development environment for SuperSplat Viewer, ensure you have [Node.js](https://nodejs.org/) 18 or later installed. Follow these steps:
132
+ To initialize a local development environment for SuperSplat Viewer, ensure you have [Node.js](https://nodejs.org/) 20 or later installed. Follow these steps:
93
133
 
94
134
  1. Clone the repository:
95
135
 
@@ -199,8 +239,8 @@ type ExperienceSettings = {
199
239
  },
200
240
  "postEffectSettings": {
201
241
  "sharpness": { "enabled": false, "amount": 0 },
202
- "bloom": { "enabled": false, "intensity": 1, "blurLevel": 2 },
203
- "grading": { "enabled": false, "brightness": 0, "contrast": 1, "saturation": 1, "tint": [1, 1, 1] },
242
+ "bloom": { "enabled": false, "intensity": 0.1, "blurLevel": 2 },
243
+ "grading": { "enabled": false, "brightness": 1, "contrast": 1, "saturation": 1, "tint": [1, 1, 1] },
204
244
  "vignette": { "enabled": false, "intensity": 0.5, "inner": 0.3, "outer": 0.75, "curvature": 1 },
205
245
  "fringing": { "enabled": false, "intensity": 0.5 }
206
246
  },
package/dist/index.d.ts CHANGED
@@ -1,3 +1,83 @@
1
- export const html: string;
2
- export const css: string;
3
- export const js: string;
1
+ /**
2
+ * Asset urls and settings the embedder supplies to the viewer.
3
+ *
4
+ * Url params on the served page take precedence over every url here, so an embed stays
5
+ * overridable per instance. Inline {@link ViewerBootstrap.settings} is the exception: it wins
6
+ * over `?settings=`, so a published experience cannot be repointed at another settings file.
7
+ */
8
+ type ViewerBootstrap = {
9
+ /**
10
+ * Experience settings as an object, avoiding a round trip. When omitted the viewer
11
+ * fetches {@link ViewerBootstrap.settingsUrl}.
12
+ */
13
+ settings?: unknown;
14
+ /** Where to fetch settings from. Defaults to `./settings.json`. */
15
+ settingsUrl?: string;
16
+ /** Splat url. May be a `data:` uri, for a document with no sibling files. */
17
+ contentUrl?: string;
18
+ /** Poster image shown, blurred, while the splat loads. */
19
+ posterUrl?: string;
20
+ /** Equirectangular skybox texture url. */
21
+ skyboxUrl?: string;
22
+ /** Collision data url, for walk mode. A `.glb` is treated as a mesh, otherwise voxels. */
23
+ collisionUrl?: string;
24
+ };
25
+ /** Options for {@link renderViewerHtml}. */
26
+ type RenderViewerHtmlOptions = {
27
+ /** Asset urls and settings for the viewer to boot with. */
28
+ bootstrap?: ViewerBootstrap;
29
+ /** Value for the document's `<base href>`, for a viewer served from a sub-path. */
30
+ baseHref?: string;
31
+ /**
32
+ * Page background, applied before the first frame renders to avoid a flash. Components
33
+ * are normalized 0..1, not 0..255, matching `background.color` in the settings format —
34
+ * so an experience's own colour can be passed straight through.
35
+ */
36
+ backgroundColor?: readonly [number, number, number];
37
+ /** Raw markup injected before `</head>`, for analytics or error reporting. */
38
+ headExtras?: string;
39
+ /**
40
+ * Raw markup injected immediately after `<body>`, for content that must precede the
41
+ * canvas — a marker element a screenshot pipeline waits on, for example.
42
+ */
43
+ bodyStartExtras?: string;
44
+ /** Inline the stylesheet into a `<style>` block instead of linking `./index.css`. */
45
+ inlineCss?: boolean;
46
+ /**
47
+ * Inline the module bundle instead of importing `./index.js`. Independent of
48
+ * {@link RenderViewerHtmlOptions.inlineCss}: a host serving the bundle from its own route
49
+ * wants the css inlined to avoid a round trip before first paint, but not a megabyte of
50
+ * js in every page.
51
+ */
52
+ inlineJs?: boolean;
53
+ };
54
+ /**
55
+ * Render a standalone viewer document.
56
+ *
57
+ * This is the supported way to embed the viewer in a page you generate. Called with no
58
+ * options it returns the document this package ships, unmodified.
59
+ *
60
+ * @param options - Embedding options; see {@link RenderViewerHtmlOptions}.
61
+ * @returns The rendered html document.
62
+ */
63
+ declare const renderViewerHtml: (options?: RenderViewerHtmlOptions) => string;
64
+
65
+ /**
66
+ * The viewer's html document.
67
+ *
68
+ * @deprecated Use {@link renderViewerHtml} instead. Pattern-matching this string is
69
+ * unsupported — its formatting is not part of this package's api and changes between
70
+ * releases.
71
+ */
72
+ declare const html: string;
73
+ /**
74
+ * The viewer's stylesheet.
75
+ *
76
+ * @deprecated Use {@link renderViewerHtml} instead, which can inline it for you.
77
+ */
78
+ declare const css: string;
79
+ /** The viewer's module bundle, for serving alongside a rendered document. */
80
+ declare const js: string;
81
+
82
+ export { css, html, js, renderViewerHtml };
83
+ export type { RenderViewerHtmlOptions, ViewerBootstrap };