@playcanvas/supersplat-viewer 1.29.3 → 1.30.1
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 +59 -16
- package/dist/index.d.ts +86 -3
- package/dist/index.js +133 -4
- package/dist/index.js.map +1 -1
- package/dist/settings.d.ts +142 -13
- package/dist/settings.js +327 -39
- package/dist/settings.js.map +1 -1
- package/package.json +20 -15
- package/public/index.css +1 -3
- package/public/index.html +30 -8
- package/public/index.js +150 -39
- package/public/index.js.map +1 -1
package/README.md
CHANGED
|
@@ -56,40 +56,83 @@ By default the viewer uses WebGPU when available (falling back automatically whe
|
|
|
56
56
|
|
|
57
57
|
## NPM Package
|
|
58
58
|
|
|
59
|
-
|
|
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 {
|
|
65
|
+
import { renderViewerHtml } from '@playcanvas/supersplat-viewer';
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
68
|
-
|
|
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
|
-
|
|
71
|
-
|
|
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. A `data:` URI has no filename and the splat format is chosen by the
|
|
88
|
+
name's extension, so name its content with the bootstrap's `contentFilename` (e.g.
|
|
89
|
+
`scene.sog`). The flags are independent, so a server that serves the bundle from its own
|
|
90
|
+
route can inline only the stylesheet.
|
|
91
|
+
|
|
92
|
+
`html` is still exported as a raw string, but is **deprecated**: its formatting is not part of
|
|
93
|
+
this package's API and changes between releases, so pattern-matching it is unsupported. `css`
|
|
94
|
+
and `js` remain exported for serving (or writing) the stylesheet and bundle alongside a
|
|
95
|
+
rendered document that doesn't inline them.
|
|
73
96
|
|
|
74
|
-
|
|
97
|
+
### Settings
|
|
98
|
+
|
|
99
|
+
The `/settings` subpath exports the schema types plus helpers for generating, validating and
|
|
100
|
+
migrating a `settings.json` file:
|
|
75
101
|
|
|
76
102
|
```ts
|
|
77
103
|
import {
|
|
104
|
+
defaultSettings,
|
|
78
105
|
importSettings,
|
|
79
106
|
validateSettings,
|
|
107
|
+
POST_EFFECT_RANGES,
|
|
80
108
|
type ExperienceSettings
|
|
81
109
|
} from '@playcanvas/supersplat-viewer/settings';
|
|
82
110
|
|
|
83
|
-
//
|
|
111
|
+
// a complete settings object every tool agrees on; pass 'object' to frame a subject
|
|
112
|
+
// from outside rather than a captured space from within
|
|
113
|
+
const settings: ExperienceSettings = defaultSettings();
|
|
114
|
+
|
|
115
|
+
// throws on invalid input, naming the offending field
|
|
84
116
|
validateSettings(json);
|
|
85
117
|
|
|
86
|
-
//
|
|
87
|
-
|
|
118
|
+
// additionally check the authoring bounds — stricter than what the viewer will render,
|
|
119
|
+
// so existing files may fail. Producers writing new settings should enable it
|
|
120
|
+
validateSettings(json, { limits: true });
|
|
121
|
+
|
|
122
|
+
// migrates older versions forward; does not mutate its argument
|
|
123
|
+
const migrated = importSettings(json);
|
|
124
|
+
|
|
125
|
+
// the bounds are data, so an editor UI can drive a slider from the same numbers
|
|
126
|
+
const { min, max, step } = POST_EFFECT_RANGES.bloom.intensity;
|
|
88
127
|
```
|
|
89
128
|
|
|
129
|
+
`CAMERA_FOV_RANGE`, `POST_EFFECT_RANGES`, `ANIM_TRACK_LIMITS` and `ANNOTATION_LIMITS` are
|
|
130
|
+
exported as data, so an editor UI can drive sliders from the same bounds the validator uses.
|
|
131
|
+
They are frozen at runtime.
|
|
132
|
+
|
|
90
133
|
## Local Development
|
|
91
134
|
|
|
92
|
-
To initialize a local development environment for SuperSplat Viewer, ensure you have [Node.js](https://nodejs.org/)
|
|
135
|
+
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
136
|
|
|
94
137
|
1. Clone the repository:
|
|
95
138
|
|
|
@@ -199,8 +242,8 @@ type ExperienceSettings = {
|
|
|
199
242
|
},
|
|
200
243
|
"postEffectSettings": {
|
|
201
244
|
"sharpness": { "enabled": false, "amount": 0 },
|
|
202
|
-
"bloom": { "enabled": false, "intensity": 1, "blurLevel": 2 },
|
|
203
|
-
"grading": { "enabled": false, "brightness":
|
|
245
|
+
"bloom": { "enabled": false, "intensity": 0.1, "blurLevel": 2 },
|
|
246
|
+
"grading": { "enabled": false, "brightness": 1, "contrast": 1, "saturation": 1, "tint": [1, 1, 1] },
|
|
204
247
|
"vignette": { "enabled": false, "intensity": 0.5, "inner": 0.3, "outer": 0.75, "curvature": 1 },
|
|
205
248
|
"fringing": { "enabled": false, "intensity": 0.5 }
|
|
206
249
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
/**
|
|
19
|
+
* Filename describing {@link ViewerBootstrap.contentUrl}, e.g. `scene.sog`. The splat
|
|
20
|
+
* format is chosen by the name's extension, so this is required when the url itself has
|
|
21
|
+
* no usable name — a `data:` uri. Ignored when a `?content=` url param overrides the url
|
|
22
|
+
* it describes.
|
|
23
|
+
*/
|
|
24
|
+
contentFilename?: string;
|
|
25
|
+
/** Poster image shown, blurred, while the splat loads. */
|
|
26
|
+
posterUrl?: string;
|
|
27
|
+
/** Equirectangular skybox texture url. */
|
|
28
|
+
skyboxUrl?: string;
|
|
29
|
+
/** Collision data url, for walk mode. A `.glb` is treated as a mesh, otherwise voxels. */
|
|
30
|
+
collisionUrl?: string;
|
|
31
|
+
};
|
|
32
|
+
/** Options for {@link renderViewerHtml}. */
|
|
33
|
+
type RenderViewerHtmlOptions = {
|
|
34
|
+
/** Asset urls and settings for the viewer to boot with. */
|
|
35
|
+
bootstrap?: ViewerBootstrap;
|
|
36
|
+
/** Value for the document's `<base href>`, for a viewer served from a sub-path. */
|
|
37
|
+
baseHref?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Page background, applied before the first frame renders to avoid a flash. Components
|
|
40
|
+
* are normalized 0..1, not 0..255, matching `background.color` in the settings format —
|
|
41
|
+
* so an experience's own colour can be passed straight through.
|
|
42
|
+
*/
|
|
43
|
+
backgroundColor?: readonly [number, number, number];
|
|
44
|
+
/** Raw markup injected before `</head>`, for analytics or error reporting. */
|
|
45
|
+
headExtras?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Raw markup injected immediately after `<body>`, for content that must precede the
|
|
48
|
+
* canvas — a marker element a screenshot pipeline waits on, for example.
|
|
49
|
+
*/
|
|
50
|
+
bodyStartExtras?: string;
|
|
51
|
+
/** Inline the stylesheet into a `<style>` block instead of linking `./index.css`. */
|
|
52
|
+
inlineCss?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Inline the module bundle instead of importing `./index.js`. Independent of
|
|
55
|
+
* {@link RenderViewerHtmlOptions.inlineCss}: a host serving the bundle from its own route
|
|
56
|
+
* wants the css inlined to avoid a round trip before first paint, but not a megabyte of
|
|
57
|
+
* js in every page.
|
|
58
|
+
*/
|
|
59
|
+
inlineJs?: boolean;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Render a standalone viewer document.
|
|
63
|
+
*
|
|
64
|
+
* This is the supported way to embed the viewer in a page you generate. Called with no
|
|
65
|
+
* options it returns the document this package ships, unmodified.
|
|
66
|
+
*
|
|
67
|
+
* @param options - Embedding options; see {@link RenderViewerHtmlOptions}.
|
|
68
|
+
* @returns The rendered html document.
|
|
69
|
+
*/
|
|
70
|
+
declare const renderViewerHtml: (options?: RenderViewerHtmlOptions) => string;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The viewer's html document.
|
|
74
|
+
*
|
|
75
|
+
* @deprecated Use {@link renderViewerHtml} instead. Pattern-matching this string is
|
|
76
|
+
* unsupported — its formatting is not part of this package's api and changes between
|
|
77
|
+
* releases.
|
|
78
|
+
*/
|
|
79
|
+
declare const html: string;
|
|
80
|
+
/** The viewer's stylesheet, for serving alongside a rendered document. */
|
|
81
|
+
declare const css: string;
|
|
82
|
+
/** The viewer's module bundle, for serving alongside a rendered document. */
|
|
83
|
+
declare const js: string;
|
|
84
|
+
|
|
85
|
+
export { css, html, js, renderViewerHtml };
|
|
86
|
+
export type { RenderViewerHtmlOptions, ViewerBootstrap };
|