@babylonjs/loaders 8.28.0 → 8.28.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/OBJ/solidParser.d.ts +8 -7
  2. package/OBJ/solidParser.js +95 -53
  3. package/OBJ/solidParser.js.map +1 -1
  4. package/glTF/2.0/Extensions/KHR_materials_anisotropy.d.ts +1 -1
  5. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +15 -10
  6. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -1
  7. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +44 -28
  8. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  9. package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.d.ts +42 -0
  10. package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.js +66 -0
  11. package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.js.map +1 -0
  12. package/glTF/2.0/Extensions/KHR_materials_clearcoat_color.d.ts +42 -0
  13. package/glTF/2.0/Extensions/KHR_materials_clearcoat_color.js +62 -0
  14. package/glTF/2.0/Extensions/KHR_materials_clearcoat_color.js.map +1 -0
  15. package/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.d.ts +43 -0
  16. package/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.js +62 -0
  17. package/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.js.map +1 -0
  18. package/glTF/2.0/Extensions/{EXT_materials_diffuse_roughness.d.ts → KHR_materials_diffuse_roughness.d.ts} +5 -5
  19. package/glTF/2.0/Extensions/{EXT_materials_diffuse_roughness.js → KHR_materials_diffuse_roughness.js} +8 -18
  20. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.js.map +1 -0
  21. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +6 -31
  22. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -1
  23. package/glTF/2.0/Extensions/KHR_materials_dispersion.js +3 -7
  24. package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -1
  25. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +5 -9
  26. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
  27. package/glTF/2.0/Extensions/KHR_materials_ior.js +3 -10
  28. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
  29. package/glTF/2.0/Extensions/KHR_materials_iridescence.js +13 -11
  30. package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
  31. package/glTF/2.0/Extensions/KHR_materials_sheen.js +11 -22
  32. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  33. package/glTF/2.0/Extensions/KHR_materials_specular.js +9 -17
  34. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  35. package/glTF/2.0/Extensions/KHR_materials_transmission.js +21 -32
  36. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  37. package/glTF/2.0/Extensions/KHR_materials_unlit.js +7 -13
  38. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
  39. package/glTF/2.0/Extensions/KHR_materials_volume.js +13 -22
  40. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
  41. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +1 -2
  42. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
  43. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +5 -8
  44. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
  45. package/glTF/2.0/Extensions/dynamic.js +3 -3
  46. package/glTF/2.0/Extensions/dynamic.js.map +1 -1
  47. package/glTF/2.0/Extensions/index.d.ts +4 -1
  48. package/glTF/2.0/Extensions/index.js +4 -1
  49. package/glTF/2.0/Extensions/index.js.map +1 -1
  50. package/glTF/2.0/glTFLoader.d.ts +17 -0
  51. package/glTF/2.0/glTFLoader.js +104 -50
  52. package/glTF/2.0/glTFLoader.js.map +1 -1
  53. package/glTF/2.0/index.d.ts +2 -0
  54. package/glTF/2.0/index.js +2 -0
  55. package/glTF/2.0/index.js.map +1 -1
  56. package/glTF/2.0/materialLoadingAdapter.d.ts +314 -0
  57. package/glTF/2.0/materialLoadingAdapter.js +2 -0
  58. package/glTF/2.0/materialLoadingAdapter.js.map +1 -0
  59. package/glTF/2.0/openPbrMaterialLoadingAdapter.d.ts +594 -0
  60. package/glTF/2.0/openPbrMaterialLoadingAdapter.js +902 -0
  61. package/glTF/2.0/openPbrMaterialLoadingAdapter.js.map +1 -0
  62. package/glTF/2.0/pbrMaterialLoadingAdapter.d.ts +612 -0
  63. package/glTF/2.0/pbrMaterialLoadingAdapter.js +973 -0
  64. package/glTF/2.0/pbrMaterialLoadingAdapter.js.map +1 -0
  65. package/glTF/glTFFileLoader.d.ts +5 -0
  66. package/glTF/glTFFileLoader.js +6 -0
  67. package/glTF/glTFFileLoader.js.map +1 -1
  68. package/package.json +3 -3
  69. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js.map +0 -1
@@ -94,13 +94,14 @@ export declare class SolidParser {
94
94
  * If a tuple of (position, normal) is not set, add the data into the corresponding array
95
95
  * If the tuple already exist, add only their indice
96
96
  *
97
- * @param indicePositionFromObj Integer The index in positions array
98
- * @param indiceUvsFromObj Integer The index in uvs array
99
- * @param indiceNormalFromObj Integer The index in normals array
100
- * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
101
- * @param textureVectorFromOBJ Vector3 The value of uvs
102
- * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
103
- * @param positionColorsFromOBJ
97
+ * @param data The vertex's data
98
+ * * indicesPositionFromObj: The index in positions array
99
+ * * indicesUvsFromObj: The index in uvs array
100
+ * * indicesNormalFromObj: The index in normals array
101
+ * * positionVectorFromOBJ: The value of position at index objIndice
102
+ * * textureVectorFromOBJ: The value of uvs
103
+ * * normalsVectorFromOBJ: The value of normals at index objNormale
104
+ * * positionColorsFromOBJ: The value of color at index objIndice
104
105
  */
105
106
  private _setData;
106
107
  /**
@@ -78,22 +78,26 @@ export class SolidParser {
78
78
  * If a tuple of (position, normal) is not set, add the data into the corresponding array
79
79
  * If the tuple already exist, add only their indice
80
80
  *
81
- * @param indicePositionFromObj Integer The index in positions array
82
- * @param indiceUvsFromObj Integer The index in uvs array
83
- * @param indiceNormalFromObj Integer The index in normals array
84
- * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
85
- * @param textureVectorFromOBJ Vector3 The value of uvs
86
- * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
87
- * @param positionColorsFromOBJ
81
+ * @param data The vertex's data
82
+ * * indicesPositionFromObj: The index in positions array
83
+ * * indicesUvsFromObj: The index in uvs array
84
+ * * indicesNormalFromObj: The index in normals array
85
+ * * positionVectorFromOBJ: The value of position at index objIndice
86
+ * * textureVectorFromOBJ: The value of uvs
87
+ * * normalsVectorFromOBJ: The value of normals at index objNormale
88
+ * * positionColorsFromOBJ: The value of color at index objIndice
88
89
  */
89
- _setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positionVectorFromOBJ, textureVectorFromOBJ, normalsVectorFromOBJ, positionColorsFromOBJ) {
90
+ _setData(data) {
91
+ //Use default values if undefined
92
+ data.indiceUvsFromObj ?? (data.indiceUvsFromObj = -1);
93
+ data.indiceNormalFromObj ?? (data.indiceNormalFromObj = -1);
90
94
  //Check if this tuple already exists in the list of tuples
91
95
  let _index;
92
96
  if (this._loadingOptions.optimizeWithUV) {
93
- _index = this._isInArrayUV(this._tuplePosNorm, [indicePositionFromObj, indiceNormalFromObj, indiceUvsFromObj]);
97
+ _index = this._isInArrayUV(this._tuplePosNorm, [data.indicePositionFromObj, data.indiceNormalFromObj, data.indiceUvsFromObj]);
94
98
  }
95
99
  else {
96
- _index = this._isInArray(this._tuplePosNorm, [indicePositionFromObj, indiceNormalFromObj]);
100
+ _index = this._isInArray(this._tuplePosNorm, [data.indicePositionFromObj, data.indiceNormalFromObj]);
97
101
  }
98
102
  //If it not exists
99
103
  if (_index === -1) {
@@ -103,25 +107,27 @@ export class SolidParser {
103
107
  this._indicesForBabylon.push(this._wrappedPositionForBabylon.length);
104
108
  //Push the position of vertice for Babylon
105
109
  //Each element is a Vector3(x,y,z)
106
- this._wrappedPositionForBabylon.push(positionVectorFromOBJ);
107
- //Push the uvs for Babylon
108
- //Each element is a Vector2(u,v)
109
- //If the UVs are missing, set (u,v)=(0,0)
110
- textureVectorFromOBJ = textureVectorFromOBJ ?? new Vector2(0, 0);
111
- this._wrappedUvsForBabylon.push(textureVectorFromOBJ);
112
- //Push the normals for Babylon
113
- //Each element is a Vector3(x,y,z)
114
- this._wrappedNormalsForBabylon.push(normalsVectorFromOBJ);
115
- if (positionColorsFromOBJ !== undefined) {
110
+ this._wrappedPositionForBabylon.push(data.positionVectorFromOBJ);
111
+ if (data.textureVectorFromOBJ !== undefined) {
112
+ //Push the uvs for Babylon
113
+ //Each element is a Vector2(u,v)
114
+ this._wrappedUvsForBabylon.push(data.textureVectorFromOBJ);
115
+ }
116
+ if (data.normalsVectorFromOBJ !== undefined) {
117
+ //Push the normals for Babylon
118
+ //Each element is a Vector3(x,y,z)
119
+ this._wrappedNormalsForBabylon.push(data.normalsVectorFromOBJ);
120
+ }
121
+ if (data.positionColorsFromOBJ !== undefined) {
116
122
  //Push the colors for Babylon
117
123
  //Each element is a BABYLON.Color4(r,g,b,a)
118
- this._wrappedColorsForBabylon.push(positionColorsFromOBJ);
124
+ this._wrappedColorsForBabylon.push(data.positionColorsFromOBJ);
119
125
  }
120
126
  //Add the tuple in the comparison list
121
- this._tuplePosNorm[indicePositionFromObj].normals.push(indiceNormalFromObj);
122
- this._tuplePosNorm[indicePositionFromObj].idx.push(this._curPositionInIndices++);
127
+ this._tuplePosNorm[data.indicePositionFromObj].normals.push(data.indiceNormalFromObj);
128
+ this._tuplePosNorm[data.indicePositionFromObj].idx.push(this._curPositionInIndices++);
123
129
  if (this._loadingOptions.optimizeWithUV) {
124
- this._tuplePosNorm[indicePositionFromObj].uv.push(indiceUvsFromObj);
130
+ this._tuplePosNorm[data.indicePositionFromObj].uv.push(data.indiceUvsFromObj);
125
131
  }
126
132
  }
127
133
  else {
@@ -140,9 +146,13 @@ export class SolidParser {
140
146
  for (let l = 0; l < this._wrappedPositionForBabylon.length; l++) {
141
147
  //Push the x, y, z values of each element in the unwrapped array
142
148
  this._unwrappedPositionsForBabylon.push(this._wrappedPositionForBabylon[l].x * this._handednessSign, this._wrappedPositionForBabylon[l].y, this._wrappedPositionForBabylon[l].z);
143
- this._unwrappedNormalsForBabylon.push(this._wrappedNormalsForBabylon[l].x * this._handednessSign, this._wrappedNormalsForBabylon[l].y, this._wrappedNormalsForBabylon[l].z);
144
- this._unwrappedUVForBabylon.push(this._wrappedUvsForBabylon[l].x, this._wrappedUvsForBabylon[l].y); //z is an optional value not supported by BABYLON
145
- if (this._loadingOptions.importVertexColors) {
149
+ if (this._wrappedNormalsForBabylon.length) {
150
+ this._unwrappedNormalsForBabylon.push(this._wrappedNormalsForBabylon[l].x * this._handednessSign, this._wrappedNormalsForBabylon[l].y, this._wrappedNormalsForBabylon[l].z);
151
+ }
152
+ if (this._wrappedUvsForBabylon.length) {
153
+ this._unwrappedUVForBabylon.push(this._wrappedUvsForBabylon[l].x, this._wrappedUvsForBabylon[l].y); //z is an optional value not supported by BABYLON
154
+ }
155
+ if (this._unwrappedColorsForBabylon.length) {
146
156
  //Push the r, g, b, a values of each element in the unwrapped array
147
157
  this._unwrappedColorsForBabylon.push(this._wrappedColorsForBabylon[l].r, this._wrappedColorsForBabylon[l].g, this._wrappedColorsForBabylon[l].b, this._wrappedColorsForBabylon[l].a);
148
158
  }
@@ -212,10 +222,11 @@ export class SolidParser {
212
222
  for (let k = 0; k < this._triangles.length; k++) {
213
223
  // Set position indice
214
224
  const indicePositionFromObj = parseInt(this._triangles[k]) - 1;
215
- this._setData(indicePositionFromObj, 0, 0, // In the pattern 1, normals and uvs are not defined
216
- this._positions[indicePositionFromObj], // Get the vectors data
217
- Vector2.Zero(), Vector3.Up(), // Create default vectors
218
- this._getColor(indicePositionFromObj));
225
+ this._setData({
226
+ indicePositionFromObj,
227
+ positionVectorFromOBJ: this._positions[indicePositionFromObj],
228
+ positionColorsFromOBJ: this._getColor(indicePositionFromObj),
229
+ });
219
230
  }
220
231
  //Reset variable for the next line
221
232
  this._triangles.length = 0;
@@ -237,10 +248,13 @@ export class SolidParser {
237
248
  const indicePositionFromObj = parseInt(point[0]) - 1;
238
249
  //Set uv indice
239
250
  const indiceUvsFromObj = parseInt(point[1]) - 1;
240
- this._setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
241
- this._positions[indicePositionFromObj], //Get the values for each element
242
- this._uvs[indiceUvsFromObj] ?? Vector2.Zero(), Vector3.Up(), //Default value for normals
243
- this._getColor(indicePositionFromObj));
251
+ this._setData({
252
+ indicePositionFromObj,
253
+ indiceUvsFromObj,
254
+ positionVectorFromOBJ: this._positions[indicePositionFromObj],
255
+ textureVectorFromOBJ: this._uvs[indiceUvsFromObj],
256
+ positionColorsFromOBJ: this._getColor(indicePositionFromObj),
257
+ });
244
258
  }
245
259
  //Reset variable for the next line
246
260
  this._triangles.length = 0;
@@ -264,8 +278,14 @@ export class SolidParser {
264
278
  const indiceUvsFromObj = parseInt(point[1]) - 1;
265
279
  // Set normal indice
266
280
  const indiceNormalFromObj = parseInt(point[2]) - 1;
267
- this._setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, this._positions[indicePositionFromObj], this._uvs[indiceUvsFromObj] ?? Vector2.Zero(), this._normals[indiceNormalFromObj] ?? Vector3.Up() //Set the vector for each component
268
- );
281
+ this._setData({
282
+ indicePositionFromObj,
283
+ indiceUvsFromObj,
284
+ indiceNormalFromObj,
285
+ positionVectorFromOBJ: this._positions[indicePositionFromObj],
286
+ textureVectorFromOBJ: this._uvs[indiceUvsFromObj],
287
+ normalsVectorFromOBJ: this._normals[indiceNormalFromObj],
288
+ });
269
289
  }
270
290
  //Reset variable for the next line
271
291
  this._triangles.length = 0;
@@ -285,9 +305,13 @@ export class SolidParser {
285
305
  // We check indices, and normals
286
306
  const indicePositionFromObj = parseInt(point[0]) - 1;
287
307
  const indiceNormalFromObj = parseInt(point[1]) - 1;
288
- this._setData(indicePositionFromObj, 1, //Default value for uv
289
- indiceNormalFromObj, this._positions[indicePositionFromObj], //Get each vector of data
290
- Vector2.Zero(), this._normals[indiceNormalFromObj], this._getColor(indicePositionFromObj));
308
+ this._setData({
309
+ indicePositionFromObj,
310
+ indiceNormalFromObj,
311
+ positionVectorFromOBJ: this._positions[indicePositionFromObj],
312
+ normalsVectorFromOBJ: this._normals[indiceNormalFromObj],
313
+ positionColorsFromOBJ: this._getColor(indicePositionFromObj),
314
+ });
291
315
  }
292
316
  //Reset variable for the next line
293
317
  this._triangles.length = 0;
@@ -311,8 +335,15 @@ export class SolidParser {
311
335
  const indiceUvsFromObj = this._uvs.length + parseInt(point[1]);
312
336
  // Set normal indice
313
337
  const indiceNormalFromObj = this._normals.length + parseInt(point[2]);
314
- this._setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, this._positions[indicePositionFromObj], this._uvs[indiceUvsFromObj], this._normals[indiceNormalFromObj], //Set the vector for each component
315
- this._getColor(indicePositionFromObj));
338
+ this._setData({
339
+ indicePositionFromObj,
340
+ indiceUvsFromObj,
341
+ indiceNormalFromObj,
342
+ positionVectorFromOBJ: this._positions[indicePositionFromObj],
343
+ textureVectorFromOBJ: this._uvs[indiceUvsFromObj],
344
+ normalsVectorFromOBJ: this._normals[indiceNormalFromObj],
345
+ positionColorsFromOBJ: this._getColor(indicePositionFromObj),
346
+ });
316
347
  }
317
348
  //Reset variable for the next line
318
349
  this._triangles.length = 0;
@@ -333,12 +364,16 @@ export class SolidParser {
333
364
  //Slice the array to avoid rewriting because of the fact this is the same var which be rewrited
334
365
  this._handledMesh.indices = this._indicesForBabylon.slice();
335
366
  this._handledMesh.positions = this._unwrappedPositionsForBabylon.slice();
336
- this._handledMesh.normals = this._unwrappedNormalsForBabylon.slice();
337
- this._handledMesh.uvs = this._unwrappedUVForBabylon.slice();
338
- this._handledMesh.hasLines = this._hasLineData;
339
- if (this._loadingOptions.importVertexColors) {
367
+ if (this._unwrappedNormalsForBabylon.length) {
368
+ this._handledMesh.normals = this._unwrappedNormalsForBabylon.slice();
369
+ }
370
+ if (this._unwrappedUVForBabylon.length) {
371
+ this._handledMesh.uvs = this._unwrappedUVForBabylon.slice();
372
+ }
373
+ if (this._unwrappedColorsForBabylon.length) {
340
374
  this._handledMesh.colors = this._unwrappedColorsForBabylon.slice();
341
375
  }
376
+ this._handledMesh.hasLines = this._hasLineData;
342
377
  //Reset the array for the next mesh
343
378
  this._indicesForBabylon.length = 0;
344
379
  this._unwrappedPositionsForBabylon.length = 0;
@@ -677,12 +712,16 @@ export class SolidParser {
677
712
  //Set array
678
713
  this._handledMesh.indices = this._indicesForBabylon;
679
714
  this._handledMesh.positions = this._unwrappedPositionsForBabylon;
680
- this._handledMesh.normals = this._unwrappedNormalsForBabylon;
681
- this._handledMesh.uvs = this._unwrappedUVForBabylon;
682
- this._handledMesh.hasLines = this._hasLineData;
683
- if (this._loadingOptions.importVertexColors) {
715
+ if (this._unwrappedNormalsForBabylon.length) {
716
+ this._handledMesh.normals = this._unwrappedNormalsForBabylon;
717
+ }
718
+ if (this._unwrappedUVForBabylon.length) {
719
+ this._handledMesh.uvs = this._unwrappedUVForBabylon;
720
+ }
721
+ if (this._unwrappedColorsForBabylon.length) {
684
722
  this._handledMesh.colors = this._unwrappedColorsForBabylon;
685
723
  }
724
+ this._handledMesh.hasLines = this._hasLineData;
686
725
  }
687
726
  // If any o or g keyword not found, create a mesh with a random id
688
727
  if (!this._hasMeshes) {
@@ -795,10 +834,10 @@ export class SolidParser {
795
834
  }
796
835
  const vertexData = new VertexData(); //The container for the values
797
836
  //Set the data for the babylonMesh
798
- vertexData.uvs = this._handledMesh.uvs;
799
837
  vertexData.indices = this._handledMesh.indices;
800
838
  vertexData.positions = this._handledMesh.positions;
801
- if (this._loadingOptions.computeNormals) {
839
+ if (this._loadingOptions.computeNormals || !this._handledMesh.normals) {
840
+ // Compute normals if requested or if normals are not defined
802
841
  const normals = new Array();
803
842
  VertexData.ComputeNormals(this._handledMesh.positions, this._handledMesh.indices, normals);
804
843
  vertexData.normals = normals;
@@ -806,7 +845,10 @@ export class SolidParser {
806
845
  else {
807
846
  vertexData.normals = this._handledMesh.normals;
808
847
  }
809
- if (this._loadingOptions.importVertexColors) {
848
+ if (this._handledMesh.uvs) {
849
+ vertexData.uvs = this._handledMesh.uvs;
850
+ }
851
+ if (this._handledMesh.colors) {
810
852
  vertexData.colors = this._handledMesh.colors;
811
853
  }
812
854
  //Set the data from the VertexBuffer to the current Mesh