@combeenation/3d-viewer 4.2.0 → 5.0.0-alpha1

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 (95) hide show
  1. package/README.md +2 -2
  2. package/dist/lib-cjs/api/classes/dottedPath.js +2 -5
  3. package/dist/lib-cjs/api/classes/dottedPath.js.map +1 -1
  4. package/dist/lib-cjs/api/classes/element.d.ts +9 -0
  5. package/dist/lib-cjs/api/classes/element.js +114 -66
  6. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  7. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  8. package/dist/lib-cjs/api/classes/eventBroadcaster.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/parameter.js +3 -2
  10. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  11. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  12. package/dist/lib-cjs/api/classes/parameterizable.js.map +1 -1
  13. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +1 -0
  14. package/dist/lib-cjs/api/classes/placementAnimation.js +2 -2
  15. package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
  16. package/dist/lib-cjs/api/classes/variant.js +26 -19
  17. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  18. package/dist/lib-cjs/api/classes/variantInstance.js +19 -19
  19. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  20. package/dist/lib-cjs/api/classes/variantParameterizable.js.map +1 -1
  21. package/dist/lib-cjs/api/classes/viewer.d.ts +40 -1
  22. package/dist/lib-cjs/api/classes/viewer.js +144 -48
  23. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  24. package/dist/lib-cjs/api/classes/viewerLight.js +25 -25
  25. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  26. package/dist/lib-cjs/api/internal/debugViewer.js +1 -2
  27. package/dist/lib-cjs/api/internal/debugViewer.js.map +1 -1
  28. package/dist/lib-cjs/api/internal/lensRendering.js.map +1 -1
  29. package/dist/lib-cjs/api/internal/sceneSetup.js +25 -22
  30. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  31. package/dist/lib-cjs/api/manager/animationManager.js +24 -15
  32. package/dist/lib-cjs/api/manager/animationManager.js.map +1 -1
  33. package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +40 -10
  34. package/dist/lib-cjs/api/manager/gltfExportManager.js +135 -20
  35. package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
  36. package/dist/lib-cjs/api/manager/sceneManager.js +3 -3
  37. package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
  38. package/dist/lib-cjs/api/manager/variantInstanceManager.js +10 -7
  39. package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +1 -1
  40. package/dist/lib-cjs/api/store/specStorage.js.map +1 -1
  41. package/dist/lib-cjs/api/util/babylonHelper.d.ts +1 -1
  42. package/dist/lib-cjs/api/util/babylonHelper.js +12 -15
  43. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  44. package/dist/lib-cjs/api/util/globalTypes.d.ts +41 -25
  45. package/dist/lib-cjs/api/util/resourceHelper.js +3 -1
  46. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  47. package/dist/lib-cjs/api/util/stringHelper.d.ts +1 -1
  48. package/dist/lib-cjs/api/util/stringHelper.js +2 -2
  49. package/dist/lib-cjs/api/util/stringHelper.js.map +1 -1
  50. package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -0
  51. package/dist/lib-cjs/api/util/structureHelper.js +45 -0
  52. package/dist/lib-cjs/api/util/structureHelper.js.map +1 -0
  53. package/dist/lib-cjs/index.js +1 -0
  54. package/dist/lib-cjs/index.js.map +1 -1
  55. package/package.json +11 -7
  56. package/src/api/classes/animationInterface.ts +4 -6
  57. package/src/api/classes/dottedPath.ts +179 -187
  58. package/src/api/classes/element.ts +665 -621
  59. package/src/api/classes/event.ts +310 -313
  60. package/src/api/classes/eventBroadcaster.ts +47 -49
  61. package/src/api/classes/parameter.ts +394 -397
  62. package/src/api/classes/parameterObservable.ts +84 -83
  63. package/src/api/classes/parameterizable.ts +71 -73
  64. package/src/api/classes/placementAnimation.ts +130 -130
  65. package/src/api/classes/variant.ts +806 -778
  66. package/src/api/classes/variantInstance.ts +60 -52
  67. package/src/api/classes/variantParameterizable.ts +72 -67
  68. package/src/api/classes/viewer.ts +592 -490
  69. package/src/api/classes/viewerLight.ts +301 -301
  70. package/src/api/internal/debugViewer.ts +61 -53
  71. package/src/api/internal/lensRendering.ts +2 -3
  72. package/src/api/internal/sceneSetup.ts +144 -137
  73. package/src/api/manager/animationManager.ts +122 -97
  74. package/src/api/manager/gltfExportManager.ts +192 -0
  75. package/src/api/manager/sceneManager.ts +83 -86
  76. package/src/api/manager/variantInstanceManager.ts +234 -224
  77. package/src/api/store/specStorage.ts +48 -51
  78. package/src/api/util/babylonHelper.ts +329 -325
  79. package/src/api/util/globalTypes.ts +260 -246
  80. package/src/api/util/resourceHelper.ts +97 -109
  81. package/src/api/util/stringHelper.ts +13 -16
  82. package/src/api/util/structureHelper.ts +43 -0
  83. package/src/buildinfo.json +2 -2
  84. package/src/commonjs.tsconfig.json +8 -11
  85. package/src/declaration.tsconfig.json +6 -8
  86. package/src/dev.ts +28 -29
  87. package/src/es6.tsconfig.json +8 -11
  88. package/src/index.ts +40 -39
  89. package/src/pagesconfig.json +4 -0
  90. package/src/tsconfig.json +30 -41
  91. package/src/tsconfig.types.json +8 -9
  92. package/src/types.d.ts +0 -1
  93. package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +0 -14
  94. package/dist/lib-cjs/api/classes/elementParameterizable.js +0 -135
  95. package/dist/lib-cjs/api/classes/elementParameterizable.js.map +0 -1
@@ -9,109 +9,134 @@ import { PlacementAnimation } from '../classes/placementAnimation';
9
9
 
10
10
  //gsap.registerPlugin( CustomEase, ExpoScaleEase, RoughEase, SlowMo );
11
11
 
12
+ export class AnimationManager {
13
+ public animations: AnimationInterface[] = [];
12
14
 
13
- export class AnimationManager {
15
+ /**
16
+ * Constructor.
17
+ */
18
+ protected constructor(protected scene: Scene) {}
14
19
 
15
- public animations: AnimationInterface[] = [];
20
+ /**
21
+ * Creates an {@link AnimationManager} based on given BabylonJS scene.
22
+ */
23
+ public static async create(scene: BabylonScene): Promise<AnimationManager> {
24
+ return new AnimationManager(scene);
25
+ }
16
26
 
17
- /**
18
- * Constructor.
19
- */
20
- protected constructor( protected scene: Scene ) {
21
- }
27
+ /**
28
+ * @deprecated Use viewer.moveCameraTo().
29
+ */
30
+ public resetCamera(animate: boolean = false) {
31
+ //TODO currently only works for arcrotate. are there any other cameras?
32
+ let activeCamera = this.scene.activeCamera as Nullable<ArcRotateCamera>;
33
+ if (!activeCamera) {
34
+ throw new Error('There is no active camera');
35
+ }
22
36
 
23
- /**
24
- * Creates an {@link AnimationManager} based on given BabylonJS scene.
25
- */
26
- public static async create( scene: BabylonScene ): Promise<AnimationManager> {
27
- return new AnimationManager( scene );
28
- }
37
+ const initAlpha = activeCamera.metadata.alpha;
38
+ const initBeta = activeCamera.metadata.beta;
39
+ const initRadius = activeCamera.metadata.radius;
29
40
 
30
- /**
31
- * @deprecated Use viewer.moveCameraTo().
32
- */
33
- public resetCamera(animate: boolean = false) {
34
- //TODO currently only works for arcrotate. are there any other cameras?
35
- let activeCamera = this.scene.activeCamera as Nullable<ArcRotateCamera>;
36
- if( ! activeCamera ) {
37
- throw new Error( 'There is no active camera' );
38
- }
41
+ if (animate) {
42
+ this.animateArcRotateCamera(initAlpha, initBeta, initRadius);
43
+ } else {
44
+ activeCamera.alpha = initAlpha;
45
+ activeCamera.beta = initBeta;
46
+ activeCamera.radius = initRadius;
47
+ }
48
+ }
39
49
 
40
- const initAlpha = activeCamera.metadata.alpha;
41
- const initBeta = activeCamera.metadata.beta;
42
- const initRadius = activeCamera.metadata.radius;
50
+ /**
51
+ * @deprecated Use viewer.moveCameraTo().
52
+ */
53
+ public animateArcRotateCamera(targetAlpha: number, targetBeta: number, targetRadius: number) {
54
+ let activeCamera = this.scene.activeCamera as Nullable<ArcRotateCamera>;
55
+ if (!activeCamera) {
56
+ throw new Error('There is no active camera');
57
+ }
58
+ const alphaAnimation = new BabylonAnimation(
59
+ 'alphaAnimation',
60
+ 'alpha',
61
+ 30,
62
+ BabylonAnimation.ANIMATIONTYPE_FLOAT,
63
+ BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT
64
+ );
65
+ const betaAnimation = new BabylonAnimation(
66
+ 'betaAnimation',
67
+ 'beta',
68
+ 30,
69
+ BabylonAnimation.ANIMATIONTYPE_FLOAT,
70
+ BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT
71
+ );
72
+ const radiusAnimation = new BabylonAnimation(
73
+ 'radiusAnimation',
74
+ 'radius',
75
+ 30,
76
+ BabylonAnimation.ANIMATIONTYPE_FLOAT,
77
+ BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT
78
+ );
79
+ alphaAnimation.setKeys([
80
+ {
81
+ frame: 0,
82
+ value: activeCamera.alpha,
83
+ },
84
+ {
85
+ frame: 100,
86
+ value: targetAlpha,
87
+ },
88
+ ]);
89
+ betaAnimation.setKeys([
90
+ {
91
+ frame: 0,
92
+ value: activeCamera.beta,
93
+ },
94
+ {
95
+ frame: 100,
96
+ value: targetBeta,
97
+ },
98
+ ]);
99
+ radiusAnimation.setKeys([
100
+ {
101
+ frame: 0,
102
+ value: activeCamera.radius,
103
+ },
104
+ {
105
+ frame: 100,
106
+ value: targetRadius,
107
+ },
108
+ ]);
109
+ activeCamera.animations.push(alphaAnimation);
110
+ activeCamera.animations.push(betaAnimation);
111
+ activeCamera.animations.push(radiusAnimation);
43
112
 
44
- if( animate ) {
45
- this.animateArcRotateCamera(initAlpha, initBeta, initRadius);
46
- } else {
47
- activeCamera.alpha = initAlpha;
48
- activeCamera.beta = initBeta;
49
- activeCamera.radius = initRadius;
50
- }
51
- }
113
+ let animation = this.scene.beginAnimation(activeCamera, 0, 100, false, 10);
114
+ animation.disposeOnEnd = true;
115
+ }
52
116
 
53
- /**
54
- * @deprecated Use viewer.moveCameraTo().
55
- */
56
- public animateArcRotateCamera(targetAlpha: number, targetBeta: number, targetRadius: number) {
57
- let activeCamera = this.scene.activeCamera as Nullable<ArcRotateCamera>;
58
- if( ! activeCamera ) {
59
- throw new Error( 'There is no active camera' );
60
- }
61
- const alphaAnimation = new BabylonAnimation( 'alphaAnimation', 'alpha', 30, BabylonAnimation.ANIMATIONTYPE_FLOAT, BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT );
62
- const betaAnimation = new BabylonAnimation( 'betaAnimation', 'beta', 30, BabylonAnimation.ANIMATIONTYPE_FLOAT, BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT );
63
- const radiusAnimation = new BabylonAnimation( 'radiusAnimation', 'radius', 30, BabylonAnimation.ANIMATIONTYPE_FLOAT, BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT );
64
- alphaAnimation.setKeys([{
65
- frame : 0,
66
- value : activeCamera.alpha
67
- }, {
68
- frame : 100,
69
- value : targetAlpha
70
- }]);
71
- betaAnimation.setKeys([{
72
- frame : 0,
73
- value : activeCamera.beta
74
- }, {
75
- frame : 100,
76
- value : targetBeta
77
- }]);
78
- radiusAnimation.setKeys( [{
79
- frame : 0,
80
- value : activeCamera.radius
81
- }, {
82
- frame : 100,
83
- value : targetRadius
84
- }]);
85
- activeCamera.animations.push(alphaAnimation);
86
- activeCamera.animations.push(betaAnimation);
87
- activeCamera.animations.push(radiusAnimation);
117
+ /**
118
+ * Stops and kills all running animations.
119
+ */
120
+ public killAllAnimations() {
121
+ this.animations.forEach(animation => animation.kill());
122
+ this.animations = [];
123
+ }
88
124
 
89
- let animation = this.scene.beginAnimation(activeCamera, 0, 100, false, 10);
90
- animation.disposeOnEnd = true;
91
- }
92
-
93
- /**
94
- * Stops and kills all running animations.
95
- */
96
- public killAllAnimations() {
97
- this.animations.forEach( animation => animation.kill() );
98
- this.animations = [];
99
- }
100
-
101
- /**
102
- * @see {@link PlacementAnimation.play}
103
- */
104
- public async animateToPlacement( mutable: object,
105
- placement: PlacementDefinition | string,
106
- animation?: AnimationDefinition | string ): Promise<AnimationInterface> {
107
- const _animation = new PlacementAnimation( mutable, placement, animation );
108
- this.animations.push( _animation );
109
- const animationPromise = _animation.play();
110
- animationPromise.then( a => {
111
- remove( this.animations, _a => _a === a );
112
- a.kill();
113
- } );
114
- return await animationPromise;
115
- }
116
-
117
- }
125
+ /**
126
+ * @see {@link PlacementAnimation.play}
127
+ */
128
+ public async animateToPlacement(
129
+ mutable: object,
130
+ placement: PlacementDefinition | string,
131
+ animation?: AnimationDefinition | string
132
+ ): Promise<AnimationInterface> {
133
+ const _animation = new PlacementAnimation(mutable, placement, animation);
134
+ this.animations.push(_animation);
135
+ const animationPromise = _animation.play();
136
+ animationPromise.then(a => {
137
+ remove(this.animations, _a => _a === a);
138
+ a.kill();
139
+ });
140
+ return await animationPromise;
141
+ }
142
+ }
@@ -0,0 +1,192 @@
1
+ import { Mesh } from '@babylonjs/core';
2
+ import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';
3
+ import { Color3 } from '@babylonjs/core/Maths/math.color';
4
+ import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';
5
+ import { Scene } from '@babylonjs/core/scene';
6
+ import { GLTF2Export, IExportOptions } from '@babylonjs/serializers';
7
+ import { isMeshIncludedInExclusionList } from '../util/structureHelper';
8
+ import { merge } from 'lodash-es';
9
+
10
+ export class GltfExportManager {
11
+ /**
12
+ * Constructor.
13
+ */
14
+ protected constructor(protected viewer: Viewer) {}
15
+
16
+ /**
17
+ * Creates an {@link GltfExportManager}.
18
+ */
19
+ public static async create(viewer: Viewer): Promise<GltfExportManager> {
20
+ return new GltfExportManager(viewer);
21
+ }
22
+
23
+ /**
24
+ * Exports selected nodes to a file.
25
+ * @param filename optional name of the exported .GLB file.
26
+ * @param exportOptions export options to be merged with default options. See {@link gltfExportOptions}.
27
+ * @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export.
28
+ */
29
+ public async exportGlb(
30
+ filename = 'glb-export.glb',
31
+ exportOptions: IExportOptions = {},
32
+ excluded?: ExcludedGeometry
33
+ ): Promise<File | undefined> {
34
+ this.exportPreProcess();
35
+ const glbData = await GLTF2Export.GLBAsync(
36
+ this.viewer.scene,
37
+ 'dummy',
38
+ this.gltfExportOptions(exportOptions, excluded)
39
+ );
40
+ this.exportPostProcess();
41
+ const resBlob = glbData.glTFFiles['dummy.glb']; // should be only one file for glb
42
+
43
+ // check if result is valid, according to the typings this could also be a string
44
+ if (resBlob instanceof Blob) {
45
+ if (!filename.endsWith('.glb')) {
46
+ filename += '.glb';
47
+ }
48
+ return new File([resBlob], filename);
49
+ } else {
50
+ // result was not a valid blob
51
+ return undefined;
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Exports selected nodes to GLTF. This may result in more than one file, since textures are exported separately.
57
+ * @param filename name of the main (text-based) .GLTF file referring to separate texture files.
58
+ * @param exportOptions export options to be merged with default options. See {@link gltfExportOptions}.
59
+ * @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export.
60
+ */
61
+ public async exportGltfToFile(filename: string, exportOptions: IExportOptions = {}, excluded?: ExcludedGeometry) {
62
+ this.exportPreProcess();
63
+ await GLTF2Export.GLTFAsync(this.viewer.scene, filename, this.gltfExportOptions(exportOptions, excluded)).then(
64
+ glb => {
65
+ glb.downloadFiles();
66
+ }
67
+ );
68
+ this.exportPostProcess();
69
+ }
70
+
71
+ /**
72
+ * Exports selected nodes to GLB. This results in one binary file.
73
+ * @param filename name of the .GLB file.
74
+ * @param exportOptions export options to be merged with default options. See {@link gltfExportOptions}.
75
+ * @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
76
+ */
77
+ public async exportGlbToFile(filename: string, exportOptions: IExportOptions = {}, excluded?: ExcludedGeometry) {
78
+ this.exportPreProcess();
79
+ await GLTF2Export.GLBAsync(this.viewer.scene, filename, this.gltfExportOptions(exportOptions, excluded)).then(
80
+ glb => {
81
+ glb.downloadFiles();
82
+ }
83
+ );
84
+ this.exportPostProcess();
85
+ }
86
+
87
+ /**
88
+ * Gets predefined {@link IExportOptions } merged with given ones.
89
+ */
90
+ protected gltfExportOptions(mergeWithOptions: IExportOptions = {}, excluded?: ExcludedGeometry): IExportOptions {
91
+ const defaultOptions = {
92
+ // includeCoordinateSystemConversionNodes: true,
93
+ shouldExportNode: function (node: any) {
94
+ if (!node.isEnabled()) {
95
+ return false;
96
+ }
97
+ if (node.isVisible === false) {
98
+ return false;
99
+ }
100
+ if (node.name === '__bounding_box__') {
101
+ return false;
102
+ }
103
+ if (excluded && node instanceof Mesh && isMeshIncludedInExclusionList(node, excluded)) {
104
+ return false;
105
+ }
106
+ return true;
107
+ },
108
+ };
109
+ return merge({}, defaultOptions, mergeWithOptions);
110
+ }
111
+
112
+ /**
113
+ * Stuff to be done before exporting to GLTF
114
+ */
115
+ protected exportPreProcess() {
116
+ this.viewer.pauseRendering();
117
+ this.exchangeRefractionMaterials();
118
+ }
119
+
120
+ /**
121
+ * Stuff to be done after the GLTF export
122
+ */
123
+ protected exportPostProcess() {
124
+ this.restoreRefractionMaterials();
125
+ this.viewer.resumeRendering();
126
+ }
127
+
128
+ /**
129
+ * Materials with refraction set are not exported properly.
130
+ * Exchange all such (relevant) materials with a more export-friendly version
131
+ */
132
+ protected exchangeRefractionMaterials() {
133
+ for (const n of this.viewer.scene.getNodes()) {
134
+ if (!(n instanceof AbstractMesh)) continue;
135
+ if (!(n.material instanceof PBRMaterial)) continue;
136
+ if (!(n.material as PBRMaterial).subSurface.isRefractionEnabled) continue;
137
+ if ((n.material as PBRMaterial).transparencyMode !== PBRMaterial.PBRMATERIAL_OPAQUE) continue;
138
+ // if we're here, we have a node holding a material with set refraction whose transparencyMode is set to PBRMATERIAL_OPAQUE
139
+ n.material = this.createRefractionMaterialReplacement(n.material);
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Restore original materials with set refraction.
145
+ */
146
+ protected restoreRefractionMaterials() {
147
+ for (const n of this.viewer.scene.getNodes()) {
148
+ if (!(n instanceof AbstractMesh)) continue;
149
+ if (!(n.material instanceof PBRMaterial)) continue;
150
+ if (!this.isMaterialClonedForExport(n.material)) continue;
151
+ // at this point we have a pbrmaterial tagged as cloned in its metadata that's set on a mesh
152
+
153
+ // restore and dispose
154
+ const currMaterial = n.material;
155
+ const prevMaterial = this.viewer.scene.getMaterialByUniqueID(n.material.metadata.clonedFrom);
156
+ if (prevMaterial) {
157
+ n.material = prevMaterial; // restore previous material
158
+ currMaterial.dispose(false, true); // dispose of clone
159
+ }
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Create an export-friendly replacement material for a material using refraction.
165
+ * @param mat Material to be replaced
166
+ */
167
+ protected createRefractionMaterialReplacement(mat: PBRMaterial): PBRMaterial {
168
+ // if we're dealing with a clone already, return it instead of cloning
169
+ if (this.isMaterialClonedForExport(mat)) return mat;
170
+
171
+ // change material according to https://www.notion.so/combeenation/Glas-materials-don-t-look-glasy-after-export-d5fda2c6515e4420a8772744d3e6b460
172
+ let clonedMaterial = mat.clone(mat.name); // clone material. clone uses same name
173
+ clonedMaterial.metadata = { ...mat.metadata, clonedFrom: mat.uniqueId }; // create shallow copy of metadata on clone. see https://forum.babylonjs.com/t/the-metadata-of-the-mesh-cloned-by-the-instantiatemodelstoscene-method-is-a-shallow-copy/21563
174
+ clonedMaterial.refractionTexture = null;
175
+ clonedMaterial.metallicReflectanceTexture = null; // is this the correct one for metallic roughness?
176
+ clonedMaterial.alpha = 0.7;
177
+ clonedMaterial.albedoColor = new Color3(0.3, 0.3, 0.3);
178
+ clonedMaterial.transparencyMode = PBRMaterial.PBRMATERIAL_ALPHABLEND;
179
+ clonedMaterial.metallic = 0.65;
180
+ clonedMaterial.roughness = 0.15;
181
+
182
+ return clonedMaterial;
183
+ }
184
+
185
+ /**
186
+ * Inspect if a material was temporarily cloned for GLB export
187
+ * @param mat Material to be inspected
188
+ */
189
+ protected isMaterialClonedForExport(mat: PBRMaterial): boolean {
190
+ return mat.metadata.clonedFrom;
191
+ }
192
+ }
@@ -8,98 +8,95 @@ import { SpecStorage } from '../store/specStorage';
8
8
  import { mergeMaps } from '../util/resourceHelper';
9
9
 
10
10
  export class SceneManager extends ParameterObservable {
11
+ protected readonly _parameterObservers: Map<string, ParameterObserver[]> = new Map();
11
12
 
12
- protected readonly _parameterObservers: Map<string, ParameterObserver[]> = new Map();
13
+ protected readonly parameterDeclaration: ParameterDeclarations = {
14
+ 'environment': { type: 'string' },
15
+ 'environment.rotation': { type: 'number' },
16
+ };
13
17
 
14
- protected readonly parameterDeclaration: ParameterDeclarations = {
15
- 'environment': { type: 'string' },
16
- 'environment.rotation': { type: 'number' }
17
- };
18
+ /**
19
+ * Constructor.
20
+ */
21
+ protected constructor(public scene: BabylonScene) {
22
+ super();
23
+ this.addParameterObservers();
24
+ }
18
25
 
19
- /**
20
- * Constructor.
21
- */
22
- protected constructor( public scene: BabylonScene ) {
23
- super();
24
- this.addParameterObservers();
25
- }
26
+ /**
27
+ * Creates a {@link SceneManager} based on given BabylonJS scene.
28
+ */
29
+ public static async create(scene: BabylonScene): Promise<SceneManager> {
30
+ const sceneManager = new SceneManager(scene);
31
+ await sceneManager.bootstrapParameters(SpecStorage.get<ParameterBag>('scene.parameters'));
32
+ return sceneManager;
33
+ }
26
34
 
27
- /**
28
- * Creates a {@link SceneManager} based on given BabylonJS scene.
29
- */
30
- public static async create( scene: BabylonScene ): Promise<SceneManager> {
31
- const sceneManager = new SceneManager( scene );
32
- await sceneManager.bootstrapParameters( SpecStorage.get<ParameterBag>( 'scene.parameters' ) );
33
- return sceneManager;
34
- }
35
+ /**
36
+ * The active `Camera`.
37
+ */
38
+ get activeCamera(): Camera {
39
+ if (!this.scene.activeCamera) {
40
+ throw new Error('Scene has no active camera.');
41
+ }
42
+ return this.scene.activeCamera;
43
+ }
35
44
 
36
- /**
37
- * The active `Camera`.
38
- */
39
- get activeCamera(): Camera {
40
- if( !this.scene.activeCamera ) {
41
- throw new Error( 'Scene has no active camera.' );
42
- }
43
- return this.scene.activeCamera;
44
- }
45
+ /**
46
+ * Places the given {@link ParameterBag} in the {@link SceneManager}'s parameters, replaces all patterns in the
47
+ * {@link StructureJson} and broadcasts all {@link ParameterObserver}s.
48
+ *
49
+ * @emit {@link Event.SCENE_PARAMETER_COMMITTED}
50
+ */
51
+ public async commitParameters(parameters?: ParameterBag): Promise<SceneManager> {
52
+ if (!parameters) {
53
+ parameters = {};
54
+ }
55
+ const oldParameters = cloneDeep(this.parameters);
56
+ merge(this.parameters, parameters);
45
57
 
46
- /**
47
- * Places the given {@link ParameterBag} in the {@link SceneManager}'s parameters, replaces all patterns in the
48
- * {@link StructureJson} and broadcasts all {@link ParameterObserver}s.
49
- *
50
- * @emit {@link Event.SCENE_PARAMETER_COMMITTED}
51
- */
52
- public async commitParameters( parameters?: ParameterBag ): Promise<SceneManager> {
53
- if( !parameters ) {
54
- parameters = {};
55
- }
56
- const oldParameters = cloneDeep( this.parameters );
57
- merge( this.parameters, parameters );
58
+ // handle parameter observers
59
+ for (const parameter in this.parameters) {
60
+ const oldParameterValue = oldParameters[parameter];
61
+ const newParameterValue = this.parameters[parameter];
62
+ this.assertParameter(this.parameterDeclaration, parameter, newParameterValue);
63
+ if (oldParameterValue === newParameterValue) {
64
+ continue;
65
+ }
66
+ // parameter changed
67
+ const parameterObservers = mergeMaps(this._parameterObservers, this.parameterObservers);
68
+ if (parameterObservers.has(parameter)) {
69
+ const observers = parameterObservers.get(parameter)!;
70
+ observers.forEach(observer => {
71
+ observer(this, oldParameterValue, newParameterValue);
72
+ this.broadcastEvent(Event.SCENE_PARAMETER_COMMITTED, this, parameter, oldParameterValue, newParameterValue);
73
+ });
74
+ }
75
+ }
76
+ return this;
77
+ }
58
78
 
59
- // handle parameter observers
60
- for( const parameter in this.parameters ) {
61
- const oldParameterValue = oldParameters[parameter];
62
- const newParameterValue = this.parameters[parameter];
63
- this.assertParameter( this.parameterDeclaration, parameter, newParameterValue );
64
- if( oldParameterValue === newParameterValue ) {
65
- continue;
66
- }
67
- // parameter changed
68
- const parameterObservers = mergeMaps( this._parameterObservers, this.parameterObservers );
69
- if( parameterObservers.has( parameter ) ) {
70
- const observers = parameterObservers.get( parameter )!;
71
- observers.forEach( observer => {
72
- observer( this, oldParameterValue, newParameterValue );
73
- this.broadcastEvent( Event.SCENE_PARAMETER_COMMITTED, this, parameter,
74
- oldParameterValue, newParameterValue );
75
- } );
76
- }
77
- }
78
- return this;
79
- }
80
-
81
- protected addParameterObservers(): SceneManager {
82
- this._parameterObservers.set( 'environment', [
83
- ( manager: SceneManager, oldValue: ParameterValue, newValue: ParameterValue ) => {
84
- manager.scene.environmentTexture = CubeTexture.CreateFromPrefilteredData( newValue.toString(), manager.scene );
85
- }
86
- ] );
87
- this._parameterObservers.set( 'environment.rotation', [
88
- ( manager: SceneManager, oldValue: ParameterValue, newValue: ParameterValue ) => {
89
- if( manager.scene.environmentTexture instanceof CubeTexture ) {
90
- manager.scene.environmentTexture.rotationY = (parseFloat( newValue.toString() ) * Math.PI) / 180;
91
- }
92
- }
93
- ] );
94
- return this;
95
- }
96
-
97
- /**
98
- * Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
99
- */
100
- protected async bootstrapParameters( parameters?: ParameterBag ): Promise<SceneManager> {
101
- await this.commitParameters( merge( cloneDeep( this.parameters ), parameters ) );
102
- return this;
103
- }
79
+ protected addParameterObservers(): SceneManager {
80
+ this._parameterObservers.set('environment', [
81
+ (manager: SceneManager, oldValue: ParameterValue, newValue: ParameterValue) => {
82
+ manager.scene.environmentTexture = CubeTexture.CreateFromPrefilteredData(newValue.toString(), manager.scene);
83
+ },
84
+ ]);
85
+ this._parameterObservers.set('environment.rotation', [
86
+ (manager: SceneManager, oldValue: ParameterValue, newValue: ParameterValue) => {
87
+ if (manager.scene.environmentTexture instanceof CubeTexture) {
88
+ manager.scene.environmentTexture.rotationY = (parseFloat(newValue.toString()) * Math.PI) / 180;
89
+ }
90
+ },
91
+ ]);
92
+ return this;
93
+ }
104
94
 
95
+ /**
96
+ * Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
97
+ */
98
+ protected async bootstrapParameters(parameters?: ParameterBag): Promise<SceneManager> {
99
+ await this.commitParameters(merge(cloneDeep(this.parameters), parameters));
100
+ return this;
101
+ }
105
102
  }