@combeenation/3d-viewer 4.0.0-alpha7 → 4.0.0-beta2

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.
Files changed (57) hide show
  1. package/README.md +1 -0
  2. package/dist/lib-cjs/api/classes/element.d.ts +12 -16
  3. package/dist/lib-cjs/api/classes/element.js +125 -180
  4. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  5. package/dist/lib-cjs/api/classes/event.d.ts +1 -15
  6. package/dist/lib-cjs/api/classes/event.js +1 -15
  7. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  8. package/dist/lib-cjs/api/classes/parameter.d.ts +7 -101
  9. package/dist/lib-cjs/api/classes/parameter.js +21 -141
  10. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  11. package/dist/lib-cjs/api/classes/parameterObservable.js +36 -11
  12. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  13. package/dist/lib-cjs/api/classes/variant.d.ts +14 -48
  14. package/dist/lib-cjs/api/classes/variant.js +56 -315
  15. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  16. package/dist/lib-cjs/api/classes/variantInstance.d.ts +1 -5
  17. package/dist/lib-cjs/api/classes/variantInstance.js +0 -10
  18. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  19. package/dist/lib-cjs/api/classes/viewer.d.ts +1 -0
  20. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  21. package/dist/lib-cjs/api/classes/viewerLight.js +27 -19
  22. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  23. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +1 -5
  24. package/dist/lib-cjs/api/internal/sceneSetup.js +71 -75
  25. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  26. package/dist/lib-cjs/api/util/babylonHelper.d.ts +4 -51
  27. package/dist/lib-cjs/api/util/babylonHelper.js +8 -141
  28. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  29. package/dist/lib-cjs/api/util/globalTypes.d.ts +11 -53
  30. package/dist/lib-cjs/api/util/resourceHelper.d.ts +8 -4
  31. package/dist/lib-cjs/api/util/resourceHelper.js +25 -59
  32. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  33. package/dist/lib-cjs/index.d.ts +22 -24
  34. package/dist/lib-cjs/index.js +38 -42
  35. package/dist/lib-cjs/index.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/api/classes/element.ts +112 -133
  38. package/src/api/classes/{parameterizable.ts → elementParameterizable.ts} +1 -12
  39. package/src/api/classes/event.ts +1 -16
  40. package/src/api/classes/parameter.ts +22 -153
  41. package/src/api/classes/parameterObservable.ts +31 -9
  42. package/src/api/classes/variant.ts +51 -184
  43. package/src/api/classes/variantInstance.ts +1 -8
  44. package/src/api/classes/viewer.ts +1 -0
  45. package/src/api/internal/sceneSetup.ts +109 -99
  46. package/src/api/util/babylonHelper.ts +9 -153
  47. package/src/api/util/globalTypes.ts +13 -64
  48. package/src/api/util/resourceHelper.ts +24 -26
  49. package/src/dev.ts +7 -5
  50. package/src/index.ts +23 -27
  51. package/src/pagesconfig.json +13 -8
  52. package/dist/lib-cjs/api/emitter.d.ts +0 -35
  53. package/dist/lib-cjs/api/emitter.js +0 -61
  54. package/dist/lib-cjs/api/emitter.js.map +0 -1
  55. package/src/api/classes/variantParameterizable.ts +0 -73
  56. package/src/api/classes/viewerLight.ts +0 -326
  57. package/src/api/util/stringHelper.ts +0 -26
@@ -8,7 +8,6 @@ type VariantInstance = import("../classes/variantInstance").VariantInstance;
8
8
  */
9
9
  type VariantElement = import("../classes/element").Element;
10
10
  type DottedPath = import("../classes/dottedPath").DottedPath;
11
- type ViewerLight = import("../classes/viewerLight").ViewerLight;
12
11
 
13
12
  // global accessible types imported from BabylonJS
14
13
  type Scene = import("@babylonjs/core/scene").Scene;
@@ -69,10 +68,6 @@ type Asset = {
69
68
  fileName: string | undefined
70
69
  };
71
70
 
72
- type ElementDefinitions = {
73
- [name: string]: ElementDefinition | string[]
74
- };
75
-
76
71
  type ElementDefinition = {
77
72
  paths: PathDefinitions,
78
73
  traceables?: TraceableDefinitions,
@@ -97,9 +92,9 @@ type StructureJson = {
97
92
  glTF?: Asset | string,
98
93
  parameterDeclaration?: ParameterDeclarations,
99
94
  parameters?: ParameterBag,
100
- elements?: ElementDefinitions,
101
- lights?: LightDefinitions,
102
- grounds?: GroundDefinitions,
95
+ elements?: {
96
+ [name: string]: ElementDefinition | string[]
97
+ },
103
98
  /**
104
99
  * `variants` is a declarative description of 3D-model variations in the configurator. Each variant itself is a
105
100
  * {@link StructureJson} which must at least define a `name` in the key of the list and the properties `glTF` and
@@ -128,7 +123,7 @@ type StructureJson = {
128
123
  */
129
124
  variants?: {
130
125
  [id: string]: StructureJson,
131
- },
126
+ }
132
127
  };
133
128
 
134
129
  type SceneJson = {
@@ -149,7 +144,8 @@ type SceneJson = {
149
144
 
150
145
  type SceneDefinition = {
151
146
  globals: SceneGlobals,
152
- cameras?: CameraDefinitions,
147
+ lights?: LightDefinitions,
148
+ cameras?: CameraDefinitions
153
149
  };
154
150
 
155
151
  type SceneGlobals = {
@@ -193,29 +189,12 @@ type SceneGlobals = {
193
189
  }
194
190
  };
195
191
 
196
- /**
197
- * {@link Viewer.screenshot} internally uses Babylons [ScreenshotTools.CreateScreenshotUsingRenderTarget](https://doc.babylonjs.com/typedoc/classes/babylon.screenshottools#createscreenshotusingrendertarget). \
198
- * See this link for additional info about the properties.
199
- */
200
192
  type ScreenshotSettings = {
201
- /** Defaults to canvas width & height */
202
193
  size?: IScreenshotSize,
203
- /**
204
- * Default `image/png`
205
- *
206
- * **Info regarding JPEG:** \
207
- * Use mimeType `image/jpeg` (**not** `image/jpg`) when creating jpeg's. \
208
- * Also ensure that {@link Scene.clearColor | viewer.scene.clearColor} has an alpha value of `1` as jpeg's don't support
209
- * transparency. Otherwise background will always be black for jpeg's.
210
- */
211
194
  mimeType?: string,
212
- /** Default `1` */
213
195
  samples?: number,
214
- /** Default `false` */
215
196
  antialiasing?: boolean,
216
- /** Default `screenshot.png` */
217
197
  fileName?: string,
218
- /** Default `false` */
219
198
  renderSprites?: boolean
220
199
  };
221
200
 
@@ -231,40 +210,11 @@ type AutofocusSettings = {
231
210
  };
232
211
 
233
212
  type LightDefinitions = {
234
- [name: string]: LightDefinition | string
213
+ [light: string]: LightDefinition
235
214
  };
236
215
 
237
216
  type LightDefinition = {
238
- type: 'baked' | 'hemispheric' | 'point' | 'directional' | 'spot',
239
- path?: string,
240
- shadowGenerator?: ShadowGeneratorDefinition
241
- };
242
-
243
- type ShadowGeneratorDefinition = {
244
- mapSize: number
245
- [others: string]: any,
246
- /**
247
- * Further properties like `usePoissonSampling` are set directly on the ShadowGenerator object.
248
- * [Shadows](https://doc.babylonjs.com/divingDeeper/lights/shadows)
249
- */
250
- };
251
-
252
- type GroundDefinitions = {
253
- [ground: string]: GroundDefinition
254
- };
255
-
256
- type GroundDefinition = {
257
- type: 'baked' | 'ground' | 'heightmap',
258
- meshId?: string,
259
- url?: string,
260
- width?: number,
261
- height?: number,
262
- subdivisions?: number,
263
- receiveShadows?: boolean,
264
- minHeight?: number,
265
- maxHeight?: number,
266
- alphaFilter?: number,
267
- onReady?: any
217
+ type: 'hemispheric' | 'point'
268
218
  };
269
219
 
270
220
  type CameraDefinitions = {
@@ -280,6 +230,10 @@ type CameraDefinition = {
280
230
  /**
281
231
  * `arc` is a default camera position where the 3D-model is the center and the camera rotates around the 3D-model.
282
232
  * More Information about `arc` in [ArcRotateCamera](https://doc.babylonjs.com/typedoc/classes/babylon.arcrotatecamera).
233
+ *
234
+ * NOTE: While "baked" camera definitions from a GLB or babylon file can currently not be instatiated within the `Specification`, it's still possible to use them in the viewer.\
235
+ * For the moment all camera definitions inside these files are automatically added to the scene and can be actived using the {@link switchCamera} function.\
236
+ * The `newCamera` input has to match the name of the camera node inside the GLB/babylon file.
283
237
  */
284
238
  type: 'arc'
285
239
  /**
@@ -304,8 +258,7 @@ type ParameterDeclarations = {
304
258
  };
305
259
 
306
260
  type ParameterDeclaration = {
307
- type: 'string' | 'boolean' | 'number' | 'color' | 'select' | 'vector' | 'csl',
308
- parser?: any,
261
+ type: 'string' | 'boolean' | 'number' | 'color' | 'select' | 'vector',
309
262
  options?: ParameterValue[]
310
263
  };
311
264
 
@@ -315,10 +268,6 @@ type ParameterBag = {
315
268
  [name: string]: ParameterValue
316
269
  };
317
270
 
318
- type ParsedParameterBag = {
319
- [name: string]: any
320
- };
321
-
322
271
  type DottedPathArgument = string | string[] | DottedPath;
323
272
 
324
273
  type ParameterObserver = (
@@ -56,6 +56,16 @@ const debounce = function( func: Function, wait: number, immediate: boolean = fa
56
56
  };
57
57
  };
58
58
 
59
+ /**
60
+ * Creates a random uuidv4.
61
+ */
62
+ const uuidv4 = function() {
63
+ // @ts-ignore
64
+ return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace( /[018]/g, c =>
65
+ (c ^ crypto.getRandomValues( new Uint8Array( 1 ) )[0] & 15 >> c / 4).toString( 16 )
66
+ );
67
+ };
68
+
59
69
  /**
60
70
  * Merges multiple maps.
61
71
  */
@@ -70,31 +80,19 @@ const mergeMaps = function <TKey, TValue>( ...maps: Map<TKey, TValue>[] ): Map<T
70
80
  };
71
81
 
72
82
  /**
73
- * Creates an `ImageBitmap` from a SVG string using native `createImageBitmap` functionality.
83
+ * Converts a svg string into an URL with a base64 representation of that image.\
84
+ * This URL can be used as the basis of a paintable texture.
74
85
  */
75
- const createImageBitmapFromSvg = async function( svgSrc: string ): Promise<ImageBitmap> {
76
- return new Promise( async resolve => {
77
- const svgWithAssetsEmbedded = await _embedAssets( svgSrc );
78
- const svgBlob = new Blob( [svgWithAssetsEmbedded], { type: 'image/svg+xml;charset=utf-8' } );
79
- const svgBase64 = URL.createObjectURL( svgBlob );
80
- let img = new Image();
81
- img.onload = async () => {
82
- const imgBitmap = await createImageBitmap( img );
83
- resolve( imgBitmap );
84
- };
85
- img.src = svgBase64;
86
- } );
87
- };
86
+ const createImageUrlFromSvg = async function( svgSrc: string ): Promise<string> {
87
+ // replace assets with their base64 versions in svg source code
88
+ const svgWithAssetsEmbedded = await _embedAssets( svgSrc );
88
89
 
89
- const createImageBitmapFromImgSrc = async function( imgSrc: string ): Promise<ImageBitmap> {
90
- const img = new Image();
91
- img.src = imgSrc;
92
- return new Promise( resolve => {
93
- img.onload = async () => {
94
- const imgBitmap = await createImageBitmap( img );
95
- resolve( imgBitmap );
96
- };
97
- } );
90
+ // create blob from that
91
+ const svgBlob = new Blob( [svgWithAssetsEmbedded], { type: 'image/svg+xml' } );
92
+
93
+ // create URL that can be used in HTML (?)
94
+ const imgUrl = URL.createObjectURL( svgBlob );
95
+ return imgUrl;
98
96
  };
99
97
 
100
98
  /**
@@ -102,7 +100,7 @@ const createImageBitmapFromImgSrc = async function( imgSrc: string ): Promise<Im
102
100
  */
103
101
  const _embedAssets = async function( svgSrc: string ): Promise<string> {
104
102
  const _imageExtensions = ['png', 'gif', 'jpg', 'jpeg', 'svg', 'bmp'];
105
- const _fontExtensions = ['woff2'];
103
+ const _fontExtensions = ['woff2', 'woff', 'ttf', 'otf'];
106
104
  const _assetExtensions = [..._imageExtensions, ..._fontExtensions];
107
105
  // Regex copied from https://stackoverflow.com/a/8943487/1273551, not "stress tested"...
108
106
  const urlRegex = /(\bhttps?:\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi;
@@ -152,7 +150,7 @@ export {
152
150
  loadJson,
153
151
  loadText,
154
152
  debounce,
153
+ uuidv4,
155
154
  mergeMaps,
156
- createImageBitmapFromSvg,
157
- createImageBitmapFromImgSrc
155
+ createImageUrlFromSvg
158
156
  };
package/src/dev.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import '@babylonjs/core';
2
2
  import { Event } from 'api/classes/event';
3
- import { merge, set } from 'lodash-es';
3
+ import { set } from 'lodash-es';
4
4
 
5
5
  import { Emitter, Viewer } from '.';
6
- import { createCombobox } from '../assets/ctrls-helper';
7
-
8
- import { createSpec, beforeBootstrap, afterBootstrap, createUIelements } from '../assets/streetscene/main';
9
- //import { createSpec, beforeBootstrap, afterBootstrap, createUIelements } from '../assets/KTM1290SA/ktm1290SA_2';
10
6
 
7
+ /**
8
+ * (i) HERE YOU @TODO (1) ADJUST THE CURRENT DEMO YOU ARE WORKING ON.
9
+ */
10
+ import { createSpec, beforeBootstrap, afterBootstrap, createUIelements } from '../assets/hulahoop/main';
11
11
  const loadingElement = document.getElementById( 'loading' ) as HTMLDivElement;
12
12
 
13
13
  Emitter.on( Event.BOOTSTRAP_START, () => {
@@ -41,5 +41,7 @@ async function bootstrapViewer() {
41
41
  }
42
42
  await afterBootstrap( viewer );
43
43
  await createUIelements( viewer );
44
+ console.info( ' --- UI Initialized ---');
45
+
44
46
  return viewer;
45
47
  }
package/src/index.ts CHANGED
@@ -1,50 +1,48 @@
1
1
  /// <reference path="api/util/globalTypes.ts" />
2
2
 
3
- import { Animation as BabylonAnimation } from '@babylonjs/core/Animations/animation';
4
3
  import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
5
4
  import { Engine } from '@babylonjs/core/Engines/engine';
6
- import { DirectionalLight } from '@babylonjs/core/Lights/directionalLight';
7
- import { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight';
8
5
  import { Material } from '@babylonjs/core/Materials/material';
9
6
  import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';
10
7
  import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';
11
- import { CubeTexture } from '@babylonjs/core/Materials/Textures/cubeTexture';
12
8
  import { DynamicTexture } from '@babylonjs/core/Materials/Textures/dynamicTexture';
13
- import { Texture } from '@babylonjs/core/Materials/Textures/texture';
14
9
  import { Color3, Color4 } from '@babylonjs/core/Maths/math.color';
15
10
  import { Vector3 } from '@babylonjs/core/Maths/math.vector';
16
11
  import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';
17
12
  import { InstancedMesh } from '@babylonjs/core/Meshes/instancedMesh';
18
13
  import { Mesh } from '@babylonjs/core/Meshes/mesh';
19
- import { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';
20
14
  import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
21
15
  import { Node } from '@babylonjs/core/node';
22
-
23
- /**
24
- * Without explicitly importing the "BoundingBoxRenderer", we're getting "scene.getBoundingBoxRenderer is undefined"
25
- * errors when creating HighlightLayer instances. Not sure why but those errors only happen when using the built
26
- * version of the viewer (e.g. when pulling it from NPM etc.)...
27
- */
28
- import '@babylonjs/core/Rendering/boundingBoxRenderer';
29
16
  import { Scene } from '@babylonjs/core/scene';
30
- import { Parameterizable } from './api/classes/parameterizable';
31
- import { VariantParameterizable } from './api/classes/variantParameterizable';
17
+ import { VariantInstance } from './api/classes/variantInstance';
18
+ import { Viewer } from './api/classes/viewer';
19
+ import { Event, emitter } from './api/classes/event';
32
20
  import { EventEmitter } from 'eventemitter3';
33
- import { Element } from './api/classes/element';
34
- import { emitter, Event } from './api/classes/event';
35
- import { EventBroadcaster } from './api/classes/eventBroadcaster';
36
21
  import { Parameter } from './api/classes/parameter';
37
- import { ParameterObservable } from './api/classes/parameterObservable';
38
- import { PlacementAnimation } from './api/classes/placementAnimation';
22
+ import { CubeTexture } from '@babylonjs/core/Materials/Textures/cubeTexture';
23
+ import { Animation as BabylonAnimation } from '@babylonjs/core/Animations/animation';
24
+ import { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';
25
+ import { Texture } from '@babylonjs/core/Materials/Textures/texture';
26
+ import { DirectionalLight } from '@babylonjs/core/Lights/directionalLight';
27
+ import { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight';
39
28
  import { Variant } from './api/classes/variant';
40
- import { VariantInstance } from './api/classes/variantInstance';
41
- import { Viewer } from './api/classes/viewer';
42
- import { ViewerLight } from './api/classes/viewerLight';
29
+ import { ParameterObservable } from './api/classes/parameterObservable';
30
+ import { ElementParameterizable } from './api/classes/elementParameterizable';
31
+ import { Element } from './api/classes/element';
32
+ import { VariantInstanceManager } from './api/manager/variantInstanceManager';
43
33
  import { AnimationManager } from './api/manager/animationManager';
34
+ import { EventBroadcaster } from './api/classes/eventBroadcaster';
44
35
  import { SceneManager } from './api/manager/sceneManager';
45
- import { VariantInstanceManager } from './api/manager/variantInstanceManager';
36
+ import { PlacementAnimation } from './api/classes/placementAnimation';
46
37
  import * as BabylonHelper from './api/util/babylonHelper';
47
38
 
39
+ /**
40
+ * Without explicitly importing the "BoundingBoxRenderer", we're getting "scene.getBoundingBoxRenderer is undefined"
41
+ * errors when creating HighlightLayer instances. Not sure why but those errors only happen when using the built
42
+ * version of the viewer (e.g. when pulling it from NPM etc.)...
43
+ */
44
+ import '@babylonjs/core/Rendering/boundingBoxRenderer';
45
+
48
46
  /**
49
47
  * Expose some frequently used babylon modules by our consumers.
50
48
  */
@@ -54,9 +52,7 @@ export {
54
52
  VariantInstanceManager,
55
53
  Viewer,
56
54
  ParameterObservable,
57
- Parameterizable,
58
- VariantParameterizable,
59
- ViewerLight,
55
+ ElementParameterizable,
60
56
  emitter as Emitter,
61
57
  EventEmitter,
62
58
  Event,
@@ -32,21 +32,26 @@
32
32
  "pages": [
33
33
  {
34
34
  "title": "Specification",
35
- "source": "./doc/Specification.md"
35
+ "source": "./doc/documentation/Specification.md"
36
36
  },
37
37
  {
38
38
  "title": "Parameters",
39
- "source": "./doc/Parameters.md"
40
- },
41
- {
42
- "title": "ViewerLights",
43
- "source": "./doc/ViewerLights.md"
39
+ "source": "./doc/documentation/Parameters.md"
44
40
  },
45
41
  {
46
42
  "title": "Paintables",
47
- "source": "./doc/Paintables.md"
43
+ "source": "./doc/documentation/Paintables.md"
44
+ }
45
+ ]
46
+ },
47
+ {
48
+ "title": "Best Practice",
49
+ "pages": [
50
+ {
51
+ "title": "How to change custom material properties",
52
+ "source": "./doc/best-practice/Custom-material-properties.md"
48
53
  }
49
54
  ]
50
55
  }
51
56
  ]
52
- }
57
+ }
@@ -1,35 +0,0 @@
1
- /** @internal **/
2
- export declare const emitter: import("eventemitter3")<string | symbol, any>;
3
- /**
4
- *
5
- * # ATTENTION
6
- *
7
- * This `Event` class only exists inside TypeScript and is used to consistently link to the Events. When using the module inside
8
- * JavaScript, **only** use the "alias" names e.g. bootstrapStart instead of Events.BOOTSTRAP_START
9
- */
10
- export declare const enum Events {
11
- BOOTSTRAP_START = "bootstrapStart",
12
- BOOTSTRAP_END = "bootstrapEnd",
13
- LOADING_START = "loadingStart",
14
- LOADING_END = "loadingEnd",
15
- ASSET_LOADING_START = "assetLoadingStart",
16
- ASSET_LOADING_END = "assetLoadingEnd",
17
- SCENE_PROCESSING_START = "sceneProcessingStart",
18
- SCENE_PROCESSING_END = "sceneProcessingEnd",
19
- ANIMATION_END = "animationEnd",
20
- VARIANT_CREATED = "variantCreated",
21
- VARIANT_CREATED_LIVING = "variantCreatedLiving",
22
- VARIANT_DESTROYED = "variantDestroyed",
23
- VARIANT_PICKED = "variantPicked",
24
- ELEMENT_PICKED = "elementPicked",
25
- VARIANT_PARAMETER_COMMITTED = "variantParameterCommitted",
26
- VARIANT_INSTANCE_CREATED = "variantInstanceCreated",
27
- VARIANT_INSTANCE_REGISTERED = "variantInstanceRegistered",
28
- VARIANT_INSTANCE_CLONED = "variantInstanceCloned",
29
- VARIANT_INSTANCE_DESTROYED = "variantInstanceDestroyed",
30
- ELEMENT_PARAMETER_COMMITTED = "elementParameterCommitted",
31
- SCENE_PARAMETER_COMMITTED = "sceneParameterCommitted",
32
- CAMERA_SWITCHED = "cameraSwitched",
33
- MESH_PICKED = "meshPicked"
34
- }
35
- export declare const eventNames: string[];
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var eventemitter3_1 = require("eventemitter3");
4
- /** @internal **/
5
- exports.emitter = new eventemitter3_1.EventEmitter();
6
- //const allows inlining by tsc
7
- /**
8
- *
9
- * # ATTENTION
10
- *
11
- * This `Event` class only exists inside TypeScript and is used to consistently link to the Events. When using the module inside
12
- * JavaScript, **only** use the "alias" names e.g. bootstrapStart instead of Events.BOOTSTRAP_START
13
- */
14
- var Events;
15
- (function (Events) {
16
- Events["BOOTSTRAP_START"] = "bootstrapStart";
17
- Events["BOOTSTRAP_END"] = "bootstrapEnd";
18
- Events["LOADING_START"] = "loadingStart";
19
- Events["LOADING_END"] = "loadingEnd";
20
- Events["ASSET_LOADING_START"] = "assetLoadingStart";
21
- Events["ASSET_LOADING_END"] = "assetLoadingEnd";
22
- Events["SCENE_PROCESSING_START"] = "sceneProcessingStart";
23
- Events["SCENE_PROCESSING_END"] = "sceneProcessingEnd";
24
- Events["ANIMATION_END"] = "animationEnd";
25
- Events["VARIANT_CREATED"] = "variantCreated";
26
- Events["VARIANT_CREATED_LIVING"] = "variantCreatedLiving";
27
- Events["VARIANT_DESTROYED"] = "variantDestroyed";
28
- Events["VARIANT_PICKED"] = "variantPicked";
29
- Events["ELEMENT_PICKED"] = "elementPicked";
30
- Events["VARIANT_PARAMETER_COMMITTED"] = "variantParameterCommitted";
31
- Events["VARIANT_INSTANCE_CREATED"] = "variantInstanceCreated";
32
- Events["VARIANT_INSTANCE_REGISTERED"] = "variantInstanceRegistered";
33
- Events["VARIANT_INSTANCE_CLONED"] = "variantInstanceCloned";
34
- Events["VARIANT_INSTANCE_DESTROYED"] = "variantInstanceDestroyed";
35
- Events["ELEMENT_PARAMETER_COMMITTED"] = "elementParameterCommitted";
36
- Events["SCENE_PARAMETER_COMMITTED"] = "sceneParameterCommitted";
37
- Events["CAMERA_SWITCHED"] = "cameraSwitched";
38
- Events["MESH_PICKED"] = "meshPicked";
39
- })(Events = exports.Events || (exports.Events = {}));
40
- exports.eventNames = [
41
- 'bootstrapStart',
42
- 'bootstrapEnd',
43
- 'loadingStart',
44
- 'loadingEnd',
45
- 'sceneProcessingStart',
46
- 'sceneProcessingEnd',
47
- 'animationEnd',
48
- 'variantCreated',
49
- 'variantCreatedLiving',
50
- 'variantDestroyed',
51
- 'variantPicked',
52
- 'variantParameterCommitted',
53
- 'variantInstanceCreated',
54
- 'variantInstanceRegistered',
55
- 'variantInstanceCloned',
56
- 'variantInstanceDestroyed',
57
- 'elementParameterCommitted',
58
- 'cameraSwitched',
59
- 'meshPicked',
60
- ];
61
- //# sourceMappingURL=emitter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"emitter.js","sourceRoot":"","sources":["../../../src/api/emitter.ts"],"names":[],"mappings":";;AAAA,+CAA6C;AAE7C,iBAAiB;AACJ,QAAA,OAAO,GAAG,IAAI,4BAAY,EAAE,CAAC;AAG1C,8BAA8B;AAC9B;;;;;;GAMG;AACH,IAAkB,MAoCjB;AApCD,WAAkB,MAAM;IACvB,4CAAkC,CAAA;IAClC,wCAA8B,CAAA;IAE9B,wCAA8B,CAAA;IAC9B,oCAA0B,CAAA;IAE1B,mDAAyC,CAAA;IACzC,+CAAqC,CAAA;IAErC,yDAA+C,CAAA;IAC/C,qDAA2C,CAAA;IAE3C,wCAA8B,CAAA;IAE9B,4CAAkC,CAAA;IAClC,yDAA+C,CAAA;IAC/C,gDAAsC,CAAA;IAEtC,0CAAgC,CAAA;IAChC,0CAAgC,CAAA;IAEhC,mEAAyD,CAAA;IAEzD,6DAAmD,CAAA;IACnD,mEAAyD,CAAA;IACzD,2DAAiD,CAAA;IACjD,iEAAuD,CAAA;IAEvD,mEAAyD,CAAA;IAEzD,+DAAqD,CAAA;IAErD,4CAAkC,CAAA;IAElC,oCAA0B,CAAA;AAC3B,CAAC,EApCiB,MAAM,GAAN,cAAM,KAAN,cAAM,QAoCvB;AAEY,QAAA,UAAU,GAAG;IACzB,gBAAgB;IAChB,cAAc;IAEd,cAAc;IACd,YAAY;IAEZ,sBAAsB;IACtB,oBAAoB;IAEpB,cAAc;IAEd,gBAAgB;IAChB,sBAAsB;IACtB,kBAAkB;IAElB,eAAe;IAEf,2BAA2B;IAE3B,wBAAwB;IACxB,2BAA2B;IAC3B,uBAAuB;IACvB,0BAA0B;IAE1B,2BAA2B;IAE3B,gBAAgB;IAEhB,YAAY;CACZ,CAAC"}
@@ -1,73 +0,0 @@
1
- import { DottedPath } from './../classes/dottedPath';
2
- import { Event } from './../classes/event';
3
- import { Parameterizable } from './../classes/parameterizable';
4
- import { Variant } from './../classes/variant';
5
- import { mergeMaps } from './../util/resourceHelper';
6
- import { camelToSnakeCase } from './../util/stringHelper';
7
- import { cloneDeep, concat, get, merge } from 'lodash-es';
8
-
9
- export abstract class VariantParameterizable extends Parameterizable {
10
-
11
- protected readonly _parameterObservers: Map<string, ParameterObserver[]> = new Map();
12
-
13
- protected constructor( public readonly variant: Variant,
14
- public readonly name: string ) {
15
- super();
16
- }
17
-
18
- /**
19
- * Gets the inherited parameters from the {@link Variant} with cleaned {@link Parameterizable} prefix.
20
- */
21
- get inheritedParameters(): ParameterBag {
22
- const parameterBag: ParameterBag = {};
23
- for( const parameter in this.variant.inheritedParameters ) {
24
- const dpp = DottedPath.create( parameter );
25
- if( dpp.firstPart !== this.name ) {
26
- continue;
27
- }
28
- dpp.shiftPart();
29
- parameterBag[dpp.path] = this.variant.inheritedParameters[parameter];
30
- }
31
- return parameterBag;
32
- }
33
-
34
- /**
35
- * Places the given {@link ParameterBag} in the {@link VariantParameterizable}'s parameters, replaces all patterns in the
36
- * {@link StructureJson} and broadcasts all {@link ParameterObserver}s.
37
- */
38
- public async commitParameters( parameters?: ParameterBag ): Promise<VariantParameterizable> {
39
- if( !parameters ) {
40
- parameters = {};
41
- }
42
- const oldParameters = cloneDeep( this.parameters );
43
- merge( this.parameters, parameters );
44
- // handle parameter observers
45
- let observerPromises: Promise<void | ParameterObserver>[] = [];
46
- for( const parameter in this.parameters ) {
47
- const oldParameterValue = oldParameters[parameter];
48
- const newParameterValue = this.parameters[parameter];
49
- this.variant.assertParameter( this.variant.inheritedParameterDeclaration, parameter, newParameterValue );
50
- if( oldParameterValue === newParameterValue ) {
51
- continue;
52
- }
53
- // parameter changed
54
- const parameterObservers = mergeMaps( this._parameterObservers, this.parameterObservers );
55
- if( parameterObservers.has( parameter ) ) {
56
- const observers = parameterObservers.get( parameter )!;
57
- observerPromises = concat( observerPromises, observers.map( observer => {
58
- const observerResult = observer( this, oldParameterValue, newParameterValue );
59
- const observerPromise = Promise.resolve( observerResult );
60
- observerPromise.then( () => {
61
- const clsName = camelToSnakeCase( this.constructor.name ).toUpperCase();
62
- this.broadcastEvent( get( Event, clsName + '_PARAMETER_COMMITTED' ),
63
- this, parameter, oldParameterValue, newParameterValue );
64
- } );
65
- return observerPromise;
66
- } ) );
67
- }
68
- }
69
- await Promise.all( observerPromises );
70
- return this;
71
- }
72
-
73
- }