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