@babylonjs/loaders 5.0.0-rc.1 → 5.0.0-rc.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. package/OBJ/index.d.ts +4 -4
  2. package/OBJ/index.js +4 -4
  3. package/OBJ/index.js.map +1 -1
  4. package/OBJ/mtlFileLoader.d.ts +41 -40
  5. package/OBJ/mtlFileLoader.js +232 -231
  6. package/OBJ/mtlFileLoader.js.map +1 -1
  7. package/OBJ/objFileLoader.d.ts +126 -133
  8. package/OBJ/objFileLoader.js +296 -300
  9. package/OBJ/objFileLoader.js.map +1 -1
  10. package/OBJ/objLoadingOptions.d.ts +43 -43
  11. package/OBJ/objLoadingOptions.js +1 -1
  12. package/OBJ/objLoadingOptions.js.map +1 -1
  13. package/OBJ/solidParser.d.ts +154 -153
  14. package/OBJ/solidParser.js +693 -699
  15. package/OBJ/solidParser.js.map +1 -1
  16. package/STL/index.d.ts +1 -1
  17. package/STL/index.js +1 -1
  18. package/STL/index.js.map +1 -1
  19. package/STL/stlFileLoader.d.ts +64 -71
  20. package/STL/stlFileLoader.js +233 -239
  21. package/STL/stlFileLoader.js.map +1 -1
  22. package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
  23. package/glTF/1.0/glTFBinaryExtension.js +60 -61
  24. package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
  25. package/glTF/1.0/glTFLoader.d.ts +136 -106
  26. package/glTF/1.0/glTFLoader.js +1814 -1696
  27. package/glTF/1.0/glTFLoader.js.map +1 -1
  28. package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
  29. package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
  30. package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
  31. package/glTF/1.0/glTFLoaderUtils.d.ts +63 -62
  32. package/glTF/1.0/glTFLoaderUtils.js +250 -232
  33. package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
  34. package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
  35. package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -127
  36. package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
  37. package/glTF/1.0/index.d.ts +5 -5
  38. package/glTF/1.0/index.js +5 -5
  39. package/glTF/1.0/index.js.map +1 -1
  40. package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +43 -36
  41. package/glTF/2.0/Extensions/EXT_lights_image_based.js +117 -110
  42. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
  43. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -28
  44. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +88 -80
  45. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  46. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +34 -27
  47. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +49 -42
  48. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
  49. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +29 -21
  50. package/glTF/2.0/Extensions/EXT_texture_webp.js +40 -32
  51. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
  52. package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -32
  53. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -55
  54. package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
  55. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +39 -31
  56. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +112 -101
  57. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
  58. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +36 -28
  59. package/glTF/2.0/Extensions/KHR_lights_punctual.js +89 -81
  60. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  61. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +39 -31
  62. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -86
  63. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  64. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +38 -30
  65. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +53 -45
  66. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
  67. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +42 -34
  68. package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -54
  69. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
  70. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +38 -30
  71. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +80 -72
  72. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
  73. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +39 -31
  74. package/glTF/2.0/Extensions/KHR_materials_sheen.js +84 -76
  75. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  76. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +38 -30
  77. package/glTF/2.0/Extensions/KHR_materials_specular.js +74 -66
  78. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  79. package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +39 -31
  80. package/glTF/2.0/Extensions/KHR_materials_translucency.js +83 -76
  81. package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
  82. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +38 -30
  83. package/glTF/2.0/Extensions/KHR_materials_transmission.js +288 -277
  84. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  85. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +38 -30
  86. package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -65
  87. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
  88. package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +87 -76
  89. package/glTF/2.0/Extensions/KHR_materials_variants.js +254 -243
  90. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
  91. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +39 -31
  92. package/glTF/2.0/Extensions/KHR_materials_volume.js +85 -78
  93. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
  94. package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +22 -19
  95. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -21
  96. package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
  97. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +29 -21
  98. package/glTF/2.0/Extensions/KHR_texture_basisu.js +40 -32
  99. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
  100. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +33 -25
  101. package/glTF/2.0/Extensions/KHR_texture_transform.js +61 -53
  102. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
  103. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +32 -29
  104. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +49 -46
  105. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
  106. package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +54 -38
  107. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +240 -216
  108. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
  109. package/glTF/2.0/Extensions/MSFT_lod.d.ts +109 -75
  110. package/glTF/2.0/Extensions/MSFT_lod.js +369 -333
  111. package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
  112. package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +14 -14
  113. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +36 -36
  114. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
  115. package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +14 -14
  116. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +36 -36
  117. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
  118. package/glTF/2.0/Extensions/index.d.ts +26 -26
  119. package/glTF/2.0/Extensions/index.js +26 -26
  120. package/glTF/2.0/Extensions/index.js.map +1 -1
  121. package/glTF/2.0/glTFLoader.d.ts +406 -357
  122. package/glTF/2.0/glTFLoader.js +2366 -2266
  123. package/glTF/2.0/glTFLoader.js.map +1 -1
  124. package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
  125. package/glTF/2.0/glTFLoaderExtension.js +1 -1
  126. package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
  127. package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -209
  128. package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
  129. package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
  130. package/glTF/2.0/index.d.ts +4 -4
  131. package/glTF/2.0/index.js +5 -4
  132. package/glTF/2.0/index.js.map +1 -1
  133. package/glTF/glTFFileLoader.d.ts +433 -373
  134. package/glTF/glTFFileLoader.js +927 -870
  135. package/glTF/glTFFileLoader.js.map +1 -1
  136. package/glTF/glTFValidation.d.ts +29 -29
  137. package/glTF/glTFValidation.js +123 -121
  138. package/glTF/glTFValidation.js.map +1 -1
  139. package/glTF/index.d.ts +5 -5
  140. package/glTF/index.js +6 -5
  141. package/glTF/index.js.map +1 -1
  142. package/index.d.ts +3 -3
  143. package/index.js +4 -3
  144. package/index.js.map +1 -1
  145. package/legacy/legacy-glTF.d.ts +2 -2
  146. package/legacy/legacy-glTF.js +18 -18
  147. package/legacy/legacy-glTF.js.map +1 -1
  148. package/legacy/legacy-glTF1.d.ts +2 -2
  149. package/legacy/legacy-glTF1.js +15 -14
  150. package/legacy/legacy-glTF1.js.map +1 -1
  151. package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
  152. package/legacy/legacy-glTF1FileLoader.js +3 -2
  153. package/legacy/legacy-glTF1FileLoader.js.map +1 -1
  154. package/legacy/legacy-glTF2.d.ts +2 -2
  155. package/legacy/legacy-glTF2.js +33 -32
  156. package/legacy/legacy-glTF2.js.map +1 -1
  157. package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
  158. package/legacy/legacy-glTF2FileLoader.js +3 -2
  159. package/legacy/legacy-glTF2FileLoader.js.map +1 -1
  160. package/legacy/legacy-glTFFileLoader.d.ts +3 -3
  161. package/legacy/legacy-glTFFileLoader.js +4 -3
  162. package/legacy/legacy-glTFFileLoader.js.map +1 -1
  163. package/legacy/legacy-objFileLoader.d.ts +1 -1
  164. package/legacy/legacy-objFileLoader.js +13 -12
  165. package/legacy/legacy-objFileLoader.js.map +1 -1
  166. package/legacy/legacy-stlFileLoader.d.ts +1 -1
  167. package/legacy/legacy-stlFileLoader.js +13 -12
  168. package/legacy/legacy-stlFileLoader.js.map +1 -1
  169. package/legacy/legacy.d.ts +6 -6
  170. package/legacy/legacy.js +8 -6
  171. package/legacy/legacy.js.map +1 -1
  172. package/license.md +71 -0
  173. package/package.json +37 -193
  174. package/readme.md +2 -2
@@ -1,111 +1,118 @@
1
- import { Scalar } from "@babylonjs/core/Maths/math.scalar.js";
2
- import { SphericalHarmonics, SphericalPolynomial } from "@babylonjs/core/Maths/sphericalPolynomial.js";
3
- import { Quaternion, Matrix } from "@babylonjs/core/Maths/math.vector.js";
4
- import { RawCubeTexture } from "@babylonjs/core/Materials/Textures/rawCubeTexture.js";
5
- import { GLTFLoader, ArrayItem } from "../glTFLoader.js";
6
- var NAME = "EXT_lights_image_based";
7
- /**
8
- * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
9
- */
10
- var EXT_lights_image_based = /** @class */ (function () {
11
- /** @hidden */
12
- function EXT_lights_image_based(loader) {
13
- /**
14
- * The name of this extension.
15
- */
16
- this.name = NAME;
17
- this._loader = loader;
18
- this.enabled = this._loader.isExtensionUsed(NAME);
19
- }
20
- /** @hidden */
21
- EXT_lights_image_based.prototype.dispose = function () {
22
- this._loader = null;
23
- delete this._lights;
24
- };
25
- /** @hidden */
26
- EXT_lights_image_based.prototype.onLoading = function () {
27
- var extensions = this._loader.gltf.extensions;
28
- if (extensions && extensions[this.name]) {
29
- var extension = extensions[this.name];
30
- this._lights = extension.lights;
31
- }
32
- };
33
- /** @hidden */
34
- EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
35
- var _this = this;
36
- return GLTFLoader.LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
37
- var promises = new Array();
38
- promises.push(_this._loader.loadSceneAsync(context, scene));
39
- _this._loader.logOpen("".concat(extensionContext));
40
- var light = ArrayItem.Get("".concat(extensionContext, "/light"), _this._lights, extension.light);
41
- promises.push(_this._loadLightAsync("/extensions/".concat(_this.name, "/lights/").concat(extension.light), light).then(function (texture) {
42
- _this._loader.babylonScene.environmentTexture = texture;
43
- }));
44
- _this._loader.logClose();
45
- return Promise.all(promises).then(function () { });
46
- });
47
- };
48
- EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
49
- var _this = this;
50
- if (!light._loaded) {
51
- var promises = new Array();
52
- this._loader.logOpen("".concat(context));
53
- var imageData_1 = new Array(light.specularImages.length);
54
- var _loop_1 = function (mipmap) {
55
- var faces = light.specularImages[mipmap];
56
- imageData_1[mipmap] = new Array(faces.length);
57
- var _loop_2 = function (face) {
58
- var specularImageContext = "".concat(context, "/specularImages/").concat(mipmap, "/").concat(face);
59
- this_1._loader.logOpen("".concat(specularImageContext));
60
- var index = faces[face];
61
- var image = ArrayItem.Get(specularImageContext, this_1._loader.gltf.images, index);
62
- promises.push(this_1._loader.loadImageAsync("/images/".concat(index), image).then(function (data) {
63
- imageData_1[mipmap][face] = data;
64
- }));
65
- this_1._loader.logClose();
66
- };
67
- for (var face = 0; face < faces.length; face++) {
68
- _loop_2(face);
69
- }
70
- };
71
- var this_1 = this;
72
- for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
73
- _loop_1(mipmap);
74
- }
75
- this._loader.logClose();
76
- light._loaded = Promise.all(promises).then(function () {
77
- var babylonTexture = new RawCubeTexture(_this._loader.babylonScene, null, light.specularImageSize);
78
- babylonTexture.name = light.name || "environment";
79
- light._babylonTexture = babylonTexture;
80
- if (light.intensity != undefined) {
81
- babylonTexture.level = light.intensity;
82
- }
83
- if (light.rotation) {
84
- var rotation = Quaternion.FromArray(light.rotation);
85
- // Invert the rotation so that positive rotation is counter-clockwise.
86
- if (!_this._loader.babylonScene.useRightHandedSystem) {
87
- rotation = Quaternion.Inverse(rotation);
88
- }
89
- Matrix.FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
90
- }
91
- if (!light.irradianceCoefficients) {
92
- throw new Error("".concat(context, ": Irradiance coefficients are missing"));
93
- }
94
- var sphericalHarmonics = SphericalHarmonics.FromArray(light.irradianceCoefficients);
95
- sphericalHarmonics.scaleInPlace(light.intensity);
96
- sphericalHarmonics.convertIrradianceToLambertianRadiance();
97
- var sphericalPolynomial = SphericalPolynomial.FromHarmonics(sphericalHarmonics);
98
- // Compute the lod generation scale to fit exactly to the number of levels available.
99
- var lodGenerationScale = (imageData_1.length - 1) / Scalar.Log2(light.specularImageSize);
100
- return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
101
- });
102
- }
103
- return light._loaded.then(function () {
104
- return light._babylonTexture;
105
- });
106
- };
107
- return EXT_lights_image_based;
108
- }());
109
- export { EXT_lights_image_based };
110
- GLTFLoader.RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
1
+ import { Scalar } from "@babylonjs/core/Maths/math.scalar.js";
2
+ import { SphericalHarmonics, SphericalPolynomial } from "@babylonjs/core/Maths/sphericalPolynomial.js";
3
+ import { Quaternion, Matrix } from "@babylonjs/core/Maths/math.vector.js";
4
+ import { RawCubeTexture } from "@babylonjs/core/Materials/Textures/rawCubeTexture.js";
5
+ import { GLTFLoader, ArrayItem } from "../glTFLoader";
6
+ var NAME = "EXT_lights_image_based";
7
+ /**
8
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
9
+ */
10
+ var EXT_lights_image_based = /** @class */ (function () {
11
+ /**
12
+ * @param loader
13
+ * @hidden
14
+ */
15
+ function EXT_lights_image_based(loader) {
16
+ /**
17
+ * The name of this extension.
18
+ */
19
+ this.name = NAME;
20
+ this._loader = loader;
21
+ this.enabled = this._loader.isExtensionUsed(NAME);
22
+ }
23
+ /** @hidden */
24
+ EXT_lights_image_based.prototype.dispose = function () {
25
+ this._loader = null;
26
+ delete this._lights;
27
+ };
28
+ /** @hidden */
29
+ EXT_lights_image_based.prototype.onLoading = function () {
30
+ var extensions = this._loader.gltf.extensions;
31
+ if (extensions && extensions[this.name]) {
32
+ var extension = extensions[this.name];
33
+ this._lights = extension.lights;
34
+ }
35
+ };
36
+ /**
37
+ * @param context
38
+ * @param scene
39
+ * @hidden
40
+ */
41
+ EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
42
+ var _this = this;
43
+ return GLTFLoader.LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
44
+ var promises = new Array();
45
+ promises.push(_this._loader.loadSceneAsync(context, scene));
46
+ _this._loader.logOpen("".concat(extensionContext));
47
+ var light = ArrayItem.Get("".concat(extensionContext, "/light"), _this._lights, extension.light);
48
+ promises.push(_this._loadLightAsync("/extensions/".concat(_this.name, "/lights/").concat(extension.light), light).then(function (texture) {
49
+ _this._loader.babylonScene.environmentTexture = texture;
50
+ }));
51
+ _this._loader.logClose();
52
+ return Promise.all(promises).then(function () { });
53
+ });
54
+ };
55
+ EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
56
+ var _this = this;
57
+ if (!light._loaded) {
58
+ var promises = new Array();
59
+ this._loader.logOpen("".concat(context));
60
+ var imageData_1 = new Array(light.specularImages.length);
61
+ var _loop_1 = function (mipmap) {
62
+ var faces = light.specularImages[mipmap];
63
+ imageData_1[mipmap] = new Array(faces.length);
64
+ var _loop_2 = function (face) {
65
+ var specularImageContext = "".concat(context, "/specularImages/").concat(mipmap, "/").concat(face);
66
+ this_1._loader.logOpen("".concat(specularImageContext));
67
+ var index = faces[face];
68
+ var image = ArrayItem.Get(specularImageContext, this_1._loader.gltf.images, index);
69
+ promises.push(this_1._loader.loadImageAsync("/images/".concat(index), image).then(function (data) {
70
+ imageData_1[mipmap][face] = data;
71
+ }));
72
+ this_1._loader.logClose();
73
+ };
74
+ for (var face = 0; face < faces.length; face++) {
75
+ _loop_2(face);
76
+ }
77
+ };
78
+ var this_1 = this;
79
+ for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
80
+ _loop_1(mipmap);
81
+ }
82
+ this._loader.logClose();
83
+ light._loaded = Promise.all(promises).then(function () {
84
+ var babylonTexture = new RawCubeTexture(_this._loader.babylonScene, null, light.specularImageSize);
85
+ babylonTexture.name = light.name || "environment";
86
+ light._babylonTexture = babylonTexture;
87
+ if (light.intensity != undefined) {
88
+ babylonTexture.level = light.intensity;
89
+ }
90
+ if (light.rotation) {
91
+ var rotation = Quaternion.FromArray(light.rotation);
92
+ // Invert the rotation so that positive rotation is counter-clockwise.
93
+ if (!_this._loader.babylonScene.useRightHandedSystem) {
94
+ rotation = Quaternion.Inverse(rotation);
95
+ }
96
+ Matrix.FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
97
+ }
98
+ if (!light.irradianceCoefficients) {
99
+ throw new Error("".concat(context, ": Irradiance coefficients are missing"));
100
+ }
101
+ var sphericalHarmonics = SphericalHarmonics.FromArray(light.irradianceCoefficients);
102
+ sphericalHarmonics.scaleInPlace(light.intensity);
103
+ sphericalHarmonics.convertIrradianceToLambertianRadiance();
104
+ var sphericalPolynomial = SphericalPolynomial.FromHarmonics(sphericalHarmonics);
105
+ // Compute the lod generation scale to fit exactly to the number of levels available.
106
+ var lodGenerationScale = (imageData_1.length - 1) / Scalar.Log2(light.specularImageSize);
107
+ return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
108
+ });
109
+ }
110
+ return light._loaded.then(function () {
111
+ return light._babylonTexture;
112
+ });
113
+ };
114
+ return EXT_lights_image_based;
115
+ }());
116
+ export { EXT_lights_image_based };
117
+ GLTFLoader.RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
111
118
  //# sourceMappingURL=EXT_lights_image_based.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EXT_lights_image_based.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/EXT_lights_image_based.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAEvE,OAAO,EAAE,cAAc,EAAE,MAAM,mDAAmD,CAAC;AAKnF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEtD,IAAM,IAAI,GAAG,wBAAwB,CAAC;AAUtC;;GAEG;AACH;IAcI,cAAc;IACd,gCAAY,MAAkB;QAd9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAYxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,cAAc;IACP,wCAAO,GAAd;QACK,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,cAAc;IACP,0CAAS,GAAhB;QACI,IAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACrC,IAAM,SAAS,GAAG,UAAU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IAAM,kBAAkB,GAAG,CAAC,WAAS,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;gBACzF,OAAO,cAAc,CAAC,eAAe,CAAC,WAAS,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;YAC9F,CAAC,CAAC,CAAC;SACN;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YACtB,OAAO,KAAK,CAAC,eAAgB,CAAC;QAClC,CAAC,CAAC,CAAC;IACP,CAAC;IACL,6BAAC;AAAD,CAAC,AAzHD,IAyHC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,sBAAsB,CAAC,MAAM,CAAC,EAAlC,CAAkC,CAAC,CAAC","sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\r\nimport { Scalar } from \"@babylonjs/core/Maths/math.scalar\";\r\nimport { SphericalHarmonics, SphericalPolynomial } from \"@babylonjs/core/Maths/sphericalPolynomial\";\r\nimport { Quaternion, Matrix } from \"@babylonjs/core/Maths/math.vector\";\r\nimport { BaseTexture } from \"@babylonjs/core/Materials/Textures/baseTexture\";\r\nimport { RawCubeTexture } from \"@babylonjs/core/Materials/Textures/rawCubeTexture\";\r\n\r\nimport { IEXTLightsImageBased_LightReferenceImageBased, IEXTLightsImageBased_LightImageBased, IEXTLightsImageBased } from \"babylonjs-gltf2interface\";\r\nimport { IScene } from \"../glTFLoaderInterfaces\";\r\nimport { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nconst NAME = \"EXT_lights_image_based\";\r\n\r\ndeclare module \"babylonjs-gltf2interface\" {\r\n /** @hidden */\r\n interface IEXTLightsImageBased_LightImageBased {\r\n _babylonTexture?: BaseTexture;\r\n _loaded?: Promise<void>;\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)\r\n */\r\nexport class EXT_lights_image_based implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n private _lights?: IEXTLightsImageBased_LightImageBased[];\r\n\r\n /** @hidden */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @hidden */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._lights;\r\n }\r\n\r\n /** @hidden */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as IEXTLightsImageBased;\r\n this._lights = extension.lights;\r\n }\r\n }\r\n\r\n /** @hidden */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTLightsImageBased_LightReferenceImageBased>(context, scene, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n const light = ArrayItem.Get(`${extensionContext}/light`, this._lights, extension.light);\r\n promises.push(this._loadLightAsync(`/extensions/${this.name}/lights/${extension.light}`, light).then((texture) => {\r\n this._loader.babylonScene.environmentTexture = texture;\r\n }));\r\n\r\n this._loader.logClose();\r\n\r\n return Promise.all(promises).then(() => { });\r\n });\r\n }\r\n\r\n private _loadLightAsync(context: string, light: IEXTLightsImageBased_LightImageBased): Promise<BaseTexture> {\r\n if (!light._loaded) {\r\n const promises = new Array<Promise<any>>();\r\n\r\n this._loader.logOpen(`${context}`);\r\n\r\n const imageData = new Array<Array<ArrayBufferView>>(light.specularImages.length);\r\n for (let mipmap = 0; mipmap < light.specularImages.length; mipmap++) {\r\n const faces = light.specularImages[mipmap];\r\n imageData[mipmap] = new Array<ArrayBufferView>(faces.length);\r\n for (let face = 0; face < faces.length; face++) {\r\n const specularImageContext = `${context}/specularImages/${mipmap}/${face}`;\r\n this._loader.logOpen(`${specularImageContext}`);\r\n\r\n const index = faces[face];\r\n const image = ArrayItem.Get(specularImageContext, this._loader.gltf.images, index);\r\n promises.push(this._loader.loadImageAsync(`/images/${index}`, image).then((data) => {\r\n imageData[mipmap][face] = data;\r\n }));\r\n\r\n this._loader.logClose();\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n\r\n light._loaded = Promise.all(promises).then(() => {\r\n const babylonTexture = new RawCubeTexture(this._loader.babylonScene, null, light.specularImageSize);\r\n babylonTexture.name = light.name || \"environment\";\r\n light._babylonTexture = babylonTexture;\r\n\r\n if (light.intensity != undefined) {\r\n babylonTexture.level = light.intensity;\r\n }\r\n\r\n if (light.rotation) {\r\n let rotation = Quaternion.FromArray(light.rotation);\r\n\r\n // Invert the rotation so that positive rotation is counter-clockwise.\r\n if (!this._loader.babylonScene.useRightHandedSystem) {\r\n rotation = Quaternion.Inverse(rotation);\r\n }\r\n\r\n Matrix.FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());\r\n }\r\n\r\n if (!light.irradianceCoefficients) {\r\n throw new Error(`${context}: Irradiance coefficients are missing`);\r\n }\r\n\r\n const sphericalHarmonics = SphericalHarmonics.FromArray(light.irradianceCoefficients);\r\n sphericalHarmonics.scaleInPlace(light.intensity);\r\n\r\n sphericalHarmonics.convertIrradianceToLambertianRadiance();\r\n const sphericalPolynomial = SphericalPolynomial.FromHarmonics(sphericalHarmonics);\r\n\r\n // Compute the lod generation scale to fit exactly to the number of levels available.\r\n const lodGenerationScale = (imageData.length - 1) / Scalar.Log2(light.specularImageSize);\r\n return babylonTexture.updateRGBDAsync(imageData, sphericalPolynomial, lodGenerationScale);\r\n });\r\n }\r\n\r\n return light._loaded.then(() => {\r\n return light._babylonTexture!;\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new EXT_lights_image_based(loader));"]}
1
+ {"version":3,"file":"EXT_lights_image_based.js","sourceRoot":"","sources":["../../../../../../../lts/loaders/generated/glTF/2.0/Extensions/EXT_lights_image_based.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAChD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,qDAAuC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,6CAA+B;AAE5D,OAAO,EAAE,cAAc,EAAE,6DAA+C;AAKxE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEtD,IAAM,IAAI,GAAG,wBAAwB,CAAC;AAUtC;;GAEG;AACH;IAcI;;;OAGG;IACH,gCAAY,MAAkB;QAjB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAexB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,cAAc;IACP,wCAAO,GAAd;QACK,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,cAAc;IACP,0CAAS,GAAhB;QACI,IAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACrC,IAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAyB,CAAC;YAChE,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC;SACnC;IACL,CAAC;IAED;;;;OAIG;IACI,+CAAc,GAArB,UAAsB,OAAe,EAAE,KAAa;QAApD,iBAmB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AmB,EAAE,kBAAkB,CAAC,CAAC;YAC9F,CAAC,CAAC,CAAC;SACN;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YACtB,OAAO,KAAK,CAAC,eAAgB,CAAC;QAClC,CAAC,CAAC,CAAC;IACP,CAAC;IACL,6BAAC;AAAD,CAAC,AApID,IAoIC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,sBAAsB,CAAC,MAAM,CAAC,EAAlC,CAAkC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { Scalar } from \"core/Maths/math.scalar\";\r\nimport { SphericalHarmonics, SphericalPolynomial } from \"core/Maths/sphericalPolynomial\";\r\nimport { Quaternion, Matrix } from \"core/Maths/math.vector\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { RawCubeTexture } from \"core/Materials/Textures/rawCubeTexture\";\r\n\r\nimport type { IEXTLightsImageBased_LightReferenceImageBased, IEXTLightsImageBased_LightImageBased, IEXTLightsImageBased } from \"babylonjs-gltf2interface\";\r\nimport type { IScene } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nconst NAME = \"EXT_lights_image_based\";\r\n\r\ndeclare module \"babylonjs-gltf2interface\" {\r\n /** @hidden */\r\n interface IEXTLightsImageBased_LightImageBased {\r\n _babylonTexture?: BaseTexture;\r\n _loaded?: Promise<void>;\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)\r\n */\r\nexport class EXT_lights_image_based implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n private _lights?: IEXTLightsImageBased_LightImageBased[];\r\n\r\n /**\r\n * @param loader\r\n * @hidden\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @hidden */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._lights;\r\n }\r\n\r\n /** @hidden */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as IEXTLightsImageBased;\r\n this._lights = extension.lights;\r\n }\r\n }\r\n\r\n /**\r\n * @param context\r\n * @param scene\r\n * @hidden\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTLightsImageBased_LightReferenceImageBased>(context, scene, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n const light = ArrayItem.Get(`${extensionContext}/light`, this._lights, extension.light);\r\n promises.push(\r\n this._loadLightAsync(`/extensions/${this.name}/lights/${extension.light}`, light).then((texture) => {\r\n this._loader.babylonScene.environmentTexture = texture;\r\n })\r\n );\r\n\r\n this._loader.logClose();\r\n\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadLightAsync(context: string, light: IEXTLightsImageBased_LightImageBased): Promise<BaseTexture> {\r\n if (!light._loaded) {\r\n const promises = new Array<Promise<any>>();\r\n\r\n this._loader.logOpen(`${context}`);\r\n\r\n const imageData = new Array<Array<ArrayBufferView>>(light.specularImages.length);\r\n for (let mipmap = 0; mipmap < light.specularImages.length; mipmap++) {\r\n const faces = light.specularImages[mipmap];\r\n imageData[mipmap] = new Array<ArrayBufferView>(faces.length);\r\n for (let face = 0; face < faces.length; face++) {\r\n const specularImageContext = `${context}/specularImages/${mipmap}/${face}`;\r\n this._loader.logOpen(`${specularImageContext}`);\r\n\r\n const index = faces[face];\r\n const image = ArrayItem.Get(specularImageContext, this._loader.gltf.images, index);\r\n promises.push(\r\n this._loader.loadImageAsync(`/images/${index}`, image).then((data) => {\r\n imageData[mipmap][face] = data;\r\n })\r\n );\r\n\r\n this._loader.logClose();\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n\r\n light._loaded = Promise.all(promises).then(() => {\r\n const babylonTexture = new RawCubeTexture(this._loader.babylonScene, null, light.specularImageSize);\r\n babylonTexture.name = light.name || \"environment\";\r\n light._babylonTexture = babylonTexture;\r\n\r\n if (light.intensity != undefined) {\r\n babylonTexture.level = light.intensity;\r\n }\r\n\r\n if (light.rotation) {\r\n let rotation = Quaternion.FromArray(light.rotation);\r\n\r\n // Invert the rotation so that positive rotation is counter-clockwise.\r\n if (!this._loader.babylonScene.useRightHandedSystem) {\r\n rotation = Quaternion.Inverse(rotation);\r\n }\r\n\r\n Matrix.FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());\r\n }\r\n\r\n if (!light.irradianceCoefficients) {\r\n throw new Error(`${context}: Irradiance coefficients are missing`);\r\n }\r\n\r\n const sphericalHarmonics = SphericalHarmonics.FromArray(light.irradianceCoefficients);\r\n sphericalHarmonics.scaleInPlace(light.intensity);\r\n\r\n sphericalHarmonics.convertIrradianceToLambertianRadiance();\r\n const sphericalPolynomial = SphericalPolynomial.FromHarmonics(sphericalHarmonics);\r\n\r\n // Compute the lod generation scale to fit exactly to the number of levels available.\r\n const lodGenerationScale = (imageData.length - 1) / Scalar.Log2(light.specularImageSize);\r\n return babylonTexture.updateRGBDAsync(imageData, sphericalPolynomial, lodGenerationScale);\r\n });\r\n }\r\n\r\n return light._loaded.then(() => {\r\n return light._babylonTexture!;\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new EXT_lights_image_based(loader));\r\n"]}
@@ -1,28 +1,36 @@
1
- import { TransformNode } from "@babylonjs/core/Meshes/transformNode";
2
- import { Nullable } from "@babylonjs/core/types";
3
- import { GLTFLoader } from "../glTFLoader";
4
- import { IGLTFLoaderExtension } from "../glTFLoaderExtension";
5
- import { INode } from "../glTFLoaderInterfaces";
6
- import "@babylonjs/core/Meshes/thinInstanceMesh";
7
- /**
8
- * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
9
- * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
10
- * !!! Experimental Extension Subject to Changes !!!
11
- */
12
- export declare class EXT_mesh_gpu_instancing implements IGLTFLoaderExtension {
13
- /**
14
- * The name of this extension.
15
- */
16
- readonly name = "EXT_mesh_gpu_instancing";
17
- /**
18
- * Defines whether this extension is enabled.
19
- */
20
- enabled: boolean;
21
- private _loader;
22
- /** @hidden */
23
- constructor(loader: GLTFLoader);
24
- /** @hidden */
25
- dispose(): void;
26
- /** @hidden */
27
- loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
28
- }
1
+ import type { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
2
+ import type { Nullable } from "@babylonjs/core/types.js";
3
+ import { GLTFLoader } from "../glTFLoader";
4
+ import type { IGLTFLoaderExtension } from "../glTFLoaderExtension";
5
+ import type { INode } from "../glTFLoaderInterfaces";
6
+ import "@babylonjs/core/Meshes/thinInstanceMesh.js";
7
+ /**
8
+ * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
9
+ * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
10
+ * !!! Experimental Extension Subject to Changes !!!
11
+ */
12
+ export declare class EXT_mesh_gpu_instancing implements IGLTFLoaderExtension {
13
+ /**
14
+ * The name of this extension.
15
+ */
16
+ readonly name = "EXT_mesh_gpu_instancing";
17
+ /**
18
+ * Defines whether this extension is enabled.
19
+ */
20
+ enabled: boolean;
21
+ private _loader;
22
+ /**
23
+ * @param loader
24
+ * @hidden
25
+ */
26
+ constructor(loader: GLTFLoader);
27
+ /** @hidden */
28
+ dispose(): void;
29
+ /**
30
+ * @param context
31
+ * @param node
32
+ * @param assign
33
+ * @hidden
34
+ */
35
+ loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
36
+ }
@@ -1,81 +1,89 @@
1
- import { Vector3, Quaternion, Matrix } from '@babylonjs/core/Maths/math.vector.js';
2
- import { GLTFLoader, ArrayItem } from "../glTFLoader.js";
3
- import { TmpVectors } from '@babylonjs/core/Maths/math.vector.js';
4
- import "@babylonjs/core/Meshes/thinInstanceMesh.js";
5
- var NAME = "EXT_mesh_gpu_instancing";
6
- /**
7
- * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
8
- * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
9
- * !!! Experimental Extension Subject to Changes !!!
10
- */
11
- var EXT_mesh_gpu_instancing = /** @class */ (function () {
12
- /** @hidden */
13
- function EXT_mesh_gpu_instancing(loader) {
14
- /**
15
- * The name of this extension.
16
- */
17
- this.name = NAME;
18
- this._loader = loader;
19
- this.enabled = this._loader.isExtensionUsed(NAME);
20
- }
21
- /** @hidden */
22
- EXT_mesh_gpu_instancing.prototype.dispose = function () {
23
- this._loader = null;
24
- };
25
- /** @hidden */
26
- EXT_mesh_gpu_instancing.prototype.loadNodeAsync = function (context, node, assign) {
27
- var _this = this;
28
- return GLTFLoader.LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
29
- _this._loader._disableInstancedMesh++;
30
- var promise = _this._loader.loadNodeAsync("/nodes/".concat(node.index), node, assign);
31
- _this._loader._disableInstancedMesh--;
32
- if (!node._primitiveBabylonMeshes) {
33
- return promise;
34
- }
35
- var promises = new Array();
36
- var instanceCount = 0;
37
- var loadAttribute = function (attribute) {
38
- if (extension.attributes[attribute] == undefined) {
39
- promises.push(Promise.resolve(null));
40
- return;
41
- }
42
- var accessor = ArrayItem.Get("".concat(extensionContext, "/attributes/").concat(attribute), _this._loader.gltf.accessors, extension.attributes[attribute]);
43
- promises.push(_this._loader._loadFloatAccessorAsync("/accessors/".concat(accessor.bufferView), accessor));
44
- if (instanceCount === 0) {
45
- instanceCount = accessor.count;
46
- }
47
- else if (instanceCount !== accessor.count) {
48
- throw new Error("".concat(extensionContext, "/attributes: Instance buffer accessors do not have the same count."));
49
- }
50
- };
51
- loadAttribute("TRANSLATION");
52
- loadAttribute("ROTATION");
53
- loadAttribute("SCALE");
54
- return promise.then(function (babylonTransformNode) {
55
- return Promise.all(promises).then(function (_a) {
56
- var translationBuffer = _a[0], rotationBuffer = _a[1], scaleBuffer = _a[2];
57
- var matrices = new Float32Array(instanceCount * 16);
58
- TmpVectors.Vector3[0].copyFromFloats(0, 0, 0); // translation
59
- TmpVectors.Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation
60
- TmpVectors.Vector3[1].copyFromFloats(1, 1, 1); // scale
61
- for (var i = 0; i < instanceCount; ++i) {
62
- translationBuffer && Vector3.FromArrayToRef(translationBuffer, i * 3, TmpVectors.Vector3[0]);
63
- rotationBuffer && Quaternion.FromArrayToRef(rotationBuffer, i * 4, TmpVectors.Quaternion[0]);
64
- scaleBuffer && Vector3.FromArrayToRef(scaleBuffer, i * 3, TmpVectors.Vector3[1]);
65
- Matrix.ComposeToRef(TmpVectors.Vector3[1], TmpVectors.Quaternion[0], TmpVectors.Vector3[0], TmpVectors.Matrix[0]);
66
- TmpVectors.Matrix[0].copyToArray(matrices, i * 16);
67
- }
68
- for (var _i = 0, _b = node._primitiveBabylonMeshes; _i < _b.length; _i++) {
69
- var babylonMesh = _b[_i];
70
- babylonMesh.thinInstanceSetBuffer("matrix", matrices, 16, true);
71
- }
72
- return babylonTransformNode;
73
- });
74
- });
75
- });
76
- };
77
- return EXT_mesh_gpu_instancing;
78
- }());
79
- export { EXT_mesh_gpu_instancing };
80
- GLTFLoader.RegisterExtension(NAME, function (loader) { return new EXT_mesh_gpu_instancing(loader); });
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+ import { Vector3, Quaternion, Matrix, TmpVectors } from "@babylonjs/core/Maths/math.vector.js";
3
+ import { GLTFLoader, ArrayItem } from "../glTFLoader";
4
+ import "@babylonjs/core/Meshes/thinInstanceMesh.js";
5
+ var NAME = "EXT_mesh_gpu_instancing";
6
+ /**
7
+ * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
8
+ * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
9
+ * !!! Experimental Extension Subject to Changes !!!
10
+ */
11
+ var EXT_mesh_gpu_instancing = /** @class */ (function () {
12
+ /**
13
+ * @param loader
14
+ * @hidden
15
+ */
16
+ function EXT_mesh_gpu_instancing(loader) {
17
+ /**
18
+ * The name of this extension.
19
+ */
20
+ this.name = NAME;
21
+ this._loader = loader;
22
+ this.enabled = this._loader.isExtensionUsed(NAME);
23
+ }
24
+ /** @hidden */
25
+ EXT_mesh_gpu_instancing.prototype.dispose = function () {
26
+ this._loader = null;
27
+ };
28
+ /**
29
+ * @param context
30
+ * @param node
31
+ * @param assign
32
+ * @hidden
33
+ */
34
+ EXT_mesh_gpu_instancing.prototype.loadNodeAsync = function (context, node, assign) {
35
+ var _this = this;
36
+ return GLTFLoader.LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
37
+ _this._loader._disableInstancedMesh++;
38
+ var promise = _this._loader.loadNodeAsync("/nodes/".concat(node.index), node, assign);
39
+ _this._loader._disableInstancedMesh--;
40
+ if (!node._primitiveBabylonMeshes) {
41
+ return promise;
42
+ }
43
+ var promises = new Array();
44
+ var instanceCount = 0;
45
+ var loadAttribute = function (attribute) {
46
+ if (extension.attributes[attribute] == undefined) {
47
+ promises.push(Promise.resolve(null));
48
+ return;
49
+ }
50
+ var accessor = ArrayItem.Get("".concat(extensionContext, "/attributes/").concat(attribute), _this._loader.gltf.accessors, extension.attributes[attribute]);
51
+ promises.push(_this._loader._loadFloatAccessorAsync("/accessors/".concat(accessor.bufferView), accessor));
52
+ if (instanceCount === 0) {
53
+ instanceCount = accessor.count;
54
+ }
55
+ else if (instanceCount !== accessor.count) {
56
+ throw new Error("".concat(extensionContext, "/attributes: Instance buffer accessors do not have the same count."));
57
+ }
58
+ };
59
+ loadAttribute("TRANSLATION");
60
+ loadAttribute("ROTATION");
61
+ loadAttribute("SCALE");
62
+ return promise.then(function (babylonTransformNode) {
63
+ return Promise.all(promises).then(function (_a) {
64
+ var translationBuffer = _a[0], rotationBuffer = _a[1], scaleBuffer = _a[2];
65
+ var matrices = new Float32Array(instanceCount * 16);
66
+ TmpVectors.Vector3[0].copyFromFloats(0, 0, 0); // translation
67
+ TmpVectors.Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation
68
+ TmpVectors.Vector3[1].copyFromFloats(1, 1, 1); // scale
69
+ for (var i = 0; i < instanceCount; ++i) {
70
+ translationBuffer && Vector3.FromArrayToRef(translationBuffer, i * 3, TmpVectors.Vector3[0]);
71
+ rotationBuffer && Quaternion.FromArrayToRef(rotationBuffer, i * 4, TmpVectors.Quaternion[0]);
72
+ scaleBuffer && Vector3.FromArrayToRef(scaleBuffer, i * 3, TmpVectors.Vector3[1]);
73
+ Matrix.ComposeToRef(TmpVectors.Vector3[1], TmpVectors.Quaternion[0], TmpVectors.Vector3[0], TmpVectors.Matrix[0]);
74
+ TmpVectors.Matrix[0].copyToArray(matrices, i * 16);
75
+ }
76
+ for (var _i = 0, _b = node._primitiveBabylonMeshes; _i < _b.length; _i++) {
77
+ var babylonMesh = _b[_i];
78
+ babylonMesh.thinInstanceSetBuffer("matrix", matrices, 16, true);
79
+ }
80
+ return babylonTransformNode;
81
+ });
82
+ });
83
+ });
84
+ };
85
+ return EXT_mesh_gpu_instancing;
86
+ }());
87
+ export { EXT_mesh_gpu_instancing };
88
+ GLTFLoader.RegisterExtension(NAME, function (loader) { return new EXT_mesh_gpu_instancing(loader); });
81
89
  //# sourceMappingURL=EXT_mesh_gpu_instancing.js.map
@@ -1 +1 @@
1
- {"version":3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ACjB,WAAoB,CAAC,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;qBAC7E;oBAED,OAAO,oBAAoB,CAAC;gBAChC,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IACL,8BAAC;AAAD,CAAC,AAvFD,IAuFC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,uBAAuB,CAAC,MAAM,CAAC,EAAnC,CAAmC,CAAC,CAAC","sourcesContent":["import { Vector3, Quaternion, Matrix } from '@babylonjs/core/Maths/math.vector';\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\nimport { TransformNode } from \"@babylonjs/core/Meshes/transformNode\";\nimport { Nullable } from \"@babylonjs/core/types\";\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\nimport { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\nimport { INode } from \"../glTFLoaderInterfaces\";\nimport { TmpVectors } from '@babylonjs/core/Maths/math.vector';\nimport { IEXTMeshGpuInstancing } from \"babylonjs-gltf2interface\";\n\nimport \"@babylonjs/core/Meshes/thinInstanceMesh\";\n\nconst NAME = \"EXT_mesh_gpu_instancing\";\n\n/**\n * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)\n * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)\n * !!! Experimental Extension Subject to Changes !!!\n */\nexport class EXT_mesh_gpu_instancing implements IGLTFLoaderExtension {\n /**\n * The name of this extension.\n */\n public readonly name = NAME;\n\n /**\n * Defines whether this extension is enabled.\n */\n public enabled: boolean;\n\n private _loader: GLTFLoader;\n\n /** @hidden */\n constructor(loader: GLTFLoader) {\n this._loader = loader;\n this.enabled = this._loader.isExtensionUsed(NAME);\n }\n\n /** @hidden */\n public dispose() {\n (this._loader as any) = null;\n }\n\n /** @hidden */\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\n return GLTFLoader.LoadExtensionAsync<IEXTMeshGpuInstancing, TransformNode>(context, node, this.name, (extensionContext, extension) => {\n this._loader._disableInstancedMesh++;\n\n const promise = this._loader.loadNodeAsync(`/nodes/${node.index}`, node, assign);\n\n this._loader._disableInstancedMesh--;\n\n if (!node._primitiveBabylonMeshes) {\n return promise;\n }\n\n const promises = new Array<Promise<Nullable<Float32Array>>>();\n let instanceCount = 0;\n\n const loadAttribute = (attribute: string) => {\n if (extension.attributes[attribute] == undefined) {\n promises.push(Promise.resolve(null));\n return;\n }\n\n const accessor = ArrayItem.Get(`${extensionContext}/attributes/${attribute}`, this._loader.gltf.accessors, extension.attributes[attribute]);\n promises.push(this._loader._loadFloatAccessorAsync(`/accessors/${accessor.bufferView}`, accessor));\n\n if (instanceCount === 0) {\n instanceCount = accessor.count;\n } else if (instanceCount !== accessor.count) {\n throw new Error(`${extensionContext}/attributes: Instance buffer accessors do not have the same count.`);\n }\n };\n\n loadAttribute(\"TRANSLATION\");\n loadAttribute(\"ROTATION\");\n loadAttribute(\"SCALE\");\n\n return promise.then((babylonTransformNode) => {\n return Promise.all(promises).then(([translationBuffer, rotationBuffer, scaleBuffer]) => {\n const matrices = new Float32Array(instanceCount * 16);\n\n TmpVectors.Vector3[0].copyFromFloats(0, 0, 0); // translation\n TmpVectors.Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation\n TmpVectors.Vector3[1].copyFromFloats(1, 1, 1); // scale\n\n for (let i = 0; i < instanceCount; ++i) {\n translationBuffer && Vector3.FromArrayToRef(translationBuffer, i * 3, TmpVectors.Vector3[0]);\n rotationBuffer && Quaternion.FromArrayToRef(rotationBuffer, i * 4, TmpVectors.Quaternion[0]);\n scaleBuffer && Vector3.FromArrayToRef(scaleBuffer, i * 3, TmpVectors.Vector3[1]);\n\n Matrix.ComposeToRef(TmpVectors.Vector3[1], TmpVectors.Quaternion[0], TmpVectors.Vector3[0], TmpVectors.Matrix[0]);\n\n TmpVectors.Matrix[0].copyToArray(matrices, i * 16);\n }\n\n for (const babylonMesh of node._primitiveBabylonMeshes!) {\n (babylonMesh as Mesh).thinInstanceSetBuffer(\"matrix\", matrices, 16, true);\n }\n\n return babylonTransformNode;\n });\n });\n });\n }\n}\n\nGLTFLoader.RegisterExtension(NAME, (loader) => new EXT_mesh_gpu_instancing(loader));\n"]}
1
+ {"version":3,"file":"EXT_mesh_gpu_instancing.js","sourceRoot":"","sources":["../../../../../../../lts/loaders/generated/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,6CAA+B;AAIjF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAMtD,oDAAsC;AAEtC,IAAM,IAAI,GAAG,yBAAyB,CAAC;AAEvC;;;;GAIG;AACH;IAaI;;;OAGG;IACH,iCAAY,MAAkB;QAhB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAcxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,cAAc;IACP,yCAAO,GAAd;QACK,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;;;;OAKG;IACI,+CAAa,GAApB,UAAqB,OAAe,EAAE,IAAW,EAAE,MAAqD;QAAxG,iBA6DC;QA5DG,OAAO,UAAU,CAAC,kBAAkB,CAAuC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,UAAC,gBAAgB,EAAE,SAAS;YAC7H,KAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;YAErC,IAAM,OAAO,GAAG,KAAI,CAAC,OAAO,CAAC,aAAa,CAAC,iBAAU,IAAI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AAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;qBACtD;oBAED,KAA0B,UAA6B,EAA7B,KAAA,IAAI,CAAC,uBAAwB,EAA7B,cAA6B,EAA7B,IAA6B,EAAE;wBAApD,IAAM,WAAW,SAAA;wBACjB,WAAoB,CAAC,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;qBAC7E;oBAED,OAAO,oBAAoB,CAAC;gBAChC,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IACL,8BAAC;AAAD,CAAC,AA/FD,IA+FC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,uBAAuB,CAAC,MAAM,CAAC,EAAnC,CAAmC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Vector3, Quaternion, Matrix, TmpVectors } from \"core/Maths/math.vector\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport type { INode } from \"../glTFLoaderInterfaces\";\r\n\r\nimport type { IEXTMeshGpuInstancing } from \"babylonjs-gltf2interface\";\r\n\r\nimport \"core/Meshes/thinInstanceMesh\";\r\n\r\nconst NAME = \"EXT_mesh_gpu_instancing\";\r\n\r\n/**\r\n * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)\r\n * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)\r\n * !!! Experimental Extension Subject to Changes !!!\r\n */\r\nexport class EXT_mesh_gpu_instancing implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @param loader\r\n * @hidden\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @hidden */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @param context\r\n * @param node\r\n * @param assign\r\n * @hidden\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTMeshGpuInstancing, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n this._loader._disableInstancedMesh++;\r\n\r\n const promise = this._loader.loadNodeAsync(`/nodes/${node.index}`, node, assign);\r\n\r\n this._loader._disableInstancedMesh--;\r\n\r\n if (!node._primitiveBabylonMeshes) {\r\n return promise;\r\n }\r\n\r\n const promises = new Array<Promise<Nullable<Float32Array>>>();\r\n let instanceCount = 0;\r\n\r\n const loadAttribute = (attribute: string) => {\r\n if (extension.attributes[attribute] == undefined) {\r\n promises.push(Promise.resolve(null));\r\n return;\r\n }\r\n\r\n const accessor = ArrayItem.Get(`${extensionContext}/attributes/${attribute}`, this._loader.gltf.accessors, extension.attributes[attribute]);\r\n promises.push(this._loader._loadFloatAccessorAsync(`/accessors/${accessor.bufferView}`, accessor));\r\n\r\n if (instanceCount === 0) {\r\n instanceCount = accessor.count;\r\n } else if (instanceCount !== accessor.count) {\r\n throw new Error(`${extensionContext}/attributes: Instance buffer accessors do not have the same count.`);\r\n }\r\n };\r\n\r\n loadAttribute(\"TRANSLATION\");\r\n loadAttribute(\"ROTATION\");\r\n loadAttribute(\"SCALE\");\r\n\r\n return promise.then((babylonTransformNode) => {\r\n return Promise.all(promises).then(([translationBuffer, rotationBuffer, scaleBuffer]) => {\r\n const matrices = new Float32Array(instanceCount * 16);\r\n\r\n TmpVectors.Vector3[0].copyFromFloats(0, 0, 0); // translation\r\n TmpVectors.Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation\r\n TmpVectors.Vector3[1].copyFromFloats(1, 1, 1); // scale\r\n\r\n for (let i = 0; i < instanceCount; ++i) {\r\n translationBuffer && Vector3.FromArrayToRef(translationBuffer, i * 3, TmpVectors.Vector3[0]);\r\n rotationBuffer && Quaternion.FromArrayToRef(rotationBuffer, i * 4, TmpVectors.Quaternion[0]);\r\n scaleBuffer && Vector3.FromArrayToRef(scaleBuffer, i * 3, TmpVectors.Vector3[1]);\r\n\r\n Matrix.ComposeToRef(TmpVectors.Vector3[1], TmpVectors.Quaternion[0], TmpVectors.Vector3[0], TmpVectors.Matrix[0]);\r\n\r\n TmpVectors.Matrix[0].copyToArray(matrices, i * 16);\r\n }\r\n\r\n for (const babylonMesh of node._primitiveBabylonMeshes!) {\r\n (babylonMesh as Mesh).thinInstanceSetBuffer(\"matrix\", matrices, 16, true);\r\n }\r\n\r\n return babylonTransformNode;\r\n });\r\n });\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new EXT_mesh_gpu_instancing(loader));\r\n"]}