@combeenation/3d-viewer 3.1.1-alpha7 → 3.1.2

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 (94) hide show
  1. package/README.md +111 -111
  2. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  3. package/dist/lib-cjs/api/classes/animationInterface.js +1 -1
  4. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  5. package/dist/lib-cjs/api/classes/dottedPath.js +190 -190
  6. package/dist/lib-cjs/api/classes/element.d.ts +125 -126
  7. package/dist/lib-cjs/api/classes/element.js +678 -674
  8. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -14
  10. package/dist/lib-cjs/api/classes/elementParameterizable.js +134 -134
  11. package/dist/lib-cjs/api/classes/event.d.ts +312 -312
  12. package/dist/lib-cjs/api/classes/event.js +357 -357
  13. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  14. package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
  15. package/dist/lib-cjs/api/classes/parameter.d.ts +165 -165
  16. package/dist/lib-cjs/api/classes/parameter.js +267 -267
  17. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  18. package/dist/lib-cjs/api/classes/parameterObservable.js +126 -126
  19. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  20. package/dist/lib-cjs/api/classes/parameterizable.js +149 -149
  21. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +38 -38
  22. package/dist/lib-cjs/api/classes/placementAnimation.js +138 -138
  23. package/dist/lib-cjs/api/classes/variant.d.ts +180 -190
  24. package/dist/lib-cjs/api/classes/variant.js +863 -873
  25. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  26. package/dist/lib-cjs/api/classes/variantInstance.d.ts +41 -41
  27. package/dist/lib-cjs/api/classes/variantInstance.js +98 -98
  28. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  29. package/dist/lib-cjs/api/classes/variantParameterizable.js +92 -92
  30. package/dist/lib-cjs/api/classes/viewer.d.ts +128 -128
  31. package/dist/lib-cjs/api/classes/viewer.js +486 -486
  32. package/dist/lib-cjs/api/classes/viewerLight.d.ts +65 -66
  33. package/dist/lib-cjs/api/classes/viewerLight.js +322 -389
  34. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  35. package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
  36. package/dist/lib-cjs/api/internal/debugViewer.js +87 -87
  37. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  38. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  39. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +6 -6
  40. package/dist/lib-cjs/api/internal/sceneSetup.js +227 -227
  41. package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
  42. package/dist/lib-cjs/api/manager/animationManager.js +121 -121
  43. package/dist/lib-cjs/api/manager/sceneManager.d.ts +32 -32
  44. package/dist/lib-cjs/api/manager/sceneManager.js +132 -132
  45. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +90 -90
  46. package/dist/lib-cjs/api/manager/variantInstanceManager.js +321 -321
  47. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  48. package/dist/lib-cjs/api/store/specStorage.js +51 -51
  49. package/dist/lib-cjs/api/util/babylonHelper.d.ts +125 -125
  50. package/dist/lib-cjs/api/util/babylonHelper.js +368 -368
  51. package/dist/lib-cjs/api/util/globalTypes.d.ts +275 -275
  52. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  53. package/dist/lib-cjs/api/util/resourceHelper.d.ts +30 -30
  54. package/dist/lib-cjs/api/util/resourceHelper.js +247 -203
  55. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  56. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
  57. package/dist/lib-cjs/api/util/stringHelper.js +25 -25
  58. package/dist/lib-cjs/buildinfo.json +3 -3
  59. package/dist/lib-cjs/index.d.ts +46 -46
  60. package/dist/lib-cjs/index.js +82 -82
  61. package/dist/webpack-stats.json +0 -0
  62. package/package.json +83 -83
  63. package/src/api/classes/animationInterface.ts +11 -11
  64. package/src/api/classes/dottedPath.ts +189 -189
  65. package/src/api/classes/element.ts +608 -606
  66. package/src/api/classes/elementParameterizable.ts +78 -78
  67. package/src/api/classes/event.ts +355 -355
  68. package/src/api/classes/eventBroadcaster.ts +54 -54
  69. package/src/api/classes/parameter.ts +277 -277
  70. package/src/api/classes/parameterObservable.ts +121 -121
  71. package/src/api/classes/placementAnimation.ts +133 -133
  72. package/src/api/classes/variant.ts +659 -670
  73. package/src/api/classes/variantInstance.ts +81 -81
  74. package/src/api/classes/viewer.ts +421 -421
  75. package/src/api/internal/debugViewer.ts +81 -81
  76. package/src/api/internal/lensRendering.ts +10 -10
  77. package/src/api/internal/sceneSetup.ts +203 -203
  78. package/src/api/manager/animationManager.ts +116 -116
  79. package/src/api/manager/sceneManager.ts +105 -105
  80. package/src/api/manager/variantInstanceManager.ts +236 -236
  81. package/src/api/store/specStorage.ts +53 -53
  82. package/src/api/util/babylonHelper.ts +392 -392
  83. package/src/api/util/globalTypes.ts +314 -314
  84. package/src/api/util/resourceHelper.ts +168 -155
  85. package/src/buildinfo.json +2 -2
  86. package/src/commonjs.tsconfig.json +13 -13
  87. package/src/declaration.tsconfig.json +10 -10
  88. package/src/dev.ts +44 -46
  89. package/src/es6.tsconfig.json +13 -13
  90. package/src/index.ts +87 -87
  91. package/src/pagesconfig.json +47 -47
  92. package/src/tsconfig.json +43 -43
  93. package/src/tsconfig.types.json +9 -9
  94. package/src/types.d.ts +4 -4
@@ -1,122 +1,122 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AnimationManager = void 0;
4
- var tslib_1 = require("tslib");
5
- var animation_1 = require("@babylonjs/core/Animations/animation");
6
- //import { CustomEase } from 'gsap/CustomEase';
7
- //import { ExpoScaleEase, RoughEase, SlowMo } from 'gsap/EasePack';
8
- var lodash_es_1 = require("lodash-es");
9
- var placementAnimation_1 = require("../classes/placementAnimation");
10
- //gsap.registerPlugin( CustomEase, ExpoScaleEase, RoughEase, SlowMo );
11
- var AnimationManager = /** @class */ (function () {
12
- /**
13
- * Constructor.
14
- */
15
- function AnimationManager(scene) {
16
- this.scene = scene;
17
- this.animations = [];
18
- }
19
- /**
20
- * Creates an {@link AnimationManager} based on given BabylonJS scene.
21
- */
22
- AnimationManager.create = function (scene) {
23
- return tslib_1.__awaiter(this, void 0, void 0, function () {
24
- return tslib_1.__generator(this, function (_b) {
25
- return [2 /*return*/, new AnimationManager(scene)];
26
- });
27
- });
28
- };
29
- /**
30
- * @deprecated Use viewer.moveCameraTo().
31
- */
32
- AnimationManager.prototype.resetCamera = function (animate) {
33
- if (animate === void 0) { animate = false; }
34
- //TODO currently only works for arcrotate. are there any other cameras?
35
- var activeCamera = this.scene.activeCamera;
36
- if (!activeCamera) {
37
- throw new Error('There is no active camera');
38
- }
39
- var initAlpha = activeCamera.metadata.alpha;
40
- var initBeta = activeCamera.metadata.beta;
41
- var initRadius = activeCamera.metadata.radius;
42
- if (animate) {
43
- this.animateArcRotateCamera(initAlpha, initBeta, initRadius);
44
- }
45
- else {
46
- activeCamera.alpha = initAlpha;
47
- activeCamera.beta = initBeta;
48
- activeCamera.radius = initRadius;
49
- }
50
- };
51
- /**
52
- * @deprecated Use viewer.moveCameraTo().
53
- */
54
- AnimationManager.prototype.animateArcRotateCamera = function (targetAlpha, targetBeta, targetRadius) {
55
- var activeCamera = this.scene.activeCamera;
56
- if (!activeCamera) {
57
- throw new Error('There is no active camera');
58
- }
59
- var alphaAnimation = new animation_1.Animation('alphaAnimation', 'alpha', 30, animation_1.Animation.ANIMATIONTYPE_FLOAT, animation_1.Animation.ANIMATIONLOOPMODE_CONSTANT);
60
- var betaAnimation = new animation_1.Animation('betaAnimation', 'beta', 30, animation_1.Animation.ANIMATIONTYPE_FLOAT, animation_1.Animation.ANIMATIONLOOPMODE_CONSTANT);
61
- var radiusAnimation = new animation_1.Animation('radiusAnimation', 'radius', 30, animation_1.Animation.ANIMATIONTYPE_FLOAT, animation_1.Animation.ANIMATIONLOOPMODE_CONSTANT);
62
- alphaAnimation.setKeys([{
63
- frame: 0,
64
- value: activeCamera.alpha
65
- }, {
66
- frame: 100,
67
- value: targetAlpha
68
- }]);
69
- betaAnimation.setKeys([{
70
- frame: 0,
71
- value: activeCamera.beta
72
- }, {
73
- frame: 100,
74
- value: targetBeta
75
- }]);
76
- radiusAnimation.setKeys([{
77
- frame: 0,
78
- value: activeCamera.radius
79
- }, {
80
- frame: 100,
81
- value: targetRadius
82
- }]);
83
- activeCamera.animations.push(alphaAnimation);
84
- activeCamera.animations.push(betaAnimation);
85
- activeCamera.animations.push(radiusAnimation);
86
- var animation = this.scene.beginAnimation(activeCamera, 0, 100, false, 10);
87
- animation.disposeOnEnd = true;
88
- };
89
- /**
90
- * Stops and kills all running animations.
91
- */
92
- AnimationManager.prototype.killAllAnimations = function () {
93
- this.animations.forEach(function (animation) { return animation.kill(); });
94
- this.animations = [];
95
- };
96
- /**
97
- * @see {@link PlacementAnimation.play}
98
- */
99
- AnimationManager.prototype.animateToPlacement = function (mutable, placement, animation) {
100
- return tslib_1.__awaiter(this, void 0, void 0, function () {
101
- var _animation, animationPromise;
102
- var _this = this;
103
- return tslib_1.__generator(this, function (_b) {
104
- switch (_b.label) {
105
- case 0:
106
- _animation = new placementAnimation_1.PlacementAnimation(mutable, placement, animation);
107
- this.animations.push(_animation);
108
- animationPromise = _animation.play();
109
- animationPromise.then(function (a) {
110
- lodash_es_1.remove(_this.animations, function (_a) { return _a === a; });
111
- a.kill();
112
- });
113
- return [4 /*yield*/, animationPromise];
114
- case 1: return [2 /*return*/, _b.sent()];
115
- }
116
- });
117
- });
118
- };
119
- return AnimationManager;
120
- }());
121
- exports.AnimationManager = AnimationManager;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnimationManager = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var animation_1 = require("@babylonjs/core/Animations/animation");
6
+ //import { CustomEase } from 'gsap/CustomEase';
7
+ //import { ExpoScaleEase, RoughEase, SlowMo } from 'gsap/EasePack';
8
+ var lodash_es_1 = require("lodash-es");
9
+ var placementAnimation_1 = require("../classes/placementAnimation");
10
+ //gsap.registerPlugin( CustomEase, ExpoScaleEase, RoughEase, SlowMo );
11
+ var AnimationManager = /** @class */ (function () {
12
+ /**
13
+ * Constructor.
14
+ */
15
+ function AnimationManager(scene) {
16
+ this.scene = scene;
17
+ this.animations = [];
18
+ }
19
+ /**
20
+ * Creates an {@link AnimationManager} based on given BabylonJS scene.
21
+ */
22
+ AnimationManager.create = function (scene) {
23
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
24
+ return tslib_1.__generator(this, function (_b) {
25
+ return [2 /*return*/, new AnimationManager(scene)];
26
+ });
27
+ });
28
+ };
29
+ /**
30
+ * @deprecated Use viewer.moveCameraTo().
31
+ */
32
+ AnimationManager.prototype.resetCamera = function (animate) {
33
+ if (animate === void 0) { animate = false; }
34
+ //TODO currently only works for arcrotate. are there any other cameras?
35
+ var activeCamera = this.scene.activeCamera;
36
+ if (!activeCamera) {
37
+ throw new Error('There is no active camera');
38
+ }
39
+ var initAlpha = activeCamera.metadata.alpha;
40
+ var initBeta = activeCamera.metadata.beta;
41
+ var initRadius = activeCamera.metadata.radius;
42
+ if (animate) {
43
+ this.animateArcRotateCamera(initAlpha, initBeta, initRadius);
44
+ }
45
+ else {
46
+ activeCamera.alpha = initAlpha;
47
+ activeCamera.beta = initBeta;
48
+ activeCamera.radius = initRadius;
49
+ }
50
+ };
51
+ /**
52
+ * @deprecated Use viewer.moveCameraTo().
53
+ */
54
+ AnimationManager.prototype.animateArcRotateCamera = function (targetAlpha, targetBeta, targetRadius) {
55
+ var activeCamera = this.scene.activeCamera;
56
+ if (!activeCamera) {
57
+ throw new Error('There is no active camera');
58
+ }
59
+ var alphaAnimation = new animation_1.Animation('alphaAnimation', 'alpha', 30, animation_1.Animation.ANIMATIONTYPE_FLOAT, animation_1.Animation.ANIMATIONLOOPMODE_CONSTANT);
60
+ var betaAnimation = new animation_1.Animation('betaAnimation', 'beta', 30, animation_1.Animation.ANIMATIONTYPE_FLOAT, animation_1.Animation.ANIMATIONLOOPMODE_CONSTANT);
61
+ var radiusAnimation = new animation_1.Animation('radiusAnimation', 'radius', 30, animation_1.Animation.ANIMATIONTYPE_FLOAT, animation_1.Animation.ANIMATIONLOOPMODE_CONSTANT);
62
+ alphaAnimation.setKeys([{
63
+ frame: 0,
64
+ value: activeCamera.alpha
65
+ }, {
66
+ frame: 100,
67
+ value: targetAlpha
68
+ }]);
69
+ betaAnimation.setKeys([{
70
+ frame: 0,
71
+ value: activeCamera.beta
72
+ }, {
73
+ frame: 100,
74
+ value: targetBeta
75
+ }]);
76
+ radiusAnimation.setKeys([{
77
+ frame: 0,
78
+ value: activeCamera.radius
79
+ }, {
80
+ frame: 100,
81
+ value: targetRadius
82
+ }]);
83
+ activeCamera.animations.push(alphaAnimation);
84
+ activeCamera.animations.push(betaAnimation);
85
+ activeCamera.animations.push(radiusAnimation);
86
+ var animation = this.scene.beginAnimation(activeCamera, 0, 100, false, 10);
87
+ animation.disposeOnEnd = true;
88
+ };
89
+ /**
90
+ * Stops and kills all running animations.
91
+ */
92
+ AnimationManager.prototype.killAllAnimations = function () {
93
+ this.animations.forEach(function (animation) { return animation.kill(); });
94
+ this.animations = [];
95
+ };
96
+ /**
97
+ * @see {@link PlacementAnimation.play}
98
+ */
99
+ AnimationManager.prototype.animateToPlacement = function (mutable, placement, animation) {
100
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
101
+ var _animation, animationPromise;
102
+ var _this = this;
103
+ return tslib_1.__generator(this, function (_b) {
104
+ switch (_b.label) {
105
+ case 0:
106
+ _animation = new placementAnimation_1.PlacementAnimation(mutable, placement, animation);
107
+ this.animations.push(_animation);
108
+ animationPromise = _animation.play();
109
+ animationPromise.then(function (a) {
110
+ lodash_es_1.remove(_this.animations, function (_a) { return _a === a; });
111
+ a.kill();
112
+ });
113
+ return [4 /*yield*/, animationPromise];
114
+ case 1: return [2 /*return*/, _b.sent()];
115
+ }
116
+ });
117
+ });
118
+ };
119
+ return AnimationManager;
120
+ }());
121
+ exports.AnimationManager = AnimationManager;
122
122
  //# sourceMappingURL=animationManager.js.map
@@ -1,32 +1,32 @@
1
- import { Camera } from '@babylonjs/core/Cameras/camera';
2
- import { Scene as BabylonScene } from '@babylonjs/core/scene';
3
- import { ParameterObservable } from '../classes/parameterObservable';
4
- export declare class SceneManager extends ParameterObservable {
5
- scene: BabylonScene;
6
- protected readonly _parameterObservers: Map<string, ParameterObserver[]>;
7
- protected readonly parameterDeclaration: ParameterDeclarations;
8
- /**
9
- * Constructor.
10
- */
11
- protected constructor(scene: BabylonScene);
12
- /**
13
- * Creates a {@link SceneManager} based on given BabylonJS scene.
14
- */
15
- static create(scene: BabylonScene): Promise<SceneManager>;
16
- /**
17
- * The active `Camera`.
18
- */
19
- get activeCamera(): Camera;
20
- /**
21
- * Places the given {@link ParameterBag} in the {@link SceneManager}'s parameters, replaces all patterns in the
22
- * {@link StructureJson} and broadcasts all {@link ParameterObserver}s.
23
- *
24
- * @emit {@link Event.SCENE_PARAMETER_COMMITTED}
25
- */
26
- commitParameters(parameters?: ParameterBag): Promise<SceneManager>;
27
- protected addParameterObservers(): SceneManager;
28
- /**
29
- * Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
30
- */
31
- protected bootstrapParameters(parameters?: ParameterBag): Promise<SceneManager>;
32
- }
1
+ import { Camera } from '@babylonjs/core/Cameras/camera';
2
+ import { Scene as BabylonScene } from '@babylonjs/core/scene';
3
+ import { ParameterObservable } from '../classes/parameterObservable';
4
+ export declare class SceneManager extends ParameterObservable {
5
+ scene: BabylonScene;
6
+ protected readonly _parameterObservers: Map<string, ParameterObserver[]>;
7
+ protected readonly parameterDeclaration: ParameterDeclarations;
8
+ /**
9
+ * Constructor.
10
+ */
11
+ protected constructor(scene: BabylonScene);
12
+ /**
13
+ * Creates a {@link SceneManager} based on given BabylonJS scene.
14
+ */
15
+ static create(scene: BabylonScene): Promise<SceneManager>;
16
+ /**
17
+ * The active `Camera`.
18
+ */
19
+ get activeCamera(): Camera;
20
+ /**
21
+ * Places the given {@link ParameterBag} in the {@link SceneManager}'s parameters, replaces all patterns in the
22
+ * {@link StructureJson} and broadcasts all {@link ParameterObserver}s.
23
+ *
24
+ * @emit {@link Event.SCENE_PARAMETER_COMMITTED}
25
+ */
26
+ commitParameters(parameters?: ParameterBag): Promise<SceneManager>;
27
+ protected addParameterObservers(): SceneManager;
28
+ /**
29
+ * Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
30
+ */
31
+ protected bootstrapParameters(parameters?: ParameterBag): Promise<SceneManager>;
32
+ }
@@ -1,133 +1,133 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SceneManager = void 0;
4
- var tslib_1 = require("tslib");
5
- var cubeTexture_1 = require("@babylonjs/core/Materials/Textures/cubeTexture");
6
- var lodash_es_1 = require("lodash-es");
7
- var parameterObservable_1 = require("../classes/parameterObservable");
8
- var event_1 = require("../classes/event");
9
- var specStorage_1 = require("../store/specStorage");
10
- var resourceHelper_1 = require("../util/resourceHelper");
11
- var SceneManager = /** @class */ (function (_super) {
12
- tslib_1.__extends(SceneManager, _super);
13
- /**
14
- * Constructor.
15
- */
16
- function SceneManager(scene) {
17
- var _this = _super.call(this) || this;
18
- _this.scene = scene;
19
- _this._parameterObservers = new Map();
20
- _this.parameterDeclaration = {
21
- 'environment': { type: 'string' },
22
- 'environment.rotation': { type: 'number' }
23
- };
24
- _this.addParameterObservers();
25
- return _this;
26
- }
27
- /**
28
- * Creates a {@link SceneManager} based on given BabylonJS scene.
29
- */
30
- SceneManager.create = function (scene) {
31
- return tslib_1.__awaiter(this, void 0, void 0, function () {
32
- var sceneManager;
33
- return tslib_1.__generator(this, function (_a) {
34
- switch (_a.label) {
35
- case 0:
36
- sceneManager = new SceneManager(scene);
37
- return [4 /*yield*/, sceneManager.bootstrapParameters(specStorage_1.SpecStorage.get('scene.parameters'))];
38
- case 1:
39
- _a.sent();
40
- return [2 /*return*/, sceneManager];
41
- }
42
- });
43
- });
44
- };
45
- Object.defineProperty(SceneManager.prototype, "activeCamera", {
46
- /**
47
- * The active `Camera`.
48
- */
49
- get: function () {
50
- if (!this.scene.activeCamera) {
51
- throw new Error('Scene has no active camera.');
52
- }
53
- return this.scene.activeCamera;
54
- },
55
- enumerable: false,
56
- configurable: true
57
- });
58
- /**
59
- * Places the given {@link ParameterBag} in the {@link SceneManager}'s parameters, replaces all patterns in the
60
- * {@link StructureJson} and broadcasts all {@link ParameterObserver}s.
61
- *
62
- * @emit {@link Event.SCENE_PARAMETER_COMMITTED}
63
- */
64
- SceneManager.prototype.commitParameters = function (parameters) {
65
- return tslib_1.__awaiter(this, void 0, void 0, function () {
66
- var oldParameters, _loop_1, this_1, parameter;
67
- var _this = this;
68
- return tslib_1.__generator(this, function (_a) {
69
- if (!parameters) {
70
- parameters = {};
71
- }
72
- oldParameters = lodash_es_1.cloneDeep(this.parameters);
73
- lodash_es_1.merge(this.parameters, parameters);
74
- _loop_1 = function (parameter) {
75
- var oldParameterValue = oldParameters[parameter];
76
- var newParameterValue = this_1.parameters[parameter];
77
- this_1.assertParameter(this_1.parameterDeclaration, parameter, newParameterValue);
78
- if (oldParameterValue === newParameterValue) {
79
- return "continue";
80
- }
81
- // parameter changed
82
- var parameterObservers = resourceHelper_1.mergeMaps(this_1._parameterObservers, this_1.parameterObservers);
83
- if (parameterObservers.has(parameter)) {
84
- var observers = parameterObservers.get(parameter);
85
- observers.forEach(function (observer) {
86
- observer(_this, oldParameterValue, newParameterValue);
87
- _this.broadcastEvent(event_1.Event.SCENE_PARAMETER_COMMITTED, _this, parameter, oldParameterValue, newParameterValue);
88
- });
89
- }
90
- };
91
- this_1 = this;
92
- // handle parameter observers
93
- for (parameter in this.parameters) {
94
- _loop_1(parameter);
95
- }
96
- return [2 /*return*/, this];
97
- });
98
- });
99
- };
100
- SceneManager.prototype.addParameterObservers = function () {
101
- this._parameterObservers.set('environment', [
102
- function (manager, oldValue, newValue) {
103
- manager.scene.environmentTexture = cubeTexture_1.CubeTexture.CreateFromPrefilteredData(newValue.toString(), manager.scene);
104
- }
105
- ]);
106
- this._parameterObservers.set('environment.rotation', [
107
- function (manager, oldValue, newValue) {
108
- if (manager.scene.environmentTexture instanceof cubeTexture_1.CubeTexture) {
109
- manager.scene.environmentTexture.rotationY = (parseFloat(newValue.toString()) * Math.PI) / 180;
110
- }
111
- }
112
- ]);
113
- return this;
114
- };
115
- /**
116
- * Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
117
- */
118
- SceneManager.prototype.bootstrapParameters = function (parameters) {
119
- return tslib_1.__awaiter(this, void 0, void 0, function () {
120
- return tslib_1.__generator(this, function (_a) {
121
- switch (_a.label) {
122
- case 0: return [4 /*yield*/, this.commitParameters(lodash_es_1.merge(lodash_es_1.cloneDeep(this.parameters), parameters))];
123
- case 1:
124
- _a.sent();
125
- return [2 /*return*/, this];
126
- }
127
- });
128
- });
129
- };
130
- return SceneManager;
131
- }(parameterObservable_1.ParameterObservable));
132
- exports.SceneManager = SceneManager;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SceneManager = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var cubeTexture_1 = require("@babylonjs/core/Materials/Textures/cubeTexture");
6
+ var lodash_es_1 = require("lodash-es");
7
+ var parameterObservable_1 = require("../classes/parameterObservable");
8
+ var event_1 = require("../classes/event");
9
+ var specStorage_1 = require("../store/specStorage");
10
+ var resourceHelper_1 = require("../util/resourceHelper");
11
+ var SceneManager = /** @class */ (function (_super) {
12
+ tslib_1.__extends(SceneManager, _super);
13
+ /**
14
+ * Constructor.
15
+ */
16
+ function SceneManager(scene) {
17
+ var _this = _super.call(this) || this;
18
+ _this.scene = scene;
19
+ _this._parameterObservers = new Map();
20
+ _this.parameterDeclaration = {
21
+ 'environment': { type: 'string' },
22
+ 'environment.rotation': { type: 'number' }
23
+ };
24
+ _this.addParameterObservers();
25
+ return _this;
26
+ }
27
+ /**
28
+ * Creates a {@link SceneManager} based on given BabylonJS scene.
29
+ */
30
+ SceneManager.create = function (scene) {
31
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
32
+ var sceneManager;
33
+ return tslib_1.__generator(this, function (_a) {
34
+ switch (_a.label) {
35
+ case 0:
36
+ sceneManager = new SceneManager(scene);
37
+ return [4 /*yield*/, sceneManager.bootstrapParameters(specStorage_1.SpecStorage.get('scene.parameters'))];
38
+ case 1:
39
+ _a.sent();
40
+ return [2 /*return*/, sceneManager];
41
+ }
42
+ });
43
+ });
44
+ };
45
+ Object.defineProperty(SceneManager.prototype, "activeCamera", {
46
+ /**
47
+ * The active `Camera`.
48
+ */
49
+ get: function () {
50
+ if (!this.scene.activeCamera) {
51
+ throw new Error('Scene has no active camera.');
52
+ }
53
+ return this.scene.activeCamera;
54
+ },
55
+ enumerable: false,
56
+ configurable: true
57
+ });
58
+ /**
59
+ * Places the given {@link ParameterBag} in the {@link SceneManager}'s parameters, replaces all patterns in the
60
+ * {@link StructureJson} and broadcasts all {@link ParameterObserver}s.
61
+ *
62
+ * @emit {@link Event.SCENE_PARAMETER_COMMITTED}
63
+ */
64
+ SceneManager.prototype.commitParameters = function (parameters) {
65
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
66
+ var oldParameters, _loop_1, this_1, parameter;
67
+ var _this = this;
68
+ return tslib_1.__generator(this, function (_a) {
69
+ if (!parameters) {
70
+ parameters = {};
71
+ }
72
+ oldParameters = lodash_es_1.cloneDeep(this.parameters);
73
+ lodash_es_1.merge(this.parameters, parameters);
74
+ _loop_1 = function (parameter) {
75
+ var oldParameterValue = oldParameters[parameter];
76
+ var newParameterValue = this_1.parameters[parameter];
77
+ this_1.assertParameter(this_1.parameterDeclaration, parameter, newParameterValue);
78
+ if (oldParameterValue === newParameterValue) {
79
+ return "continue";
80
+ }
81
+ // parameter changed
82
+ var parameterObservers = resourceHelper_1.mergeMaps(this_1._parameterObservers, this_1.parameterObservers);
83
+ if (parameterObservers.has(parameter)) {
84
+ var observers = parameterObservers.get(parameter);
85
+ observers.forEach(function (observer) {
86
+ observer(_this, oldParameterValue, newParameterValue);
87
+ _this.broadcastEvent(event_1.Event.SCENE_PARAMETER_COMMITTED, _this, parameter, oldParameterValue, newParameterValue);
88
+ });
89
+ }
90
+ };
91
+ this_1 = this;
92
+ // handle parameter observers
93
+ for (parameter in this.parameters) {
94
+ _loop_1(parameter);
95
+ }
96
+ return [2 /*return*/, this];
97
+ });
98
+ });
99
+ };
100
+ SceneManager.prototype.addParameterObservers = function () {
101
+ this._parameterObservers.set('environment', [
102
+ function (manager, oldValue, newValue) {
103
+ manager.scene.environmentTexture = cubeTexture_1.CubeTexture.CreateFromPrefilteredData(newValue.toString(), manager.scene);
104
+ }
105
+ ]);
106
+ this._parameterObservers.set('environment.rotation', [
107
+ function (manager, oldValue, newValue) {
108
+ if (manager.scene.environmentTexture instanceof cubeTexture_1.CubeTexture) {
109
+ manager.scene.environmentTexture.rotationY = (parseFloat(newValue.toString()) * Math.PI) / 180;
110
+ }
111
+ }
112
+ ]);
113
+ return this;
114
+ };
115
+ /**
116
+ * Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
117
+ */
118
+ SceneManager.prototype.bootstrapParameters = function (parameters) {
119
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
120
+ return tslib_1.__generator(this, function (_a) {
121
+ switch (_a.label) {
122
+ case 0: return [4 /*yield*/, this.commitParameters(lodash_es_1.merge(lodash_es_1.cloneDeep(this.parameters), parameters))];
123
+ case 1:
124
+ _a.sent();
125
+ return [2 /*return*/, this];
126
+ }
127
+ });
128
+ });
129
+ };
130
+ return SceneManager;
131
+ }(parameterObservable_1.ParameterObservable));
132
+ exports.SceneManager = SceneManager;
133
133
  //# sourceMappingURL=sceneManager.js.map