@babylonjs/loaders 5.0.0-alpha.8 → 5.0.0-beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. package/OBJ/index.d.ts +2 -0
  2. package/OBJ/index.js +4 -2
  3. package/OBJ/index.js.map +1 -1
  4. package/OBJ/mtlFileLoader.d.ts +4 -2
  5. package/OBJ/mtlFileLoader.js +7 -6
  6. package/OBJ/mtlFileLoader.js.map +1 -1
  7. package/OBJ/objFileLoader.d.ts +12 -84
  8. package/OBJ/objFileLoader.js +50 -667
  9. package/OBJ/objFileLoader.js.map +1 -1
  10. package/OBJ/objLoadingOptions.d.ts +43 -0
  11. package/OBJ/objLoadingOptions.js +2 -0
  12. package/OBJ/objLoadingOptions.js.map +1 -0
  13. package/OBJ/solidParser.d.ts +153 -0
  14. package/OBJ/solidParser.js +700 -0
  15. package/OBJ/solidParser.js.map +1 -0
  16. package/STL/index.js +1 -1
  17. package/STL/stlFileLoader.d.ts +6 -0
  18. package/STL/stlFileLoader.js +38 -11
  19. package/STL/stlFileLoader.js.map +1 -1
  20. package/glTF/1.0/glTFBinaryExtension.js +4 -4
  21. package/glTF/1.0/glTFLoader.d.ts +4 -4
  22. package/glTF/1.0/glTFLoader.js +60 -55
  23. package/glTF/1.0/glTFLoader.js.map +1 -1
  24. package/glTF/1.0/glTFLoaderInterfaces.d.ts +3 -1
  25. package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
  26. package/glTF/1.0/glTFLoaderUtils.js +6 -6
  27. package/glTF/1.0/glTFMaterialsCommonExtension.js +12 -12
  28. package/glTF/1.0/index.js +5 -5
  29. package/glTF/2.0/Extensions/EXT_lights_image_based.js +8 -5
  30. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
  31. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +3 -3
  32. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  33. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +1 -5
  34. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +5 -21
  35. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
  36. package/glTF/2.0/Extensions/EXT_texture_webp.js +2 -2
  37. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
  38. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +1 -1
  39. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +8 -4
  40. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
  41. package/glTF/2.0/Extensions/KHR_lights_punctual.js +9 -8
  42. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  43. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +2 -2
  44. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +30 -0
  45. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +46 -0
  46. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -0
  47. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +1 -2
  48. package/glTF/2.0/Extensions/KHR_materials_ior.js +3 -4
  49. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
  50. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +3 -4
  51. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
  52. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +0 -1
  53. package/glTF/2.0/Extensions/KHR_materials_sheen.js +3 -4
  54. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  55. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +1 -2
  56. package/glTF/2.0/Extensions/KHR_materials_specular.js +12 -6
  57. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  58. package/glTF/2.0/Extensions/KHR_materials_translucency.js +6 -6
  59. package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
  60. package/glTF/2.0/Extensions/KHR_materials_transmission.js +93 -84
  61. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  62. package/glTF/2.0/Extensions/KHR_materials_unlit.js +3 -3
  63. package/glTF/2.0/Extensions/KHR_materials_variants.js +70 -5
  64. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
  65. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +31 -0
  66. package/glTF/2.0/Extensions/KHR_materials_volume.js +79 -0
  67. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -0
  68. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +1 -1
  69. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +1 -2
  70. package/glTF/2.0/Extensions/KHR_texture_basisu.js +3 -4
  71. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
  72. package/glTF/2.0/Extensions/KHR_texture_transform.js +2 -2
  73. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +2 -2
  74. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +6 -3
  75. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
  76. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +6 -7
  77. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
  78. package/glTF/2.0/Extensions/MSFT_lod.d.ts +2 -1
  79. package/glTF/2.0/Extensions/MSFT_lod.js +48 -8
  80. package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
  81. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +2 -2
  82. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +2 -2
  83. package/glTF/2.0/Extensions/index.d.ts +2 -0
  84. package/glTF/2.0/Extensions/index.js +26 -24
  85. package/glTF/2.0/Extensions/index.js.map +1 -1
  86. package/glTF/2.0/glTFLoader.d.ts +6 -11
  87. package/glTF/2.0/glTFLoader.js +129 -95
  88. package/glTF/2.0/glTFLoader.js.map +1 -1
  89. package/glTF/2.0/glTFLoaderInterfaces.d.ts +4 -2
  90. package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
  91. package/glTF/2.0/index.d.ts +1 -1
  92. package/glTF/2.0/index.js +4 -4
  93. package/glTF/2.0/index.js.map +1 -1
  94. package/glTF/glTFFileLoader.d.ts +15 -9
  95. package/glTF/glTFFileLoader.js +62 -76
  96. package/glTF/glTFFileLoader.js.map +1 -1
  97. package/glTF/glTFValidation.js +1 -1
  98. package/glTF/glTFValidation.js.map +1 -1
  99. package/glTF/index.d.ts +2 -2
  100. package/glTF/index.js +4 -4
  101. package/glTF/index.js.map +1 -1
  102. package/index.d.ts +3 -3
  103. package/index.js +3 -3
  104. package/index.js.map +1 -1
  105. package/legacy/legacy-glTF.js +4 -4
  106. package/legacy/legacy-glTF1.d.ts +1 -1
  107. package/legacy/legacy-glTF1.js +1 -1
  108. package/legacy/legacy-glTF1.js.map +1 -1
  109. package/legacy/legacy-glTF1FileLoader.js +2 -2
  110. package/legacy/legacy-glTF2.d.ts +1 -1
  111. package/legacy/legacy-glTF2.js +3 -3
  112. package/legacy/legacy-glTF2.js.map +1 -1
  113. package/legacy/legacy-glTF2FileLoader.js +2 -2
  114. package/legacy/legacy-glTFFileLoader.js +3 -3
  115. package/legacy/legacy-objFileLoader.d.ts +1 -1
  116. package/legacy/legacy-objFileLoader.js +2 -2
  117. package/legacy/legacy-objFileLoader.js.map +1 -1
  118. package/legacy/legacy-stlFileLoader.d.ts +1 -1
  119. package/legacy/legacy-stlFileLoader.js +2 -2
  120. package/legacy/legacy-stlFileLoader.js.map +1 -1
  121. package/legacy/legacy.js +6 -6
  122. package/package.json +16 -4
@@ -1,13 +1,9 @@
1
- import { Vector3, Vector2 } from "@babylonjs/core/Maths/math.vector";
2
- import { Color4 } from '@babylonjs/core/Maths/math.color';
3
- import { Tools } from "@babylonjs/core/Misc/tools";
4
- import { VertexData } from "@babylonjs/core/Meshes/mesh.vertexData";
5
- import { Geometry } from "@babylonjs/core/Meshes/geometry";
6
- import { Mesh } from "@babylonjs/core/Meshes/mesh";
7
- import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader";
8
- import { AssetContainer } from "@babylonjs/core/assetContainer";
9
- import { MTLFileLoader } from './mtlFileLoader';
10
- import { VertexBuffer } from "@babylonjs/core/Meshes/buffer";
1
+ import { Vector2 } from "@babylonjs/core/Maths/math.vector.js";
2
+ import { Tools } from "@babylonjs/core/Misc/tools.js";
3
+ import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
4
+ import { AssetContainer } from "@babylonjs/core/assetContainer.js";
5
+ import { MTLFileLoader } from './mtlFileLoader.js';
6
+ import { SolidParser } from "./solidParser.js";
11
7
  /**
12
8
  * OBJ file type loader.
13
9
  * This is a babylon scene loader plugin.
@@ -16,9 +12,9 @@ var OBJFileLoader = /** @class */ (function () {
16
12
  /**
17
13
  * Creates loader for .OBJ files
18
14
  *
19
- * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
15
+ * @param loadingOptions options for loading and parsing OBJ/MTL files.
20
16
  */
21
- function OBJFileLoader(meshLoadOptions) {
17
+ function OBJFileLoader(loadingOptions) {
22
18
  /**
23
19
  * Defines the name of the plugin.
24
20
  */
@@ -27,41 +23,8 @@ var OBJFileLoader = /** @class */ (function () {
27
23
  * Defines the extension the plugin is able to load.
28
24
  */
29
25
  this.extensions = ".obj";
30
- /** @hidden */
31
- this.obj = /^o/;
32
- /** @hidden */
33
- this.group = /^g/;
34
- /** @hidden */
35
- this.mtllib = /^mtllib /;
36
- /** @hidden */
37
- this.usemtl = /^usemtl /;
38
- /** @hidden */
39
- this.smooth = /^s /;
40
- /** @hidden */
41
- this.vertexPattern = /v(\s+[\d|\.|\+|\-|e|E]+){3,7}/;
42
- // vn float float float
43
- /** @hidden */
44
- this.normalPattern = /vn(\s+[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
45
- // vt float float
46
- /** @hidden */
47
- this.uvPattern = /vt(\s+[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
48
- // f vertex vertex vertex ...
49
- /** @hidden */
50
- this.facePattern1 = /f\s+(([\d]{1,}[\s]?){3,})+/;
51
- // f vertex/uvs vertex/uvs vertex/uvs ...
52
- /** @hidden */
53
- this.facePattern2 = /f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
54
- // f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal ...
55
- /** @hidden */
56
- this.facePattern3 = /f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
57
- // f vertex//normal vertex//normal vertex//normal ...
58
- /** @hidden */
59
- this.facePattern4 = /f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/;
60
- // f -vertex/-uvs/-normal -vertex/-uvs/-normal -vertex/-uvs/-normal ...
61
- /** @hidden */
62
- this.facePattern5 = /f\s+(((-[\d]{1,}\/-[\d]{1,}\/-[\d]{1,}[\s]?){3,})+)/;
63
- this._forAssetContainer = false;
64
- this._meshLoadOptions = meshLoadOptions || OBJFileLoader.currentMeshLoadOptions;
26
+ this._assetContainer = null;
27
+ this._loadingOptions = loadingOptions || OBJFileLoader.DefaultLoadingOptions;
65
28
  }
66
29
  Object.defineProperty(OBJFileLoader, "INVERT_TEXTURE_Y", {
67
30
  /**
@@ -76,18 +39,18 @@ var OBJFileLoader = /** @class */ (function () {
76
39
  enumerable: false,
77
40
  configurable: true
78
41
  });
79
- Object.defineProperty(OBJFileLoader, "currentMeshLoadOptions", {
42
+ Object.defineProperty(OBJFileLoader, "DefaultLoadingOptions", {
80
43
  get: function () {
81
44
  return {
82
- ComputeNormals: OBJFileLoader.COMPUTE_NORMALS,
83
- OptimizeNormals: OBJFileLoader.OPTIMIZE_NORMALS,
84
- ImportVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
85
- InvertY: OBJFileLoader.INVERT_Y,
86
- InvertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
45
+ computeNormals: OBJFileLoader.COMPUTE_NORMALS,
46
+ optimizeNormals: OBJFileLoader.OPTIMIZE_NORMALS,
47
+ importVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
48
+ invertY: OBJFileLoader.INVERT_Y,
49
+ invertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
87
50
  UVScaling: OBJFileLoader.UV_SCALING,
88
- MaterialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
89
- OptimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
90
- SkipMaterials: OBJFileLoader.SKIP_MATERIALS
51
+ materialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
52
+ optimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
53
+ skipMaterials: OBJFileLoader.SKIP_MATERIALS
91
54
  };
92
55
  },
93
56
  enumerable: false,
@@ -100,13 +63,12 @@ var OBJFileLoader = /** @class */ (function () {
100
63
  * In consequence it is impossible to get material information in your HTML file
101
64
  *
102
65
  * @param url The URL of the MTL file
103
- * @param rootUrl
66
+ * @param rootUrl defines where to load data from
104
67
  * @param onSuccess Callback function to be called when the MTL file is loaded
105
- * @private
106
68
  */
107
69
  OBJFileLoader.prototype._loadMTL = function (url, rootUrl, onSuccess, onFailure) {
108
70
  //The complete path to the mtl file
109
- var pathOfFile = Tools.BaseUrl + rootUrl + url;
71
+ var pathOfFile = rootUrl + url;
110
72
  // Loads through the babylon tools to allow fileInput search.
111
73
  Tools.LoadFile(pathOfFile, onSuccess, undefined, undefined, false, function (request, exception) {
112
74
  onFailure(pathOfFile, exception);
@@ -117,7 +79,7 @@ var OBJFileLoader = /** @class */ (function () {
117
79
  * @returns the created plugin
118
80
  */
119
81
  OBJFileLoader.prototype.createPlugin = function () {
120
- return new OBJFileLoader(OBJFileLoader.currentMeshLoadOptions);
82
+ return new OBJFileLoader(OBJFileLoader.DefaultLoadingOptions);
121
83
  };
122
84
  /**
123
85
  * If the data string can be loaded directly.
@@ -178,9 +140,9 @@ var OBJFileLoader = /** @class */ (function () {
178
140
  */
179
141
  OBJFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
180
142
  var _this = this;
181
- this._forAssetContainer = true;
143
+ var container = new AssetContainer(scene);
144
+ this._assetContainer = container;
182
145
  return this.importMeshAsync(null, scene, data, rootUrl).then(function (result) {
183
- var container = new AssetContainer(scene);
184
146
  result.meshes.forEach(function (mesh) { return container.meshes.push(mesh); });
185
147
  result.meshes.forEach(function (mesh) {
186
148
  var material = mesh.material;
@@ -198,629 +160,44 @@ var OBJFileLoader = /** @class */ (function () {
198
160
  }
199
161
  }
200
162
  });
201
- _this._forAssetContainer = false;
163
+ _this._assetContainer = null;
202
164
  return container;
203
165
  }).catch(function (ex) {
204
- _this._forAssetContainer = false;
166
+ _this._assetContainer = null;
205
167
  throw ex;
206
168
  });
207
169
  };
208
- OBJFileLoader.prototype._optimizeNormals = function (mesh) {
209
- var positions = mesh.getVerticesData(VertexBuffer.PositionKind);
210
- var normals = mesh.getVerticesData(VertexBuffer.NormalKind);
211
- var mapVertices = {};
212
- if (!positions || !normals) {
213
- return;
214
- }
215
- for (var i = 0; i < positions.length / 3; i++) {
216
- var x = positions[i * 3 + 0];
217
- var y = positions[i * 3 + 1];
218
- var z = positions[i * 3 + 2];
219
- var key = x + "_" + y + "_" + z;
220
- var lst = mapVertices[key];
221
- if (!lst) {
222
- lst = [];
223
- mapVertices[key] = lst;
224
- }
225
- lst.push(i);
226
- }
227
- var normal = new Vector3();
228
- for (var key in mapVertices) {
229
- var lst = mapVertices[key];
230
- if (lst.length < 2) {
231
- continue;
232
- }
233
- var v0Idx = lst[0];
234
- for (var i = 1; i < lst.length; ++i) {
235
- var vIdx = lst[i];
236
- normals[v0Idx * 3 + 0] += normals[vIdx * 3 + 0];
237
- normals[v0Idx * 3 + 1] += normals[vIdx * 3 + 1];
238
- normals[v0Idx * 3 + 2] += normals[vIdx * 3 + 2];
239
- }
240
- normal.copyFromFloats(normals[v0Idx * 3 + 0], normals[v0Idx * 3 + 1], normals[v0Idx * 3 + 2]);
241
- normal.normalize();
242
- for (var i = 0; i < lst.length; ++i) {
243
- var vIdx = lst[i];
244
- normals[vIdx * 3 + 0] = normal.x;
245
- normals[vIdx * 3 + 1] = normal.y;
246
- normals[vIdx * 3 + 2] = normal.z;
247
- }
248
- }
249
- mesh.setVerticesData(VertexBuffer.NormalKind, normals);
250
- };
251
170
  /**
252
171
  * Read the OBJ file and create an Array of meshes.
253
172
  * Each mesh contains all information given by the OBJ and the MTL file.
254
173
  * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
255
- *
256
- * @param meshesNames
257
- * @param scene Scene The scene where are displayed the data
258
- * @param data String The content of the obj file
259
- * @param rootUrl String The path to the folder
260
- * @returns Array<AbstractMesh>
261
- * @private
174
+ * @param meshesNames defines a string or array of strings of the mesh names that should be loaded from the file
175
+ * @param scene defines the scene where are displayed the data
176
+ * @param data defines the content of the obj file
177
+ * @param rootUrl defines the path to the folder
178
+ * @returns the list of loaded meshes
262
179
  */
263
180
  OBJFileLoader.prototype._parseSolid = function (meshesNames, scene, data, rootUrl) {
264
181
  var _this = this;
265
- var positions = []; //values for the positions of vertices
266
- var normals = []; //Values for the normals
267
- var uvs = []; //Values for the textures
268
- var colors = [];
269
- var meshesFromObj = []; //[mesh] Contains all the obj meshes
270
- var handledMesh; //The current mesh of meshes array
271
- var indicesForBabylon = []; //The list of indices for VertexData
272
- var wrappedPositionForBabylon = []; //The list of position in vectors
273
- var wrappedUvsForBabylon = []; //Array with all value of uvs to match with the indices
274
- var wrappedColorsForBabylon = []; // Array with all color values to match with the indices
275
- var wrappedNormalsForBabylon = []; //Array with all value of normals to match with the indices
276
- var tuplePosNorm = []; //Create a tuple with indice of Position, Normal, UV [pos, norm, uvs]
277
- var curPositionInIndices = 0;
278
- var hasMeshes = false; //Meshes are defined in the file
279
- var unwrappedPositionsForBabylon = []; //Value of positionForBabylon w/o Vector3() [x,y,z]
280
- var unwrappedColorsForBabylon = []; // Value of colorForBabylon w/o Color4() [r,g,b,a]
281
- var unwrappedNormalsForBabylon = []; //Value of normalsForBabylon w/o Vector3() [x,y,z]
282
- var unwrappedUVForBabylon = []; //Value of uvsForBabylon w/o Vector3() [x,y,z]
283
- var triangles = []; //Indices from new triangles coming from polygons
284
- var materialNameFromObj = ""; //The name of the current material
285
182
  var fileToLoad = ""; //The name of the mtlFile to load
286
183
  var materialsFromMTLFile = new MTLFileLoader();
287
- var objMeshName = ""; //The name of the current obj mesh
288
- var increment = 1; //Id for meshes created by the multimaterial
289
- var isFirstMaterial = true;
290
- var grayColor = new Color4(0.5, 0.5, 0.5, 1);
291
- /**
292
- * Search for obj in the given array.
293
- * This function is called to check if a couple of data already exists in an array.
294
- *
295
- * If found, returns the index of the founded tuple index. Returns -1 if not found
296
- * @param arr Array<{ normals: Array<number>, idx: Array<number> }>
297
- * @param obj Array<number>
298
- * @returns {boolean}
299
- */
300
- var isInArray = function (arr, obj) {
301
- if (!arr[obj[0]]) {
302
- arr[obj[0]] = { normals: [], idx: [] };
303
- }
304
- var idx = arr[obj[0]].normals.indexOf(obj[1]);
305
- return idx === -1 ? -1 : arr[obj[0]].idx[idx];
306
- };
307
- var isInArrayUV = function (arr, obj) {
308
- if (!arr[obj[0]]) {
309
- arr[obj[0]] = { normals: [], idx: [], uv: [] };
310
- }
311
- var idx = arr[obj[0]].normals.indexOf(obj[1]);
312
- if (idx != 1 && (obj[2] === arr[obj[0]].uv[idx])) {
313
- return arr[obj[0]].idx[idx];
314
- }
315
- return -1;
316
- };
317
- /**
318
- * This function set the data for each triangle.
319
- * Data are position, normals and uvs
320
- * If a tuple of (position, normal) is not set, add the data into the corresponding array
321
- * If the tuple already exist, add only their indice
322
- *
323
- * @param indicePositionFromObj Integer The index in positions array
324
- * @param indiceUvsFromObj Integer The index in uvs array
325
- * @param indiceNormalFromObj Integer The index in normals array
326
- * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
327
- * @param textureVectorFromOBJ Vector3 The value of uvs
328
- * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
329
- */
330
- var setData = function (indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positionVectorFromOBJ, textureVectorFromOBJ, normalsVectorFromOBJ, positionColorsFromOBJ) {
331
- //Check if this tuple already exists in the list of tuples
332
- var _index;
333
- if (_this._meshLoadOptions.OptimizeWithUV) {
334
- _index = isInArrayUV(tuplePosNorm, [
335
- indicePositionFromObj,
336
- indiceNormalFromObj,
337
- indiceUvsFromObj
338
- ]);
339
- }
340
- else {
341
- _index = isInArray(tuplePosNorm, [
342
- indicePositionFromObj,
343
- indiceNormalFromObj
344
- ]);
345
- }
346
- //If it not exists
347
- if (_index === -1) {
348
- //Add an new indice.
349
- //The array of indices is only an array with his length equal to the number of triangles - 1.
350
- //We add vertices data in this order
351
- indicesForBabylon.push(wrappedPositionForBabylon.length);
352
- //Push the position of vertice for Babylon
353
- //Each element is a Vector3(x,y,z)
354
- wrappedPositionForBabylon.push(positionVectorFromOBJ);
355
- //Push the uvs for Babylon
356
- //Each element is a Vector3(u,v)
357
- wrappedUvsForBabylon.push(textureVectorFromOBJ);
358
- //Push the normals for Babylon
359
- //Each element is a Vector3(x,y,z)
360
- wrappedNormalsForBabylon.push(normalsVectorFromOBJ);
361
- if (positionColorsFromOBJ !== undefined) {
362
- //Push the colors for Babylon
363
- //Each element is a BABYLON.Color4(r,g,b,a)
364
- wrappedColorsForBabylon.push(positionColorsFromOBJ);
365
- }
366
- //Add the tuple in the comparison list
367
- tuplePosNorm[indicePositionFromObj].normals.push(indiceNormalFromObj);
368
- tuplePosNorm[indicePositionFromObj].idx.push(curPositionInIndices++);
369
- if (_this._meshLoadOptions.OptimizeWithUV) {
370
- tuplePosNorm[indicePositionFromObj].uv.push(indiceUvsFromObj);
371
- }
372
- }
373
- else {
374
- //The tuple already exists
375
- //Add the index of the already existing tuple
376
- //At this index we can get the value of position, normal, color and uvs of vertex
377
- indicesForBabylon.push(_index);
378
- }
379
- };
380
- /**
381
- * Transform Vector() and BABYLON.Color() objects into numbers in an array
382
- */
383
- var unwrapData = function () {
384
- //Every array has the same length
385
- for (var l = 0; l < wrappedPositionForBabylon.length; l++) {
386
- //Push the x, y, z values of each element in the unwrapped array
387
- unwrappedPositionsForBabylon.push(wrappedPositionForBabylon[l].x, wrappedPositionForBabylon[l].y, wrappedPositionForBabylon[l].z);
388
- unwrappedNormalsForBabylon.push(wrappedNormalsForBabylon[l].x, wrappedNormalsForBabylon[l].y, wrappedNormalsForBabylon[l].z);
389
- unwrappedUVForBabylon.push(wrappedUvsForBabylon[l].x, wrappedUvsForBabylon[l].y); //z is an optional value not supported by BABYLON
390
- if (_this._meshLoadOptions.ImportVertexColors === true) {
391
- //Push the r, g, b, a values of each element in the unwrapped array
392
- unwrappedColorsForBabylon.push(wrappedColorsForBabylon[l].r, wrappedColorsForBabylon[l].g, wrappedColorsForBabylon[l].b, wrappedColorsForBabylon[l].a);
393
- }
394
- }
395
- // Reset arrays for the next new meshes
396
- wrappedPositionForBabylon = [];
397
- wrappedNormalsForBabylon = [];
398
- wrappedUvsForBabylon = [];
399
- wrappedColorsForBabylon = [];
400
- tuplePosNorm = [];
401
- curPositionInIndices = 0;
402
- };
403
- /**
404
- * Create triangles from polygons
405
- * It is important to notice that a triangle is a polygon
406
- * We get 5 patterns of face defined in OBJ File :
407
- * facePattern1 = ["1","2","3","4","5","6"]
408
- * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"]
409
- * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"]
410
- * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
411
- * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"]
412
- * Each pattern is divided by the same method
413
- * @param face Array[String] The indices of elements
414
- * @param v Integer The variable to increment
415
- */
416
- var getTriangles = function (faces, v) {
417
- //Work for each element of the array
418
- for (var faceIndex = v; faceIndex < faces.length - 1; faceIndex++) {
419
- //Add on the triangle variable the indexes to obtain triangles
420
- triangles.push(faces[0], faces[faceIndex], faces[faceIndex + 1]);
421
- }
422
- //Result obtained after 2 iterations:
423
- //Pattern1 => triangle = ["1","2","3","1","3","4"];
424
- //Pattern2 => triangle = ["1/1","2/2","3/3","1/1","3/3","4/4"];
425
- //Pattern3 => triangle = ["1/1/1","2/2/2","3/3/3","1/1/1","3/3/3","4/4/4"];
426
- //Pattern4 => triangle = ["1//1","2//2","3//3","1//1","3//3","4//4"];
427
- //Pattern5 => triangle = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-1/-1/-1","-3/-3/-3","-4/-4/-4"];
428
- };
429
- /**
430
- * Create triangles and push the data for each polygon for the pattern 1
431
- * In this pattern we get vertice positions
432
- * @param face
433
- * @param v
434
- */
435
- var setDataForCurrentFaceWithPattern1 = function (face, v) {
436
- //Get the indices of triangles for each polygon
437
- getTriangles(face, v);
438
- //For each element in the triangles array.
439
- //This var could contains 1 to an infinity of triangles
440
- for (var k = 0; k < triangles.length; k++) {
441
- // Set position indice
442
- var indicePositionFromObj = parseInt(triangles[k]) - 1;
443
- setData(indicePositionFromObj, 0, 0, //In the pattern 1, normals and uvs are not defined
444
- positions[indicePositionFromObj], //Get the vectors data
445
- Vector2.Zero(), Vector3.Up(), //Create default vectors
446
- _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
447
- }
448
- //Reset variable for the next line
449
- triangles = [];
450
- };
451
- /**
452
- * Create triangles and push the data for each polygon for the pattern 2
453
- * In this pattern we get vertice positions and uvsu
454
- * @param face
455
- * @param v
456
- */
457
- var setDataForCurrentFaceWithPattern2 = function (face, v) {
458
- //Get the indices of triangles for each polygon
459
- getTriangles(face, v);
460
- for (var k = 0; k < triangles.length; k++) {
461
- //triangle[k] = "1/1"
462
- //Split the data for getting position and uv
463
- var point = triangles[k].split("/"); // ["1", "1"]
464
- //Set position indice
465
- var indicePositionFromObj = parseInt(point[0]) - 1;
466
- //Set uv indice
467
- var indiceUvsFromObj = parseInt(point[1]) - 1;
468
- setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
469
- positions[indicePositionFromObj], //Get the values for each element
470
- uvs[indiceUvsFromObj], Vector3.Up(), //Default value for normals
471
- _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
472
- }
473
- //Reset variable for the next line
474
- triangles = [];
475
- };
476
- /**
477
- * Create triangles and push the data for each polygon for the pattern 3
478
- * In this pattern we get vertice positions, uvs and normals
479
- * @param face
480
- * @param v
481
- */
482
- var setDataForCurrentFaceWithPattern3 = function (face, v) {
483
- //Get the indices of triangles for each polygon
484
- getTriangles(face, v);
485
- for (var k = 0; k < triangles.length; k++) {
486
- //triangle[k] = "1/1/1"
487
- //Split the data for getting position, uv, and normals
488
- var point = triangles[k].split("/"); // ["1", "1", "1"]
489
- // Set position indice
490
- var indicePositionFromObj = parseInt(point[0]) - 1;
491
- // Set uv indice
492
- var indiceUvsFromObj = parseInt(point[1]) - 1;
493
- // Set normal indice
494
- var indiceNormalFromObj = parseInt(point[2]) - 1;
495
- setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj] //Set the vector for each component
496
- );
497
- }
498
- //Reset variable for the next line
499
- triangles = [];
500
- };
501
- /**
502
- * Create triangles and push the data for each polygon for the pattern 4
503
- * In this pattern we get vertice positions and normals
504
- * @param face
505
- * @param v
506
- */
507
- var setDataForCurrentFaceWithPattern4 = function (face, v) {
508
- getTriangles(face, v);
509
- for (var k = 0; k < triangles.length; k++) {
510
- //triangle[k] = "1//1"
511
- //Split the data for getting position and normals
512
- var point = triangles[k].split("//"); // ["1", "1"]
513
- // We check indices, and normals
514
- var indicePositionFromObj = parseInt(point[0]) - 1;
515
- var indiceNormalFromObj = parseInt(point[1]) - 1;
516
- setData(indicePositionFromObj, 1, //Default value for uv
517
- indiceNormalFromObj, positions[indicePositionFromObj], //Get each vector of data
518
- Vector2.Zero(), normals[indiceNormalFromObj], _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
519
- }
520
- //Reset variable for the next line
521
- triangles = [];
522
- };
523
- /**
524
- * Create triangles and push the data for each polygon for the pattern 3
525
- * In this pattern we get vertice positions, uvs and normals
526
- * @param face
527
- * @param v
528
- */
529
- var setDataForCurrentFaceWithPattern5 = function (face, v) {
530
- //Get the indices of triangles for each polygon
531
- getTriangles(face, v);
532
- for (var k = 0; k < triangles.length; k++) {
533
- //triangle[k] = "-1/-1/-1"
534
- //Split the data for getting position, uv, and normals
535
- var point = triangles[k].split("/"); // ["-1", "-1", "-1"]
536
- // Set position indice
537
- var indicePositionFromObj = positions.length + parseInt(point[0]);
538
- // Set uv indice
539
- var indiceUvsFromObj = uvs.length + parseInt(point[1]);
540
- // Set normal indice
541
- var indiceNormalFromObj = normals.length + parseInt(point[2]);
542
- setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj], //Set the vector for each component
543
- _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
544
- }
545
- //Reset variable for the next line
546
- triangles = [];
547
- };
548
- var addPreviousObjMesh = function () {
549
- //Check if it is not the first mesh. Otherwise we don't have data.
550
- if (meshesFromObj.length > 0) {
551
- //Get the previous mesh for applying the data about the faces
552
- //=> in obj file, faces definition append after the name of the mesh
553
- handledMesh = meshesFromObj[meshesFromObj.length - 1];
554
- //Set the data into Array for the mesh
555
- unwrapData();
556
- // Reverse tab. Otherwise face are displayed in the wrong sens
557
- indicesForBabylon.reverse();
558
- //Set the information for the mesh
559
- //Slice the array to avoid rewriting because of the fact this is the same var which be rewrited
560
- handledMesh.indices = indicesForBabylon.slice();
561
- handledMesh.positions = unwrappedPositionsForBabylon.slice();
562
- handledMesh.normals = unwrappedNormalsForBabylon.slice();
563
- handledMesh.uvs = unwrappedUVForBabylon.slice();
564
- if (_this._meshLoadOptions.ImportVertexColors === true) {
565
- handledMesh.colors = unwrappedColorsForBabylon.slice();
566
- }
567
- //Reset the array for the next mesh
568
- indicesForBabylon = [];
569
- unwrappedPositionsForBabylon = [];
570
- unwrappedColorsForBabylon = [];
571
- unwrappedNormalsForBabylon = [];
572
- unwrappedUVForBabylon = [];
573
- }
574
- };
575
- //Main function
576
- //Split the file into lines
577
- var lines = data.split('\n');
578
- //Look at each line
579
- for (var i = 0; i < lines.length; i++) {
580
- var line = lines[i].trim().replace(/\s\s/g, " ");
581
- var result;
582
- //Comment or newLine
583
- if (line.length === 0 || line.charAt(0) === '#') {
584
- continue;
585
- //Get information about one position possible for the vertices
586
- }
587
- else if (this.vertexPattern.test(line)) {
588
- result = line.match(/[^ ]+/g); // match will return non-null due to passing regex pattern
589
- // Value of result with line: "v 1.0 2.0 3.0"
590
- // ["v", "1.0", "2.0", "3.0"]
591
- // Create a Vector3 with the position x, y, z
592
- positions.push(new Vector3(parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
593
- if (this._meshLoadOptions.ImportVertexColors === true) {
594
- if (result.length >= 7) {
595
- // TODO: if these numbers are > 1 we can use Color4.FromInts(r,g,b,a)
596
- colors.push(new Color4(parseFloat(result[4]), parseFloat(result[5]), parseFloat(result[6]), (result.length === 7 || result[7] === undefined) ? 1 : parseFloat(result[7])));
597
- }
598
- else {
599
- // TODO: maybe push NULL and if all are NULL to skip (and remove grayColor var).
600
- colors.push(grayColor);
601
- }
602
- }
603
- }
604
- else if ((result = this.normalPattern.exec(line)) !== null) {
605
- //Create a Vector3 with the normals x, y, z
606
- //Value of result
607
- // ["vn 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
608
- //Add the Vector in the list of normals
609
- normals.push(new Vector3(parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
610
- }
611
- else if ((result = this.uvPattern.exec(line)) !== null) {
612
- //Create a Vector2 with the normals u, v
613
- //Value of result
614
- // ["vt 0.1 0.2 0.3", "0.1", "0.2"]
615
- //Add the Vector in the list of uvs
616
- uvs.push(new Vector2(parseFloat(result[1]) * OBJFileLoader.UV_SCALING.x, parseFloat(result[2]) * OBJFileLoader.UV_SCALING.y));
617
- //Identify patterns of faces
618
- //Face could be defined in different type of pattern
619
- }
620
- else if ((result = this.facePattern3.exec(line)) !== null) {
621
- //Value of result:
622
- //["f 1/1/1 2/2/2 3/3/3", "1/1/1 2/2/2 3/3/3"...]
623
- //Set the data for this face
624
- setDataForCurrentFaceWithPattern3(result[1].trim().split(" "), // ["1/1/1", "2/2/2", "3/3/3"]
625
- 1);
626
- }
627
- else if ((result = this.facePattern4.exec(line)) !== null) {
628
- //Value of result:
629
- //["f 1//1 2//2 3//3", "1//1 2//2 3//3"...]
630
- //Set the data for this face
631
- setDataForCurrentFaceWithPattern4(result[1].trim().split(" "), // ["1//1", "2//2", "3//3"]
632
- 1);
633
- }
634
- else if ((result = this.facePattern5.exec(line)) !== null) {
635
- //Value of result:
636
- //["f -1/-1/-1 -2/-2/-2 -3/-3/-3", "-1/-1/-1 -2/-2/-2 -3/-3/-3"...]
637
- //Set the data for this face
638
- setDataForCurrentFaceWithPattern5(result[1].trim().split(" "), // ["-1/-1/-1", "-2/-2/-2", "-3/-3/-3"]
639
- 1);
640
- }
641
- else if ((result = this.facePattern2.exec(line)) !== null) {
642
- //Value of result:
643
- //["f 1/1 2/2 3/3", "1/1 2/2 3/3"...]
644
- //Set the data for this face
645
- setDataForCurrentFaceWithPattern2(result[1].trim().split(" "), // ["1/1", "2/2", "3/3"]
646
- 1);
647
- }
648
- else if ((result = this.facePattern1.exec(line)) !== null) {
649
- //Value of result
650
- //["f 1 2 3", "1 2 3"...]
651
- //Set the data for this face
652
- setDataForCurrentFaceWithPattern1(result[1].trim().split(" "), // ["1", "2", "3"]
653
- 1);
654
- //Define a mesh or an object
655
- //Each time this keyword is analysed, create a new Object with all data for creating a babylonMesh
656
- }
657
- else if (this.group.test(line) || this.obj.test(line)) {
658
- //Create a new mesh corresponding to the name of the group.
659
- //Definition of the mesh
660
- var objMesh = {
661
- name: line.substring(2).trim(),
662
- indices: undefined,
663
- positions: undefined,
664
- normals: undefined,
665
- uvs: undefined,
666
- colors: undefined,
667
- materialName: ""
668
- };
669
- addPreviousObjMesh();
670
- //Push the last mesh created with only the name
671
- meshesFromObj.push(objMesh);
672
- //Set this variable to indicate that now meshesFromObj has objects defined inside
673
- hasMeshes = true;
674
- isFirstMaterial = true;
675
- increment = 1;
676
- //Keyword for applying a material
677
- }
678
- else if (this.usemtl.test(line)) {
679
- //Get the name of the material
680
- materialNameFromObj = line.substring(7).trim();
681
- //If this new material is in the same mesh
682
- if (!isFirstMaterial || !hasMeshes) {
683
- //Set the data for the previous mesh
684
- addPreviousObjMesh();
685
- //Create a new mesh
686
- var objMesh =
687
- //Set the name of the current obj mesh
688
- {
689
- name: (objMeshName || "mesh") + "_mm" + increment.toString(),
690
- indices: undefined,
691
- positions: undefined,
692
- normals: undefined,
693
- uvs: undefined,
694
- colors: undefined,
695
- materialName: materialNameFromObj
696
- };
697
- increment++;
698
- //If meshes are already defined
699
- meshesFromObj.push(objMesh);
700
- hasMeshes = true;
701
- }
702
- //Set the material name if the previous line define a mesh
703
- if (hasMeshes && isFirstMaterial) {
704
- //Set the material name to the previous mesh (1 material per mesh)
705
- meshesFromObj[meshesFromObj.length - 1].materialName = materialNameFromObj;
706
- isFirstMaterial = false;
707
- }
708
- //Keyword for loading the mtl file
709
- }
710
- else if (this.mtllib.test(line)) {
711
- //Get the name of mtl file
712
- fileToLoad = line.substring(7).trim();
713
- //Apply smoothing
714
- }
715
- else if (this.smooth.test(line)) {
716
- // smooth shading => apply smoothing
717
- //Today I don't know it work with babylon and with obj.
718
- //With the obj file an integer is set
719
- }
720
- else {
721
- //If there is another possibility
722
- console.log("Unhandled expression at line : " + line);
723
- }
724
- }
725
- //At the end of the file, add the last mesh into the meshesFromObj array
726
- if (hasMeshes) {
727
- //Set the data for the last mesh
728
- handledMesh = meshesFromObj[meshesFromObj.length - 1];
729
- //Reverse indices for displaying faces in the good sense
730
- indicesForBabylon.reverse();
731
- //Get the good array
732
- unwrapData();
733
- //Set array
734
- handledMesh.indices = indicesForBabylon;
735
- handledMesh.positions = unwrappedPositionsForBabylon;
736
- handledMesh.normals = unwrappedNormalsForBabylon;
737
- handledMesh.uvs = unwrappedUVForBabylon;
738
- if (this._meshLoadOptions.ImportVertexColors === true) {
739
- handledMesh.colors = unwrappedColorsForBabylon;
740
- }
741
- }
742
- //If any o or g keyword found, create a mesh with a random id
743
- if (!hasMeshes) {
744
- // reverse tab of indices
745
- indicesForBabylon.reverse();
746
- //Get positions normals uvs
747
- unwrapData();
748
- //Set data for one mesh
749
- meshesFromObj.push({
750
- name: Geometry.RandomId(),
751
- indices: indicesForBabylon,
752
- positions: unwrappedPositionsForBabylon,
753
- colors: unwrappedColorsForBabylon,
754
- normals: unwrappedNormalsForBabylon,
755
- uvs: unwrappedUVForBabylon,
756
- materialName: materialNameFromObj
757
- });
758
- }
759
- //Create a Mesh list
760
- var babylonMeshesArray = []; //The mesh for babylon
761
184
  var materialToUse = new Array();
762
- //Set data for each mesh
763
- for (var j = 0; j < meshesFromObj.length; j++) {
764
- //check meshesNames (stlFileLoader)
765
- if (meshesNames && meshesFromObj[j].name) {
766
- if (meshesNames instanceof Array) {
767
- if (meshesNames.indexOf(meshesFromObj[j].name) === -1) {
768
- continue;
769
- }
770
- }
771
- else {
772
- if (meshesFromObj[j].name !== meshesNames) {
773
- continue;
774
- }
775
- }
776
- }
777
- //Get the current mesh
778
- //Set the data with VertexBuffer for each mesh
779
- handledMesh = meshesFromObj[j];
780
- //Create a Mesh with the name of the obj mesh
781
- scene._blockEntityCollection = this._forAssetContainer;
782
- var babylonMesh = new Mesh(meshesFromObj[j].name, scene);
783
- scene._blockEntityCollection = false;
784
- //Push the name of the material to an array
785
- //This is indispensable for the importMesh function
786
- materialToUse.push(meshesFromObj[j].materialName);
787
- var vertexData = new VertexData(); //The container for the values
788
- //Set the data for the babylonMesh
789
- vertexData.uvs = handledMesh.uvs;
790
- vertexData.indices = handledMesh.indices;
791
- vertexData.positions = handledMesh.positions;
792
- if (this._meshLoadOptions.ComputeNormals === true) {
793
- var normals_1 = new Array();
794
- VertexData.ComputeNormals(handledMesh.positions, handledMesh.indices, normals_1);
795
- vertexData.normals = normals_1;
796
- }
797
- else {
798
- vertexData.normals = handledMesh.normals;
799
- }
800
- if (this._meshLoadOptions.ImportVertexColors === true) {
801
- vertexData.colors = handledMesh.colors;
802
- }
803
- //Set the data from the VertexBuffer to the current Mesh
804
- vertexData.applyToMesh(babylonMesh);
805
- if (this._meshLoadOptions.InvertY) {
806
- babylonMesh.scaling.y *= -1;
807
- }
808
- if (this._meshLoadOptions.OptimizeNormals === true) {
809
- this._optimizeNormals(babylonMesh);
810
- }
811
- //Push the mesh into an array
812
- babylonMeshesArray.push(babylonMesh);
813
- }
185
+ var babylonMeshesArray = []; //The mesh for babylon
186
+ // Main function
187
+ var solidParser = new SolidParser(materialToUse, babylonMeshesArray, this._loadingOptions);
188
+ solidParser.parse(meshesNames, data, scene, this._assetContainer, function (fileName) {
189
+ fileToLoad = fileName;
190
+ });
191
+ // load the materials
814
192
  var mtlPromises = [];
815
- //load the materials
816
- //Check if we have a file to load
817
- if (fileToLoad !== "" && this._meshLoadOptions.SkipMaterials === false) {
193
+ // Check if we have a file to load
194
+ if (fileToLoad !== "" && !this._loadingOptions.skipMaterials) {
818
195
  //Load the file synchronously
819
196
  mtlPromises.push(new Promise(function (resolve, reject) {
820
197
  _this._loadMTL(fileToLoad, rootUrl, function (dataLoaded) {
821
198
  try {
822
199
  //Create materials thanks MTLLoader function
823
- materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, _this._forAssetContainer);
200
+ materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, _this._assetContainer);
824
201
  //Look at each material loaded in the mtl file
825
202
  for (var n = 0; n < materialsFromMTLFile.materials.length; n++) {
826
203
  //Three variables to get all meshes with the same material
@@ -842,7 +219,13 @@ var OBJFileLoader = /** @class */ (function () {
842
219
  else {
843
220
  for (var o = 0; o < _indices.length; o++) {
844
221
  //Apply the material to the Mesh for each mesh with the material
845
- babylonMeshesArray[_indices[o]].material = materialsFromMTLFile.materials[n];
222
+ var mesh = babylonMeshesArray[_indices[o]];
223
+ var material = materialsFromMTLFile.materials[n];
224
+ mesh.material = material;
225
+ if (!mesh.getTotalIndices()) {
226
+ // No indices, we need to turn on point cloud
227
+ material.pointsCloud = true;
228
+ }
846
229
  }
847
230
  }
848
231
  }
@@ -850,7 +233,7 @@ var OBJFileLoader = /** @class */ (function () {
850
233
  }
851
234
  catch (e) {
852
235
  Tools.Warn("Error processing MTL file: '" + fileToLoad + "'");
853
- if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
236
+ if (_this._loadingOptions.materialLoadingFailsSilently) {
854
237
  resolve();
855
238
  }
856
239
  else {
@@ -859,7 +242,7 @@ var OBJFileLoader = /** @class */ (function () {
859
242
  }
860
243
  }, function (pathOfFile, exception) {
861
244
  Tools.Warn("Error downloading MTL file: '" + fileToLoad + "'");
862
- if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
245
+ if (_this._loadingOptions.materialLoadingFailsSilently) {
863
246
  resolve();
864
247
  }
865
248
  else {