@configura/babylon-view 1.2.1 → 1.3.0-alpha.3

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 (115) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +1 -1
  3. package/dist/animation/AnimatableObject.d.ts +8 -8
  4. package/dist/animation/AnimatableObject.js +3 -3
  5. package/dist/animation/animator/Animator.d.ts +33 -33
  6. package/dist/animation/animator/Animator.js +58 -58
  7. package/dist/animation/animator/AnimatorEasing.d.ts +16 -16
  8. package/dist/animation/animator/AnimatorEasing.js +31 -31
  9. package/dist/animation/animator/AnimatorEasingMatrix.d.ts +14 -14
  10. package/dist/animation/animator/AnimatorEasingMatrix.js +16 -16
  11. package/dist/animation/animator/AnimatorHighlight.d.ts +16 -16
  12. package/dist/animation/animator/AnimatorHighlight.js +32 -32
  13. package/dist/animation/animator/AnimatorPointToPoint.d.ts +8 -8
  14. package/dist/animation/animator/AnimatorPointToPoint.js +14 -14
  15. package/dist/animation/animator/AnimatorQueue.d.ts +13 -13
  16. package/dist/animation/animator/AnimatorQueue.js +57 -57
  17. package/dist/animation/animator/AnimatorScale.d.ts +8 -8
  18. package/dist/animation/animator/AnimatorScale.js +13 -13
  19. package/dist/animation/animator/AnimatorSpin.d.ts +10 -10
  20. package/dist/animation/animator/AnimatorSpin.js +13 -13
  21. package/dist/animation/animator/EasingFunctions.d.ts +35 -35
  22. package/dist/animation/animator/EasingFunctions.js +137 -137
  23. package/dist/animation/coordinator/Coordinator.d.ts +28 -28
  24. package/dist/animation/coordinator/Coordinator.js +47 -47
  25. package/dist/animation/coordinator/CoordinatorDropAndSpin.d.ts +22 -22
  26. package/dist/animation/coordinator/CoordinatorDropAndSpin.js +133 -133
  27. package/dist/animation/coordinator/CoordinatorIdentity.d.ts +11 -11
  28. package/dist/animation/coordinator/CoordinatorIdentity.js +12 -12
  29. package/dist/animation/coordinator/CoordinatorNodeQueues.d.ts +18 -18
  30. package/dist/animation/coordinator/CoordinatorNodeQueues.js +50 -50
  31. package/dist/animation/coordinator/CoordinatorPulse.d.ts +21 -21
  32. package/dist/animation/coordinator/CoordinatorPulse.js +47 -47
  33. package/dist/animation/coordinator/CoordinatorPulseBounce.d.ts +14 -14
  34. package/dist/animation/coordinator/CoordinatorPulseBounce.js +40 -40
  35. package/dist/animation/coordinator/CoordinatorPulseHighlight.d.ts +13 -13
  36. package/dist/animation/coordinator/CoordinatorPulseHighlight.js +34 -34
  37. package/dist/animation/coordinator/CoordinatorPulseInflate.d.ts +14 -14
  38. package/dist/animation/coordinator/CoordinatorPulseInflate.js +30 -30
  39. package/dist/camera/CameraCreator.d.ts +5 -5
  40. package/dist/camera/CameraCreator.js +4 -4
  41. package/dist/camera/CfgArcRotateCameraPointersInput.d.ts +10 -10
  42. package/dist/camera/CfgArcRotateCameraPointersInput.js +262 -262
  43. package/dist/camera/CfgOrbitalCamera.d.ts +68 -64
  44. package/dist/camera/CfgOrbitalCamera.js +250 -233
  45. package/dist/camera/CfgOrbitalCameraControlProps.d.ts +6 -6
  46. package/dist/camera/CfgOrbitalCameraControlProps.js +3 -3
  47. package/dist/camera/GradingApplier.d.ts +3 -3
  48. package/dist/camera/GradingApplier.js +48 -48
  49. package/dist/engine/EngineCreator.d.ts +3 -3
  50. package/dist/engine/EngineCreator.js +10 -10
  51. package/dist/geometry/CfgGeometry.d.ts +12 -12
  52. package/dist/geometry/CfgGeometry.js +117 -117
  53. package/dist/geometry/CfgMesh.d.ts +7 -7
  54. package/dist/geometry/CfgMesh.js +8 -8
  55. package/dist/geometry/geoSplitter.d.ts +8 -8
  56. package/dist/geometry/geoSplitter.js +192 -192
  57. package/dist/index.d.ts +13 -13
  58. package/dist/index.js +13 -13
  59. package/dist/light/CfgDirectionalLight.d.ts +8 -8
  60. package/dist/light/CfgDirectionalLight.js +18 -18
  61. package/dist/light/CfgHemisphericLight.d.ts +7 -7
  62. package/dist/light/CfgHemisphericLight.js +17 -17
  63. package/dist/light/CfgPointLight.d.ts +8 -8
  64. package/dist/light/CfgPointLight.js +18 -18
  65. package/dist/light/DefaultLightRig.d.ts +19 -19
  66. package/dist/light/DefaultLightRig.js +77 -77
  67. package/dist/light/LightRigCreator.d.ts +9 -9
  68. package/dist/light/LightRigCreator.js +3 -3
  69. package/dist/material/CfgMaterial.d.ts +53 -53
  70. package/dist/material/CfgMaterial.js +454 -454
  71. package/dist/material/DummyMaterialCreator.d.ts +4 -4
  72. package/dist/material/DummyMaterialCreator.js +15 -15
  73. package/dist/material/material.d.ts +18 -18
  74. package/dist/material/material.js +128 -128
  75. package/dist/material/texture.d.ts +14 -14
  76. package/dist/material/texture.js +304 -304
  77. package/dist/nodes/CfgContentRootNode.d.ts +19 -19
  78. package/dist/nodes/CfgContentRootNode.js +75 -75
  79. package/dist/nodes/CfgDeferredMeshNode.d.ts +48 -48
  80. package/dist/nodes/CfgDeferredMeshNode.js +347 -347
  81. package/dist/nodes/CfgProductNode.d.ts +61 -61
  82. package/dist/nodes/CfgProductNode.js +486 -486
  83. package/dist/nodes/CfgSymNode.d.ts +42 -42
  84. package/dist/nodes/CfgSymNode.js +216 -216
  85. package/dist/nodes/CfgSymRootNode.d.ts +33 -33
  86. package/dist/nodes/CfgSymRootNode.js +175 -175
  87. package/dist/nodes/CfgTransformNode.d.ts +29 -29
  88. package/dist/nodes/CfgTransformNode.js +81 -81
  89. package/dist/scene/SceneCreator.d.ts +6 -6
  90. package/dist/scene/SceneCreator.js +22 -22
  91. package/dist/utilities/CfgBoundingBox.d.ts +16 -16
  92. package/dist/utilities/CfgBoundingBox.js +64 -64
  93. package/dist/utilities/utilities3D.d.ts +26 -26
  94. package/dist/utilities/utilities3D.js +187 -187
  95. package/dist/utilities/utilitiesColor.d.ts +18 -18
  96. package/dist/utilities/utilitiesColor.js +48 -48
  97. package/dist/utilities/utilitiesImage.d.ts +6 -6
  98. package/dist/utilities/utilitiesImage.js +107 -107
  99. package/dist/utilities/utilitiesSymRootIdentifier.d.ts +5 -5
  100. package/dist/utilities/utilitiesSymRootIdentifier.js +20 -20
  101. package/dist/view/BaseView.d.ts +70 -70
  102. package/dist/view/BaseView.js +291 -291
  103. package/dist/view/BaseViewConfiguration.d.ts +32 -32
  104. package/dist/view/BaseViewConfiguration.js +8 -8
  105. package/dist/view/RenderEnv.d.ts +38 -38
  106. package/dist/view/RenderEnv.js +7 -7
  107. package/dist/view/SingleProductDefaultCameraView.d.ts +33 -33
  108. package/dist/view/SingleProductDefaultCameraView.js +141 -140
  109. package/dist/view/SingleProductDefaultCameraViewConfiguration.d.ts +46 -44
  110. package/dist/view/SingleProductDefaultCameraViewConfiguration.js +11 -11
  111. package/dist/view/SingleProductView.d.ts +42 -42
  112. package/dist/view/SingleProductView.js +205 -205
  113. package/dist/view/SingleProductViewConfiguration.d.ts +32 -32
  114. package/dist/view/SingleProductViewConfiguration.js +19 -19
  115. package/package.json +5 -5
@@ -1,291 +1,291 @@
1
- import "@babylonjs/core/Debug/debugLayer.js";
2
- import { Matrix } from "@babylonjs/core/Maths/math.vector.js";
3
- import { AssetsManager } from "@babylonjs/core/Misc/assetsManager.js";
4
- import { SymGetMeshEnv } from "@configura/web-core/dist/cm/format/cmsym/components/SymGetMeshEnv.js";
5
- import { DexManager } from "@configura/web-core/dist/cm/format/dex/DexManager.js";
6
- import { AggregatedLoadingObservable, isAbortError, Observable, PromiseCache, toError, } from "@configura/web-utilities";
7
- import { getDefaultGradingApplier } from "../camera/GradingApplier.js";
8
- import { getDefaultEngine } from "../engine/EngineCreator.js";
9
- import { getDefaultLightRigCreator } from "../light/DefaultLightRig.js";
10
- import { defaultDummyMaterialCreator, } from "../material/DummyMaterialCreator.js";
11
- import { CfgContentRootNode } from "../nodes/CfgContentRootNode.js";
12
- import { getDefaultScene } from "../scene/SceneCreator.js";
13
- import { CfgBoundingBox } from "../utilities/CfgBoundingBox.js";
14
- import { cameraConfigurationPropsEquals, DetailLevel, } from "./BaseViewConfiguration.js";
15
- // CET coordinate system is Z-up, Babylon is Y-up, both are right handed
16
- // CET coordinates are used in the CfgProductNode and all its children.
17
- export const CET_TO_BABYLON_MATRIX = Matrix.RotationX(-Math.PI / 2);
18
- export const BABYLON_TO_CET_MATRIX = Matrix.RotationX(Math.PI / 2);
19
- const ENABLE_CONTINUOUS_RENDER = false;
20
- const CULL_EMPTY_NODES = true;
21
- /// Load the highest quality meshes by default.
22
- ///
23
- /// @remarks We only use "base" as a last fallback. The reason is that even though this LOD level
24
- /// could theoretically include a better version than "super" it is not normally included in CmSym
25
- /// files and never used by CET, which makes it unpredictable. See WRD-387 for a case where it
26
- /// caused problems when it was the first choice.
27
- export const DEFAULT_DETAIL_LEVELS = [
28
- DetailLevel.super,
29
- DetailLevel.high,
30
- DetailLevel.medium,
31
- DetailLevel.low,
32
- DetailLevel.base,
33
- ];
34
- // As this cache contains items read from a another resource undefined
35
- // is an acceptable cache value representing a value that will not be
36
- // anything but undefined no mather how many times you try.
37
- const geometryCache = new PromiseCache();
38
- const symNodeCache = new PromiseCache();
39
- const materialCache = new PromiseCache();
40
- const textureImageCache = new PromiseCache();
41
- const derivedNormalMapCache = new PromiseCache();
42
- // Singletons
43
- const SYM_MESH_ENV = new SymGetMeshEnv();
44
- const DEX_MANAGER = new DexManager("BabylonCanvas");
45
- function getAssetManager(scene) {
46
- const assetsManager = new AssetsManager(scene);
47
- assetsManager.useDefaultLoadingScreen = false;
48
- return assetsManager;
49
- }
50
- export class BaseView {
51
- constructor(options) {
52
- this._destroyed = false;
53
- this._inspectorActive = false;
54
- this._needsRenderFrame = false;
55
- this._dumpNextFrameToImage = [];
56
- this._enginePauseSemaphore = 0;
57
- this._errorObservable = new Observable();
58
- this._loadingObservable = new AggregatedLoadingObservable();
59
- this._renderEnvironmentObservable = new Observable();
60
- // To be able to add/remove event listeners without binding them
61
- this._boundNotifyCameraListeners = () => {
62
- this.notifyCameraListeners();
63
- this.scheduleRerender();
64
- };
65
- this.notifyError = (e) => {
66
- if (isAbortError(e)) {
67
- return;
68
- }
69
- this._errorObservable.notifyAll(toError(e));
70
- };
71
- const { canvas, cameraCreator, engineCreator, lightRigCreator, sceneCreator, gradingApplier, dummyMaterialCreator, } = options;
72
- this._canvas = canvas;
73
- // This workaround prevents canvas long taps to select text near the canvas on iOS
74
- for (const eventName of [
75
- "click",
76
- "dblclick",
77
- "mousedown",
78
- "mouseup",
79
- "mousemove",
80
- "touchstart",
81
- "touchend",
82
- "touchmove",
83
- ]) {
84
- canvas.addEventListener(eventName, (event) => {
85
- event.preventDefault();
86
- });
87
- }
88
- const { width, height } = canvas.getBoundingClientRect();
89
- this._viewportSize = [width, height];
90
- const engine = (engineCreator || getDefaultEngine)(canvas, width, height);
91
- const scene = (sceneCreator || getDefaultScene)(engine);
92
- scene.useRightHandedSystem = true;
93
- const camera = cameraCreator(scene, canvas);
94
- (gradingApplier || getDefaultGradingApplier())(camera);
95
- this._scene = scene;
96
- this._engine = engine;
97
- this._camera = camera;
98
- const lightRig = (lightRigCreator || getDefaultLightRigCreator(true))(scene, camera);
99
- this._lightRig = lightRig;
100
- this._dummyMaterialCreator = dummyMaterialCreator || defaultDummyMaterialCreator;
101
- this._renderEnvironment = {
102
- scene,
103
- assetsManager: getAssetManager(scene),
104
- geometryCache,
105
- symNodeCache,
106
- materialCache,
107
- textureImageCache,
108
- derivedNormalMapCache,
109
- lightRig,
110
- dummyMaterial: this._dummyMaterialCreator(scene, lightRig.lightCount),
111
- scheduleRerender: this.scheduleRerender.bind(this),
112
- notifyError: this.notifyError.bind(this),
113
- symMeshEnv: SYM_MESH_ENV,
114
- dexManager: DEX_MANAGER,
115
- cullEmptyNodes: CULL_EMPTY_NODES,
116
- allowedDetailLevels: DEFAULT_DETAIL_LEVELS,
117
- };
118
- this._contentRoot = new CfgContentRootNode(this._renderEnvironment);
119
- this.setConfiguration({}); // Init the RenderEnv
120
- requestAnimationFrame(this.browserTick.bind(this));
121
- // NOTE: As of now we mix view and projection-related properties when we notify, so let's subscribe to both
122
- this._camera.onViewMatrixChangedObservable.add(this._boundNotifyCameraListeners);
123
- this._camera.onProjectionMatrixChangedObservable.add(this._boundNotifyCameraListeners);
124
- }
125
- destroy() {
126
- this._destroyed = true;
127
- this._camera.onViewMatrixChangedObservable.removeCallback(this._boundNotifyCameraListeners);
128
- this._camera.onProjectionMatrixChangedObservable.removeCallback(this._boundNotifyCameraListeners);
129
- this._hideInspector();
130
- this._camera.dispose();
131
- geometryCache.clear();
132
- materialCache.clear();
133
- }
134
- pauseRendering() {
135
- this._enginePauseSemaphore += 1;
136
- }
137
- resumeRendering() {
138
- this._enginePauseSemaphore = Math.max(0, this._enginePauseSemaphore - 1);
139
- }
140
- _hideInspector() {
141
- // The debugLayer getter initializes the backing field _debugLayer, but if we do that before
142
- // "@babylonjs/inspector" is loaded it will not work properly.
143
- if (this._scene._debugLayer === undefined) {
144
- return;
145
- }
146
- this._scene.debugLayer.hide();
147
- }
148
- showInspector(target) {
149
- if (target === undefined) {
150
- this._hideInspector();
151
- }
152
- else {
153
- if (!this._scene.debugLayer.BJSINSPECTOR) {
154
- console.warn("@babylonjs/inspector has to be loaded before the Inspector can be shown.");
155
- return;
156
- }
157
- this._scene.debugLayer.show({
158
- globalRoot: target,
159
- enableClose: false,
160
- });
161
- }
162
- this._inspectorActive = target !== undefined;
163
- }
164
- setConfiguration(configuration) {
165
- if (configuration.allowedDetailLevels !== undefined) {
166
- this._renderEnvironment.allowedDetailLevels = configuration.allowedDetailLevels;
167
- }
168
- this._renderEnvironmentObservable.notifyAll(this._renderEnvironment);
169
- }
170
- get cameraConfiguration() {
171
- return {
172
- nearClipping: this._camera.minZ,
173
- farClipping: this._camera.maxZ,
174
- position: this._camera.position.clone(),
175
- contentPosition: this.contentCenter,
176
- fov: this._camera.fov,
177
- aspect: this._engine.getScreenAspectRatio(),
178
- };
179
- }
180
- get contentCenter() {
181
- const { min, max } = this._contentRoot.getHierarchyBoundingVectors();
182
- return new CfgBoundingBox(min, max).center;
183
- }
184
- notifyCameraListeners() {
185
- if (this._cameraConfigurationObservable === undefined) {
186
- return;
187
- }
188
- const cameraConf = this.cameraConfiguration;
189
- if (this._previousCameraConf !== undefined &&
190
- cameraConfigurationPropsEquals(this._previousCameraConf, cameraConf)) {
191
- return;
192
- }
193
- this._cameraConfigurationObservable.notifyAll(cameraConf, this._cameraConfigurationObservable);
194
- this._previousCameraConf = cameraConf;
195
- }
196
- addEventListener(event, listener) {
197
- switch (event) {
198
- case "cameraConfiguration":
199
- if (this._cameraConfigurationObservable === undefined) {
200
- this._cameraConfigurationObservable =
201
- new Observable();
202
- }
203
- this._cameraConfigurationObservable.listen(listener);
204
- break;
205
- case "renderEnv":
206
- const l = listener;
207
- this._renderEnvironmentObservable.listen(l);
208
- l(this._renderEnvironment);
209
- break;
210
- case "error":
211
- this._errorObservable.listen(listener);
212
- break;
213
- case "loading":
214
- this._loadingObservable.listen(listener);
215
- break;
216
- default:
217
- throw Error(`Unknown event-type ${event}`);
218
- }
219
- }
220
- removeEventListener(event, listener) {
221
- switch (event) {
222
- case "cameraConfiguration":
223
- if (this._cameraConfigurationObservable === undefined) {
224
- return;
225
- }
226
- this._cameraConfigurationObservable.stopListen(listener);
227
- break;
228
- case "renderEnv":
229
- this._renderEnvironmentObservable.stopListen(listener);
230
- break;
231
- case "error":
232
- this._errorObservable.stopListen(listener);
233
- break;
234
- case "loading":
235
- this._loadingObservable.stopListen(listener);
236
- break;
237
- default:
238
- throw Error(`Unknown event-type ${event}`);
239
- }
240
- }
241
- scheduleRerender(dumpNextFrameToImage) {
242
- this._needsRenderFrame = true;
243
- if (dumpNextFrameToImage !== undefined) {
244
- this._dumpNextFrameToImage.push(dumpNextFrameToImage);
245
- }
246
- }
247
- isContinuousRender() {
248
- return ENABLE_CONTINUOUS_RENDER || this._inspectorActive;
249
- }
250
- getNeededFrameRender(time) {
251
- return this._needsRenderFrame || this.isContinuousRender();
252
- }
253
- browserTick(time) {
254
- if (this._destroyed) {
255
- return;
256
- }
257
- this._camera.update();
258
- if (this._enginePauseSemaphore === 0 && this.getNeededFrameRender(time)) {
259
- this.renderFrame(time);
260
- }
261
- requestAnimationFrame(this.browserTick.bind(this));
262
- }
263
- renderFrame(time) {
264
- if (this._viewportSize === undefined) {
265
- console.warn("Size not inited");
266
- return;
267
- }
268
- this._needsRenderFrame = false;
269
- this.refreshCameraNearFar();
270
- this._engine.beginFrame();
271
- this._scene.render();
272
- this._engine.endFrame();
273
- if (0 < this._dumpNextFrameToImage.length) {
274
- const dataUrl = this._canvas.toDataURL("image/png");
275
- this._dumpNextFrameToImage.forEach((c) => c(dataUrl));
276
- this._dumpNextFrameToImage.length = 0;
277
- }
278
- }
279
- resizeViewport(width, height) {
280
- this._viewportSize = [width, height];
281
- this._canvas.style.width = Math.floor(width) + "px";
282
- this._canvas.style.height = Math.floor(height) + "px";
283
- this._engine.resize();
284
- this.handleSizing(false);
285
- this.scheduleRerender();
286
- }
287
- // Exists to be overridden
288
- handleSizing(_force) { }
289
- // Exists to be overridden
290
- refreshCameraNearFar() { }
291
- }
1
+ import "@babylonjs/core/Debug/debugLayer.js";
2
+ import { Matrix } from "@babylonjs/core/Maths/math.vector.js";
3
+ import { AssetsManager } from "@babylonjs/core/Misc/assetsManager.js";
4
+ import { SymGetMeshEnv } from "@configura/web-core/dist/cm/format/cmsym/components/SymGetMeshEnv.js";
5
+ import { DexManager } from "@configura/web-core/dist/cm/format/dex/DexManager.js";
6
+ import { AggregatedLoadingObservable, isAbortError, Observable, PromiseCache, toError, } from "@configura/web-utilities";
7
+ import { getDefaultGradingApplier } from "../camera/GradingApplier.js";
8
+ import { getDefaultEngine } from "../engine/EngineCreator.js";
9
+ import { getDefaultLightRigCreator } from "../light/DefaultLightRig.js";
10
+ import { defaultDummyMaterialCreator, } from "../material/DummyMaterialCreator.js";
11
+ import { CfgContentRootNode } from "../nodes/CfgContentRootNode.js";
12
+ import { getDefaultScene } from "../scene/SceneCreator.js";
13
+ import { CfgBoundingBox } from "../utilities/CfgBoundingBox.js";
14
+ import { cameraConfigurationPropsEquals, DetailLevel, } from "./BaseViewConfiguration.js";
15
+ // CET coordinate system is Z-up, Babylon is Y-up, both are right handed
16
+ // CET coordinates are used in the CfgProductNode and all its children.
17
+ export const CET_TO_BABYLON_MATRIX = Matrix.RotationX(-Math.PI / 2);
18
+ export const BABYLON_TO_CET_MATRIX = Matrix.RotationX(Math.PI / 2);
19
+ const ENABLE_CONTINUOUS_RENDER = false;
20
+ const CULL_EMPTY_NODES = true;
21
+ /// Load the highest quality meshes by default.
22
+ ///
23
+ /// @remarks We only use "base" as a last fallback. The reason is that even though this LOD level
24
+ /// could theoretically include a better version than "super" it is not normally included in CmSym
25
+ /// files and never used by CET, which makes it unpredictable. See WRD-387 for a case where it
26
+ /// caused problems when it was the first choice.
27
+ export const DEFAULT_DETAIL_LEVELS = [
28
+ DetailLevel.super,
29
+ DetailLevel.high,
30
+ DetailLevel.medium,
31
+ DetailLevel.low,
32
+ DetailLevel.base,
33
+ ];
34
+ // As this cache contains items read from a another resource undefined
35
+ // is an acceptable cache value representing a value that will not be
36
+ // anything but undefined no mather how many times you try.
37
+ const geometryCache = new PromiseCache();
38
+ const symNodeCache = new PromiseCache();
39
+ const materialCache = new PromiseCache();
40
+ const textureImageCache = new PromiseCache();
41
+ const derivedNormalMapCache = new PromiseCache();
42
+ // Singletons
43
+ const SYM_MESH_ENV = new SymGetMeshEnv();
44
+ const DEX_MANAGER = new DexManager("BabylonCanvas");
45
+ function getAssetManager(scene) {
46
+ const assetsManager = new AssetsManager(scene);
47
+ assetsManager.useDefaultLoadingScreen = false;
48
+ return assetsManager;
49
+ }
50
+ export class BaseView {
51
+ constructor(options) {
52
+ this._destroyed = false;
53
+ this._inspectorActive = false;
54
+ this._needsRenderFrame = false;
55
+ this._dumpNextFrameToImage = [];
56
+ this._enginePauseSemaphore = 0;
57
+ this._errorObservable = new Observable();
58
+ this._loadingObservable = new AggregatedLoadingObservable();
59
+ this._renderEnvironmentObservable = new Observable();
60
+ // To be able to add/remove event listeners without binding them
61
+ this._boundNotifyCameraListeners = () => {
62
+ this.notifyCameraListeners();
63
+ this.scheduleRerender();
64
+ };
65
+ this.notifyError = (e) => {
66
+ if (isAbortError(e)) {
67
+ return;
68
+ }
69
+ this._errorObservable.notifyAll(toError(e));
70
+ };
71
+ const { canvas, cameraCreator, engineCreator, lightRigCreator, sceneCreator, gradingApplier, dummyMaterialCreator, } = options;
72
+ this._canvas = canvas;
73
+ // This workaround prevents canvas long taps to select text near the canvas on iOS
74
+ for (const eventName of [
75
+ "click",
76
+ "dblclick",
77
+ "mousedown",
78
+ "mouseup",
79
+ "mousemove",
80
+ "touchstart",
81
+ "touchend",
82
+ "touchmove",
83
+ ]) {
84
+ canvas.addEventListener(eventName, (event) => {
85
+ event.preventDefault();
86
+ });
87
+ }
88
+ const { width, height } = canvas.getBoundingClientRect();
89
+ this._viewportSize = [width, height];
90
+ const engine = (engineCreator || getDefaultEngine)(canvas, width, height);
91
+ const scene = (sceneCreator || getDefaultScene)(engine);
92
+ scene.useRightHandedSystem = true;
93
+ const camera = cameraCreator(scene, canvas);
94
+ (gradingApplier || getDefaultGradingApplier())(camera);
95
+ this._scene = scene;
96
+ this._engine = engine;
97
+ this._camera = camera;
98
+ const lightRig = (lightRigCreator || getDefaultLightRigCreator(true))(scene, camera);
99
+ this._lightRig = lightRig;
100
+ this._dummyMaterialCreator = dummyMaterialCreator || defaultDummyMaterialCreator;
101
+ this._renderEnvironment = {
102
+ scene,
103
+ assetsManager: getAssetManager(scene),
104
+ geometryCache,
105
+ symNodeCache,
106
+ materialCache,
107
+ textureImageCache,
108
+ derivedNormalMapCache,
109
+ lightRig,
110
+ dummyMaterial: this._dummyMaterialCreator(scene, lightRig.lightCount),
111
+ scheduleRerender: this.scheduleRerender.bind(this),
112
+ notifyError: this.notifyError.bind(this),
113
+ symMeshEnv: SYM_MESH_ENV,
114
+ dexManager: DEX_MANAGER,
115
+ cullEmptyNodes: CULL_EMPTY_NODES,
116
+ allowedDetailLevels: DEFAULT_DETAIL_LEVELS,
117
+ };
118
+ this._contentRoot = new CfgContentRootNode(this._renderEnvironment);
119
+ this.setConfiguration({}); // Init the RenderEnv
120
+ requestAnimationFrame(this.browserTick.bind(this));
121
+ // NOTE: As of now we mix view and projection-related properties when we notify, so let's subscribe to both
122
+ this._camera.onViewMatrixChangedObservable.add(this._boundNotifyCameraListeners);
123
+ this._camera.onProjectionMatrixChangedObservable.add(this._boundNotifyCameraListeners);
124
+ }
125
+ destroy() {
126
+ this._destroyed = true;
127
+ this._camera.onViewMatrixChangedObservable.removeCallback(this._boundNotifyCameraListeners);
128
+ this._camera.onProjectionMatrixChangedObservable.removeCallback(this._boundNotifyCameraListeners);
129
+ this._hideInspector();
130
+ this._camera.dispose();
131
+ geometryCache.clear();
132
+ materialCache.clear();
133
+ }
134
+ pauseRendering() {
135
+ this._enginePauseSemaphore += 1;
136
+ }
137
+ resumeRendering() {
138
+ this._enginePauseSemaphore = Math.max(0, this._enginePauseSemaphore - 1);
139
+ }
140
+ _hideInspector() {
141
+ // The debugLayer getter initializes the backing field _debugLayer, but if we do that before
142
+ // "@babylonjs/inspector" is loaded it will not work properly.
143
+ if (this._scene._debugLayer === undefined) {
144
+ return;
145
+ }
146
+ this._scene.debugLayer.hide();
147
+ }
148
+ showInspector(target) {
149
+ if (target === undefined) {
150
+ this._hideInspector();
151
+ }
152
+ else {
153
+ if (!this._scene.debugLayer.BJSINSPECTOR) {
154
+ console.warn("@babylonjs/inspector has to be loaded before the Inspector can be shown.");
155
+ return;
156
+ }
157
+ this._scene.debugLayer.show({
158
+ globalRoot: target,
159
+ enableClose: false,
160
+ });
161
+ }
162
+ this._inspectorActive = target !== undefined;
163
+ }
164
+ setConfiguration(configuration) {
165
+ if (configuration.allowedDetailLevels !== undefined) {
166
+ this._renderEnvironment.allowedDetailLevels = configuration.allowedDetailLevels;
167
+ }
168
+ this._renderEnvironmentObservable.notifyAll(this._renderEnvironment);
169
+ }
170
+ get cameraConfiguration() {
171
+ return {
172
+ nearClipping: this._camera.minZ,
173
+ farClipping: this._camera.maxZ,
174
+ position: this._camera.position.clone(),
175
+ contentPosition: this.contentCenter,
176
+ fov: this._camera.fov,
177
+ aspect: this._engine.getScreenAspectRatio(),
178
+ };
179
+ }
180
+ get contentCenter() {
181
+ const { min, max } = this._contentRoot.getHierarchyBoundingVectors();
182
+ return new CfgBoundingBox(min, max).center;
183
+ }
184
+ notifyCameraListeners() {
185
+ if (this._cameraConfigurationObservable === undefined) {
186
+ return;
187
+ }
188
+ const cameraConf = this.cameraConfiguration;
189
+ if (this._previousCameraConf !== undefined &&
190
+ cameraConfigurationPropsEquals(this._previousCameraConf, cameraConf)) {
191
+ return;
192
+ }
193
+ this._cameraConfigurationObservable.notifyAll(cameraConf, this._cameraConfigurationObservable);
194
+ this._previousCameraConf = cameraConf;
195
+ }
196
+ addEventListener(event, listener) {
197
+ switch (event) {
198
+ case "cameraConfiguration":
199
+ if (this._cameraConfigurationObservable === undefined) {
200
+ this._cameraConfigurationObservable =
201
+ new Observable();
202
+ }
203
+ this._cameraConfigurationObservable.listen(listener);
204
+ break;
205
+ case "renderEnv":
206
+ const l = listener;
207
+ this._renderEnvironmentObservable.listen(l);
208
+ l(this._renderEnvironment);
209
+ break;
210
+ case "error":
211
+ this._errorObservable.listen(listener);
212
+ break;
213
+ case "loading":
214
+ this._loadingObservable.listen(listener);
215
+ break;
216
+ default:
217
+ throw Error(`Unknown event-type ${event}`);
218
+ }
219
+ }
220
+ removeEventListener(event, listener) {
221
+ switch (event) {
222
+ case "cameraConfiguration":
223
+ if (this._cameraConfigurationObservable === undefined) {
224
+ return;
225
+ }
226
+ this._cameraConfigurationObservable.stopListen(listener);
227
+ break;
228
+ case "renderEnv":
229
+ this._renderEnvironmentObservable.stopListen(listener);
230
+ break;
231
+ case "error":
232
+ this._errorObservable.stopListen(listener);
233
+ break;
234
+ case "loading":
235
+ this._loadingObservable.stopListen(listener);
236
+ break;
237
+ default:
238
+ throw Error(`Unknown event-type ${event}`);
239
+ }
240
+ }
241
+ scheduleRerender(dumpNextFrameToImage) {
242
+ this._needsRenderFrame = true;
243
+ if (dumpNextFrameToImage !== undefined) {
244
+ this._dumpNextFrameToImage.push(dumpNextFrameToImage);
245
+ }
246
+ }
247
+ isContinuousRender() {
248
+ return ENABLE_CONTINUOUS_RENDER || this._inspectorActive;
249
+ }
250
+ getNeededFrameRender(time) {
251
+ return this._needsRenderFrame || this.isContinuousRender();
252
+ }
253
+ browserTick(time) {
254
+ if (this._destroyed) {
255
+ return;
256
+ }
257
+ this._camera.update();
258
+ if (this._enginePauseSemaphore === 0 && this.getNeededFrameRender(time)) {
259
+ this.renderFrame(time);
260
+ }
261
+ requestAnimationFrame(this.browserTick.bind(this));
262
+ }
263
+ renderFrame(time) {
264
+ if (this._viewportSize === undefined) {
265
+ console.warn("Size not inited");
266
+ return;
267
+ }
268
+ this._needsRenderFrame = false;
269
+ this.refreshCameraNearFar();
270
+ this._engine.beginFrame();
271
+ this._scene.render();
272
+ this._engine.endFrame();
273
+ if (0 < this._dumpNextFrameToImage.length) {
274
+ const dataUrl = this._canvas.toDataURL("image/png");
275
+ this._dumpNextFrameToImage.forEach((c) => c(dataUrl));
276
+ this._dumpNextFrameToImage.length = 0;
277
+ }
278
+ }
279
+ resizeViewport(width, height) {
280
+ this._viewportSize = [width, height];
281
+ this._canvas.style.width = Math.floor(width) + "px";
282
+ this._canvas.style.height = Math.floor(height) + "px";
283
+ this._engine.resize();
284
+ this.handleSizing(false);
285
+ this.scheduleRerender();
286
+ }
287
+ // Exists to be overridden
288
+ handleSizing(_force) { }
289
+ // Exists to be overridden
290
+ refreshCameraNearFar() { }
291
+ }
@@ -1,33 +1,33 @@
1
- import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";
2
- import { DetailLevel } from "@configura/web-core/dist/cm/geometry/DetailMask.js";
3
- import { EventListener } from "@configura/web-utilities";
4
- import { RenderEnv } from "./RenderEnv.js";
5
- export { DetailLevel } from "@configura/web-core/dist/cm/geometry/DetailMask.js";
6
- /**
7
- * @param allowedDetailLevels Optionally controls the detail level (LOD, level of detail) allowed
8
- * when loading the 3D models. Provide a single DetailLevel or an array of them if you want to
9
- * override the default selection and/or order. The order of the array defines the priority since
10
- * models are not guaranteed to have all DetailLevels available.
11
- */
12
- export interface BaseViewConfiguration {
13
- allowedDetailLevels?: DetailLevel | DetailLevel[];
14
- }
15
- export declare type BaseViewEventListener<K extends keyof BaseViewEventMap> = EventListener<BaseViewEventMap, K>;
16
- export declare type ScheduleRerender = (dumpNextFrameToImage?: ImageDumpCallback) => void;
17
- export declare type ImageDumpCallback = (imageDataUrl: string) => void;
18
- export interface BaseViewEventMap {
19
- renderEnv: RenderEnv;
20
- error: Error;
21
- loading: boolean;
22
- cameraConfiguration: CameraConfigurationProps;
23
- }
24
- export interface CameraConfigurationProps {
25
- nearClipping: number;
26
- farClipping: number;
27
- position: Vector3;
28
- contentPosition: Vector3;
29
- fov: number;
30
- aspect: number;
31
- }
32
- export declare function cameraConfigurationPropsEquals(left: CameraConfigurationProps, right: CameraConfigurationProps): boolean;
1
+ import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";
2
+ import { DetailLevel } from "@configura/web-core/dist/cm/geometry/DetailMask.js";
3
+ import { EventListener } from "@configura/web-utilities";
4
+ import { RenderEnv } from "./RenderEnv.js";
5
+ export { DetailLevel } from "@configura/web-core/dist/cm/geometry/DetailMask.js";
6
+ /**
7
+ * @param allowedDetailLevels Optionally controls the detail level (LOD, level of detail) allowed
8
+ * when loading the 3D models. Provide a single DetailLevel or an array of them if you want to
9
+ * override the default selection and/or order. The order of the array defines the priority since
10
+ * models are not guaranteed to have all DetailLevels available.
11
+ */
12
+ export interface BaseViewConfiguration {
13
+ allowedDetailLevels?: DetailLevel | DetailLevel[];
14
+ }
15
+ export declare type BaseViewEventListener<K extends keyof BaseViewEventMap> = EventListener<BaseViewEventMap, K>;
16
+ export declare type ScheduleRerender = (dumpNextFrameToImage?: ImageDumpCallback) => void;
17
+ export declare type ImageDumpCallback = (imageDataUrl: string) => void;
18
+ export interface BaseViewEventMap {
19
+ renderEnv: RenderEnv;
20
+ error: Error;
21
+ loading: boolean;
22
+ cameraConfiguration: CameraConfigurationProps;
23
+ }
24
+ export interface CameraConfigurationProps {
25
+ nearClipping: number;
26
+ farClipping: number;
27
+ position: Vector3;
28
+ contentPosition: Vector3;
29
+ fov: number;
30
+ aspect: number;
31
+ }
32
+ export declare function cameraConfigurationPropsEquals(left: CameraConfigurationProps, right: CameraConfigurationProps): boolean;
33
33
  //# sourceMappingURL=BaseViewConfiguration.d.ts.map