@babylonjs/viewer 5.0.0-rc.3 → 5.0.1

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 (192) hide show
  1. package/configuration/configuration.d.ts +107 -107
  2. package/configuration/configuration.js +15 -15
  3. package/configuration/configuration.js.map +1 -1
  4. package/configuration/configurationCompatibility.d.ts +8 -8
  5. package/configuration/configurationCompatibility.js +65 -65
  6. package/configuration/configurationCompatibility.js.map +1 -1
  7. package/configuration/configurationContainer.d.ts +10 -10
  8. package/configuration/configurationContainer.js +9 -9
  9. package/configuration/configurationContainer.js.map +1 -1
  10. package/configuration/globals.d.ts +6 -6
  11. package/configuration/globals.js +17 -17
  12. package/configuration/globals.js.map +1 -1
  13. package/configuration/index.d.ts +2 -2
  14. package/configuration/index.js +3 -2
  15. package/configuration/index.js.map +1 -1
  16. package/configuration/interfaces/cameraConfiguration.d.ts +31 -31
  17. package/configuration/interfaces/cameraConfiguration.js +1 -1
  18. package/configuration/interfaces/cameraConfiguration.js.map +1 -1
  19. package/configuration/interfaces/colorGradingConfiguration.d.ts +81 -81
  20. package/configuration/interfaces/colorGradingConfiguration.js +1 -1
  21. package/configuration/interfaces/colorGradingConfiguration.js.map +1 -1
  22. package/configuration/interfaces/defaultRenderingPipelineConfiguration.d.ts +20 -20
  23. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js +1 -1
  24. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js.map +1 -1
  25. package/configuration/interfaces/environmentMapConfiguration.d.ts +22 -22
  26. package/configuration/interfaces/environmentMapConfiguration.js +1 -1
  27. package/configuration/interfaces/environmentMapConfiguration.js.map +1 -1
  28. package/configuration/interfaces/groundConfiguration.d.ts +24 -24
  29. package/configuration/interfaces/groundConfiguration.js +1 -1
  30. package/configuration/interfaces/groundConfiguration.js.map +1 -1
  31. package/configuration/interfaces/imageProcessingConfiguration.d.ts +43 -43
  32. package/configuration/interfaces/imageProcessingConfiguration.js +1 -1
  33. package/configuration/interfaces/imageProcessingConfiguration.js.map +1 -1
  34. package/configuration/interfaces/index.d.ts +15 -15
  35. package/configuration/interfaces/index.js +15 -15
  36. package/configuration/interfaces/index.js.map +1 -1
  37. package/configuration/interfaces/lightConfiguration.d.ts +60 -60
  38. package/configuration/interfaces/lightConfiguration.js +1 -1
  39. package/configuration/interfaces/lightConfiguration.js.map +1 -1
  40. package/configuration/interfaces/modelAnimationConfiguration.d.ts +26 -26
  41. package/configuration/interfaces/modelAnimationConfiguration.js +1 -1
  42. package/configuration/interfaces/modelAnimationConfiguration.js.map +1 -1
  43. package/configuration/interfaces/modelConfiguration.d.ts +65 -65
  44. package/configuration/interfaces/modelConfiguration.js +1 -1
  45. package/configuration/interfaces/modelConfiguration.js.map +1 -1
  46. package/configuration/interfaces/observersConfiguration.d.ts +5 -5
  47. package/configuration/interfaces/observersConfiguration.js +1 -1
  48. package/configuration/interfaces/observersConfiguration.js.map +1 -1
  49. package/configuration/interfaces/sceneConfiguration.d.ts +48 -48
  50. package/configuration/interfaces/sceneConfiguration.js +1 -1
  51. package/configuration/interfaces/sceneConfiguration.js.map +1 -1
  52. package/configuration/interfaces/sceneOptimizerConfiguration.d.ts +23 -23
  53. package/configuration/interfaces/sceneOptimizerConfiguration.js +1 -1
  54. package/configuration/interfaces/sceneOptimizerConfiguration.js.map +1 -1
  55. package/configuration/interfaces/skyboxConfiguration.d.ts +21 -21
  56. package/configuration/interfaces/skyboxConfiguration.js +1 -1
  57. package/configuration/interfaces/skyboxConfiguration.js.map +1 -1
  58. package/configuration/interfaces/templateConfiguration.d.ts +67 -67
  59. package/configuration/interfaces/templateConfiguration.js +1 -1
  60. package/configuration/interfaces/templateConfiguration.js.map +1 -1
  61. package/configuration/interfaces/vrConfiguration.d.ts +16 -16
  62. package/configuration/interfaces/vrConfiguration.js +1 -1
  63. package/configuration/interfaces/vrConfiguration.js.map +1 -1
  64. package/configuration/loader.d.ts +4 -4
  65. package/configuration/loader.js +16 -28
  66. package/configuration/loader.js.map +1 -1
  67. package/configuration/mappers.d.ts +42 -42
  68. package/configuration/mappers.js +190 -189
  69. package/configuration/mappers.js.map +1 -1
  70. package/configuration/renderOnlyLoader.d.ts +33 -33
  71. package/configuration/renderOnlyLoader.js +161 -158
  72. package/configuration/renderOnlyLoader.js.map +1 -1
  73. package/configuration/types/default.d.ts +6 -6
  74. package/configuration/types/default.js +120 -119
  75. package/configuration/types/default.js.map +1 -1
  76. package/configuration/types/environmentMap.d.ts +5 -5
  77. package/configuration/types/environmentMap.js +13 -13
  78. package/configuration/types/environmentMap.js.map +1 -1
  79. package/configuration/types/extended.d.ts +6 -6
  80. package/configuration/types/extended.js +316 -316
  81. package/configuration/types/extended.js.map +1 -1
  82. package/configuration/types/index.d.ts +13 -13
  83. package/configuration/types/index.js +49 -48
  84. package/configuration/types/index.js.map +1 -1
  85. package/configuration/types/minimal.d.ts +6 -6
  86. package/configuration/types/minimal.js +42 -42
  87. package/configuration/types/minimal.js.map +1 -1
  88. package/configuration/types/renderOnlyDefault.d.ts +30 -30
  89. package/configuration/types/renderOnlyDefault.js +30 -30
  90. package/configuration/types/renderOnlyDefault.js.map +1 -1
  91. package/configuration/types/shadowLight.d.ts +9 -9
  92. package/configuration/types/shadowLight.js +63 -63
  93. package/configuration/types/shadowLight.js.map +1 -1
  94. package/helper/index.d.ts +26 -26
  95. package/helper/index.js +62 -56
  96. package/helper/index.js.map +1 -1
  97. package/index.d.ts +30 -30
  98. package/index.js +45 -41
  99. package/index.js.map +1 -1
  100. package/initializer.d.ts +11 -11
  101. package/initializer.js +34 -33
  102. package/initializer.js.map +1 -1
  103. package/interfaces.d.ts +5 -5
  104. package/interfaces.js +1 -1
  105. package/interfaces.js.map +1 -1
  106. package/labs/environmentSerializer.d.ts +126 -126
  107. package/labs/environmentSerializer.js +190 -186
  108. package/labs/environmentSerializer.js.map +1 -1
  109. package/labs/texture.d.ts +183 -184
  110. package/labs/texture.js +300 -297
  111. package/labs/texture.js.map +1 -1
  112. package/labs/viewerLabs.d.ts +51 -51
  113. package/labs/viewerLabs.js +133 -131
  114. package/labs/viewerLabs.js.map +1 -1
  115. package/license.md +71 -0
  116. package/loader/modelLoader.d.ts +47 -44
  117. package/loader/modelLoader.js +189 -182
  118. package/loader/modelLoader.js.map +1 -1
  119. package/loader/plugins/applyMaterialConfig.d.ts +12 -12
  120. package/loader/plugins/applyMaterialConfig.js +15 -15
  121. package/loader/plugins/applyMaterialConfig.js.map +1 -1
  122. package/loader/plugins/extendedMaterialLoaderPlugin.d.ts +9 -9
  123. package/loader/plugins/extendedMaterialLoaderPlugin.js +15 -15
  124. package/loader/plugins/extendedMaterialLoaderPlugin.js.map +1 -1
  125. package/loader/plugins/index.d.ts +18 -17
  126. package/loader/plugins/index.js +42 -41
  127. package/loader/plugins/index.js.map +1 -1
  128. package/loader/plugins/loaderPlugin.d.ts +24 -24
  129. package/loader/plugins/loaderPlugin.js +1 -1
  130. package/loader/plugins/loaderPlugin.js.map +1 -1
  131. package/loader/plugins/msftLodLoaderPlugin.d.ts +12 -12
  132. package/loader/plugins/msftLodLoaderPlugin.js +20 -19
  133. package/loader/plugins/msftLodLoaderPlugin.js.map +1 -1
  134. package/loader/plugins/telemetryLoaderPlugin.d.ts +12 -12
  135. package/loader/plugins/telemetryLoaderPlugin.js +35 -35
  136. package/loader/plugins/telemetryLoaderPlugin.js.map +1 -1
  137. package/managers/observablesManager.d.ts +66 -66
  138. package/managers/observablesManager.js +34 -34
  139. package/managers/observablesManager.js.map +1 -1
  140. package/managers/sceneManager.d.ts +243 -245
  141. package/managers/sceneManager.js +1388 -1387
  142. package/managers/sceneManager.js.map +1 -1
  143. package/managers/telemetryManager.d.ts +57 -57
  144. package/managers/telemetryManager.js +113 -113
  145. package/managers/telemetryManager.js.map +1 -1
  146. package/model/modelAnimation.d.ts +215 -215
  147. package/model/modelAnimation.js +232 -232
  148. package/model/modelAnimation.js.map +1 -1
  149. package/model/viewerModel.d.ts +228 -236
  150. package/model/viewerModel.js +669 -664
  151. package/model/viewerModel.js.map +1 -1
  152. package/optimizer/custom/extended.d.ts +11 -13
  153. package/optimizer/custom/extended.js +98 -100
  154. package/optimizer/custom/extended.js.map +1 -1
  155. package/optimizer/custom/index.d.ts +8 -8
  156. package/optimizer/custom/index.js +24 -24
  157. package/optimizer/custom/index.js.map +1 -1
  158. package/package.json +41 -215
  159. package/readme.md +12 -8
  160. package/renderOnlyIndex.d.ts +11 -11
  161. package/renderOnlyIndex.js +17 -15
  162. package/renderOnlyIndex.js.map +1 -1
  163. package/templating/eventManager.d.ts +35 -35
  164. package/templating/eventManager.js +65 -63
  165. package/templating/eventManager.js.map +1 -1
  166. package/templating/plugins/hdButtonPlugin.d.ts +9 -9
  167. package/templating/plugins/hdButtonPlugin.js +21 -34
  168. package/templating/plugins/hdButtonPlugin.js.map +1 -1
  169. package/templating/plugins/printButton.d.ts +9 -10
  170. package/templating/plugins/printButton.js +40 -53
  171. package/templating/plugins/printButton.js.map +1 -1
  172. package/templating/templateManager.d.ts +190 -189
  173. package/templating/templateManager.js +553 -543
  174. package/templating/templateManager.js.map +1 -1
  175. package/templating/viewerTemplatePlugin.d.ts +21 -21
  176. package/templating/viewerTemplatePlugin.js +68 -68
  177. package/templating/viewerTemplatePlugin.js.map +1 -1
  178. package/viewer/defaultViewer.d.ts +122 -116
  179. package/viewer/defaultViewer.js +665 -670
  180. package/viewer/defaultViewer.js.map +1 -1
  181. package/viewer/renderOnlyViewer.d.ts +8 -8
  182. package/viewer/renderOnlyViewer.js +43 -50
  183. package/viewer/renderOnlyViewer.js.map +1 -1
  184. package/viewer/viewer.d.ts +254 -253
  185. package/viewer/viewer.js +777 -763
  186. package/viewer/viewer.js.map +1 -1
  187. package/viewer/viewerManager.d.ts +55 -55
  188. package/viewer/viewerManager.js +87 -86
  189. package/viewer/viewerManager.js.map +1 -1
  190. package/viewer/viewerWithTemplate.d.ts +9 -9
  191. package/viewer/viewerWithTemplate.js +19 -32
  192. package/viewer/viewerWithTemplate.js.map +1 -1
@@ -1,126 +1,126 @@
1
- import { Vector3 } from '@babylonjs/core/Maths/math';
2
- import { TextureCube } from './texture';
3
- /**
4
- * Spherical polynomial coefficients (counter part to spherical harmonic coefficients used in shader irradiance calculation)
5
- * @ignoreChildren
6
- */
7
- export interface SphericalPolynomalCoefficients {
8
- x: Vector3;
9
- y: Vector3;
10
- z: Vector3;
11
- xx: Vector3;
12
- yy: Vector3;
13
- zz: Vector3;
14
- yz: Vector3;
15
- zx: Vector3;
16
- xy: Vector3;
17
- }
18
- /**
19
- * Wraps data and maps required for environments with physically based rendering
20
- */
21
- export interface PBREnvironment {
22
- /**
23
- * Spherical Polynomial Coefficients representing an irradiance map
24
- */
25
- irradiancePolynomialCoefficients: SphericalPolynomalCoefficients;
26
- /**
27
- * Specular cubemap
28
- */
29
- specularTexture?: TextureCube;
30
- /**
31
- * A scale factor applied to RGB values after reading from environment maps
32
- */
33
- textureIntensityScale: number;
34
- }
35
- /**
36
- * Environment map representations: layouts, projections and approximations
37
- */
38
- export declare type MapType = 'irradiance_sh_coefficients_9' | 'cubemap_faces';
39
- /**
40
- * Image type used for environment map
41
- */
42
- export declare type ImageType = 'png';
43
- /**
44
- * A generic field in JSON that report's its type
45
- */
46
- export interface TypedObject<T> {
47
- type: T;
48
- }
49
- /**
50
- * Describes a range of bytes starting at byte pos (inclusive) and finishing at byte pos + length - 1
51
- */
52
- export interface ByteRange {
53
- pos: number;
54
- length: number;
55
- }
56
- /**
57
- * Complete Spectre Environment JSON Descriptor
58
- */
59
- export interface EnvJsonDescriptor {
60
- radiance: TypedObject<MapType>;
61
- irradiance: TypedObject<MapType>;
62
- specular: TypedObject<MapType>;
63
- }
64
- /**
65
- * Spherical harmonic coefficients to provide an irradiance map
66
- */
67
- export interface IrradianceSHCoefficients9 extends TypedObject<MapType> {
68
- l00: Array<number>;
69
- l1_1: Array<number>;
70
- l10: Array<number>;
71
- l11: Array<number>;
72
- l2_2: Array<number>;
73
- l2_1: Array<number>;
74
- l20: Array<number>;
75
- l21: Array<number>;
76
- l22: Array<number>;
77
- }
78
- /**
79
- * A generic set of images, where the image content is specified by byte ranges in the mipmaps field
80
- */
81
- export interface ImageSet<T> extends TypedObject<MapType> {
82
- imageType: ImageType;
83
- width: number;
84
- height: number;
85
- mipmaps: Array<T>;
86
- multiplier: number;
87
- }
88
- /**
89
- * A set of cubemap faces
90
- */
91
- export declare type CubemapFaces = ImageSet<Array<ByteRange>>;
92
- /**
93
- * A single image containing an atlas of equirectangular-projection maps across all mip levels
94
- */
95
- export declare type EquirectangularMipmapAtlas = ImageSet<ByteRange>;
96
- /**
97
- * A static class proving methods to aid parsing Spectre environment files
98
- */
99
- export declare class EnvironmentDeserializer {
100
- /**
101
- * Parses an arraybuffer into a new PBREnvironment object
102
- * @param arrayBuffer The arraybuffer of the Spectre environment file
103
- * @return a PBREnvironment object
104
- */
105
- static Parse(arrayBuffer: ArrayBuffer): PBREnvironment;
106
- /**
107
- * Convert from irradiance to outgoing radiance for Lambertian BDRF, suitable for efficient shader evaluation.
108
- * L = (1/pi) * E * rho
109
- *
110
- * This is done by an additional scale by 1/pi, so is a fairly trivial operation but important conceptually.
111
- * @param harmonics Spherical harmonic coefficients (9)
112
- */
113
- private static _ConvertSHIrradianceToLambertianRadiance;
114
- /**
115
- * Convert spherical harmonics to spherical polynomial coefficients
116
- * @param harmonics Spherical harmonic coefficients (9)
117
- * @param outPolynomialCoefficents Polynomial coefficients (9) object to store result
118
- */
119
- private static _ConvertSHToSP;
120
- /**
121
- * Multiplies harmonic coefficients in place
122
- * @param harmonics Spherical harmonic coefficients (9)
123
- * @param scaleFactor Value to multiply by
124
- */
125
- private static _ScaleSH;
126
- }
1
+ import { Vector3 } from "@babylonjs/core/Maths/math.js";
2
+ import { TextureCube } from "./texture";
3
+ /**
4
+ * Spherical polynomial coefficients (counter part to spherical harmonic coefficients used in shader irradiance calculation)
5
+ * @ignoreChildren
6
+ */
7
+ export interface SphericalPolynomalCoefficients {
8
+ x: Vector3;
9
+ y: Vector3;
10
+ z: Vector3;
11
+ xx: Vector3;
12
+ yy: Vector3;
13
+ zz: Vector3;
14
+ yz: Vector3;
15
+ zx: Vector3;
16
+ xy: Vector3;
17
+ }
18
+ /**
19
+ * Wraps data and maps required for environments with physically based rendering
20
+ */
21
+ export interface PBREnvironment {
22
+ /**
23
+ * Spherical Polynomial Coefficients representing an irradiance map
24
+ */
25
+ irradiancePolynomialCoefficients: SphericalPolynomalCoefficients;
26
+ /**
27
+ * Specular cubemap
28
+ */
29
+ specularTexture?: TextureCube;
30
+ /**
31
+ * A scale factor applied to RGB values after reading from environment maps
32
+ */
33
+ textureIntensityScale: number;
34
+ }
35
+ /**
36
+ * Environment map representations: layouts, projections and approximations
37
+ */
38
+ export declare type MapType = "irradiance_sh_coefficients_9" | "cubemap_faces";
39
+ /**
40
+ * Image type used for environment map
41
+ */
42
+ export declare type ImageType = "png";
43
+ /**
44
+ * A generic field in JSON that report's its type
45
+ */
46
+ export interface TypedObject<T> {
47
+ type: T;
48
+ }
49
+ /**
50
+ * Describes a range of bytes starting at byte pos (inclusive) and finishing at byte pos + length - 1
51
+ */
52
+ export interface ByteRange {
53
+ pos: number;
54
+ length: number;
55
+ }
56
+ /**
57
+ * Complete Spectre Environment JSON Descriptor
58
+ */
59
+ export interface EnvJsonDescriptor {
60
+ radiance: TypedObject<MapType>;
61
+ irradiance: TypedObject<MapType>;
62
+ specular: TypedObject<MapType>;
63
+ }
64
+ /**
65
+ * Spherical harmonic coefficients to provide an irradiance map
66
+ */
67
+ export interface IrradianceSHCoefficients9 extends TypedObject<MapType> {
68
+ l00: Array<number>;
69
+ l1_1: Array<number>;
70
+ l10: Array<number>;
71
+ l11: Array<number>;
72
+ l2_2: Array<number>;
73
+ l2_1: Array<number>;
74
+ l20: Array<number>;
75
+ l21: Array<number>;
76
+ l22: Array<number>;
77
+ }
78
+ /**
79
+ * A generic set of images, where the image content is specified by byte ranges in the mipmaps field
80
+ */
81
+ export interface ImageSet<T> extends TypedObject<MapType> {
82
+ imageType: ImageType;
83
+ width: number;
84
+ height: number;
85
+ mipmaps: Array<T>;
86
+ multiplier: number;
87
+ }
88
+ /**
89
+ * A set of cubemap faces
90
+ */
91
+ export declare type CubemapFaces = ImageSet<Array<ByteRange>>;
92
+ /**
93
+ * A single image containing an atlas of equirectangular-projection maps across all mip levels
94
+ */
95
+ export declare type EquirectangularMipmapAtlas = ImageSet<ByteRange>;
96
+ /**
97
+ * A static class proving methods to aid parsing Spectre environment files
98
+ */
99
+ export declare class EnvironmentDeserializer {
100
+ /**
101
+ * Parses an arraybuffer into a new PBREnvironment object
102
+ * @param arrayBuffer The arraybuffer of the Spectre environment file
103
+ * @return a PBREnvironment object
104
+ */
105
+ static Parse(arrayBuffer: ArrayBuffer): PBREnvironment;
106
+ /**
107
+ * Convert from irradiance to outgoing radiance for Lambertian BDRF, suitable for efficient shader evaluation.
108
+ * L = (1/pi) * E * rho
109
+ *
110
+ * This is done by an additional scale by 1/pi, so is a fairly trivial operation but important conceptually.
111
+ * @param harmonics Spherical harmonic coefficients (9)
112
+ */
113
+ private static _ConvertSHIrradianceToLambertianRadiance;
114
+ /**
115
+ * Convert spherical harmonics to spherical polynomial coefficients
116
+ * @param harmonics Spherical harmonic coefficients (9)
117
+ * @param outPolynomialCoefficents Polynomial coefficients (9) object to store result
118
+ */
119
+ private static _ConvertSHToSP;
120
+ /**
121
+ * Multiplies harmonic coefficients in place
122
+ * @param harmonics Spherical harmonic coefficients (9)
123
+ * @param scaleFactor Value to multiply by
124
+ */
125
+ private static _ScaleSH;
126
+ }
@@ -1,187 +1,191 @@
1
- import { Vector3 } from '@babylonjs/core/Maths/math.js';
2
- import { Tools } from '@babylonjs/core/Misc/tools.js';
3
- import { TextureCube } from './texture.js';
4
- /**
5
- * A static class proving methods to aid parsing Spectre environment files
6
- */
7
- var EnvironmentDeserializer = /** @class */ (function () {
8
- function EnvironmentDeserializer() {
9
- }
10
- /**
11
- * Parses an arraybuffer into a new PBREnvironment object
12
- * @param arrayBuffer The arraybuffer of the Spectre environment file
13
- * @return a PBREnvironment object
14
- */
15
- EnvironmentDeserializer.Parse = function (arrayBuffer) {
16
- var environment = {
17
- //irradiance
18
- irradiancePolynomialCoefficients: {
19
- x: new Vector3(0, 0, 0),
20
- y: new Vector3(0, 0, 0),
21
- z: new Vector3(0, 0, 0),
22
- xx: new Vector3(0, 0, 0),
23
- yy: new Vector3(0, 0, 0),
24
- zz: new Vector3(0, 0, 0),
25
- yz: new Vector3(0, 0, 0),
26
- zx: new Vector3(0, 0, 0),
27
- xy: new Vector3(0, 0, 0)
28
- },
29
- //specular
30
- textureIntensityScale: 1.0,
31
- };
32
- //read .env
33
- var littleEndian = false;
34
- var magicBytes = [0x86, 0x16, 0x87, 0x96, 0xf6, 0xd6, 0x96, 0x36];
35
- var dataView = new DataView(arrayBuffer);
36
- var pos = 0;
37
- for (var i = 0; i < magicBytes.length; i++) {
38
- if (dataView.getUint8(pos++) !== magicBytes[i]) {
39
- Tools.Error('Not a Spectre environment map');
40
- }
41
- }
42
- var version = dataView.getUint16(pos, littleEndian);
43
- pos += 2;
44
- if (version !== 1) {
45
- Tools.Warn('Unsupported Spectre environment map version "' + version + '"');
46
- }
47
- //read json descriptor - collect characters up to null terminator
48
- var descriptorString = '';
49
- var charCode = 0x00;
50
- while ((charCode = dataView.getUint8(pos++))) {
51
- descriptorString += String.fromCharCode(charCode);
52
- }
53
- var descriptor = JSON.parse(descriptorString);
54
- var payloadPos = pos;
55
- //irradiance
56
- switch (descriptor.irradiance.type) {
57
- case 'irradiance_sh_coefficients_9':
58
- //irradiance
59
- var harmonics = descriptor.irradiance;
60
- EnvironmentDeserializer._ConvertSHIrradianceToLambertianRadiance(harmonics);
61
- //harmonics now represent radiance
62
- EnvironmentDeserializer._ConvertSHToSP(harmonics, environment.irradiancePolynomialCoefficients);
63
- break;
64
- default:
65
- Tools.Error('Unhandled MapType descriptor.irradiance.type (' + descriptor.irradiance.type + ')');
66
- }
67
- //specular
68
- switch (descriptor.specular.type) {
69
- case 'cubemap_faces':
70
- var specularDescriptor = descriptor.specular;
71
- var specularTexture = environment.specularTexture = new TextureCube(6408 /* RGBA */, 5121 /* UNSIGNED_BYTE */);
72
- environment.textureIntensityScale = specularDescriptor.multiplier != null ? specularDescriptor.multiplier : 1.0;
73
- var mipmaps = specularDescriptor.mipmaps;
74
- var imageType = specularDescriptor.imageType;
75
- for (var l = 0; l < mipmaps.length; l++) {
76
- var faceRanges = mipmaps[l];
77
- specularTexture.source[l] = [];
78
- for (var i = 0; i < 6; i++) {
79
- var range = faceRanges[i];
80
- var bytes = new Uint8Array(arrayBuffer, payloadPos + range.pos, range.length);
81
- switch (imageType) {
82
- case 'png':
83
- //construct image element from bytes
84
- var image = new Image();
85
- var src = URL.createObjectURL(new Blob([bytes], { type: 'image/png' }));
86
- image.src = src;
87
- specularTexture.source[l][i] = image;
88
- break;
89
- default:
90
- Tools.Error('Unhandled ImageType descriptor.specular.imageType (' + imageType + ')');
91
- }
92
- }
93
- }
94
- break;
95
- default:
96
- Tools.Error('Unhandled MapType descriptor.specular.type (' + descriptor.specular.type + ')');
97
- }
98
- return environment;
99
- };
100
- /**
101
- * Convert from irradiance to outgoing radiance for Lambertian BDRF, suitable for efficient shader evaluation.
102
- * L = (1/pi) * E * rho
103
- *
104
- * This is done by an additional scale by 1/pi, so is a fairly trivial operation but important conceptually.
105
- * @param harmonics Spherical harmonic coefficients (9)
106
- */
107
- EnvironmentDeserializer._ConvertSHIrradianceToLambertianRadiance = function (harmonics) {
108
- EnvironmentDeserializer._ScaleSH(harmonics, 1 / Math.PI);
109
- // The resultant SH now represents outgoing radiance, so includes the Lambert 1/pi normalisation factor but without albedo (rho) applied
110
- // (The pixel shader must apply albedo after texture fetches, etc).
111
- };
112
- /**
113
- * Convert spherical harmonics to spherical polynomial coefficients
114
- * @param harmonics Spherical harmonic coefficients (9)
115
- * @param outPolynomialCoefficents Polynomial coefficients (9) object to store result
116
- */
117
- EnvironmentDeserializer._ConvertSHToSP = function (harmonics, outPolynomialCoefficents) {
118
- var rPi = 1 / Math.PI;
119
- //x
120
- outPolynomialCoefficents.x.x = 1.02333 * harmonics.l11[0] * rPi;
121
- outPolynomialCoefficents.x.y = 1.02333 * harmonics.l11[1] * rPi;
122
- outPolynomialCoefficents.x.z = 1.02333 * harmonics.l11[2] * rPi;
123
- outPolynomialCoefficents.y.x = 1.02333 * harmonics.l1_1[0] * rPi;
124
- outPolynomialCoefficents.y.y = 1.02333 * harmonics.l1_1[1] * rPi;
125
- outPolynomialCoefficents.y.z = 1.02333 * harmonics.l1_1[2] * rPi;
126
- outPolynomialCoefficents.z.x = 1.02333 * harmonics.l10[0] * rPi;
127
- outPolynomialCoefficents.z.y = 1.02333 * harmonics.l10[1] * rPi;
128
- outPolynomialCoefficents.z.z = 1.02333 * harmonics.l10[2] * rPi;
129
- //xx
130
- outPolynomialCoefficents.xx.x = (0.886277 * harmonics.l00[0] - 0.247708 * harmonics.l20[0] + 0.429043 * harmonics.l22[0]) * rPi;
131
- outPolynomialCoefficents.xx.y = (0.886277 * harmonics.l00[1] - 0.247708 * harmonics.l20[1] + 0.429043 * harmonics.l22[1]) * rPi;
132
- outPolynomialCoefficents.xx.z = (0.886277 * harmonics.l00[2] - 0.247708 * harmonics.l20[2] + 0.429043 * harmonics.l22[2]) * rPi;
133
- outPolynomialCoefficents.yy.x = (0.886277 * harmonics.l00[0] - 0.247708 * harmonics.l20[0] - 0.429043 * harmonics.l22[0]) * rPi;
134
- outPolynomialCoefficents.yy.y = (0.886277 * harmonics.l00[1] - 0.247708 * harmonics.l20[1] - 0.429043 * harmonics.l22[1]) * rPi;
135
- outPolynomialCoefficents.yy.z = (0.886277 * harmonics.l00[2] - 0.247708 * harmonics.l20[2] - 0.429043 * harmonics.l22[2]) * rPi;
136
- outPolynomialCoefficents.zz.x = (0.886277 * harmonics.l00[0] + 0.495417 * harmonics.l20[0]) * rPi;
137
- outPolynomialCoefficents.zz.y = (0.886277 * harmonics.l00[1] + 0.495417 * harmonics.l20[1]) * rPi;
138
- outPolynomialCoefficents.zz.z = (0.886277 * harmonics.l00[2] + 0.495417 * harmonics.l20[2]) * rPi;
139
- //yz
140
- outPolynomialCoefficents.yz.x = 0.858086 * harmonics.l2_1[0] * rPi;
141
- outPolynomialCoefficents.yz.y = 0.858086 * harmonics.l2_1[1] * rPi;
142
- outPolynomialCoefficents.yz.z = 0.858086 * harmonics.l2_1[2] * rPi;
143
- outPolynomialCoefficents.zx.x = 0.858086 * harmonics.l21[0] * rPi;
144
- outPolynomialCoefficents.zx.y = 0.858086 * harmonics.l21[1] * rPi;
145
- outPolynomialCoefficents.zx.z = 0.858086 * harmonics.l21[2] * rPi;
146
- outPolynomialCoefficents.xy.x = 0.858086 * harmonics.l2_2[0] * rPi;
147
- outPolynomialCoefficents.xy.y = 0.858086 * harmonics.l2_2[1] * rPi;
148
- outPolynomialCoefficents.xy.z = 0.858086 * harmonics.l2_2[2] * rPi;
149
- };
150
- /**
151
- * Multiplies harmonic coefficients in place
152
- * @param harmonics Spherical harmonic coefficients (9)
153
- * @param scaleFactor Value to multiply by
154
- */
155
- EnvironmentDeserializer._ScaleSH = function (harmonics, scaleFactor) {
156
- harmonics.l00[0] *= scaleFactor;
157
- harmonics.l00[1] *= scaleFactor;
158
- harmonics.l00[2] *= scaleFactor;
159
- harmonics.l1_1[0] *= scaleFactor;
160
- harmonics.l1_1[1] *= scaleFactor;
161
- harmonics.l1_1[2] *= scaleFactor;
162
- harmonics.l10[0] *= scaleFactor;
163
- harmonics.l10[1] *= scaleFactor;
164
- harmonics.l10[2] *= scaleFactor;
165
- harmonics.l11[0] *= scaleFactor;
166
- harmonics.l11[1] *= scaleFactor;
167
- harmonics.l11[2] *= scaleFactor;
168
- harmonics.l2_2[0] *= scaleFactor;
169
- harmonics.l2_2[1] *= scaleFactor;
170
- harmonics.l2_2[2] *= scaleFactor;
171
- harmonics.l2_1[0] *= scaleFactor;
172
- harmonics.l2_1[1] *= scaleFactor;
173
- harmonics.l2_1[2] *= scaleFactor;
174
- harmonics.l20[0] *= scaleFactor;
175
- harmonics.l20[1] *= scaleFactor;
176
- harmonics.l20[2] *= scaleFactor;
177
- harmonics.l21[0] *= scaleFactor;
178
- harmonics.l21[1] *= scaleFactor;
179
- harmonics.l21[2] *= scaleFactor;
180
- harmonics.l22[0] *= scaleFactor;
181
- harmonics.l22[1] *= scaleFactor;
182
- harmonics.l22[2] *= scaleFactor;
183
- };
184
- return EnvironmentDeserializer;
185
- }());
186
- export { EnvironmentDeserializer };
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+ import { Vector3 } from "@babylonjs/core/Maths/math.js";
3
+ import { Tools } from "@babylonjs/core/Misc/tools.js";
4
+ import { TextureCube } from "./texture.js";
5
+ /**
6
+ * A static class proving methods to aid parsing Spectre environment files
7
+ */
8
+ var EnvironmentDeserializer = /** @class */ (function () {
9
+ function EnvironmentDeserializer() {
10
+ }
11
+ /**
12
+ * Parses an arraybuffer into a new PBREnvironment object
13
+ * @param arrayBuffer The arraybuffer of the Spectre environment file
14
+ * @return a PBREnvironment object
15
+ */
16
+ EnvironmentDeserializer.Parse = function (arrayBuffer) {
17
+ var environment = {
18
+ //irradiance
19
+ irradiancePolynomialCoefficients: {
20
+ x: new Vector3(0, 0, 0),
21
+ y: new Vector3(0, 0, 0),
22
+ z: new Vector3(0, 0, 0),
23
+ xx: new Vector3(0, 0, 0),
24
+ yy: new Vector3(0, 0, 0),
25
+ zz: new Vector3(0, 0, 0),
26
+ yz: new Vector3(0, 0, 0),
27
+ zx: new Vector3(0, 0, 0),
28
+ xy: new Vector3(0, 0, 0),
29
+ },
30
+ //specular
31
+ textureIntensityScale: 1.0,
32
+ };
33
+ //read .env
34
+ var littleEndian = false;
35
+ var magicBytes = [0x86, 0x16, 0x87, 0x96, 0xf6, 0xd6, 0x96, 0x36];
36
+ var dataView = new DataView(arrayBuffer);
37
+ var pos = 0;
38
+ for (var i = 0; i < magicBytes.length; i++) {
39
+ if (dataView.getUint8(pos++) !== magicBytes[i]) {
40
+ Tools.Error("Not a Spectre environment map");
41
+ }
42
+ }
43
+ var version = dataView.getUint16(pos, littleEndian);
44
+ pos += 2;
45
+ if (version !== 1) {
46
+ Tools.Warn('Unsupported Spectre environment map version "' + version + '"');
47
+ }
48
+ //read json descriptor - collect characters up to null terminator
49
+ var descriptorString = "";
50
+ var charCode = 0x00;
51
+ while ((charCode = dataView.getUint8(pos++))) {
52
+ descriptorString += String.fromCharCode(charCode);
53
+ }
54
+ var descriptor = JSON.parse(descriptorString);
55
+ var payloadPos = pos;
56
+ //irradiance
57
+ switch (descriptor.irradiance.type) {
58
+ case "irradiance_sh_coefficients_9": {
59
+ //irradiance
60
+ var harmonics = descriptor.irradiance;
61
+ EnvironmentDeserializer._ConvertSHIrradianceToLambertianRadiance(harmonics);
62
+ //harmonics now represent radiance
63
+ EnvironmentDeserializer._ConvertSHToSP(harmonics, environment.irradiancePolynomialCoefficients);
64
+ break;
65
+ }
66
+ default:
67
+ Tools.Error("Unhandled MapType descriptor.irradiance.type (" + descriptor.irradiance.type + ")");
68
+ }
69
+ //specular
70
+ switch (descriptor.specular.type) {
71
+ case "cubemap_faces": {
72
+ var specularDescriptor = descriptor.specular;
73
+ var specularTexture = (environment.specularTexture = new TextureCube(6408 /* RGBA */, 5121 /* UNSIGNED_BYTE */));
74
+ environment.textureIntensityScale = specularDescriptor.multiplier != null ? specularDescriptor.multiplier : 1.0;
75
+ var mipmaps = specularDescriptor.mipmaps;
76
+ var imageType = specularDescriptor.imageType;
77
+ for (var l = 0; l < mipmaps.length; l++) {
78
+ var faceRanges = mipmaps[l];
79
+ specularTexture.source[l] = [];
80
+ for (var i = 0; i < 6; i++) {
81
+ var range = faceRanges[i];
82
+ var bytes = new Uint8Array(arrayBuffer, payloadPos + range.pos, range.length);
83
+ switch (imageType) {
84
+ case "png": {
85
+ //construct image element from bytes
86
+ var image = new Image();
87
+ var src = URL.createObjectURL(new Blob([bytes], { type: "image/png" }));
88
+ image.src = src;
89
+ specularTexture.source[l][i] = image;
90
+ break;
91
+ }
92
+ default:
93
+ Tools.Error("Unhandled ImageType descriptor.specular.imageType (" + imageType + ")");
94
+ }
95
+ }
96
+ }
97
+ break;
98
+ }
99
+ default:
100
+ Tools.Error("Unhandled MapType descriptor.specular.type (" + descriptor.specular.type + ")");
101
+ }
102
+ return environment;
103
+ };
104
+ /**
105
+ * Convert from irradiance to outgoing radiance for Lambertian BDRF, suitable for efficient shader evaluation.
106
+ * L = (1/pi) * E * rho
107
+ *
108
+ * This is done by an additional scale by 1/pi, so is a fairly trivial operation but important conceptually.
109
+ * @param harmonics Spherical harmonic coefficients (9)
110
+ */
111
+ EnvironmentDeserializer._ConvertSHIrradianceToLambertianRadiance = function (harmonics) {
112
+ EnvironmentDeserializer._ScaleSH(harmonics, 1 / Math.PI);
113
+ // The resultant SH now represents outgoing radiance, so includes the Lambert 1/pi normalisation factor but without albedo (rho) applied
114
+ // (The pixel shader must apply albedo after texture fetches, etc).
115
+ };
116
+ /**
117
+ * Convert spherical harmonics to spherical polynomial coefficients
118
+ * @param harmonics Spherical harmonic coefficients (9)
119
+ * @param outPolynomialCoefficents Polynomial coefficients (9) object to store result
120
+ */
121
+ EnvironmentDeserializer._ConvertSHToSP = function (harmonics, outPolynomialCoefficents) {
122
+ var rPi = 1 / Math.PI;
123
+ //x
124
+ outPolynomialCoefficents.x.x = 1.02333 * harmonics.l11[0] * rPi;
125
+ outPolynomialCoefficents.x.y = 1.02333 * harmonics.l11[1] * rPi;
126
+ outPolynomialCoefficents.x.z = 1.02333 * harmonics.l11[2] * rPi;
127
+ outPolynomialCoefficents.y.x = 1.02333 * harmonics.l1_1[0] * rPi;
128
+ outPolynomialCoefficents.y.y = 1.02333 * harmonics.l1_1[1] * rPi;
129
+ outPolynomialCoefficents.y.z = 1.02333 * harmonics.l1_1[2] * rPi;
130
+ outPolynomialCoefficents.z.x = 1.02333 * harmonics.l10[0] * rPi;
131
+ outPolynomialCoefficents.z.y = 1.02333 * harmonics.l10[1] * rPi;
132
+ outPolynomialCoefficents.z.z = 1.02333 * harmonics.l10[2] * rPi;
133
+ //xx
134
+ outPolynomialCoefficents.xx.x = (0.886277 * harmonics.l00[0] - 0.247708 * harmonics.l20[0] + 0.429043 * harmonics.l22[0]) * rPi;
135
+ outPolynomialCoefficents.xx.y = (0.886277 * harmonics.l00[1] - 0.247708 * harmonics.l20[1] + 0.429043 * harmonics.l22[1]) * rPi;
136
+ outPolynomialCoefficents.xx.z = (0.886277 * harmonics.l00[2] - 0.247708 * harmonics.l20[2] + 0.429043 * harmonics.l22[2]) * rPi;
137
+ outPolynomialCoefficents.yy.x = (0.886277 * harmonics.l00[0] - 0.247708 * harmonics.l20[0] - 0.429043 * harmonics.l22[0]) * rPi;
138
+ outPolynomialCoefficents.yy.y = (0.886277 * harmonics.l00[1] - 0.247708 * harmonics.l20[1] - 0.429043 * harmonics.l22[1]) * rPi;
139
+ outPolynomialCoefficents.yy.z = (0.886277 * harmonics.l00[2] - 0.247708 * harmonics.l20[2] - 0.429043 * harmonics.l22[2]) * rPi;
140
+ outPolynomialCoefficents.zz.x = (0.886277 * harmonics.l00[0] + 0.495417 * harmonics.l20[0]) * rPi;
141
+ outPolynomialCoefficents.zz.y = (0.886277 * harmonics.l00[1] + 0.495417 * harmonics.l20[1]) * rPi;
142
+ outPolynomialCoefficents.zz.z = (0.886277 * harmonics.l00[2] + 0.495417 * harmonics.l20[2]) * rPi;
143
+ //yz
144
+ outPolynomialCoefficents.yz.x = 0.858086 * harmonics.l2_1[0] * rPi;
145
+ outPolynomialCoefficents.yz.y = 0.858086 * harmonics.l2_1[1] * rPi;
146
+ outPolynomialCoefficents.yz.z = 0.858086 * harmonics.l2_1[2] * rPi;
147
+ outPolynomialCoefficents.zx.x = 0.858086 * harmonics.l21[0] * rPi;
148
+ outPolynomialCoefficents.zx.y = 0.858086 * harmonics.l21[1] * rPi;
149
+ outPolynomialCoefficents.zx.z = 0.858086 * harmonics.l21[2] * rPi;
150
+ outPolynomialCoefficents.xy.x = 0.858086 * harmonics.l2_2[0] * rPi;
151
+ outPolynomialCoefficents.xy.y = 0.858086 * harmonics.l2_2[1] * rPi;
152
+ outPolynomialCoefficents.xy.z = 0.858086 * harmonics.l2_2[2] * rPi;
153
+ };
154
+ /**
155
+ * Multiplies harmonic coefficients in place
156
+ * @param harmonics Spherical harmonic coefficients (9)
157
+ * @param scaleFactor Value to multiply by
158
+ */
159
+ EnvironmentDeserializer._ScaleSH = function (harmonics, scaleFactor) {
160
+ harmonics.l00[0] *= scaleFactor;
161
+ harmonics.l00[1] *= scaleFactor;
162
+ harmonics.l00[2] *= scaleFactor;
163
+ harmonics.l1_1[0] *= scaleFactor;
164
+ harmonics.l1_1[1] *= scaleFactor;
165
+ harmonics.l1_1[2] *= scaleFactor;
166
+ harmonics.l10[0] *= scaleFactor;
167
+ harmonics.l10[1] *= scaleFactor;
168
+ harmonics.l10[2] *= scaleFactor;
169
+ harmonics.l11[0] *= scaleFactor;
170
+ harmonics.l11[1] *= scaleFactor;
171
+ harmonics.l11[2] *= scaleFactor;
172
+ harmonics.l2_2[0] *= scaleFactor;
173
+ harmonics.l2_2[1] *= scaleFactor;
174
+ harmonics.l2_2[2] *= scaleFactor;
175
+ harmonics.l2_1[0] *= scaleFactor;
176
+ harmonics.l2_1[1] *= scaleFactor;
177
+ harmonics.l2_1[2] *= scaleFactor;
178
+ harmonics.l20[0] *= scaleFactor;
179
+ harmonics.l20[1] *= scaleFactor;
180
+ harmonics.l20[2] *= scaleFactor;
181
+ harmonics.l21[0] *= scaleFactor;
182
+ harmonics.l21[1] *= scaleFactor;
183
+ harmonics.l21[2] *= scaleFactor;
184
+ harmonics.l22[0] *= scaleFactor;
185
+ harmonics.l22[1] *= scaleFactor;
186
+ harmonics.l22[2] *= scaleFactor;
187
+ };
188
+ return EnvironmentDeserializer;
189
+ }());
190
+ export { EnvironmentDeserializer };
187
191
  //# sourceMappingURL=environmentSerializer.js.map