@babylonjs/viewer 5.0.0 → 5.0.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 (127) hide show
  1. package/configuration/configuration.d.ts +107 -107
  2. package/configuration/configuration.js +15 -15
  3. package/configuration/configurationCompatibility.d.ts +8 -8
  4. package/configuration/configurationCompatibility.js +65 -65
  5. package/configuration/configurationContainer.d.ts +10 -10
  6. package/configuration/configurationContainer.js +9 -9
  7. package/configuration/globals.d.ts +6 -6
  8. package/configuration/globals.js +17 -17
  9. package/configuration/index.d.ts +2 -2
  10. package/configuration/index.js +3 -3
  11. package/configuration/interfaces/cameraConfiguration.d.ts +31 -31
  12. package/configuration/interfaces/cameraConfiguration.js +1 -1
  13. package/configuration/interfaces/colorGradingConfiguration.d.ts +81 -81
  14. package/configuration/interfaces/colorGradingConfiguration.js +1 -1
  15. package/configuration/interfaces/defaultRenderingPipelineConfiguration.d.ts +20 -20
  16. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js +1 -1
  17. package/configuration/interfaces/environmentMapConfiguration.d.ts +22 -22
  18. package/configuration/interfaces/environmentMapConfiguration.js +1 -1
  19. package/configuration/interfaces/groundConfiguration.d.ts +24 -24
  20. package/configuration/interfaces/groundConfiguration.js +1 -1
  21. package/configuration/interfaces/imageProcessingConfiguration.d.ts +43 -43
  22. package/configuration/interfaces/imageProcessingConfiguration.js +1 -1
  23. package/configuration/interfaces/index.d.ts +15 -15
  24. package/configuration/interfaces/index.js +15 -15
  25. package/configuration/interfaces/lightConfiguration.d.ts +60 -60
  26. package/configuration/interfaces/lightConfiguration.js +1 -1
  27. package/configuration/interfaces/modelAnimationConfiguration.d.ts +26 -26
  28. package/configuration/interfaces/modelAnimationConfiguration.js +1 -1
  29. package/configuration/interfaces/modelConfiguration.d.ts +65 -65
  30. package/configuration/interfaces/modelConfiguration.js +1 -1
  31. package/configuration/interfaces/observersConfiguration.d.ts +5 -5
  32. package/configuration/interfaces/observersConfiguration.js +1 -1
  33. package/configuration/interfaces/sceneConfiguration.d.ts +48 -48
  34. package/configuration/interfaces/sceneConfiguration.js +1 -1
  35. package/configuration/interfaces/sceneOptimizerConfiguration.d.ts +23 -23
  36. package/configuration/interfaces/sceneOptimizerConfiguration.js +1 -1
  37. package/configuration/interfaces/skyboxConfiguration.d.ts +21 -21
  38. package/configuration/interfaces/skyboxConfiguration.js +1 -1
  39. package/configuration/interfaces/templateConfiguration.d.ts +67 -67
  40. package/configuration/interfaces/templateConfiguration.js +1 -1
  41. package/configuration/interfaces/vrConfiguration.d.ts +16 -16
  42. package/configuration/interfaces/vrConfiguration.js +1 -1
  43. package/configuration/loader.d.ts +4 -4
  44. package/configuration/loader.js +16 -16
  45. package/configuration/mappers.d.ts +42 -42
  46. package/configuration/mappers.js +190 -190
  47. package/configuration/renderOnlyLoader.d.ts +33 -33
  48. package/configuration/renderOnlyLoader.js +161 -161
  49. package/configuration/types/default.d.ts +6 -6
  50. package/configuration/types/default.js +120 -120
  51. package/configuration/types/environmentMap.d.ts +5 -5
  52. package/configuration/types/environmentMap.js +13 -13
  53. package/configuration/types/extended.d.ts +6 -6
  54. package/configuration/types/extended.js +316 -316
  55. package/configuration/types/index.d.ts +13 -13
  56. package/configuration/types/index.js +49 -49
  57. package/configuration/types/minimal.d.ts +6 -6
  58. package/configuration/types/minimal.js +42 -42
  59. package/configuration/types/renderOnlyDefault.d.ts +30 -30
  60. package/configuration/types/renderOnlyDefault.js +30 -30
  61. package/configuration/types/shadowLight.d.ts +9 -9
  62. package/configuration/types/shadowLight.js +63 -63
  63. package/helper/index.d.ts +26 -26
  64. package/helper/index.js +62 -62
  65. package/index.d.ts +30 -30
  66. package/index.js +45 -45
  67. package/initializer.d.ts +11 -11
  68. package/initializer.js +34 -34
  69. package/interfaces.d.ts +5 -5
  70. package/interfaces.js +1 -1
  71. package/labs/environmentSerializer.d.ts +126 -126
  72. package/labs/environmentSerializer.js +190 -190
  73. package/labs/texture.d.ts +183 -183
  74. package/labs/texture.js +300 -300
  75. package/labs/viewerLabs.d.ts +51 -51
  76. package/labs/viewerLabs.js +133 -133
  77. package/loader/modelLoader.d.ts +47 -47
  78. package/loader/modelLoader.js +189 -189
  79. package/loader/plugins/applyMaterialConfig.d.ts +12 -12
  80. package/loader/plugins/applyMaterialConfig.js +15 -15
  81. package/loader/plugins/extendedMaterialLoaderPlugin.d.ts +9 -9
  82. package/loader/plugins/extendedMaterialLoaderPlugin.js +15 -15
  83. package/loader/plugins/index.d.ts +18 -18
  84. package/loader/plugins/index.js +42 -42
  85. package/loader/plugins/loaderPlugin.d.ts +24 -24
  86. package/loader/plugins/loaderPlugin.js +1 -1
  87. package/loader/plugins/msftLodLoaderPlugin.d.ts +12 -12
  88. package/loader/plugins/msftLodLoaderPlugin.js +20 -20
  89. package/loader/plugins/telemetryLoaderPlugin.d.ts +12 -12
  90. package/loader/plugins/telemetryLoaderPlugin.js +35 -35
  91. package/managers/observablesManager.d.ts +66 -66
  92. package/managers/observablesManager.js +34 -34
  93. package/managers/sceneManager.d.ts +243 -243
  94. package/managers/sceneManager.js +1388 -1388
  95. package/managers/telemetryManager.d.ts +57 -57
  96. package/managers/telemetryManager.js +113 -113
  97. package/model/modelAnimation.d.ts +215 -215
  98. package/model/modelAnimation.js +232 -232
  99. package/model/viewerModel.d.ts +228 -228
  100. package/model/viewerModel.js +669 -669
  101. package/optimizer/custom/extended.d.ts +11 -11
  102. package/optimizer/custom/extended.js +98 -98
  103. package/optimizer/custom/index.d.ts +8 -8
  104. package/optimizer/custom/index.js +24 -24
  105. package/package.json +5 -5
  106. package/renderOnlyIndex.d.ts +11 -11
  107. package/renderOnlyIndex.js +17 -17
  108. package/templating/eventManager.d.ts +35 -35
  109. package/templating/eventManager.js +65 -65
  110. package/templating/plugins/hdButtonPlugin.d.ts +9 -9
  111. package/templating/plugins/hdButtonPlugin.js +21 -21
  112. package/templating/plugins/printButton.d.ts +9 -9
  113. package/templating/plugins/printButton.js +40 -40
  114. package/templating/templateManager.d.ts +190 -190
  115. package/templating/templateManager.js +553 -553
  116. package/templating/viewerTemplatePlugin.d.ts +21 -21
  117. package/templating/viewerTemplatePlugin.js +68 -68
  118. package/viewer/defaultViewer.d.ts +122 -122
  119. package/viewer/defaultViewer.js +665 -665
  120. package/viewer/renderOnlyViewer.d.ts +8 -8
  121. package/viewer/renderOnlyViewer.js +43 -43
  122. package/viewer/viewer.d.ts +254 -254
  123. package/viewer/viewer.js +777 -777
  124. package/viewer/viewerManager.d.ts +55 -55
  125. package/viewer/viewerManager.js +87 -87
  126. package/viewer/viewerWithTemplate.d.ts +9 -9
  127. package/viewer/viewerWithTemplate.js +19 -19
package/labs/texture.js CHANGED
@@ -1,301 +1,301 @@
1
- import { CubeTexture } from "@babylonjs/core/Materials/Textures/cubeTexture.js";
2
- import { InternalTexture, InternalTextureSource } from "@babylonjs/core/Materials/Textures/internalTexture.js";
3
- import { Scalar } from "@babylonjs/core/Maths/math.scalar.js";
4
- import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
5
- /**
6
- * A minimal WebGL cubemap descriptor
7
- */
8
- var TextureCube = /** @class */ (function () {
9
- /**
10
- * constructor
11
- * @param internalFormat WebGL pixel format for the texture on the GPU
12
- * @param type WebGL pixel type of the supplied data and texture on the GPU
13
- * @param source An array containing mipmap levels of faces, where each mipmap level is an array of faces and each face is a TextureSource object
14
- */
15
- function TextureCube(internalFormat, type, source) {
16
- if (source === void 0) { source = []; }
17
- this.internalFormat = internalFormat;
18
- this.type = type;
19
- this.source = source;
20
- }
21
- Object.defineProperty(TextureCube.prototype, "Width", {
22
- /**
23
- * Returns the width of a face of the texture or 0 if not available
24
- */
25
- // eslint-disable-next-line @typescript-eslint/naming-convention
26
- get: function () {
27
- return this.source && this.source[0] && this.source[0][0] ? this.source[0][0].width : 0;
28
- },
29
- enumerable: false,
30
- configurable: true
31
- });
32
- Object.defineProperty(TextureCube.prototype, "Height", {
33
- /**
34
- * Returns the height of a face of the texture or 0 if not available
35
- */
36
- // eslint-disable-next-line @typescript-eslint/naming-convention
37
- get: function () {
38
- return this.source && this.source[0] && this.source[0][0] ? this.source[0][0].height : 0;
39
- },
40
- enumerable: false,
41
- configurable: true
42
- });
43
- return TextureCube;
44
- }());
45
- export { TextureCube };
46
- /**
47
- * A static class providing methods to aid working with Bablyon textures.
48
- */
49
- var TextureUtils = /** @class */ (function () {
50
- function TextureUtils() {
51
- }
52
- /**
53
- * Returns a BabylonCubeTexture instance from a Spectre texture cube, subject to sampling parameters.
54
- * If such a texture has already been requested in the past, this texture will be returned, otherwise a new one will be created.
55
- * The advantage of this is to enable working with texture objects without the need to initialize on the GPU until desired.
56
- * @param scene A Babylon Scene instance
57
- * @param textureCube A Spectre TextureCube object
58
- * @param automaticMipmaps Pass true to enable automatic mipmap generation where possible (requires power of images)
59
- * @param environment Specifies that the texture will be used as an environment
60
- * @param singleLod Specifies that the texture will be a singleLod (for environment)
61
- * @return Babylon cube texture
62
- */
63
- TextureUtils.GetBabylonCubeTexture = function (scene, textureCube, automaticMipmaps, environment, singleLod) {
64
- var _a;
65
- if (environment === void 0) { environment = false; }
66
- if (singleLod === void 0) { singleLod = false; }
67
- if (!textureCube) {
68
- throw new Error("no texture cube provided");
69
- }
70
- var parameters;
71
- if (environment) {
72
- parameters = singleLod ? TextureUtils._EnvironmentSingleMipSampling : TextureUtils._EnvironmentSampling;
73
- }
74
- else {
75
- parameters = {
76
- magFilter: 9728 /* NEAREST */,
77
- minFilter: 9728 /* NEAREST */,
78
- wrapS: 33071 /* CLAMP_TO_EDGE */,
79
- wrapT: 33071 /* CLAMP_TO_EDGE */,
80
- };
81
- }
82
- var key = TextureUtils.BabylonTextureKeyPrefix + parameters.magFilter + "" + parameters.minFilter + "" + parameters.wrapS + "" + parameters.wrapT;
83
- var babylonTexture = textureCube[key];
84
- if (!babylonTexture) {
85
- //initialize babylon texture
86
- babylonTexture = new CubeTexture("", scene);
87
- if (environment) {
88
- babylonTexture.lodGenerationOffset = TextureUtils.EnvironmentLODOffset;
89
- babylonTexture.lodGenerationScale = TextureUtils.EnvironmentLODScale;
90
- }
91
- babylonTexture.gammaSpace = false;
92
- var internalTexture_1 = new InternalTexture(scene.getEngine(), InternalTextureSource.CubeRaw);
93
- var glTexture_1 = (_a = internalTexture_1._hardwareTexture) === null || _a === void 0 ? void 0 : _a.underlyingResource;
94
- //babylon properties
95
- internalTexture_1.isCube = true;
96
- internalTexture_1.generateMipMaps = false;
97
- babylonTexture._texture = internalTexture_1;
98
- TextureUtils.ApplySamplingParameters(babylonTexture, parameters);
99
- var maxMipLevel_1 = automaticMipmaps ? 0 : textureCube.source.length - 1;
100
- var texturesUploaded_1 = 0;
101
- var textureComplete_1 = function () {
102
- return texturesUploaded_1 === (maxMipLevel_1 + 1) * 6;
103
- };
104
- var uploadFace_1 = function (i, level, face) {
105
- if (!glTexture_1) {
106
- return;
107
- }
108
- if (i === 0 && level === 0) {
109
- internalTexture_1.width = face.width;
110
- internalTexture_1.height = face.height;
111
- }
112
- var gl = scene.getEngine()._gl;
113
- gl.bindTexture(gl.TEXTURE_CUBE_MAP, glTexture_1);
114
- scene.getEngine()._unpackFlipY(false);
115
- if (face instanceof HTMLElement || face instanceof ImageData) {
116
- gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, level, textureCube.internalFormat, textureCube.internalFormat, textureCube.type, face);
117
- }
118
- else {
119
- var textureData = face;
120
- gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, level, textureCube.internalFormat, textureData.width, textureData.height, 0, textureData.format, textureCube.type, textureData.data);
121
- }
122
- texturesUploaded_1++;
123
- if (textureComplete_1()) {
124
- //generate mipmaps
125
- if (automaticMipmaps) {
126
- var w = face.width;
127
- var h = face.height;
128
- var isPot = (w !== 0 && w & (w - 1)) === 0 && (h !== 0 && h & (h - 1)) === 0;
129
- if (isPot) {
130
- gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
131
- }
132
- }
133
- // Upload Separate lods in case there is no support for texture lod.
134
- if (environment && !scene.getEngine().getCaps().textureLOD && !singleLod) {
135
- var mipSlices = 3;
136
- for (var i_1 = 0; i_1 < mipSlices; i_1++) {
137
- var lodKey = TextureUtils.BabylonTextureKeyPrefix + "lod" + i_1;
138
- var lod = textureCube[lodKey];
139
- //initialize lod texture if it doesn't already exist
140
- if (lod == null && textureCube.Width) {
141
- //compute LOD from even spacing in smoothness (matching shader calculation)
142
- var smoothness = i_1 / (mipSlices - 1);
143
- var roughness = 1 - smoothness;
144
- var kMinimumVariance = 0.0005;
145
- var alphaG = roughness * roughness + kMinimumVariance;
146
- var microsurfaceAverageSlopeTexels = alphaG * textureCube.Width;
147
- var environmentSpecularLOD = TextureUtils.EnvironmentLODScale * Scalar.Log2(microsurfaceAverageSlopeTexels) + TextureUtils.EnvironmentLODOffset;
148
- var maxLODIndex = textureCube.source.length - 1;
149
- var mipmapIndex = Math.min(Math.max(Math.round(environmentSpecularLOD), 0), maxLODIndex);
150
- lod = TextureUtils.GetBabylonCubeTexture(scene, new TextureCube(6408 /* RGBA */, 5121 /* UNSIGNED_BYTE */, [textureCube.source[mipmapIndex]]), false, true, true);
151
- if (i_1 === 0) {
152
- internalTexture_1._lodTextureLow = lod;
153
- }
154
- else if (i_1 === 1) {
155
- internalTexture_1._lodTextureMid = lod;
156
- }
157
- else {
158
- internalTexture_1._lodTextureHigh = lod;
159
- }
160
- textureCube[lodKey] = lod;
161
- }
162
- }
163
- }
164
- internalTexture_1.isReady = true;
165
- }
166
- gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
167
- scene.getEngine().resetTextureCache();
168
- };
169
- var _loop_1 = function (i) {
170
- var faces = textureCube.source[i];
171
- var _loop_2 = function (j) {
172
- var face = faces[j];
173
- if (face instanceof HTMLImageElement && !face.complete) {
174
- face.addEventListener("load", function () {
175
- uploadFace_1(j, i, face);
176
- }, false);
177
- }
178
- else {
179
- uploadFace_1(j, i, face);
180
- }
181
- };
182
- for (var j = 0; j < faces.length; j++) {
183
- _loop_2(j);
184
- }
185
- };
186
- for (var i = 0; i <= maxMipLevel_1; i++) {
187
- _loop_1(i);
188
- }
189
- scene.getEngine().resetTextureCache();
190
- babylonTexture.isReady = function () {
191
- return textureComplete_1();
192
- };
193
- textureCube[key] = babylonTexture;
194
- }
195
- return babylonTexture;
196
- };
197
- /**
198
- * Applies Spectre SamplingParameters to a Babylon texture by directly setting texture parameters on the internal WebGLTexture as well as setting Babylon fields
199
- * @param babylonTexture Babylon texture to apply texture to (requires the Babylon texture has an initialize _texture field)
200
- * @param parameters Spectre SamplingParameters to apply
201
- */
202
- TextureUtils.ApplySamplingParameters = function (babylonTexture, parameters) {
203
- var _a;
204
- var scene = babylonTexture.getScene();
205
- if (!scene) {
206
- return;
207
- }
208
- var gl = scene.getEngine()._gl;
209
- var target = babylonTexture.isCube ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;
210
- var internalTexture = babylonTexture._texture;
211
- if (!internalTexture) {
212
- return;
213
- }
214
- var glTexture = (_a = internalTexture._hardwareTexture) === null || _a === void 0 ? void 0 : _a.underlyingResource;
215
- gl.bindTexture(target, glTexture);
216
- if (parameters.magFilter != null) {
217
- gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, parameters.magFilter);
218
- }
219
- if (parameters.minFilter != null) {
220
- gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, parameters.minFilter);
221
- }
222
- if (parameters.wrapS != null) {
223
- gl.texParameteri(target, gl.TEXTURE_WRAP_S, parameters.wrapS);
224
- }
225
- if (parameters.wrapT != null) {
226
- gl.texParameteri(target, gl.TEXTURE_WRAP_T, parameters.wrapT);
227
- }
228
- //set babylon wrap modes from sampling parameter
229
- switch (parameters.wrapS) {
230
- case 10497 /* REPEAT */:
231
- babylonTexture.wrapU = Texture.WRAP_ADDRESSMODE;
232
- break;
233
- case 33071 /* CLAMP_TO_EDGE */:
234
- babylonTexture.wrapU = Texture.CLAMP_ADDRESSMODE;
235
- break;
236
- case 33648 /* MIRRORED_REPEAT */:
237
- babylonTexture.wrapU = Texture.MIRROR_ADDRESSMODE;
238
- break;
239
- default:
240
- babylonTexture.wrapU = Texture.CLAMP_ADDRESSMODE;
241
- }
242
- switch (parameters.wrapT) {
243
- case 10497 /* REPEAT */:
244
- babylonTexture.wrapV = Texture.WRAP_ADDRESSMODE;
245
- break;
246
- case 33071 /* CLAMP_TO_EDGE */:
247
- babylonTexture.wrapV = Texture.CLAMP_ADDRESSMODE;
248
- break;
249
- case 33648 /* MIRRORED_REPEAT */:
250
- babylonTexture.wrapV = Texture.MIRROR_ADDRESSMODE;
251
- break;
252
- default:
253
- babylonTexture.wrapV = Texture.CLAMP_ADDRESSMODE;
254
- }
255
- if (parameters.maxAnisotropy != null && parameters.maxAnisotropy > 1) {
256
- var anisotropicExt = gl.getExtension("EXT_texture_filter_anisotropic");
257
- if (anisotropicExt) {
258
- var maxAnisotropicSamples = gl.getParameter(anisotropicExt.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
259
- var maxAnisotropy = Math.min(parameters.maxAnisotropy, maxAnisotropicSamples);
260
- gl.texParameterf(target, anisotropicExt.TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
261
- babylonTexture.anisotropicFilteringLevel = maxAnisotropy;
262
- }
263
- }
264
- gl.bindTexture(target, null);
265
- scene.getEngine().resetTextureCache();
266
- };
267
- /**
268
- * A prefix used when storing a babylon texture object reference on a Spectre texture object
269
- */
270
- TextureUtils.BabylonTextureKeyPrefix = "__babylonTexture_";
271
- /**
272
- * Controls anisotropic filtering for deserialized textures.
273
- */
274
- TextureUtils.MaxAnisotropy = 4;
275
- TextureUtils._EnvironmentSampling = {
276
- magFilter: 9729 /* LINEAR */,
277
- minFilter: 9987 /* LINEAR_MIPMAP_LINEAR */,
278
- wrapS: 33071 /* CLAMP_TO_EDGE */,
279
- wrapT: 33071 /* CLAMP_TO_EDGE */,
280
- maxAnisotropy: 1,
281
- };
282
- TextureUtils._EnvironmentSingleMipSampling = {
283
- magFilter: 9729 /* LINEAR */,
284
- minFilter: 9729 /* LINEAR */,
285
- wrapS: 33071 /* CLAMP_TO_EDGE */,
286
- wrapT: 33071 /* CLAMP_TO_EDGE */,
287
- maxAnisotropy: 1,
288
- };
289
- //from "/Internal/Lighting.EnvironmentFilterScale" in Engine/*/Configuration.cpp
290
- /**
291
- * Environment preprocessing dedicated value (Internal Use or Advanced only).
292
- */
293
- TextureUtils.EnvironmentLODScale = 0.8;
294
- /**
295
- * Environment preprocessing dedicated value (Internal Use or Advanced only)..
296
- */
297
- TextureUtils.EnvironmentLODOffset = 1.0;
298
- return TextureUtils;
299
- }());
300
- export { TextureUtils };
1
+ import { CubeTexture } from "@babylonjs/core/Materials/Textures/cubeTexture.js";
2
+ import { InternalTexture, InternalTextureSource } from "@babylonjs/core/Materials/Textures/internalTexture.js";
3
+ import { Scalar } from "@babylonjs/core/Maths/math.scalar.js";
4
+ import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
5
+ /**
6
+ * A minimal WebGL cubemap descriptor
7
+ */
8
+ var TextureCube = /** @class */ (function () {
9
+ /**
10
+ * constructor
11
+ * @param internalFormat WebGL pixel format for the texture on the GPU
12
+ * @param type WebGL pixel type of the supplied data and texture on the GPU
13
+ * @param source An array containing mipmap levels of faces, where each mipmap level is an array of faces and each face is a TextureSource object
14
+ */
15
+ function TextureCube(internalFormat, type, source) {
16
+ if (source === void 0) { source = []; }
17
+ this.internalFormat = internalFormat;
18
+ this.type = type;
19
+ this.source = source;
20
+ }
21
+ Object.defineProperty(TextureCube.prototype, "Width", {
22
+ /**
23
+ * Returns the width of a face of the texture or 0 if not available
24
+ */
25
+ // eslint-disable-next-line @typescript-eslint/naming-convention
26
+ get: function () {
27
+ return this.source && this.source[0] && this.source[0][0] ? this.source[0][0].width : 0;
28
+ },
29
+ enumerable: false,
30
+ configurable: true
31
+ });
32
+ Object.defineProperty(TextureCube.prototype, "Height", {
33
+ /**
34
+ * Returns the height of a face of the texture or 0 if not available
35
+ */
36
+ // eslint-disable-next-line @typescript-eslint/naming-convention
37
+ get: function () {
38
+ return this.source && this.source[0] && this.source[0][0] ? this.source[0][0].height : 0;
39
+ },
40
+ enumerable: false,
41
+ configurable: true
42
+ });
43
+ return TextureCube;
44
+ }());
45
+ export { TextureCube };
46
+ /**
47
+ * A static class providing methods to aid working with Bablyon textures.
48
+ */
49
+ var TextureUtils = /** @class */ (function () {
50
+ function TextureUtils() {
51
+ }
52
+ /**
53
+ * Returns a BabylonCubeTexture instance from a Spectre texture cube, subject to sampling parameters.
54
+ * If such a texture has already been requested in the past, this texture will be returned, otherwise a new one will be created.
55
+ * The advantage of this is to enable working with texture objects without the need to initialize on the GPU until desired.
56
+ * @param scene A Babylon Scene instance
57
+ * @param textureCube A Spectre TextureCube object
58
+ * @param automaticMipmaps Pass true to enable automatic mipmap generation where possible (requires power of images)
59
+ * @param environment Specifies that the texture will be used as an environment
60
+ * @param singleLod Specifies that the texture will be a singleLod (for environment)
61
+ * @return Babylon cube texture
62
+ */
63
+ TextureUtils.GetBabylonCubeTexture = function (scene, textureCube, automaticMipmaps, environment, singleLod) {
64
+ var _a;
65
+ if (environment === void 0) { environment = false; }
66
+ if (singleLod === void 0) { singleLod = false; }
67
+ if (!textureCube) {
68
+ throw new Error("no texture cube provided");
69
+ }
70
+ var parameters;
71
+ if (environment) {
72
+ parameters = singleLod ? TextureUtils._EnvironmentSingleMipSampling : TextureUtils._EnvironmentSampling;
73
+ }
74
+ else {
75
+ parameters = {
76
+ magFilter: 9728 /* NEAREST */,
77
+ minFilter: 9728 /* NEAREST */,
78
+ wrapS: 33071 /* CLAMP_TO_EDGE */,
79
+ wrapT: 33071 /* CLAMP_TO_EDGE */,
80
+ };
81
+ }
82
+ var key = TextureUtils.BabylonTextureKeyPrefix + parameters.magFilter + "" + parameters.minFilter + "" + parameters.wrapS + "" + parameters.wrapT;
83
+ var babylonTexture = textureCube[key];
84
+ if (!babylonTexture) {
85
+ //initialize babylon texture
86
+ babylonTexture = new CubeTexture("", scene);
87
+ if (environment) {
88
+ babylonTexture.lodGenerationOffset = TextureUtils.EnvironmentLODOffset;
89
+ babylonTexture.lodGenerationScale = TextureUtils.EnvironmentLODScale;
90
+ }
91
+ babylonTexture.gammaSpace = false;
92
+ var internalTexture_1 = new InternalTexture(scene.getEngine(), InternalTextureSource.CubeRaw);
93
+ var glTexture_1 = (_a = internalTexture_1._hardwareTexture) === null || _a === void 0 ? void 0 : _a.underlyingResource;
94
+ //babylon properties
95
+ internalTexture_1.isCube = true;
96
+ internalTexture_1.generateMipMaps = false;
97
+ babylonTexture._texture = internalTexture_1;
98
+ TextureUtils.ApplySamplingParameters(babylonTexture, parameters);
99
+ var maxMipLevel_1 = automaticMipmaps ? 0 : textureCube.source.length - 1;
100
+ var texturesUploaded_1 = 0;
101
+ var textureComplete_1 = function () {
102
+ return texturesUploaded_1 === (maxMipLevel_1 + 1) * 6;
103
+ };
104
+ var uploadFace_1 = function (i, level, face) {
105
+ if (!glTexture_1) {
106
+ return;
107
+ }
108
+ if (i === 0 && level === 0) {
109
+ internalTexture_1.width = face.width;
110
+ internalTexture_1.height = face.height;
111
+ }
112
+ var gl = scene.getEngine()._gl;
113
+ gl.bindTexture(gl.TEXTURE_CUBE_MAP, glTexture_1);
114
+ scene.getEngine()._unpackFlipY(false);
115
+ if (face instanceof HTMLElement || face instanceof ImageData) {
116
+ gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, level, textureCube.internalFormat, textureCube.internalFormat, textureCube.type, face);
117
+ }
118
+ else {
119
+ var textureData = face;
120
+ gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, level, textureCube.internalFormat, textureData.width, textureData.height, 0, textureData.format, textureCube.type, textureData.data);
121
+ }
122
+ texturesUploaded_1++;
123
+ if (textureComplete_1()) {
124
+ //generate mipmaps
125
+ if (automaticMipmaps) {
126
+ var w = face.width;
127
+ var h = face.height;
128
+ var isPot = (w !== 0 && w & (w - 1)) === 0 && (h !== 0 && h & (h - 1)) === 0;
129
+ if (isPot) {
130
+ gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
131
+ }
132
+ }
133
+ // Upload Separate lods in case there is no support for texture lod.
134
+ if (environment && !scene.getEngine().getCaps().textureLOD && !singleLod) {
135
+ var mipSlices = 3;
136
+ for (var i_1 = 0; i_1 < mipSlices; i_1++) {
137
+ var lodKey = TextureUtils.BabylonTextureKeyPrefix + "lod" + i_1;
138
+ var lod = textureCube[lodKey];
139
+ //initialize lod texture if it doesn't already exist
140
+ if (lod == null && textureCube.Width) {
141
+ //compute LOD from even spacing in smoothness (matching shader calculation)
142
+ var smoothness = i_1 / (mipSlices - 1);
143
+ var roughness = 1 - smoothness;
144
+ var kMinimumVariance = 0.0005;
145
+ var alphaG = roughness * roughness + kMinimumVariance;
146
+ var microsurfaceAverageSlopeTexels = alphaG * textureCube.Width;
147
+ var environmentSpecularLOD = TextureUtils.EnvironmentLODScale * Scalar.Log2(microsurfaceAverageSlopeTexels) + TextureUtils.EnvironmentLODOffset;
148
+ var maxLODIndex = textureCube.source.length - 1;
149
+ var mipmapIndex = Math.min(Math.max(Math.round(environmentSpecularLOD), 0), maxLODIndex);
150
+ lod = TextureUtils.GetBabylonCubeTexture(scene, new TextureCube(6408 /* RGBA */, 5121 /* UNSIGNED_BYTE */, [textureCube.source[mipmapIndex]]), false, true, true);
151
+ if (i_1 === 0) {
152
+ internalTexture_1._lodTextureLow = lod;
153
+ }
154
+ else if (i_1 === 1) {
155
+ internalTexture_1._lodTextureMid = lod;
156
+ }
157
+ else {
158
+ internalTexture_1._lodTextureHigh = lod;
159
+ }
160
+ textureCube[lodKey] = lod;
161
+ }
162
+ }
163
+ }
164
+ internalTexture_1.isReady = true;
165
+ }
166
+ gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
167
+ scene.getEngine().resetTextureCache();
168
+ };
169
+ var _loop_1 = function (i) {
170
+ var faces = textureCube.source[i];
171
+ var _loop_2 = function (j) {
172
+ var face = faces[j];
173
+ if (face instanceof HTMLImageElement && !face.complete) {
174
+ face.addEventListener("load", function () {
175
+ uploadFace_1(j, i, face);
176
+ }, false);
177
+ }
178
+ else {
179
+ uploadFace_1(j, i, face);
180
+ }
181
+ };
182
+ for (var j = 0; j < faces.length; j++) {
183
+ _loop_2(j);
184
+ }
185
+ };
186
+ for (var i = 0; i <= maxMipLevel_1; i++) {
187
+ _loop_1(i);
188
+ }
189
+ scene.getEngine().resetTextureCache();
190
+ babylonTexture.isReady = function () {
191
+ return textureComplete_1();
192
+ };
193
+ textureCube[key] = babylonTexture;
194
+ }
195
+ return babylonTexture;
196
+ };
197
+ /**
198
+ * Applies Spectre SamplingParameters to a Babylon texture by directly setting texture parameters on the internal WebGLTexture as well as setting Babylon fields
199
+ * @param babylonTexture Babylon texture to apply texture to (requires the Babylon texture has an initialize _texture field)
200
+ * @param parameters Spectre SamplingParameters to apply
201
+ */
202
+ TextureUtils.ApplySamplingParameters = function (babylonTexture, parameters) {
203
+ var _a;
204
+ var scene = babylonTexture.getScene();
205
+ if (!scene) {
206
+ return;
207
+ }
208
+ var gl = scene.getEngine()._gl;
209
+ var target = babylonTexture.isCube ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;
210
+ var internalTexture = babylonTexture._texture;
211
+ if (!internalTexture) {
212
+ return;
213
+ }
214
+ var glTexture = (_a = internalTexture._hardwareTexture) === null || _a === void 0 ? void 0 : _a.underlyingResource;
215
+ gl.bindTexture(target, glTexture);
216
+ if (parameters.magFilter != null) {
217
+ gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, parameters.magFilter);
218
+ }
219
+ if (parameters.minFilter != null) {
220
+ gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, parameters.minFilter);
221
+ }
222
+ if (parameters.wrapS != null) {
223
+ gl.texParameteri(target, gl.TEXTURE_WRAP_S, parameters.wrapS);
224
+ }
225
+ if (parameters.wrapT != null) {
226
+ gl.texParameteri(target, gl.TEXTURE_WRAP_T, parameters.wrapT);
227
+ }
228
+ //set babylon wrap modes from sampling parameter
229
+ switch (parameters.wrapS) {
230
+ case 10497 /* REPEAT */:
231
+ babylonTexture.wrapU = Texture.WRAP_ADDRESSMODE;
232
+ break;
233
+ case 33071 /* CLAMP_TO_EDGE */:
234
+ babylonTexture.wrapU = Texture.CLAMP_ADDRESSMODE;
235
+ break;
236
+ case 33648 /* MIRRORED_REPEAT */:
237
+ babylonTexture.wrapU = Texture.MIRROR_ADDRESSMODE;
238
+ break;
239
+ default:
240
+ babylonTexture.wrapU = Texture.CLAMP_ADDRESSMODE;
241
+ }
242
+ switch (parameters.wrapT) {
243
+ case 10497 /* REPEAT */:
244
+ babylonTexture.wrapV = Texture.WRAP_ADDRESSMODE;
245
+ break;
246
+ case 33071 /* CLAMP_TO_EDGE */:
247
+ babylonTexture.wrapV = Texture.CLAMP_ADDRESSMODE;
248
+ break;
249
+ case 33648 /* MIRRORED_REPEAT */:
250
+ babylonTexture.wrapV = Texture.MIRROR_ADDRESSMODE;
251
+ break;
252
+ default:
253
+ babylonTexture.wrapV = Texture.CLAMP_ADDRESSMODE;
254
+ }
255
+ if (parameters.maxAnisotropy != null && parameters.maxAnisotropy > 1) {
256
+ var anisotropicExt = gl.getExtension("EXT_texture_filter_anisotropic");
257
+ if (anisotropicExt) {
258
+ var maxAnisotropicSamples = gl.getParameter(anisotropicExt.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
259
+ var maxAnisotropy = Math.min(parameters.maxAnisotropy, maxAnisotropicSamples);
260
+ gl.texParameterf(target, anisotropicExt.TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
261
+ babylonTexture.anisotropicFilteringLevel = maxAnisotropy;
262
+ }
263
+ }
264
+ gl.bindTexture(target, null);
265
+ scene.getEngine().resetTextureCache();
266
+ };
267
+ /**
268
+ * A prefix used when storing a babylon texture object reference on a Spectre texture object
269
+ */
270
+ TextureUtils.BabylonTextureKeyPrefix = "__babylonTexture_";
271
+ /**
272
+ * Controls anisotropic filtering for deserialized textures.
273
+ */
274
+ TextureUtils.MaxAnisotropy = 4;
275
+ TextureUtils._EnvironmentSampling = {
276
+ magFilter: 9729 /* LINEAR */,
277
+ minFilter: 9987 /* LINEAR_MIPMAP_LINEAR */,
278
+ wrapS: 33071 /* CLAMP_TO_EDGE */,
279
+ wrapT: 33071 /* CLAMP_TO_EDGE */,
280
+ maxAnisotropy: 1,
281
+ };
282
+ TextureUtils._EnvironmentSingleMipSampling = {
283
+ magFilter: 9729 /* LINEAR */,
284
+ minFilter: 9729 /* LINEAR */,
285
+ wrapS: 33071 /* CLAMP_TO_EDGE */,
286
+ wrapT: 33071 /* CLAMP_TO_EDGE */,
287
+ maxAnisotropy: 1,
288
+ };
289
+ //from "/Internal/Lighting.EnvironmentFilterScale" in Engine/*/Configuration.cpp
290
+ /**
291
+ * Environment preprocessing dedicated value (Internal Use or Advanced only).
292
+ */
293
+ TextureUtils.EnvironmentLODScale = 0.8;
294
+ /**
295
+ * Environment preprocessing dedicated value (Internal Use or Advanced only)..
296
+ */
297
+ TextureUtils.EnvironmentLODOffset = 1.0;
298
+ return TextureUtils;
299
+ }());
300
+ export { TextureUtils };
301
301
  //# sourceMappingURL=texture.js.map