@preference-sl/pref-viewer 2.16.0-beta.10 → 2.16.0-beta.11
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 +125 -102
- package/package.json +1 -1
- package/src/babylonjs-animation-opening.js +11 -5
- package/src/babylonjs-controller.js +337 -60
- package/src/pref-viewer-2d.js +14 -21
- package/src/pref-viewer-3d.js +140 -85
- package/src/pref-viewer-menu-3d.js +84 -40
- package/src/pref-viewer-task.js +7 -2
- package/src/pref-viewer.js +547 -185
- package/src/styles.js +105 -29
package/README.md
CHANGED
|
@@ -126,13 +126,22 @@ viewer.loadConfig({
|
|
|
126
126
|
shadows: true,
|
|
127
127
|
},
|
|
128
128
|
render: {
|
|
129
|
-
antiAliasingEnabled: true,
|
|
130
129
|
ambientOcclusionEnabled: true,
|
|
130
|
+
antiAliasingEnabled: true,
|
|
131
131
|
iblEnabled: true,
|
|
132
132
|
shadowsEnabled: false,
|
|
133
|
+
showAnimationMenu: true,
|
|
134
|
+
showLightingTimeOfDay: true,
|
|
135
|
+
lightingTimeOfDay: 0.5,
|
|
136
|
+
highlightEnabled: true,
|
|
137
|
+
highlightColor: "#ff6700",
|
|
133
138
|
},
|
|
134
139
|
},
|
|
140
|
+
styles: {
|
|
141
|
+
colorPrimary: "#ff6700",
|
|
142
|
+
},
|
|
135
143
|
culture: "en-EN",
|
|
144
|
+
forceReload: false,
|
|
136
145
|
});
|
|
137
146
|
```
|
|
138
147
|
|
|
@@ -175,23 +184,22 @@ Storage descriptors are passed through `model.storage`, `scene.storage`, `materi
|
|
|
175
184
|
|
|
176
185
|
## Attributes
|
|
177
186
|
|
|
187
|
+
`<pref-viewer>` observes the following attributes directly. When they change, the host component queues the corresponding load/configuration action or updates its own UI state.
|
|
188
|
+
|
|
178
189
|
| Attribute | Description |
|
|
179
190
|
| --- | --- |
|
|
180
|
-
| `config` | JSON string with the full viewer configuration. |
|
|
181
|
-
| `model` | JSON string with a model payload. |
|
|
182
|
-
| `scene` | JSON string with a scene/environment payload. |
|
|
183
|
-
| `materials` | JSON string with a materials payload. |
|
|
184
|
-
| `drawing` | JSON string with a 2D drawing payload. |
|
|
185
|
-
| `options` | JSON string with viewer options. |
|
|
186
|
-
| `culture` | UI locale. Supported values: `en-EN`, `es-ES`. |
|
|
191
|
+
| `config` | JSON string with the full viewer configuration. Forwards to `loadConfig(value)`. |
|
|
192
|
+
| `model` | JSON string with a model payload. Forwards to `loadModel(value)`. |
|
|
193
|
+
| `scene` | JSON string with a scene/environment payload. Forwards to `loadScene(value)`. |
|
|
194
|
+
| `materials` | JSON string with a materials payload. Forwards to `loadMaterials(value)`. |
|
|
195
|
+
| `drawing` | JSON string with a 2D drawing payload. Forwards to `loadDrawing(value)`. |
|
|
196
|
+
| `options` | JSON string with viewer options. Forwards to `setOptions(value)`. Use this for runtime render changes such as highlight, animation menu, IBL, shadows, and lighting time of day. |
|
|
197
|
+
| `culture` | UI locale. Supported values: `en-EN`, `es-ES`. Persists the resolved locale in `localStorage`. |
|
|
187
198
|
| `mode` | Viewer mode: `3d` or `2d`. Defaults to `3d`. |
|
|
188
|
-
| `show-model` | Shows or hides the current model. Use `true` or `false`. |
|
|
189
|
-
| `show-scene` | Shows or hides the current scene/environment. Use `true` or `false`. |
|
|
190
|
-
| `show-menu` | Shows or hides the 3D render settings menu. Defaults to visible. |
|
|
191
|
-
| `
|
|
192
|
-
| `show-animation-menu` | Enables or disables the animation menu when animations are available. |
|
|
193
|
-
| `highlight-enabled` | Enables or disables hover highlight. |
|
|
194
|
-
| `highlight-color` | CSS color used for hover highlight. Defaults to `#ff6700`. |
|
|
199
|
+
| `show-model` | Shows or hides the current 3D model. Use `true` or `false`. |
|
|
200
|
+
| `show-scene` | Shows or hides the current 3D scene/environment. Use `true` or `false`. |
|
|
201
|
+
| `show-render-menu` | Shows or hides the floating 3D render settings menu. Defaults to visible. |
|
|
202
|
+
| `styles` | JSON string with supported style overrides. Currently supports `colorPrimary`, applies it as `--pref-viewer-color-primary`, updates `PrefViewerStyleVariables.colorPrimary`, and persists it in `localStorage`. |
|
|
195
203
|
|
|
196
204
|
## Public methods
|
|
197
205
|
|
|
@@ -199,22 +207,17 @@ Storage descriptors are passed through `model.storage`, `scene.storage`, `materi
|
|
|
199
207
|
|
|
200
208
|
| Method | Description |
|
|
201
209
|
| --- | --- |
|
|
202
|
-
| `loadConfig(config)` | Queues a full configuration update. Accepts an object or JSON string. |
|
|
210
|
+
| `loadConfig(config)` | Queues a full configuration update. Accepts an object or JSON string with model, scene, materials, drawing, options, culture, styles, and visibility descriptors. |
|
|
203
211
|
| `loadModel(model)` | Queues a model update. |
|
|
204
212
|
| `loadScene(scene)` | Queues a scene/environment update. |
|
|
205
213
|
| `loadMaterials(materials)` | Queues a materials update. |
|
|
206
214
|
| `loadDrawing(drawing)` | Queues a 2D drawing update. |
|
|
207
|
-
| `setOptions(options)` | Queues camera, material, IBL, lighting,
|
|
208
|
-
| `
|
|
215
|
+
| `setOptions(options)` | Queues camera, material, IBL, lighting, animation-menu, highlight, and render option updates. |
|
|
216
|
+
| `setStyles(styles)` | Queues supported runtime style overrides. Currently supports `{ colorPrimary }`, persists it in `localStorage`, updates `PrefViewerStyleVariables.colorPrimary`, and applies `--pref-viewer-color-primary`. |
|
|
217
|
+
| `setIBL(ibl)` | Convenience wrapper for `setOptions({ ibl })`. |
|
|
218
|
+
| `setCulture(culture)` | Changes the active UI locale and persists it in `localStorage`. |
|
|
209
219
|
| `setMode(mode)` | Switches between `2d` and `3d`. |
|
|
210
|
-
|
|
211
|
-
### Parallel loading helpers
|
|
212
|
-
|
|
213
|
-
| Method | Description |
|
|
214
|
-
| --- | --- |
|
|
215
|
-
| `loadModelParallel(model)` | Loads a model without waiting for the standard task queue. |
|
|
216
|
-
| `loadSceneParallel(scene)` | Loads a scene/environment without waiting for the standard task queue. |
|
|
217
|
-
| `loadMaterialsParallel(materials)` | Loads materials without waiting for the standard task queue. |
|
|
220
|
+
| `getDebugInfo()` | Returns a 3D runtime diagnostic snapshot when the internal 3D component and controller are available. |
|
|
218
221
|
|
|
219
222
|
### Visibility and navigation
|
|
220
223
|
|
|
@@ -227,14 +230,30 @@ Storage descriptors are passed through `model.storage`, `scene.storage`, `materi
|
|
|
227
230
|
| `zoomExtentsAll()` | Fits all 2D drawing content in view. |
|
|
228
231
|
| `zoomIn()` / `zoomOut()` | Controls 2D drawing zoom. |
|
|
229
232
|
| `focusModel()` | Moves focus to the current model interaction target when available. |
|
|
230
|
-
|
|
233
|
+
|
|
234
|
+
### Semantic selection and turnable state
|
|
235
|
+
|
|
236
|
+
| Method | Description |
|
|
237
|
+
| --- | --- |
|
|
238
|
+
| `setSelectableElements(elements)` | Defines which host element ids are selectable. Accepts strings or objects with `id`/`Id`. |
|
|
239
|
+
| `setSelectedElements(elements)` | Defines selected elements. Accepts strings or objects with `id`/`Id` and optional `highlights`/`Highlights`. |
|
|
240
|
+
| `applySelectionState(state)` | Applies selectable and selected state in one call. Accepts `selectableIds`/`selectables` and `selectedItems`/`selectedIds`/`selected`. |
|
|
241
|
+
| `clearSelectedElements()` | Clears selected elements while preserving the selectable set. |
|
|
242
|
+
| `clearSelectableElements()` | Clears selectable elements while preserving the selected set. |
|
|
243
|
+
| `clearSelectionState()` | Clears all semantic selection state. |
|
|
244
|
+
| `getSelectionState()` | Returns `{ selectableIds, selectedIds, selectedItems }`. |
|
|
245
|
+
| `notifyElementClick(element)` | Emits `pref-viewer-element-click` from a host-forwarded element id or detail object. |
|
|
246
|
+
| `startTurnable(options)` | Starts semantic turnable state and emits `pref-viewer-3d-turnable-changed`. |
|
|
247
|
+
| `stopTurnable()` | Stops semantic turnable state. |
|
|
248
|
+
| `toggleTurnable(options)` | Toggles semantic turnable state. |
|
|
249
|
+
| `getTurnableState()` | Returns `{ running, speed, direction }`. |
|
|
231
250
|
|
|
232
251
|
### Animation controls
|
|
233
252
|
|
|
234
253
|
| Method | Description |
|
|
235
254
|
| --- | --- |
|
|
236
|
-
| `getAnimations()` | Returns available model animations. |
|
|
237
|
-
| `playAnimation(name, action)` |
|
|
255
|
+
| `getAnimations()` | Returns available model animations with state, progress, loop, and affected node ids. |
|
|
256
|
+
| `playAnimation(name, action)` | Controls a named animation. Supported actions are delegated to `BabylonJSAnimationController`. |
|
|
238
257
|
| `setAnimationProgress(name, progress)` | Sets animation progress from `0` to `1`. |
|
|
239
258
|
| `setAnimationLoop(name, loop)` | Enables or disables looping for a named animation. |
|
|
240
259
|
|
|
@@ -262,10 +281,9 @@ These setters are convenience bridges for framework bindings and property-based
|
|
|
262
281
|
| `materials` | Forwards to `loadMaterials(value)`. |
|
|
263
282
|
| `drawing` | Forwards to `loadDrawing(value)`. |
|
|
264
283
|
| `options` | Forwards to `setOptions(value)`. |
|
|
284
|
+
| `styles` | Forwards to `setStyles(value)`. |
|
|
265
285
|
| `culture` | Forwards to `setCulture(value)`. |
|
|
266
286
|
| `mode` | Forwards to `setMode(value)`. |
|
|
267
|
-
| `highlightEnabled` | Reflects to the `highlight-enabled` attribute. |
|
|
268
|
-
| `highlightColor` | Reflects to the `highlight-color` attribute. |
|
|
269
287
|
|
|
270
288
|
### Getters
|
|
271
289
|
|
|
@@ -277,92 +295,65 @@ These setters are convenience bridges for framework bindings and property-based
|
|
|
277
295
|
| `isLoading` | Whether a load operation is currently in progress. |
|
|
278
296
|
| `isMode2D` | `true` when the current mode is `2d`. |
|
|
279
297
|
| `isMode3D` | `true` when the current mode is `3d`. |
|
|
298
|
+
|
|
280
299
|
## Events
|
|
281
300
|
|
|
282
|
-
The component emits custom events so host applications can integrate loading indicators, error states, and viewer controls.
|
|
301
|
+
The component emits custom events so host applications can integrate loading indicators, error states, and viewer controls. Public event payloads do not include `source`. Only root-level events without an explicit 2D/3D scope include `detail.mode`, and that value is always the current `<pref-viewer>` mode (`"2d"` or `"3d"`).
|
|
283
302
|
|
|
284
|
-
|
|
285
|
-
| --- | --- |
|
|
286
|
-
| `scene-loading` | A 3D scene/model/material operation has started. |
|
|
287
|
-
| `scene-loaded` | A 3D scene/model/material operation completed. Includes operation details when available. |
|
|
288
|
-
| `scene-error` | A scene operation failed. |
|
|
289
|
-
| `scene-setting-options` | Viewer options are being applied. |
|
|
290
|
-
| `scene-set-options` | Viewer options were applied. |
|
|
291
|
-
| `model-loading` | A parallel model load started. |
|
|
292
|
-
| `model-loaded` | A model container loaded successfully. In the parallel path, this means the independent model load completed. |
|
|
293
|
-
| `model-error` | A parallel model load failed. |
|
|
294
|
-
| `environment-loaded` | The environment/scene container loaded successfully. |
|
|
295
|
-
| `materials-loading` | A parallel materials load started. |
|
|
296
|
-
| `materials-loaded` | A parallel materials load completed. |
|
|
297
|
-
| `materials-error` | A parallel materials load failed. |
|
|
298
|
-
| `drawing-loading` | A 2D drawing load started. |
|
|
299
|
-
| `drawing-loaded` | A 2D drawing load completed. |
|
|
300
|
-
| `drawing-zoom-changed` | The 2D drawing zoom changed. |
|
|
301
|
-
| `model-first-painted` | The first frame for a newly loaded model was painted. |
|
|
302
|
-
| `prefviewer-animation-changed` | A model animation state changed. |
|
|
303
|
-
| `pref-viewer-menu-3d-apply` | The 3D settings menu submitted render-setting changes. |
|
|
304
|
-
| `scene-load-assets-complete` | Performance/progress event emitted after asset-container loading completes. |
|
|
305
|
-
| `scene-load-merge-complete` | Performance/progress event emitted after loaded containers are merged into the scene. |
|
|
306
|
-
| `scene-load-shaders-complete` | Performance/progress event emitted after render/shader work completes. |
|
|
307
|
-
| `scene-load-container-complete` | Performance/progress event emitted after an independent container load completes. |
|
|
303
|
+
### General Events
|
|
308
304
|
|
|
309
|
-
|
|
305
|
+
| Event | Emitted by | Legacy alias | Description |
|
|
306
|
+
| --- | --- | --- | --- |
|
|
307
|
+
| `pref-viewer-initialized` | `<pref-viewer>` | None | The root component has been mounted and initialized. |
|
|
308
|
+
| `pref-viewer-loading` | `<pref-viewer>` | None | A 2D or 3D load operation has started. Includes `detail.mode` with the current root mode. |
|
|
309
|
+
| `pref-viewer-loaded` | `<pref-viewer>` | None | A 2D or 3D load operation completed. Includes `detail.mode` with the current root mode. |
|
|
310
|
+
| `pref-viewer-error` | `<pref-viewer>` | None | A 2D or 3D operation failed. Includes `detail.mode` with the current root mode. |
|
|
311
|
+
| `pref-viewer-selection-state-changed` | `<pref-viewer>` | None | The semantic selection state changed. |
|
|
312
|
+
| `pref-viewer-element-click` | `<pref-viewer>` | None | A selectable element was clicked or forwarded by the host integration. |
|
|
310
313
|
|
|
311
|
-
|
|
312
|
-
const viewer = document.querySelector("pref-viewer");
|
|
313
|
-
|
|
314
|
-
viewer.addEventListener("scene-loaded", (event) => {
|
|
315
|
-
console.log("Viewer scene loaded", event.detail);
|
|
316
|
-
});
|
|
314
|
+
### 3D Events
|
|
317
315
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
316
|
+
| Event | Emitted by | Legacy alias | Description |
|
|
317
|
+
| --- | --- | --- | --- |
|
|
318
|
+
| `pref-viewer-3d-loading` | `<pref-viewer>`, `<pref-viewer-3d>` | `scene-loading` | A 3D scene/model/material/options operation has started. |
|
|
319
|
+
| `pref-viewer-3d-loaded` | `<pref-viewer>`, `<pref-viewer-3d>` | `scene-loaded` | A 3D scene/model/material/options operation completed. Includes operation details when available. |
|
|
320
|
+
| `pref-viewer-3d-error` | `<pref-viewer>` | `scene-error` | A 3D operation failed. |
|
|
321
|
+
| `pref-viewer-3d-options-applying` | `<pref-viewer-3d>` | `scene-setting-options` | 3D viewer options are being applied. |
|
|
322
|
+
| `pref-viewer-3d-options-applied` | `<pref-viewer-3d>` | `scene-set-options` | 3D viewer options were applied. |
|
|
323
|
+
| `pref-viewer-3d-render-settings-change-requested` | `<pref-viewer-menu-3d>` | None | The 3D settings menu requested render-setting changes. |
|
|
324
|
+
| `pref-viewer-3d-animation-changed` | Opening animation controller | None | A model animation state changed. |
|
|
325
|
+
| `pref-viewer-3d-turnable-changed` | `<pref-viewer>` | None | The semantic turnable state changed. |
|
|
322
326
|
|
|
323
|
-
|
|
327
|
+
### 2D Events
|
|
324
328
|
|
|
325
|
-
|
|
329
|
+
| Event | Emitted by | Legacy alias | Description |
|
|
330
|
+
| --- | --- | --- | --- |
|
|
331
|
+
| `pref-viewer-2d-loading` | `<pref-viewer>`, `<pref-viewer-2d>` | `drawing-loading` | A 2D drawing load started. |
|
|
332
|
+
| `pref-viewer-2d-loaded` | `<pref-viewer>`, `<pref-viewer-2d>` | `drawing-loaded` | A 2D drawing load completed. |
|
|
333
|
+
| `pref-viewer-2d-error` | `<pref-viewer>`, `<pref-viewer-2d>` | `drawing-error` | A 2D drawing operation failed. |
|
|
334
|
+
| `pref-viewer-2d-viewport-changed` | `<pref-viewer>`, `<pref-viewer-2d>` | None | The 2D drawing pan/zoom viewport changed. |
|
|
326
335
|
|
|
327
|
-
|
|
336
|
+
### Internal Listeners
|
|
328
337
|
|
|
329
|
-
|
|
330
|
-
2. `model-loading` is dispatched immediately from `<pref-viewer>`.
|
|
331
|
-
3. The 3D component calls `loadModelIndependent(model)`.
|
|
332
|
-
4. The Babylon controller uses `loadContainerIndependent("model", ...)`.
|
|
333
|
-
5. If the model is not already claimed by a full scene load, it follows the optimistic `par` path: download/prepare the glTF container immediately, then merge it atomically.
|
|
334
|
-
6. If a full scene load already claimed the model container, it follows the `claimed` path to avoid a double-load conflict while still letting the independent path own the replacement.
|
|
335
|
-
7. The previous model is replaced without rebuilding camera-dependent effects during the merge (`releaseEffects: false`), reducing gray-frame/flicker risk.
|
|
336
|
-
8. After merge, the controller requests a few render frames and waits for paint before dispatching `model-first-painted`.
|
|
337
|
-
9. The returned detail includes `success`, `error`, `loadedContainers`, and `loadSessionId` when provided by the payload.
|
|
338
|
+
`<pref-viewer>` listens to `pref-viewer-2d-viewport-changed` from `<pref-viewer-2d>`, `pref-viewer-3d-loaded` and `pref-viewer-3d-error` from `<pref-viewer-3d>`, and `pref-viewer-3d-render-settings-change-requested` from `<pref-viewer-menu-3d>`. `BabylonJSController` listens to `pref-viewer-3d-animation-changed` from the nearest `<pref-viewer-3d>` host.
|
|
338
339
|
|
|
339
340
|
Example:
|
|
340
341
|
|
|
341
342
|
```js
|
|
342
|
-
const
|
|
343
|
+
const viewer = document.querySelector("pref-viewer");
|
|
343
344
|
|
|
344
|
-
viewer.addEventListener("
|
|
345
|
-
console.log("
|
|
345
|
+
viewer.addEventListener("pref-viewer-3d-loaded", (event) => {
|
|
346
|
+
console.log("Viewer 3D loaded", event.detail);
|
|
346
347
|
});
|
|
347
348
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
storage: {
|
|
351
|
-
url: "https://example.com/assets/model.glb",
|
|
352
|
-
},
|
|
353
|
-
visible: true,
|
|
349
|
+
viewer.addEventListener("pref-viewer-3d-error", (event) => {
|
|
350
|
+
console.error("Viewer 3D failed", event.detail);
|
|
354
351
|
});
|
|
355
352
|
```
|
|
356
353
|
|
|
357
|
-
Important constraints:
|
|
358
|
-
|
|
359
|
-
- The eager model path requires the internal Babylon scene to already exist. If there is no scene, the controller returns `success: false` with `No scene available`.
|
|
360
|
-
- Only one independent model load can run at a time. A concurrent call returns `success: false` with `Already loading model independently`.
|
|
361
|
-
- `model-loaded` means the model container load finished; `model-first-painted` is the stronger signal for UI handoff because it waits for the browser to paint after the atomic merge.
|
|
362
|
-
- Use this path when the product model should appear as soon as possible while slower scene/environment/material work continues. Use `loadConfig()` when deterministic sequential loading is more important than progressive display.
|
|
363
354
|
## Render settings
|
|
364
355
|
|
|
365
|
-
Render settings can be passed through `setOptions`,
|
|
356
|
+
Render settings can be passed through `setOptions`, `loadConfig({ options: { render } })`, property setters, or the built-in 3D menu.
|
|
366
357
|
|
|
367
358
|
```js
|
|
368
359
|
viewer.setOptions({
|
|
@@ -371,14 +362,44 @@ viewer.setOptions({
|
|
|
371
362
|
ambientOcclusionEnabled: true,
|
|
372
363
|
iblEnabled: true,
|
|
373
364
|
shadowsEnabled: false,
|
|
374
|
-
|
|
365
|
+
showAnimationMenu: true,
|
|
375
366
|
highlightEnabled: true,
|
|
376
367
|
highlightColor: "#ff6700",
|
|
368
|
+
showLightingTimeOfDay: true,
|
|
369
|
+
lightingTimeOfDay: 0.5,
|
|
377
370
|
},
|
|
378
371
|
});
|
|
379
372
|
```
|
|
380
373
|
|
|
381
|
-
|
|
374
|
+
| Setting | Type | Behavior |
|
|
375
|
+
| --- | --- | --- |
|
|
376
|
+
| `antiAliasingEnabled` | `boolean` | Enables/disables antialiasing. Changes are persisted and can trigger a render-settings reload. |
|
|
377
|
+
| `ambientOcclusionEnabled` | `boolean` | Enables/disables SSAO. Changes are persisted and can trigger a render-settings reload. |
|
|
378
|
+
| `iblEnabled` | `boolean` | Enables/disables image-based lighting. Changes are persisted and can trigger a render-settings reload. |
|
|
379
|
+
| `shadowsEnabled` | `boolean` | Enables/disables shadows. Changes are persisted and can trigger a render-settings reload. |
|
|
380
|
+
| `showAnimationMenu` | `boolean`/`"false"` | Enables the animation control menu when model animations are available. Applies immediately, persists, and refreshes menu availability. |
|
|
381
|
+
| `highlightEnabled` | `boolean`/`"false"` | Enables/disables hover highlight for animation openings. Applies immediately and persists. |
|
|
382
|
+
| `highlightColor` | `string` | Hex color used by hover highlight. Applies immediately and persists. |
|
|
383
|
+
| `showLightingTimeOfDay` | `boolean`/`"false"` | Shows or hides the time-of-day slider. When set to `false` without an explicit `lightingTimeOfDay`, the viewer resets `lightingTimeOfDay` to the default `0.5`. |
|
|
384
|
+
| `lightingTimeOfDay` | `number` | Normalized time of day from `0` to `1`; `0.5` is the default noon/day value. Applies immediately and persists unless `persist: false` is used by transient playback. |
|
|
385
|
+
|
|
386
|
+
Render settings are persisted in `localStorage` under the `pref-viewer/render-settings` key when changed through the runtime settings flow. The menu is always synchronized from the effective controller settings after changes from the menu, `setOptions`, or `loadConfig`.
|
|
387
|
+
|
|
388
|
+
## Runtime styles
|
|
389
|
+
|
|
390
|
+
Runtime styles can be passed through the `styles` attribute, the `styles` property setter, `setStyles(styles)`, or `loadConfig({ styles })`.
|
|
391
|
+
|
|
392
|
+
```html
|
|
393
|
+
<pref-viewer styles='{"colorPrimary":"#0055cc"}'></pref-viewer>
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
```js
|
|
397
|
+
viewer.setStyles({
|
|
398
|
+
colorPrimary: "#0055cc",
|
|
399
|
+
});
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
Only `colorPrimary` is currently supported. The value updates `PrefViewerStyleVariables.colorPrimary`, is exposed on the host as `--pref-viewer-color-primary`, and is persisted in `localStorage` under `pref-viewer/styles`. Persisted styles are restored when a new `<pref-viewer>` instance is created and connected.
|
|
382
403
|
|
|
383
404
|
## Localization
|
|
384
405
|
|
|
@@ -421,10 +442,10 @@ The playground is available from `playground/index.html` and serves the project
|
|
|
421
442
|
|
|
422
443
|
| Script | Description |
|
|
423
444
|
| --- | --- |
|
|
424
|
-
| `npm run build` | Bundles `src/index.js` into `dist/bundle.js` with esbuild. |
|
|
425
|
-
| `npm run build:prefweb` | Creates a production webpack build. |
|
|
426
|
-
| `npm run build:prefweb:dev` | Creates a development webpack build. |
|
|
427
|
-
| `npm start` | Builds the bundle and starts a local HTTP server on port `8080`. |
|
|
445
|
+
| `npm run build` | Bundles `src/index.js` into `dist/bundle.js` with esbuild. This is the standard ESM playground/runtime build. |
|
|
446
|
+
| `npm run build:prefweb` | Creates a production webpack UMD build for PrefWeb consumption. It limits output to a single chunk and emits `dist/bundle-umd.js`. |
|
|
447
|
+
| `npm run build:prefweb:dev` | Creates a development webpack UMD build with external source maps for PrefWeb/browser debugging. Source map module names point back to project source paths. |
|
|
448
|
+
| `npm start` | Builds the standard bundle and starts a local HTTP server on port `8080`. |
|
|
428
449
|
| `npm test` | Runs the Vitest test suite. |
|
|
429
450
|
| `npm run release` | Creates a standard-version release. |
|
|
430
451
|
| `npm run release:beta` | Creates a beta prerelease with standard-version. |
|
|
@@ -454,7 +475,9 @@ export function ProductViewer() {
|
|
|
454
475
|
- Use object-based JavaScript APIs for complex payloads. Attributes must be valid JSON strings.
|
|
455
476
|
- Remote assets must be reachable by the browser and must satisfy the expected CORS policy.
|
|
456
477
|
- glTF files with external resources are resolved and cached by the viewer when possible.
|
|
457
|
-
- Avoid repeatedly replacing large assets if only visibility, camera, lighting, or material options changed.
|
|
478
|
+
- Avoid repeatedly replacing large assets if only visibility, camera, lighting, render, or material options changed.
|
|
479
|
+
- Use `pref-viewer-initialized` only as a component-readiness signal. If a host generates model data asynchronously, wait for the host data-ready signal before calling `loadConfig()`.
|
|
480
|
+
- For PrefWeb integration, consume the webpack UMD build (`bundle-umd.js`) and prefer development UMD builds while debugging source maps.
|
|
458
481
|
|
|
459
482
|
## License
|
|
460
483
|
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ import OpeningAnimationMenu from "./babylonjs-animation-opening-menu.js";
|
|
|
8
8
|
* - Tracks animation state (paused, closed, opened, opening, closing).
|
|
9
9
|
* - Synchronizes animation progress and UI controls.
|
|
10
10
|
* - Handles loop mode and progress threshold logic.
|
|
11
|
-
* - Dispatches `
|
|
11
|
+
* - Dispatches `pref-viewer-3d-animation-changed` events with animation state snapshots.
|
|
12
12
|
* - Provides methods for play, pause, go to opened/closed, and progress control.
|
|
13
13
|
* - Manages the animation control menu (OpeningAnimationMenu) and its callbacks.
|
|
14
14
|
*
|
|
@@ -20,12 +20,17 @@ import OpeningAnimationMenu from "./babylonjs-animation-opening-menu.js";
|
|
|
20
20
|
* - pause(): Pauses the current animation.
|
|
21
21
|
* - goToOpened(): Moves animation to the fully opened state.
|
|
22
22
|
* - goToClosed(): Moves animation to the fully closed state.
|
|
23
|
+
* - setProgress(progress): Seeks the animation to a normalized position (0–1), snapping to ends when within the threshold.
|
|
24
|
+
* - setLoop(loop): Enables or disables loop mode and syncs the control menu if visible.
|
|
23
25
|
* - showControls(canvas, openingAnimations): Displays the animation control menu and sets up callbacks.
|
|
24
26
|
* - hideControls(): Hides the animation control menu.
|
|
25
27
|
* - isControlsVisible(): Returns true if the control menu is visible for this animation.
|
|
26
28
|
*
|
|
27
29
|
* Public Properties:
|
|
28
|
-
* - state: Returns the current animation state.
|
|
30
|
+
* - state: Returns the current animation state (one of OpeningAnimation.states).
|
|
31
|
+
* - progress: Returns the normalized progress (0–1) derived from the current frame position.
|
|
32
|
+
* - loop: Returns whether loop mode is currently enabled.
|
|
33
|
+
* - nodes: Returns a copy of the node ID array affected by this animation.
|
|
29
34
|
*
|
|
30
35
|
* Private Methods:
|
|
31
36
|
* - #getNodesFromAnimationGroups(): Collects node IDs affected by the animation groups.
|
|
@@ -39,7 +44,7 @@ import OpeningAnimationMenu from "./babylonjs-animation-opening-menu.js";
|
|
|
39
44
|
* - #getProgress(): Calculates progress (0-1) from current frame.
|
|
40
45
|
* - #getPrefViewer3DComponent(): Resolves and caches the nearest `pref-viewer-3d` host element.
|
|
41
46
|
* - #checkProgress(progress): Applies threshold logic to progress.
|
|
42
|
-
* - #notifyStateChange(): Emits `
|
|
47
|
+
* - #notifyStateChange(): Emits `pref-viewer-3d-animation-changed` with state/progress/loop metadata.
|
|
43
48
|
* - #updateControlsSlider(): Updates the slider in the control menu.
|
|
44
49
|
* - #updateControls(): Emits state updates and syncs controls when the menu is visible.
|
|
45
50
|
*/
|
|
@@ -315,7 +320,7 @@ export default class OpeningAnimation {
|
|
|
315
320
|
}
|
|
316
321
|
|
|
317
322
|
/**
|
|
318
|
-
* Dispatches a `
|
|
323
|
+
* Dispatches a `pref-viewer-3d-animation-changed` CustomEvent from the nearest `pref-viewer-3d` host.
|
|
319
324
|
* The event bubbles and crosses shadow DOM boundaries, exposing the current animation snapshot
|
|
320
325
|
* (`name`, `state`, `progress`, and `loop`) in `event.detail`.
|
|
321
326
|
* @private
|
|
@@ -329,6 +334,7 @@ export default class OpeningAnimation {
|
|
|
329
334
|
|
|
330
335
|
const customEventOptions = {
|
|
331
336
|
bubbles: true,
|
|
337
|
+
cancelable: false,
|
|
332
338
|
composed: true,
|
|
333
339
|
detail: {
|
|
334
340
|
name: this.name,
|
|
@@ -337,7 +343,7 @@ export default class OpeningAnimation {
|
|
|
337
343
|
loop: this.#loop,
|
|
338
344
|
},
|
|
339
345
|
};
|
|
340
|
-
this.#prefViewer3D.dispatchEvent(new CustomEvent("
|
|
346
|
+
this.#prefViewer3D.dispatchEvent(new CustomEvent("pref-viewer-3d-animation-changed", customEventOptions));
|
|
341
347
|
return true;
|
|
342
348
|
}
|
|
343
349
|
|