@babylonjs/loaders 5.0.0-rc.2 → 5.0.0-rc.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. package/OBJ/index.js.map +1 -1
  2. package/OBJ/mtlFileLoader.d.ts +7 -6
  3. package/OBJ/mtlFileLoader.js +15 -14
  4. package/OBJ/mtlFileLoader.js.map +1 -1
  5. package/OBJ/objFileLoader.d.ts +11 -18
  6. package/OBJ/objFileLoader.js +19 -23
  7. package/OBJ/objFileLoader.js.map +1 -1
  8. package/OBJ/objLoadingOptions.d.ts +1 -1
  9. package/OBJ/objLoadingOptions.js.map +1 -1
  10. package/OBJ/solidParser.d.ts +6 -5
  11. package/OBJ/solidParser.js +15 -21
  12. package/OBJ/solidParser.js.map +1 -1
  13. package/STL/index.js.map +1 -1
  14. package/STL/stlFileLoader.d.ts +7 -14
  15. package/STL/stlFileLoader.js +15 -21
  16. package/STL/stlFileLoader.js.map +1 -1
  17. package/glTF/1.0/glTFBinaryExtension.d.ts +4 -4
  18. package/glTF/1.0/glTFBinaryExtension.js +4 -5
  19. package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
  20. package/glTF/1.0/glTFLoader.d.ts +80 -50
  21. package/glTF/1.0/glTFLoader.js +265 -146
  22. package/glTF/1.0/glTFLoader.js.map +1 -1
  23. package/glTF/1.0/glTFLoaderInterfaces.d.ts +10 -10
  24. package/glTF/1.0/glTFLoaderInterfaces.js +3 -3
  25. package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
  26. package/glTF/1.0/glTFLoaderUtils.d.ts +25 -25
  27. package/glTF/1.0/glTFLoaderUtils.js +70 -52
  28. package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
  29. package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +2 -2
  30. package/glTF/1.0/glTFMaterialsCommonExtension.js +13 -11
  31. package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
  32. package/glTF/1.0/index.js.map +1 -1
  33. package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +11 -4
  34. package/glTF/2.0/Extensions/EXT_lights_image_based.js +9 -2
  35. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
  36. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +13 -5
  37. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +12 -4
  38. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  39. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +10 -3
  40. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +10 -3
  41. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
  42. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +12 -4
  43. package/glTF/2.0/Extensions/EXT_texture_webp.js +11 -3
  44. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
  45. package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +26 -8
  46. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +22 -4
  47. package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
  48. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +14 -6
  49. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +17 -6
  50. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
  51. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +12 -4
  52. package/glTF/2.0/Extensions/KHR_lights_punctual.js +11 -3
  53. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  54. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +12 -4
  55. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +10 -2
  56. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  57. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +12 -4
  58. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +10 -2
  59. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
  60. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +12 -4
  61. package/glTF/2.0/Extensions/KHR_materials_ior.js +10 -2
  62. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
  63. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +12 -4
  64. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +10 -2
  65. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
  66. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +12 -4
  67. package/glTF/2.0/Extensions/KHR_materials_sheen.js +11 -3
  68. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  69. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +12 -4
  70. package/glTF/2.0/Extensions/KHR_materials_specular.js +11 -3
  71. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  72. package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +12 -4
  73. package/glTF/2.0/Extensions/KHR_materials_translucency.js +11 -4
  74. package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
  75. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +12 -4
  76. package/glTF/2.0/Extensions/KHR_materials_transmission.js +24 -13
  77. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  78. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +12 -4
  79. package/glTF/2.0/Extensions/KHR_materials_unlit.js +10 -2
  80. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
  81. package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +17 -6
  82. package/glTF/2.0/Extensions/KHR_materials_variants.js +19 -8
  83. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
  84. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +12 -4
  85. package/glTF/2.0/Extensions/KHR_materials_volume.js +12 -5
  86. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
  87. package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +4 -1
  88. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +5 -3
  89. package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
  90. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +12 -4
  91. package/glTF/2.0/Extensions/KHR_texture_basisu.js +11 -3
  92. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
  93. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +12 -4
  94. package/glTF/2.0/Extensions/KHR_texture_transform.js +10 -2
  95. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
  96. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +4 -1
  97. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +4 -1
  98. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
  99. package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +23 -7
  100. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +38 -14
  101. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
  102. package/glTF/2.0/Extensions/MSFT_lod.d.ts +45 -11
  103. package/glTF/2.0/Extensions/MSFT_lod.js +44 -8
  104. package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
  105. package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +2 -2
  106. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
  107. package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +2 -2
  108. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
  109. package/glTF/2.0/Extensions/index.js.map +1 -1
  110. package/glTF/2.0/glTFLoader.d.ts +70 -22
  111. package/glTF/2.0/glTFLoader.js +180 -93
  112. package/glTF/2.0/glTFLoader.js.map +1 -1
  113. package/glTF/2.0/glTFLoaderExtension.d.ts +11 -11
  114. package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
  115. package/glTF/2.0/glTFLoaderInterfaces.d.ts +7 -7
  116. package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
  117. package/glTF/2.0/index.js.map +1 -1
  118. package/glTF/glTFFileLoader.d.ts +87 -27
  119. package/glTF/glTFFileLoader.js +102 -45
  120. package/glTF/glTFFileLoader.js.map +1 -1
  121. package/glTF/glTFValidation.d.ts +1 -1
  122. package/glTF/glTFValidation.js +12 -12
  123. package/glTF/glTFValidation.js.map +1 -1
  124. package/glTF/index.js.map +1 -1
  125. package/index.js.map +1 -1
  126. package/legacy/legacy-glTF.d.ts +2 -2
  127. package/legacy/legacy-glTF.js +5 -5
  128. package/legacy/legacy-glTF.js.map +1 -1
  129. package/legacy/legacy-glTF1.d.ts +1 -1
  130. package/legacy/legacy-glTF1.js +2 -2
  131. package/legacy/legacy-glTF1.js.map +1 -1
  132. package/legacy/legacy-glTF1FileLoader.js +1 -0
  133. package/legacy/legacy-glTF1FileLoader.js.map +1 -1
  134. package/legacy/legacy-glTF2.d.ts +1 -1
  135. package/legacy/legacy-glTF2.js +11 -11
  136. package/legacy/legacy-glTF2.js.map +1 -1
  137. package/legacy/legacy-glTF2FileLoader.js +1 -0
  138. package/legacy/legacy-glTF2FileLoader.js.map +1 -1
  139. package/legacy/legacy-glTFFileLoader.js +1 -0
  140. package/legacy/legacy-glTFFileLoader.js.map +1 -1
  141. package/legacy/legacy-objFileLoader.d.ts +1 -1
  142. package/legacy/legacy-objFileLoader.js +3 -3
  143. package/legacy/legacy-objFileLoader.js.map +1 -1
  144. package/legacy/legacy-stlFileLoader.d.ts +1 -1
  145. package/legacy/legacy-stlFileLoader.js +3 -3
  146. package/legacy/legacy-stlFileLoader.js.map +1 -1
  147. package/legacy/legacy.d.ts +1 -1
  148. package/legacy/legacy.js +2 -1
  149. package/legacy/legacy.js.map +1 -1
  150. package/package.json +23 -198
  151. package/readme.md +2 -2
package/OBJ/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../sourceES6/loaders/src/OBJ/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC","sourcesContent":["export * from \"./mtlFileLoader\";\r\nexport * from \"./objLoadingOptions\";\r\nexport * from \"./solidParser\";\r\nexport * from \"./objFileLoader\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../lts/loaders/generated/OBJ/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC","sourcesContent":["export * from \"./mtlFileLoader\";\r\nexport * from \"./objLoadingOptions\";\r\nexport * from \"./solidParser\";\r\nexport * from \"./objFileLoader\";\r\n"]}
@@ -1,7 +1,7 @@
1
- import { Nullable } from "@babylonjs/core/types";
2
- import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial";
3
- import { Scene } from "@babylonjs/core/scene";
4
- import { AssetContainer } from "@babylonjs/core/assetContainer";
1
+ import { Nullable } from "@babylonjs/core/types.js";
2
+ import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
3
+ import { Scene } from "@babylonjs/core/scene.js";
4
+ import { AssetContainer } from "@babylonjs/core/assetContainer.js";
5
5
  /**
6
6
  * Class reading and parsing the MTL file bundled with the obj file.
7
7
  */
@@ -30,11 +30,12 @@ export declare class MTLFileLoader {
30
30
  * Gets the texture for the material.
31
31
  *
32
32
  * If the material is imported from input file,
33
- * We sanitize the url to ensure it takes the textre from aside the material.
33
+ * We sanitize the url to ensure it takes the texture from aside the material.
34
34
  *
35
35
  * @param rootUrl The root url to load from
36
36
  * @param value The value stored in the mtl
37
+ * @param scene
37
38
  * @return The Texture
38
39
  */
39
- private static _getTexture;
40
+ private static _GetTexture;
40
41
  }
@@ -1,4 +1,4 @@
1
- import { Color3 } from '@babylonjs/core/Maths/math.color.js';
1
+ import { Color3 } from "@babylonjs/core/Maths/math.color.js";
2
2
  import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
3
3
  import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
4
4
  /**
@@ -27,7 +27,7 @@ var MTLFileLoader = /** @class */ (function () {
27
27
  return;
28
28
  }
29
29
  //Split the lines from the file
30
- var lines = data.split('\n');
30
+ var lines = data.split("\n");
31
31
  // whitespace char ie: [ \t\r\n\f]
32
32
  var delimiter_pattern = /\s+/;
33
33
  //Array with RGB colors
@@ -38,15 +38,15 @@ var MTLFileLoader = /** @class */ (function () {
38
38
  for (var i = 0; i < lines.length; i++) {
39
39
  var line = lines[i].trim();
40
40
  // Blank line or comment
41
- if (line.length === 0 || line.charAt(0) === '#') {
41
+ if (line.length === 0 || line.charAt(0) === "#") {
42
42
  continue;
43
43
  }
44
44
  //Get the first parameter (keyword)
45
- var pos = line.indexOf(' ');
46
- var key = (pos >= 0) ? line.substring(0, pos) : line;
45
+ var pos = line.indexOf(" ");
46
+ var key = pos >= 0 ? line.substring(0, pos) : line;
47
47
  key = key.toLowerCase();
48
48
  //Get the data following the key
49
- var value = (pos >= 0) ? line.substring(pos + 1).trim() : "";
49
+ var value = pos >= 0 ? line.substring(pos + 1).trim() : "";
50
50
  //This mtl keyword will create the new material
51
51
  if (key === "newmtl") {
52
52
  //Check if it is the first material.
@@ -104,16 +104,16 @@ var MTLFileLoader = /** @class */ (function () {
104
104
  else if (key === "map_ka" && material) {
105
105
  // ambient texture map with a loaded image
106
106
  //We must first get the folder of the image
107
- material.ambientTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
107
+ material.ambientTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);
108
108
  }
109
109
  else if (key === "map_kd" && material) {
110
110
  // Diffuse texture map with a loaded image
111
- material.diffuseTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
111
+ material.diffuseTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);
112
112
  }
113
113
  else if (key === "map_ks" && material) {
114
114
  // Specular texture map with a loaded image
115
115
  //We must first get the folder of the image
116
- material.specularTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
116
+ material.specularTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);
117
117
  }
118
118
  else if (key === "map_ns") {
119
119
  //Specular
@@ -127,20 +127,20 @@ var MTLFileLoader = /** @class */ (function () {
127
127
  else if (key === "map_bump" && material) {
128
128
  //The bump texture
129
129
  var values = value.split(delimiter_pattern);
130
- var bumpMultiplierIndex = values.indexOf('-bm');
130
+ var bumpMultiplierIndex = values.indexOf("-bm");
131
131
  var bumpMultiplier = null;
132
132
  if (bumpMultiplierIndex >= 0) {
133
133
  bumpMultiplier = values[bumpMultiplierIndex + 1];
134
134
  values.splice(bumpMultiplierIndex, 2); // remove
135
135
  }
136
- material.bumpTexture = MTLFileLoader._getTexture(rootUrl, values.join(' '), scene);
136
+ material.bumpTexture = MTLFileLoader._GetTexture(rootUrl, values.join(" "), scene);
137
137
  if (material.bumpTexture && bumpMultiplier !== null) {
138
138
  material.bumpTexture.level = parseFloat(bumpMultiplier);
139
139
  }
140
140
  }
141
141
  else if (key === "map_d" && material) {
142
142
  // The dissolve of the material
143
- material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
143
+ material.opacityTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);
144
144
  //Options for illumination
145
145
  }
146
146
  else if (key === "illum") {
@@ -192,13 +192,14 @@ var MTLFileLoader = /** @class */ (function () {
192
192
  * Gets the texture for the material.
193
193
  *
194
194
  * If the material is imported from input file,
195
- * We sanitize the url to ensure it takes the textre from aside the material.
195
+ * We sanitize the url to ensure it takes the texture from aside the material.
196
196
  *
197
197
  * @param rootUrl The root url to load from
198
198
  * @param value The value stored in the mtl
199
+ * @param scene
199
200
  * @return The Texture
200
201
  */
201
- MTLFileLoader._getTexture = function (rootUrl, value, scene) {
202
+ MTLFileLoader._GetTexture = function (rootUrl, value, scene) {
202
203
  if (!value) {
203
204
  return null;
204
205
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mtlFileLoader.js","sourceRoot":"","sources":["../../../sourceES6/loaders/src/OBJ/mtlFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,4CAA4C,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAI9E;;GAEG;AACH;IAAA;QAMI;;WAEG;QACI,cAAS,GAAuB,EAAE,CAAC;IAgN9C,CAAC;IA9MG;;;;;;;;;;OAUG;IACI,gCAAQ,GAAf,UAAgB,KAAY,EAAE,IAA0B,EAAE,OAAe,EAAE,cAAwC;QAC/G,IAAI,IAAI,YAAY,WAAW,EAAE;YAC7B,OAAO;SACV;QAED,+BAA+B;QAC/B,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7B,kCAAkC;QAClC,IAAI,iBAAiB,GAAG,KAAK,CAAC;QAC9B,uBAAuB;QACvB,IAAI,KAAe,CAAC;QACpB,cAAc;QACd,IAAI,QAAQ,GAA+B,IAAI,CAAC;QAEhD,mBAAmB;QACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACnC,IAAI,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAE3B,wBAAwB;YACxB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;gBAC7C,SAAS;aACZ;YAED,mCAAmC;YACnC,IAAI,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,GAAG,GAAG,CAAC,GAAG,IAAI,C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AAK,OAAO,EAAE;YACrB,IAAI,aAAa,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YAC5C,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE;gBACtB,aAAa,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;aAC1C;YAED,IAAI,aAAa,GAAG,CAAC,CAAC,EAAE;gBACpB,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;aAC1C;iBACI;gBACD,GAAG,IAAI,KAAK,CAAC;aAChB;SACJ;QACD,uBAAuB;aAClB;YACD,GAAG,IAAI,KAAK,CAAC;SAChB;QAED,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAC1E,CAAC;IAvND;;OAEG;IACW,8BAAgB,GAAG,IAAI,CAAC;IAqN1C,oBAAC;CAAA,AAzND,IAyNC;SAzNY,aAAa","sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\r\nimport { Color3 } from '@babylonjs/core/Maths/math.color';\r\nimport { Texture } from \"@babylonjs/core/Materials/Textures/texture\";\r\nimport { StandardMaterial } from \"@babylonjs/core/Materials/standardMaterial\";\r\n\r\nimport { Scene } from \"@babylonjs/core/scene\";\r\nimport { AssetContainer } from \"@babylonjs/core/assetContainer\";\r\n/**\r\n * Class reading and parsing the MTL file bundled with the obj file.\r\n */\r\nexport class MTLFileLoader {\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n public static INVERT_TEXTURE_Y = true;\r\n\r\n /**\r\n * All material loaded from the mtl will be set here\r\n */\r\n public materials: StandardMaterial[] = [];\r\n\r\n /**\r\n * This function will read the mtl file and create each material described inside\r\n * This function could be improve by adding :\r\n * -some component missing (Ni, Tf...)\r\n * -including the specific options available\r\n *\r\n * @param scene defines the scene the material will be created in\r\n * @param data defines the mtl data to parse\r\n * @param rootUrl defines the rooturl to use in order to load relative dependencies\r\n * @param assetContainer defines the asset container to store the material in (can be null)\r\n */\r\n public parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, assetContainer: Nullable<AssetContainer>): void {\r\n if (data instanceof ArrayBuffer) {\r\n return;\r\n }\r\n\r\n //Split the lines from the file\r\n var lines = data.split('\\n');\r\n // whitespace char ie: [ \\t\\r\\n\\f]\r\n var delimiter_pattern = /\\s+/;\r\n //Array with RGB colors\r\n var color: number[];\r\n //New material\r\n var material: Nullable<StandardMaterial> = null;\r\n\r\n //Look at each line\r\n for (var i = 0; i < lines.length; i++) {\r\n var line = lines[i].trim();\r\n\r\n // Blank line or comment\r\n if (line.length === 0 || line.charAt(0) === '#') {\r\n continue;\r\n }\r\n\r\n //Get the first parameter (keyword)\r\n var pos = line.indexOf(' ');\r\n var key = (pos >= 0) ? line.substring(0, pos) : line;\r\n key = key.toLowerCase();\r\n\r\n //Get the data following the key\r\n var value: string = (pos >= 0) ? line.substring(pos + 1).trim() : \"\";\r\n\r\n //This mtl keyword will create the new material\r\n if (key === \"newmtl\") {\r\n //Check if it is the first material.\r\n // Materials specifications are described after this keyword.\r\n if (material) {\r\n //Add the previous material in the material array.\r\n this.materials.push(material);\r\n }\r\n //Create a new material.\r\n // value is the name of the material read in the mtl file\r\n\r\n scene._blockEntityCollection = !!assetContainer;\r\n material = new StandardMaterial(value, scene);\r\n material._parentContainer = assetContainer;\r\n scene._blockEntityCollection = false;\r\n } else if (key === \"kd\" && material) {\r\n // Diffuse color (color under white light) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.diffuseColor = Color3.FromArray(color);\r\n } else if (key === \"ka\" && material) {\r\n // Ambient color (color under shadow) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.ambientColor = Color3.FromArray(color);\r\n } else if (key === \"ks\" && material) {\r\n // Specular color (color when light is reflected from shiny surface) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set the color into the material\r\n material.specularColor = Color3.FromArray(color);\r\n } else if (key === \"ke\" && material) {\r\n // Emissive color using RGB values\r\n color = value.split(delimiter_pattern, 3).map(parseFloat);\r\n material.emissiveColor = Color3.FromArray(color);\r\n } else if (key === \"ns\" && material) {\r\n\r\n //value = \"Integer\"\r\n material.specularPower = parseFloat(value);\r\n } else if (key === \"d\" && material) {\r\n //d is dissolve for current material. It mean alpha for BABYLON\r\n material.alpha = parseFloat(value);\r\n\r\n //Texture\r\n //This part can be improved by adding the possible options of texture\r\n } else if (key === \"map_ka\" && material) {\r\n // ambient texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.ambientTexture = MTLFileLoader._getTexture(rootUrl, value, scene);\r\n } else if (key === \"map_kd\" && material) {\r\n // Diffuse texture map with a loaded image\r\n material.diffuseTexture = MTLFileLoader._getTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ks\" && material) {\r\n // Specular texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.specularTexture = MTLFileLoader._getTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ns\") {\r\n //Specular\r\n //Specular highlight component\r\n //We must first get the folder of the image\r\n //\r\n //Not supported by BABYLON\r\n //\r\n // continue;\r\n } else if (key === \"map_bump\" && material) {\r\n //The bump texture\r\n const values = value.split(delimiter_pattern);\r\n const bumpMultiplierIndex = values.indexOf('-bm');\r\n let bumpMultiplier: Nullable<string> = null;\r\n\r\n if (bumpMultiplierIndex >= 0) {\r\n bumpMultiplier = values[bumpMultiplierIndex + 1];\r\n values.splice(bumpMultiplierIndex, 2); // remove\r\n }\r\n\r\n material.bumpTexture = MTLFileLoader._getTexture(rootUrl, values.join(' '), scene);\r\n if (material.bumpTexture && bumpMultiplier !== null) {\r\n material.bumpTexture.level = parseFloat(bumpMultiplier);\r\n }\r\n } else if (key === \"map_d\" && material) {\r\n // The dissolve of the material\r\n material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);\r\n\r\n //Options for illumination\r\n } else if (key === \"illum\") {\r\n //Illumination\r\n if (value === \"0\") {\r\n //That mean Kd == Kd\r\n } else if (value === \"1\") {\r\n //Color on and Ambient on\r\n } else if (value === \"2\") {\r\n //Highlight on\r\n } else if (value === \"3\") {\r\n //Reflection on and Ray trace on\r\n } else if (value === \"4\") {\r\n //Transparency: Glass on, Reflection: Ray trace on\r\n } else if (value === \"5\") {\r\n //Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"6\") {\r\n //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on\r\n } else if (value === \"7\") {\r\n //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"8\") {\r\n //Reflection on and Ray trace off\r\n } else if (value === \"9\") {\r\n //Transparency: Glass on, Reflection: Ray trace off\r\n } else if (value === \"10\") {\r\n //Casts shadows onto invisible surfaces\r\n }\r\n } else {\r\n // console.log(\"Unhandled expression at line : \" + i +'\\n' + \"with value : \" + line);\r\n }\r\n }\r\n //At the end of the file, add the last material\r\n if (material) {\r\n this.materials.push(material);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the texture for the material.\r\n *\r\n * If the material is imported from input file,\r\n * We sanitize the url to ensure it takes the textre from aside the material.\r\n *\r\n * @param rootUrl The root url to load from\r\n * @param value The value stored in the mtl\r\n * @return The Texture\r\n */\r\n private static _getTexture(rootUrl: string, value: string, scene: Scene): Nullable<Texture> {\r\n if (!value) {\r\n return null;\r\n }\r\n\r\n var url = rootUrl;\r\n // Load from input file.\r\n if (rootUrl === \"file:\") {\r\n var lastDelimiter = value.lastIndexOf(\"\\\\\");\r\n if (lastDelimiter === -1) {\r\n lastDelimiter = value.lastIndexOf(\"/\");\r\n }\r\n\r\n if (lastDelimiter > -1) {\r\n url += value.substr(lastDelimiter + 1);\r\n }\r\n else {\r\n url += value;\r\n }\r\n }\r\n // Not from input file.\r\n else {\r\n url += value;\r\n }\r\n\r\n return new Texture(url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"mtlFileLoader.js","sourceRoot":"","sources":["../../../../../lts/loaders/generated/OBJ/mtlFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,sDAAwC;AAInE;;GAEG;AACH;IAAA;QAMI;;WAEG;QACI,cAAS,GAAuB,EAAE,CAAC;IA+M9C,CAAC;IA7MG;;;;;;;;;;OAUG;IACI,gCAAQ,GAAf,UAAgB,KAAY,EAAE,IAA0B,EAAE,OAAe,EAAE,cAAwC;QAC/G,IAAI,IAAI,YAAY,WAAW,EAAE;YAC7B,OAAO;SACV;QAED,+BAA+B;QAC/B,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/B,kCAAkC;QAClC,IAAM,iBAAiB,GAAG,KAAK,CAAC;QAChC,uBAAuB;QACvB,IAAI,KAAe,CAAC;QACpB,cAAc;QACd,IAAI,QAAQ,GAA+B,IAAI,CAAC;QAEhD,mBAAmB;QACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACnC,IAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAE7B,wBAAwB;YACxB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;gBAC7C,SAAS;aACZ;YAED,mCAAmC;YACnC,IAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YA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QACxB,IAAI,OAAO,KAAK,OAAO,EAAE;YACrB,IAAI,aAAa,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YAC5C,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE;gBACtB,aAAa,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;aAC1C;YAED,IAAI,aAAa,GAAG,CAAC,CAAC,EAAE;gBACpB,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;aAC1C;iBAAM;gBACH,GAAG,IAAI,KAAK,CAAC;aAChB;SACJ;QACD,uBAAuB;aAClB;YACD,GAAG,IAAI,KAAK,CAAC;SAChB;QAED,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAC1E,CAAC;IAtND;;OAEG;IACW,8BAAgB,GAAG,IAAI,CAAC;IAoN1C,oBAAC;CAAA,AAxND,IAwNC;SAxNY,aAAa","sourcesContent":["import { Nullable } from \"core/types\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\n\r\nimport { Scene } from \"core/scene\";\r\nimport { AssetContainer } from \"core/assetContainer\";\r\n/**\r\n * Class reading and parsing the MTL file bundled with the obj file.\r\n */\r\nexport class MTLFileLoader {\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n public static INVERT_TEXTURE_Y = true;\r\n\r\n /**\r\n * All material loaded from the mtl will be set here\r\n */\r\n public materials: StandardMaterial[] = [];\r\n\r\n /**\r\n * This function will read the mtl file and create each material described inside\r\n * This function could be improve by adding :\r\n * -some component missing (Ni, Tf...)\r\n * -including the specific options available\r\n *\r\n * @param scene defines the scene the material will be created in\r\n * @param data defines the mtl data to parse\r\n * @param rootUrl defines the rooturl to use in order to load relative dependencies\r\n * @param assetContainer defines the asset container to store the material in (can be null)\r\n */\r\n public parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, assetContainer: Nullable<AssetContainer>): void {\r\n if (data instanceof ArrayBuffer) {\r\n return;\r\n }\r\n\r\n //Split the lines from the file\r\n const lines = data.split(\"\\n\");\r\n // whitespace char ie: [ \\t\\r\\n\\f]\r\n const delimiter_pattern = /\\s+/;\r\n //Array with RGB colors\r\n let color: number[];\r\n //New material\r\n let material: Nullable<StandardMaterial> = null;\r\n\r\n //Look at each line\r\n for (let i = 0; i < lines.length; i++) {\r\n const line = lines[i].trim();\r\n\r\n // Blank line or comment\r\n if (line.length === 0 || line.charAt(0) === \"#\") {\r\n continue;\r\n }\r\n\r\n //Get the first parameter (keyword)\r\n const pos = line.indexOf(\" \");\r\n let key = pos >= 0 ? line.substring(0, pos) : line;\r\n key = key.toLowerCase();\r\n\r\n //Get the data following the key\r\n const value: string = pos >= 0 ? line.substring(pos + 1).trim() : \"\";\r\n\r\n //This mtl keyword will create the new material\r\n if (key === \"newmtl\") {\r\n //Check if it is the first material.\r\n // Materials specifications are described after this keyword.\r\n if (material) {\r\n //Add the previous material in the material array.\r\n this.materials.push(material);\r\n }\r\n //Create a new material.\r\n // value is the name of the material read in the mtl file\r\n\r\n scene._blockEntityCollection = !!assetContainer;\r\n material = new StandardMaterial(value, scene);\r\n material._parentContainer = assetContainer;\r\n scene._blockEntityCollection = false;\r\n } else if (key === \"kd\" && material) {\r\n // Diffuse color (color under white light) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.diffuseColor = Color3.FromArray(color);\r\n } else if (key === \"ka\" && material) {\r\n // Ambient color (color under shadow) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.ambientColor = Color3.FromArray(color);\r\n } else if (key === \"ks\" && material) {\r\n // Specular color (color when light is reflected from shiny surface) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set the color into the material\r\n material.specularColor = Color3.FromArray(color);\r\n } else if (key === \"ke\" && material) {\r\n // Emissive color using RGB values\r\n color = value.split(delimiter_pattern, 3).map(parseFloat);\r\n material.emissiveColor = Color3.FromArray(color);\r\n } else if (key === \"ns\" && material) {\r\n //value = \"Integer\"\r\n material.specularPower = parseFloat(value);\r\n } else if (key === \"d\" && material) {\r\n //d is dissolve for current material. It mean alpha for BABYLON\r\n material.alpha = parseFloat(value);\r\n\r\n //Texture\r\n //This part can be improved by adding the possible options of texture\r\n } else if (key === \"map_ka\" && material) {\r\n // ambient texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.ambientTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_kd\" && material) {\r\n // Diffuse texture map with a loaded image\r\n material.diffuseTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ks\" && material) {\r\n // Specular texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.specularTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ns\") {\r\n //Specular\r\n //Specular highlight component\r\n //We must first get the folder of the image\r\n //\r\n //Not supported by BABYLON\r\n //\r\n // continue;\r\n } else if (key === \"map_bump\" && material) {\r\n //The bump texture\r\n const values = value.split(delimiter_pattern);\r\n const bumpMultiplierIndex = values.indexOf(\"-bm\");\r\n let bumpMultiplier: Nullable<string> = null;\r\n\r\n if (bumpMultiplierIndex >= 0) {\r\n bumpMultiplier = values[bumpMultiplierIndex + 1];\r\n values.splice(bumpMultiplierIndex, 2); // remove\r\n }\r\n\r\n material.bumpTexture = MTLFileLoader._GetTexture(rootUrl, values.join(\" \"), scene);\r\n if (material.bumpTexture && bumpMultiplier !== null) {\r\n material.bumpTexture.level = parseFloat(bumpMultiplier);\r\n }\r\n } else if (key === \"map_d\" && material) {\r\n // The dissolve of the material\r\n material.opacityTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n\r\n //Options for illumination\r\n } else if (key === \"illum\") {\r\n //Illumination\r\n if (value === \"0\") {\r\n //That mean Kd == Kd\r\n } else if (value === \"1\") {\r\n //Color on and Ambient on\r\n } else if (value === \"2\") {\r\n //Highlight on\r\n } else if (value === \"3\") {\r\n //Reflection on and Ray trace on\r\n } else if (value === \"4\") {\r\n //Transparency: Glass on, Reflection: Ray trace on\r\n } else if (value === \"5\") {\r\n //Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"6\") {\r\n //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on\r\n } else if (value === \"7\") {\r\n //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"8\") {\r\n //Reflection on and Ray trace off\r\n } else if (value === \"9\") {\r\n //Transparency: Glass on, Reflection: Ray trace off\r\n } else if (value === \"10\") {\r\n //Casts shadows onto invisible surfaces\r\n }\r\n } else {\r\n // console.log(\"Unhandled expression at line : \" + i +'\\n' + \"with value : \" + line);\r\n }\r\n }\r\n //At the end of the file, add the last material\r\n if (material) {\r\n this.materials.push(material);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the texture for the material.\r\n *\r\n * If the material is imported from input file,\r\n * We sanitize the url to ensure it takes the texture from aside the material.\r\n *\r\n * @param rootUrl The root url to load from\r\n * @param value The value stored in the mtl\r\n * @param scene\r\n * @return The Texture\r\n */\r\n private static _GetTexture(rootUrl: string, value: string, scene: Scene): Nullable<Texture> {\r\n if (!value) {\r\n return null;\r\n }\r\n\r\n let url = rootUrl;\r\n // Load from input file.\r\n if (rootUrl === \"file:\") {\r\n let lastDelimiter = value.lastIndexOf(\"\\\\\");\r\n if (lastDelimiter === -1) {\r\n lastDelimiter = value.lastIndexOf(\"/\");\r\n }\r\n\r\n if (lastDelimiter > -1) {\r\n url += value.substr(lastDelimiter + 1);\r\n } else {\r\n url += value;\r\n }\r\n }\r\n // Not from input file.\r\n else {\r\n url += value;\r\n }\r\n\r\n return new Texture(url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);\r\n }\r\n}\r\n"]}
@@ -1,7 +1,7 @@
1
- import { Vector2 } from "@babylonjs/core/Maths/math.vector";
2
- import { ISceneLoaderPluginAsync, ISceneLoaderProgressEvent, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult } from "@babylonjs/core/Loading/sceneLoader";
3
- import { AssetContainer } from "@babylonjs/core/assetContainer";
4
- import { Scene } from "@babylonjs/core/scene";
1
+ import { Vector2 } from "@babylonjs/core/Maths/math.vector.js";
2
+ import { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult } from "@babylonjs/core/Loading/sceneLoader.js";
3
+ import { AssetContainer } from "@babylonjs/core/assetContainer.js";
4
+ import { Scene } from "@babylonjs/core/scene.js";
5
5
  import { OBJLoadingOptions } from "./objLoadingOptions";
6
6
  /**
7
7
  * OBJ file type loader.
@@ -64,7 +64,7 @@ export declare class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoa
64
64
  * @param loadingOptions options for loading and parsing OBJ/MTL files.
65
65
  */
66
66
  constructor(loadingOptions?: OBJLoadingOptions);
67
- private static get DefaultLoadingOptions();
67
+ private static get _DefaultLoadingOptions();
68
68
  /**
69
69
  * Calls synchronously the MTL file attached to this obj.
70
70
  * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
@@ -74,6 +74,7 @@ export declare class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoa
74
74
  * @param url The URL of the MTL file
75
75
  * @param rootUrl defines where to load data from
76
76
  * @param onSuccess Callback function to be called when the MTL file is loaded
77
+ * @param onFailure
77
78
  */
78
79
  private _loadMTL;
79
80
  /**
@@ -83,42 +84,34 @@ export declare class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoa
83
84
  createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
84
85
  /**
85
86
  * If the data string can be loaded directly.
86
- *
87
- * @param data string containing the file data
88
87
  * @returns if the data can be loaded directly
89
88
  */
90
- canDirectLoad(data: string): boolean;
89
+ canDirectLoad(): boolean;
91
90
  /**
92
91
  * Imports one or more meshes from the loaded OBJ data and adds them to the scene
93
92
  * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
94
93
  * @param scene the scene the meshes should be added to
95
94
  * @param data the OBJ data to load
96
95
  * @param rootUrl root url to load from
97
- * @param onProgress event that fires when loading progress has occured
98
- * @param fileName Defines the name of the file to load
99
- * @returns a promise containg the loaded meshes, particles, skeletons and animations
96
+ * @returns a promise containing the loaded meshes, particles, skeletons and animations
100
97
  */
101
- importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<ISceneLoaderAsyncResult>;
98
+ importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string): Promise<ISceneLoaderAsyncResult>;
102
99
  /**
103
100
  * Imports all objects from the loaded OBJ data and adds them to the scene
104
101
  * @param scene the scene the objects should be added to
105
102
  * @param data the OBJ data to load
106
103
  * @param rootUrl root url to load from
107
- * @param onProgress event that fires when loading progress has occured
108
- * @param fileName Defines the name of the file to load
109
104
  * @returns a promise which completes when objects have been loaded to the scene
110
105
  */
111
- loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
106
+ loadAsync(scene: Scene, data: string, rootUrl: string): Promise<void>;
112
107
  /**
113
108
  * Load into an asset container.
114
109
  * @param scene The scene to load into
115
110
  * @param data The data to import
116
111
  * @param rootUrl The root url for scene and resources
117
- * @param onProgress The callback when the load progresses
118
- * @param fileName Defines the name of the file to load
119
112
  * @returns The loaded asset container
120
113
  */
121
- loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
114
+ loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string): Promise<AssetContainer>;
122
115
  /**
123
116
  * Read the OBJ file and create an Array of meshes.
124
117
  * Each mesh contains all information given by the OBJ and the MTL file.
@@ -2,7 +2,7 @@ import { Vector2 } from "@babylonjs/core/Maths/math.vector.js";
2
2
  import { Tools } from "@babylonjs/core/Misc/tools.js";
3
3
  import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
4
4
  import { AssetContainer } from "@babylonjs/core/assetContainer.js";
5
- import { MTLFileLoader } from './mtlFileLoader.js';
5
+ import { MTLFileLoader } from "./mtlFileLoader.js";
6
6
  import { SolidParser } from "./solidParser.js";
7
7
  /**
8
8
  * OBJ file type loader.
@@ -24,7 +24,7 @@ var OBJFileLoader = /** @class */ (function () {
24
24
  */
25
25
  this.extensions = ".obj";
26
26
  this._assetContainer = null;
27
- this._loadingOptions = loadingOptions || OBJFileLoader.DefaultLoadingOptions;
27
+ this._loadingOptions = loadingOptions || OBJFileLoader._DefaultLoadingOptions;
28
28
  }
29
29
  Object.defineProperty(OBJFileLoader, "INVERT_TEXTURE_Y", {
30
30
  /**
@@ -39,7 +39,7 @@ var OBJFileLoader = /** @class */ (function () {
39
39
  enumerable: false,
40
40
  configurable: true
41
41
  });
42
- Object.defineProperty(OBJFileLoader, "DefaultLoadingOptions", {
42
+ Object.defineProperty(OBJFileLoader, "_DefaultLoadingOptions", {
43
43
  get: function () {
44
44
  return {
45
45
  computeNormals: OBJFileLoader.COMPUTE_NORMALS,
@@ -47,10 +47,11 @@ var OBJFileLoader = /** @class */ (function () {
47
47
  importVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
48
48
  invertY: OBJFileLoader.INVERT_Y,
49
49
  invertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
50
+ // eslint-disable-next-line @typescript-eslint/naming-convention
50
51
  UVScaling: OBJFileLoader.UV_SCALING,
51
52
  materialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
52
53
  optimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
53
- skipMaterials: OBJFileLoader.SKIP_MATERIALS
54
+ skipMaterials: OBJFileLoader.SKIP_MATERIALS,
54
55
  };
55
56
  },
56
57
  enumerable: false,
@@ -65,6 +66,7 @@ var OBJFileLoader = /** @class */ (function () {
65
66
  * @param url The URL of the MTL file
66
67
  * @param rootUrl defines where to load data from
67
68
  * @param onSuccess Callback function to be called when the MTL file is loaded
69
+ * @param onFailure
68
70
  */
69
71
  OBJFileLoader.prototype._loadMTL = function (url, rootUrl, onSuccess, onFailure) {
70
72
  //The complete path to the mtl file
@@ -79,15 +81,13 @@ var OBJFileLoader = /** @class */ (function () {
79
81
  * @returns the created plugin
80
82
  */
81
83
  OBJFileLoader.prototype.createPlugin = function () {
82
- return new OBJFileLoader(OBJFileLoader.DefaultLoadingOptions);
84
+ return new OBJFileLoader(OBJFileLoader._DefaultLoadingOptions);
83
85
  };
84
86
  /**
85
87
  * If the data string can be loaded directly.
86
- *
87
- * @param data string containing the file data
88
88
  * @returns if the data can be loaded directly
89
89
  */
90
- OBJFileLoader.prototype.canDirectLoad = function (data) {
90
+ OBJFileLoader.prototype.canDirectLoad = function () {
91
91
  return false;
92
92
  };
93
93
  /**
@@ -96,11 +96,9 @@ var OBJFileLoader = /** @class */ (function () {
96
96
  * @param scene the scene the meshes should be added to
97
97
  * @param data the OBJ data to load
98
98
  * @param rootUrl root url to load from
99
- * @param onProgress event that fires when loading progress has occured
100
- * @param fileName Defines the name of the file to load
101
- * @returns a promise containg the loaded meshes, particles, skeletons and animations
99
+ * @returns a promise containing the loaded meshes, particles, skeletons and animations
102
100
  */
103
- OBJFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
101
+ OBJFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl) {
104
102
  //get the meshes from OBJ file
105
103
  return this._parseSolid(meshesNames, scene, data, rootUrl).then(function (meshes) {
106
104
  return {
@@ -110,7 +108,7 @@ var OBJFileLoader = /** @class */ (function () {
110
108
  animationGroups: [],
111
109
  transformNodes: [],
112
110
  geometries: [],
113
- lights: []
111
+ lights: [],
114
112
  };
115
113
  });
116
114
  };
@@ -119,13 +117,11 @@ var OBJFileLoader = /** @class */ (function () {
119
117
  * @param scene the scene the objects should be added to
120
118
  * @param data the OBJ data to load
121
119
  * @param rootUrl root url to load from
122
- * @param onProgress event that fires when loading progress has occured
123
- * @param fileName Defines the name of the file to load
124
120
  * @returns a promise which completes when objects have been loaded to the scene
125
121
  */
126
- OBJFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
122
+ OBJFileLoader.prototype.loadAsync = function (scene, data, rootUrl) {
127
123
  //Get the 3D model
128
- return this.importMeshAsync(null, scene, data, rootUrl, onProgress).then(function () {
124
+ return this.importMeshAsync(null, scene, data, rootUrl).then(function () {
129
125
  // return void
130
126
  });
131
127
  };
@@ -134,15 +130,14 @@ var OBJFileLoader = /** @class */ (function () {
134
130
  * @param scene The scene to load into
135
131
  * @param data The data to import
136
132
  * @param rootUrl The root url for scene and resources
137
- * @param onProgress The callback when the load progresses
138
- * @param fileName Defines the name of the file to load
139
133
  * @returns The loaded asset container
140
134
  */
141
- OBJFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
135
+ OBJFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl) {
142
136
  var _this = this;
143
137
  var container = new AssetContainer(scene);
144
138
  this._assetContainer = container;
145
- return this.importMeshAsync(null, scene, data, rootUrl).then(function (result) {
139
+ return this.importMeshAsync(null, scene, data, rootUrl)
140
+ .then(function (result) {
146
141
  result.meshes.forEach(function (mesh) { return container.meshes.push(mesh); });
147
142
  result.meshes.forEach(function (mesh) {
148
143
  var material = mesh.material;
@@ -162,7 +157,8 @@ var OBJFileLoader = /** @class */ (function () {
162
157
  });
163
158
  _this._assetContainer = null;
164
159
  return container;
165
- }).catch(function (ex) {
160
+ })
161
+ .catch(function (ex) {
166
162
  _this._assetContainer = null;
167
163
  throw ex;
168
164
  });
@@ -203,7 +199,7 @@ var OBJFileLoader = /** @class */ (function () {
203
199
  //Three variables to get all meshes with the same material
204
200
  var startIndex = 0;
205
201
  var _indices = [];
206
- var _index;
202
+ var _index = void 0;
207
203
  //The material from MTL file is used in the meshes loaded
208
204
  //Push the indice in an array
209
205
  //Check if the material is not used for another mesh
@@ -1 +1 @@
1
- {"version":3,"file":"objFileLoader.js","sourceRoot":"","sources":["../../../sourceES6/loaders/src/OBJ/objFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAEnD,OAAO,EAAE,WAAW,EAA8H,MAAM,qCAAqC,CAAC;AAC9L,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C;;;GAGG;AACH;IA8DI;;;;OAIG;IACH,uBAAY,cAAkC;QAlB9C;;WAEG;QACI,SAAI,GAAG,KAAK,CAAC;QACpB;;WAEG;QACI,eAAU,GAAG,MAAM,CAAC;QAEnB,oBAAe,GAA6B,IAAI,CAAC;QAUrD,IAAI,CAAC,eAAe,GAAG,cAAc,IAAI,aAAa,CAAC,qBAAqB,CAAC;IACjF,CAAC;IAxDD,sBAAkB,iCAAgB;QAHlC;;WAEG;aACH;YACI,OAAO,aAAa,CAAC,gBAAgB,CAAC;QAC1C,CAAC;aAED,UAAmC,KAAc;YAC7C,aAAa,CAAC,gBAAgB,GAAG,KAAK,CAAC;QAC3C,CAAC;;;OAJA;IAwDD,sBAAmB,sCAAqB;aAAxC;YACI,OAAO;gBACH,cAAc,EAAE,aAAa,CAAC,eAAe;gBAC7C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U,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7C;;OAEG;IACW,4BAAc,GAAG,KAAK,CAAC;IAErC;;;;OAIG;IACW,6CAA+B,GAAG,IAAI,CAAC;IA8PzD,oBAAC;CAAA,AA9SD,IA8SC;SA9SY,aAAa;AAgT1B,IAAI,WAAW,EAAE;IACb,0CAA0C;IAC1C,WAAW,CAAC,cAAc,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;CACnD","sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\nimport { Vector2 } from \"@babylonjs/core/Maths/math.vector\";\nimport { Tools } from \"@babylonjs/core/Misc/tools\";\nimport { AbstractMesh } from \"@babylonjs/core/Meshes/abstractMesh\";\nimport { SceneLoader, ISceneLoaderPluginAsync, ISceneLoaderProgressEvent, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult } from \"@babylonjs/core/Loading/sceneLoader\";\nimport { AssetContainer } from \"@babylonjs/core/assetContainer\";\nimport { Scene } from \"@babylonjs/core/scene\";\nimport { WebRequest } from '@babylonjs/core/Misc/webRequest';\nimport { MTLFileLoader } from './mtlFileLoader';\nimport { OBJLoadingOptions } from \"./objLoadingOptions\";\nimport { SolidParser } from \"./solidParser\";\nimport { Mesh } from \"@babylonjs/core/Meshes/mesh\";\n\n/**\n * OBJ file type loader.\n * This is a babylon scene loader plugin.\n */\nexport class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {\n\n /**\n * Defines if UVs are optimized by default during load.\n */\n public static OPTIMIZE_WITH_UV = true;\n /**\n * Invert model on y-axis (does a model scaling inversion)\n */\n public static INVERT_Y = false;\n /**\n * Invert Y-Axis of referenced textures on load\n */\n public static get INVERT_TEXTURE_Y() {\n return MTLFileLoader.INVERT_TEXTURE_Y;\n }\n\n public static set INVERT_TEXTURE_Y(value: boolean) {\n MTLFileLoader.INVERT_TEXTURE_Y = value;\n }\n\n /**\n * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.\n */\n public static IMPORT_VERTEX_COLORS = false;\n /**\n * Compute the normals for the model, even if normals are present in the file.\n */\n public static COMPUTE_NORMALS = false;\n /**\n * Optimize the normals for the model. Lighting can be uneven if you use OptimizeWithUV = true because new vertices can be created for the same location if they pertain to different faces.\n * Using OptimizehNormals = true will help smoothing the lighting by averaging the normals of those vertices.\n */\n public static OPTIMIZE_NORMALS = false;\n /**\n * Defines custom scaling of UV coordinates of loaded meshes.\n */\n public static UV_SCALING = new Vector2(1, 1);\n /**\n * Skip loading the materials even if defined in the OBJ file (materials are ignored).\n */\n public static SKIP_MATERIALS = false;\n\n /**\n * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.\n *\n * Defaults to true for backwards compatibility.\n */\n public static MATERIAL_LOADING_FAILS_SILENTLY = true;\n /**\n * Defines the name of the plugin.\n */\n public name = \"obj\";\n /**\n * Defines the extension the plugin is able to load.\n */\n public extensions = \".obj\";\n\n private _assetContainer: Nullable<AssetContainer> = null;\n\n private _loadingOptions: OBJLoadingOptions;\n\n /**\n * Creates loader for .OBJ files\n *\n * @param loadingOptions options for loading and parsing OBJ/MTL files.\n */\n constructor(loadingOptions?: OBJLoadingOptions) {\n this._loadingOptions = loadingOptions || OBJFileLoader.DefaultLoadingOptions;\n }\n\n private static get DefaultLoadingOptions(): OBJLoadingOptions {\n return {\n computeNormals: OBJFileLoader.COMPUTE_NORMALS,\n optimizeNormals: OBJFileLoader.OPTIMIZE_NORMALS,\n importVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,\n invertY: OBJFileLoader.INVERT_Y,\n invertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,\n UVScaling: OBJFileLoader.UV_SCALING,\n materialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,\n optimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,\n skipMaterials: OBJFileLoader.SKIP_MATERIALS\n };\n }\n\n /**\n * Calls synchronously the MTL file attached to this obj.\n * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.\n * Without this function materials are not displayed in the first frame (but displayed after).\n * In consequence it is impossible to get material information in your HTML file\n *\n * @param url The URL of the MTL file\n * @param rootUrl defines where to load data from\n * @param onSuccess Callback function to be called when the MTL file is loaded\n */\n private _loadMTL(url: string, rootUrl: string, onSuccess: (response: string | ArrayBuffer, responseUrl?: string) => any, onFailure: (pathOfFile: string, exception?: any) => void) {\n //The complete path to the mtl file\n var pathOfFile = rootUrl + url;\n\n // Loads through the babylon tools to allow fileInput search.\n Tools.LoadFile(\n pathOfFile,\n onSuccess,\n undefined,\n undefined,\n false,\n (request?: WebRequest | undefined, exception?: any) => {\n onFailure(pathOfFile, exception);\n }\n );\n }\n\n /**\n * Instantiates a OBJ file loader plugin.\n * @returns the created plugin\n */\n createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin {\n return new OBJFileLoader(OBJFileLoader.DefaultLoadingOptions);\n }\n\n /**\n * If the data string can be loaded directly.\n *\n * @param data string containing the file data\n * @returns if the data can be loaded directly\n */\n public canDirectLoad(data: string): boolean {\n return false;\n }\n\n /**\n * Imports one or more meshes from the loaded OBJ data and adds them to the scene\n * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file\n * @param scene the scene the meshes should be added to\n * @param data the OBJ data to load\n * @param rootUrl root url to load from\n * @param onProgress event that fires when loading progress has occured\n * @param fileName Defines the name of the file to load\n * @returns a promise containg the loaded meshes, particles, skeletons and animations\n */\n public importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<ISceneLoaderAsyncResult> {\n //get the meshes from OBJ file\n return this._parseSolid(meshesNames, scene, data, rootUrl).then((meshes) => {\n return {\n meshes: meshes,\n particleSystems: [],\n skeletons: [],\n animationGroups: [],\n transformNodes: [],\n geometries: [],\n lights: []\n };\n });\n }\n\n /**\n * Imports all objects from the loaded OBJ data and adds them to the scene\n * @param scene the scene the objects should be added to\n * @param data the OBJ data to load\n * @param rootUrl root url to load from\n * @param onProgress event that fires when loading progress has occured\n * @param fileName Defines the name of the file to load\n * @returns a promise which completes when objects have been loaded to the scene\n */\n public loadAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void> {\n //Get the 3D model\n return this.importMeshAsync(null, scene, data, rootUrl, onProgress).then(() => {\n // return void\n });\n }\n\n /**\n * Load into an asset container.\n * @param scene The scene to load into\n * @param data The data to import\n * @param rootUrl The root url for scene and resources\n * @param onProgress The callback when the load progresses\n * @param fileName Defines the name of the file to load\n * @returns The loaded asset container\n */\n public loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer> {\n var container = new AssetContainer(scene);\n this._assetContainer = container;\n\n return this.importMeshAsync(null, scene, data, rootUrl).then((result) => {\n result.meshes.forEach((mesh) => container.meshes.push(mesh));\n result.meshes.forEach((mesh) => {\n var material = mesh.material;\n if (material) {\n // Materials\n if (container.materials.indexOf(material) == -1) {\n container.materials.push(material);\n\n // Textures\n var textures = material.getActiveTextures();\n textures.forEach((t) => {\n if (container.textures.indexOf(t) == -1) {\n container.textures.push(t);\n }\n });\n }\n }\n });\n this._assetContainer = null;\n return container;\n }).catch((ex) => {\n this._assetContainer = null;\n throw ex;\n });\n }\n\n /**\n * Read the OBJ file and create an Array of meshes.\n * Each mesh contains all information given by the OBJ and the MTL file.\n * i.e. vertices positions and indices, optional normals values, optional UV values, optional material\n * @param meshesNames defines a string or array of strings of the mesh names that should be loaded from the file\n * @param scene defines the scene where are displayed the data\n * @param data defines the content of the obj file\n * @param rootUrl defines the path to the folder\n * @returns the list of loaded meshes\n */\n private _parseSolid(meshesNames: any, scene: Scene, data: string, rootUrl: string): Promise<Array<AbstractMesh>> {\n var fileToLoad: string = \"\"; //The name of the mtlFile to load\n var materialsFromMTLFile: MTLFileLoader = new MTLFileLoader();\n var materialToUse = new Array<string>();\n var babylonMeshesArray: Array<Mesh> = []; //The mesh for babylon\n\n // Main function\n const solidParser = new SolidParser(materialToUse, babylonMeshesArray, this._loadingOptions);\n\n solidParser.parse(meshesNames, data, scene, this._assetContainer, (fileName: string) => {\n fileToLoad = fileName;\n });\n\n // load the materials\n let mtlPromises: Array<Promise<void>> = [];\n // Check if we have a file to load\n if (fileToLoad !== \"\" && !this._loadingOptions.skipMaterials) {\n //Load the file synchronously\n mtlPromises.push(new Promise((resolve, reject) => {\n this._loadMTL(fileToLoad, rootUrl, (dataLoaded) => {\n try {\n //Create materials thanks MTLLoader function\n materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, this._assetContainer);\n //Look at each material loaded in the mtl file\n for (var n = 0; n < materialsFromMTLFile.materials.length; n++) {\n //Three variables to get all meshes with the same material\n var startIndex = 0;\n var _indices = [];\n var _index;\n\n //The material from MTL file is used in the meshes loaded\n //Push the indice in an array\n //Check if the material is not used for another mesh\n while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {\n _indices.push(_index);\n startIndex = _index + 1;\n }\n //If the material is not used dispose it\n if (_index === -1 && _indices.length === 0) {\n //If the material is not needed, remove it\n materialsFromMTLFile.materials[n].dispose();\n } else {\n for (var o = 0; o < _indices.length; o++) {\n //Apply the material to the Mesh for each mesh with the material\n const mesh = babylonMeshesArray[_indices[o]];\n const material = materialsFromMTLFile.materials[n];\n mesh.material = material;\n\n if (!mesh.getTotalIndices()) {\n // No indices, we need to turn on point cloud\n material.pointsCloud = true;\n }\n }\n }\n }\n resolve();\n } catch (e) {\n Tools.Warn(`Error processing MTL file: '${fileToLoad}'`);\n if (this._loadingOptions.materialLoadingFailsSilently) {\n resolve();\n } else {\n reject(e);\n }\n }\n }, (pathOfFile: string, exception?: any) => {\n Tools.Warn(`Error downloading MTL file: '${fileToLoad}'`);\n if (this._loadingOptions.materialLoadingFailsSilently) {\n resolve();\n } else {\n reject(exception);\n }\n });\n }));\n\n }\n //Return an array with all Mesh\n return Promise.all(mtlPromises).then(() => {\n return babylonMeshesArray;\n });\n }\n\n}\n\nif (SceneLoader) {\n //Add this loader into the register plugin\n SceneLoader.RegisterPlugin(new OBJFileLoader());\n}"]}
1
+ {"version":3,"file":"objFileLoader.js","sourceRoot":"","sources":["../../../../../lts/loaders/generated/OBJ/objFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAExC,OAAO,EAAE,WAAW,EAAmG,+CAAiC;AACxJ,OAAO,EAAE,cAAc,EAAE,0CAA4B;AAGrD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C;;;GAGG;AACH;IA6DI;;;;OAIG;IACH,uBAAY,cAAkC;QAlB9C;;WAEG;QACI,SAAI,GAAG,KAAK,CAAC;QACpB;;WAEG;QACI,eAAU,GAAG,MAAM,CAAC;QAEnB,oBAAe,GAA6B,IAAI,CAAC;QAUrD,IAAI,CAAC,eAAe,GAAG,cAAc,IAAI,aAAa,CAAC,sBAAsB,CAAC;IAClF,CAAC;IAxDD,sBAAkB,iCAAgB;QAHlC;;WAEG;aACH;YACI,OAAO,aAAa,CAAC,gBAAgB,CAAC;QAC1C,CAAC;aAED,UAAmC,KAAc;YAC7C,aAAa,CAAC,gBAAgB,GAAG,KAAK,CAAC;QAC3C,CAAC;;;OAJA;IAwDD,sBAAmB,uCAAsB;aAAzC;YACI,OAAO;gBACH,cAAc,EAAE,aAAa,CAAC,eAAe;gBAC7C,eAAe,EAAE,aAAa,CAAC,gBAAgB;gBAC/C,kBAAkB,EAAE,aAAa,CAAC,oBAAoB;gBACtD,OAAO,EAAE,aAAa,CAAC,QAAQ;gBAC/B,cAAc,EAAE,aAAa,CAAC,gBAAgB;gBAC9C,gEAAgE;gBAChE,SAAS,EAAE,aAAa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","sourcesContent":["import { Nullable } from \"core/types\";\r\nimport { Vector2 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport { SceneLoader, ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult } from \"core/Loading/sceneLoader\";\r\nimport { AssetContainer } from \"core/assetContainer\";\r\nimport { Scene } from \"core/scene\";\r\nimport { WebRequest } from \"core/Misc/webRequest\";\r\nimport { MTLFileLoader } from \"./mtlFileLoader\";\r\nimport { OBJLoadingOptions } from \"./objLoadingOptions\";\r\nimport { SolidParser } from \"./solidParser\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\n\r\n/**\r\n * OBJ file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {\r\n /**\r\n * Defines if UVs are optimized by default during load.\r\n */\r\n public static OPTIMIZE_WITH_UV = true;\r\n /**\r\n * Invert model on y-axis (does a model scaling inversion)\r\n */\r\n public static INVERT_Y = false;\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n public static get INVERT_TEXTURE_Y() {\r\n return MTLFileLoader.INVERT_TEXTURE_Y;\r\n }\r\n\r\n public static set INVERT_TEXTURE_Y(value: boolean) {\r\n MTLFileLoader.INVERT_TEXTURE_Y = value;\r\n }\r\n\r\n /**\r\n * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.\r\n */\r\n public static IMPORT_VERTEX_COLORS = false;\r\n /**\r\n * Compute the normals for the model, even if normals are present in the file.\r\n */\r\n public static COMPUTE_NORMALS = false;\r\n /**\r\n * Optimize the normals for the model. Lighting can be uneven if you use OptimizeWithUV = true because new vertices can be created for the same location if they pertain to different faces.\r\n * Using OptimizehNormals = true will help smoothing the lighting by averaging the normals of those vertices.\r\n */\r\n public static OPTIMIZE_NORMALS = false;\r\n /**\r\n * Defines custom scaling of UV coordinates of loaded meshes.\r\n */\r\n public static UV_SCALING = new Vector2(1, 1);\r\n /**\r\n * Skip loading the materials even if defined in the OBJ file (materials are ignored).\r\n */\r\n public static SKIP_MATERIALS = false;\r\n\r\n /**\r\n * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.\r\n *\r\n * Defaults to true for backwards compatibility.\r\n */\r\n public static MATERIAL_LOADING_FAILS_SILENTLY = true;\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public name = \"obj\";\r\n /**\r\n * Defines the extension the plugin is able to load.\r\n */\r\n public extensions = \".obj\";\r\n\r\n private _assetContainer: Nullable<AssetContainer> = null;\r\n\r\n private _loadingOptions: OBJLoadingOptions;\r\n\r\n /**\r\n * Creates loader for .OBJ files\r\n *\r\n * @param loadingOptions options for loading and parsing OBJ/MTL files.\r\n */\r\n constructor(loadingOptions?: OBJLoadingOptions) {\r\n this._loadingOptions = loadingOptions || OBJFileLoader._DefaultLoadingOptions;\r\n }\r\n\r\n private static get _DefaultLoadingOptions(): OBJLoadingOptions {\r\n return {\r\n computeNormals: OBJFileLoader.COMPUTE_NORMALS,\r\n optimizeNormals: OBJFileLoader.OPTIMIZE_NORMALS,\r\n importVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,\r\n invertY: OBJFileLoader.INVERT_Y,\r\n invertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n UVScaling: OBJFileLoader.UV_SCALING,\r\n materialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,\r\n optimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,\r\n skipMaterials: OBJFileLoader.SKIP_MATERIALS,\r\n };\r\n }\r\n\r\n /**\r\n * Calls synchronously the MTL file attached to this obj.\r\n * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.\r\n * Without this function materials are not displayed in the first frame (but displayed after).\r\n * In consequence it is impossible to get material information in your HTML file\r\n *\r\n * @param url The URL of the MTL file\r\n * @param rootUrl defines where to load data from\r\n * @param onSuccess Callback function to be called when the MTL file is loaded\r\n * @param onFailure\r\n */\r\n private _loadMTL(\r\n url: string,\r\n rootUrl: string,\r\n onSuccess: (response: string | ArrayBuffer, responseUrl?: string) => any,\r\n onFailure: (pathOfFile: string, exception?: any) => void\r\n ) {\r\n //The complete path to the mtl file\r\n const pathOfFile = rootUrl + url;\r\n\r\n // Loads through the babylon tools to allow fileInput search.\r\n Tools.LoadFile(pathOfFile, onSuccess, undefined, undefined, false, (request?: WebRequest | undefined, exception?: any) => {\r\n onFailure(pathOfFile, exception);\r\n });\r\n }\r\n\r\n /**\r\n * Instantiates a OBJ file loader plugin.\r\n * @returns the created plugin\r\n */\r\n createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin {\r\n return new OBJFileLoader(OBJFileLoader._DefaultLoadingOptions);\r\n }\r\n\r\n /**\r\n * If the data string can be loaded directly.\r\n * @returns if the data can be loaded directly\r\n */\r\n public canDirectLoad(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Imports one or more meshes from the loaded OBJ data and adds them to the scene\r\n * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file\r\n * @param scene the scene the meshes should be added to\r\n * @param data the OBJ data to load\r\n * @param rootUrl root url to load from\r\n * @returns a promise containing the loaded meshes, particles, skeletons and animations\r\n */\r\n public importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string): Promise<ISceneLoaderAsyncResult> {\r\n //get the meshes from OBJ file\r\n return this._parseSolid(meshesNames, scene, data, rootUrl).then((meshes) => {\r\n return {\r\n meshes: meshes,\r\n particleSystems: [],\r\n skeletons: [],\r\n animationGroups: [],\r\n transformNodes: [],\r\n geometries: [],\r\n lights: [],\r\n };\r\n });\r\n }\r\n\r\n /**\r\n * Imports all objects from the loaded OBJ data and adds them to the scene\r\n * @param scene the scene the objects should be added to\r\n * @param data the OBJ data to load\r\n * @param rootUrl root url to load from\r\n * @returns a promise which completes when objects have been loaded to the scene\r\n */\r\n public loadAsync(scene: Scene, data: string, rootUrl: string): Promise<void> {\r\n //Get the 3D model\r\n return this.importMeshAsync(null, scene, data, rootUrl).then(() => {\r\n // return void\r\n });\r\n }\r\n\r\n /**\r\n * Load into an asset container.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @returns The loaded asset container\r\n */\r\n public loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string): Promise<AssetContainer> {\r\n const container = new AssetContainer(scene);\r\n this._assetContainer = container;\r\n\r\n return this.importMeshAsync(null, scene, data, rootUrl)\r\n .then((result) => {\r\n result.meshes.forEach((mesh) => container.meshes.push(mesh));\r\n result.meshes.forEach((mesh) => {\r\n const material = mesh.material;\r\n if (material) {\r\n // Materials\r\n if (container.materials.indexOf(material) == -1) {\r\n container.materials.push(material);\r\n\r\n // Textures\r\n const textures = material.getActiveTextures();\r\n textures.forEach((t) => {\r\n if (container.textures.indexOf(t) == -1) {\r\n container.textures.push(t);\r\n }\r\n });\r\n }\r\n }\r\n });\r\n this._assetContainer = null;\r\n return container;\r\n })\r\n .catch((ex) => {\r\n this._assetContainer = null;\r\n throw ex;\r\n });\r\n }\r\n\r\n /**\r\n * Read the OBJ file and create an Array of meshes.\r\n * Each mesh contains all information given by the OBJ and the MTL file.\r\n * i.e. vertices positions and indices, optional normals values, optional UV values, optional material\r\n * @param meshesNames defines a string or array of strings of the mesh names that should be loaded from the file\r\n * @param scene defines the scene where are displayed the data\r\n * @param data defines the content of the obj file\r\n * @param rootUrl defines the path to the folder\r\n * @returns the list of loaded meshes\r\n */\r\n private _parseSolid(meshesNames: any, scene: Scene, data: string, rootUrl: string): Promise<Array<AbstractMesh>> {\r\n let fileToLoad: string = \"\"; //The name of the mtlFile to load\r\n const materialsFromMTLFile: MTLFileLoader = new MTLFileLoader();\r\n const materialToUse = new Array<string>();\r\n const babylonMeshesArray: Array<Mesh> = []; //The mesh for babylon\r\n\r\n // Main function\r\n const solidParser = new SolidParser(materialToUse, babylonMeshesArray, this._loadingOptions);\r\n\r\n solidParser.parse(meshesNames, data, scene, this._assetContainer, (fileName: string) => {\r\n fileToLoad = fileName;\r\n });\r\n\r\n // load the materials\r\n const mtlPromises: Array<Promise<void>> = [];\r\n // Check if we have a file to load\r\n if (fileToLoad !== \"\" && !this._loadingOptions.skipMaterials) {\r\n //Load the file synchronously\r\n mtlPromises.push(\r\n new Promise((resolve, reject) => {\r\n this._loadMTL(\r\n fileToLoad,\r\n rootUrl,\r\n (dataLoaded) => {\r\n try {\r\n //Create materials thanks MTLLoader function\r\n materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, this._assetContainer);\r\n //Look at each material loaded in the mtl file\r\n for (let n = 0; n < materialsFromMTLFile.materials.length; n++) {\r\n //Three variables to get all meshes with the same material\r\n let startIndex = 0;\r\n const _indices = [];\r\n let _index;\r\n\r\n //The material from MTL file is used in the meshes loaded\r\n //Push the indice in an array\r\n //Check if the material is not used for another mesh\r\n while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {\r\n _indices.push(_index);\r\n startIndex = _index + 1;\r\n }\r\n //If the material is not used dispose it\r\n if (_index === -1 && _indices.length === 0) {\r\n //If the material is not needed, remove it\r\n materialsFromMTLFile.materials[n].dispose();\r\n } else {\r\n for (let o = 0; o < _indices.length; o++) {\r\n //Apply the material to the Mesh for each mesh with the material\r\n const mesh = babylonMeshesArray[_indices[o]];\r\n const material = materialsFromMTLFile.materials[n];\r\n mesh.material = material;\r\n\r\n if (!mesh.getTotalIndices()) {\r\n // No indices, we need to turn on point cloud\r\n material.pointsCloud = true;\r\n }\r\n }\r\n }\r\n }\r\n resolve();\r\n } catch (e) {\r\n Tools.Warn(`Error processing MTL file: '${fileToLoad}'`);\r\n if (this._loadingOptions.materialLoadingFailsSilently) {\r\n resolve();\r\n } else {\r\n reject(e);\r\n }\r\n }\r\n },\r\n (pathOfFile: string, exception?: any) => {\r\n Tools.Warn(`Error downloading MTL file: '${fileToLoad}'`);\r\n if (this._loadingOptions.materialLoadingFailsSilently) {\r\n resolve();\r\n } else {\r\n reject(exception);\r\n }\r\n }\r\n );\r\n })\r\n );\r\n }\r\n //Return an array with all Mesh\r\n return Promise.all(mtlPromises).then(() => {\r\n return babylonMeshesArray;\r\n });\r\n }\r\n}\r\n\r\nif (SceneLoader) {\r\n //Add this loader into the register plugin\r\n SceneLoader.RegisterPlugin(new OBJFileLoader());\r\n}\r\n"]}
@@ -1,4 +1,4 @@
1
- import { Vector2 } from "@babylonjs/core/Maths/math.vector";
1
+ import { Vector2 } from "@babylonjs/core/Maths/math.vector.js";
2
2
  /**
3
3
  * Options for loading OBJ/MTL files
4
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"objLoadingOptions.js","sourceRoot":"","sources":["../../../sourceES6/loaders/src/OBJ/objLoadingOptions.ts"],"names":[],"mappings":"","sourcesContent":["import { Vector2 } from \"@babylonjs/core/Maths/math.vector\";\r\n\r\n/**\r\n * Options for loading OBJ/MTL files\r\n */\r\nexport type OBJLoadingOptions = {\r\n /**\r\n * Defines if UVs are optimized by default during load.\r\n */\r\n optimizeWithUV: boolean,\r\n /**\r\n * Defines custom scaling of UV coordinates of loaded meshes.\r\n */\r\n UVScaling: Vector2;\r\n /**\r\n * Invert model on y-axis (does a model scaling inversion)\r\n */\r\n invertY: boolean,\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n invertTextureY: boolean;\r\n /**\r\n * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.\r\n */\r\n importVertexColors: boolean,\r\n /**\r\n * Compute the normals for the model, even if normals are present in the file.\r\n */\r\n computeNormals: boolean,\r\n /**\r\n * Optimize the normals for the model. Lighting can be uneven if you use OptimizeWithUV = true because new vertices can be created for the same location if they pertain to different faces.\r\n * Using OptimizehNormals = true will help smoothing the lighting by averaging the normals of those vertices.\r\n */\r\n optimizeNormals: boolean,\r\n /**\r\n * Skip loading the materials even if defined in the OBJ file (materials are ignored).\r\n */\r\n skipMaterials: boolean,\r\n /**\r\n * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.\r\n */\r\n materialLoadingFailsSilently: boolean\r\n};\r\n"]}
1
+ {"version":3,"file":"objLoadingOptions.js","sourceRoot":"","sources":["../../../../../lts/loaders/generated/OBJ/objLoadingOptions.ts"],"names":[],"mappings":"","sourcesContent":["import { Vector2 } from \"core/Maths/math.vector\";\r\n\r\n/**\r\n * Options for loading OBJ/MTL files\r\n */\r\nexport type OBJLoadingOptions = {\r\n /**\r\n * Defines if UVs are optimized by default during load.\r\n */\r\n optimizeWithUV: boolean;\r\n /**\r\n * Defines custom scaling of UV coordinates of loaded meshes.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n UVScaling: Vector2;\r\n /**\r\n * Invert model on y-axis (does a model scaling inversion)\r\n */\r\n invertY: boolean;\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n invertTextureY: boolean;\r\n /**\r\n * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.\r\n */\r\n importVertexColors: boolean;\r\n /**\r\n * Compute the normals for the model, even if normals are present in the file.\r\n */\r\n computeNormals: boolean;\r\n /**\r\n * Optimize the normals for the model. Lighting can be uneven if you use OptimizeWithUV = true because new vertices can be created for the same location if they pertain to different faces.\r\n * Using OptimizehNormals = true will help smoothing the lighting by averaging the normals of those vertices.\r\n */\r\n optimizeNormals: boolean;\r\n /**\r\n * Skip loading the materials even if defined in the OBJ file (materials are ignored).\r\n */\r\n skipMaterials: boolean;\r\n /**\r\n * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.\r\n */\r\n materialLoadingFailsSilently: boolean;\r\n};\r\n"]}
@@ -1,7 +1,7 @@
1
- import { AssetContainer } from "@babylonjs/core/assetContainer";
2
- import { Mesh } from "@babylonjs/core/Meshes/mesh";
3
- import { Scene } from "@babylonjs/core/scene";
4
- import { Nullable } from "@babylonjs/core/types";
1
+ import { AssetContainer } from "@babylonjs/core/assetContainer.js";
2
+ import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
3
+ import { Scene } from "@babylonjs/core/scene.js";
4
+ import { Nullable } from "@babylonjs/core/types.js";
5
5
  import { OBJLoadingOptions } from "./objLoadingOptions";
6
6
  /**
7
7
  * Class used to load mesh data from OBJ content
@@ -90,6 +90,7 @@ export declare class SolidParser {
90
90
  * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
91
91
  * @param textureVectorFromOBJ Vector3 The value of uvs
92
92
  * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
93
+ * @param positionColorsFromOBJ
93
94
  */
94
95
  private _setData;
95
96
  /**
@@ -106,7 +107,7 @@ export declare class SolidParser {
106
107
  * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
107
108
  * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"]
108
109
  * Each pattern is divided by the same method
109
- * @param face Array[String] The indices of elements
110
+ * @param faces Array[String] The indices of elements
110
111
  * @param v Integer The variable to increment
111
112
  */
112
113
  private _getTriangles;