babylonjs-serializers 5.32.1 → 5.33.0

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.
@@ -1389,22 +1389,18 @@ __webpack_require__.r(__webpack_exports__);
1389
1389
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1390
1390
  /* harmony export */ "KHR_texture_transform": () => (/* binding */ KHR_texture_transform)
1391
1391
  /* harmony export */ });
1392
- /* harmony import */ var core_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! core/Materials/Textures/Procedurals/proceduralTexture */ "core/Maths/math.vector");
1392
+ /* harmony import */ var core_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! core/Misc/tools */ "core/Maths/math.vector");
1393
1393
  /* harmony import */ var core_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(core_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
1394
1394
  /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFExporter */ "../../../lts/serializers/dist/glTF/2.0/glTFExporter.js");
1395
- /* harmony import */ var _shaders_textureTransform_fragment__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../shaders/textureTransform.fragment */ "../../../lts/serializers/dist/glTF/2.0/shaders/textureTransform.fragment.js");
1396
-
1397
1395
 
1398
1396
 
1399
1397
  var NAME = "KHR_texture_transform";
1400
-
1401
1398
  /**
1402
1399
  * @internal
1403
1400
  */
1404
1401
  // eslint-disable-next-line @typescript-eslint/naming-convention
1405
1402
  var KHR_texture_transform = /** @class */ (function () {
1406
1403
  function KHR_texture_transform() {
1407
- this._recordedTextures = [];
1408
1404
  /** Name of this extension */
1409
1405
  this.name = NAME;
1410
1406
  /** Defines whether this extension is enabled */
@@ -1414,12 +1410,7 @@ var KHR_texture_transform = /** @class */ (function () {
1414
1410
  /** Reference to the glTF exporter */
1415
1411
  this._wasUsed = false;
1416
1412
  }
1417
- KHR_texture_transform.prototype.dispose = function () {
1418
- for (var _i = 0, _a = this._recordedTextures; _i < _a.length; _i++) {
1419
- var texture = _a[_i];
1420
- texture.dispose();
1421
- }
1422
- };
1413
+ KHR_texture_transform.prototype.dispose = function () { };
1423
1414
  Object.defineProperty(KHR_texture_transform.prototype, "wasUsed", {
1424
1415
  /** @internal */
1425
1416
  get: function () {
@@ -1462,67 +1453,23 @@ var KHR_texture_transform = /** @class */ (function () {
1462
1453
  }
1463
1454
  };
1464
1455
  KHR_texture_transform.prototype.preExportTextureAsync = function (context, babylonTexture) {
1465
- var _this = this;
1466
1456
  return new Promise(function (resolve, reject) {
1467
1457
  var scene = babylonTexture.getScene();
1468
1458
  if (!scene) {
1469
1459
  reject("".concat(context, ": \"scene\" is not defined for Babylon texture ").concat(babylonTexture.name, "!"));
1470
1460
  return;
1471
1461
  }
1472
- var bakeTextureTransform = false;
1473
1462
  /*
1474
1463
  * The KHR_texture_transform schema only supports rotation around the origin.
1475
- * the texture must be baked to preserve appearance.
1476
- * see: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates
1464
+ * See https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates.
1477
1465
  */
1478
1466
  if ((babylonTexture.uAng !== 0 || babylonTexture.wAng !== 0 || babylonTexture.vAng !== 0) &&
1479
1467
  (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0)) {
1480
- bakeTextureTransform = true;
1481
- }
1482
- if (!bakeTextureTransform) {
1483
- resolve(babylonTexture);
1484
- return;
1485
- }
1486
- return _this._textureTransformTextureAsync(babylonTexture, scene)
1487
- .then(function (proceduralTexture) {
1488
- resolve(proceduralTexture);
1489
- })
1490
- .catch(function (e) {
1491
- reject(e);
1492
- });
1493
- });
1494
- };
1495
- /**
1496
- * Transform the babylon texture by the offset, rotation and scale parameters using a procedural texture
1497
- * @param babylonTexture
1498
- * @param scene
1499
- */
1500
- KHR_texture_transform.prototype._textureTransformTextureAsync = function (babylonTexture, scene) {
1501
- var _this = this;
1502
- return new Promise(function (resolve) {
1503
- var proceduralTexture = new core_Misc_tools__WEBPACK_IMPORTED_MODULE_0__.ProceduralTexture("".concat(babylonTexture.name), babylonTexture.getSize(), "textureTransform", scene);
1504
- if (!proceduralTexture) {
1505
- core_Misc_tools__WEBPACK_IMPORTED_MODULE_0__.Tools.Log("Cannot create procedural texture for ".concat(babylonTexture.name, "!"));
1506
- resolve(babylonTexture);
1507
- }
1508
- proceduralTexture.reservedDataStore = {
1509
- hidden: true,
1510
- source: babylonTexture,
1511
- };
1512
- _this._recordedTextures.push(proceduralTexture);
1513
- proceduralTexture.coordinatesIndex = babylonTexture.coordinatesIndex;
1514
- proceduralTexture.setTexture("textureSampler", babylonTexture);
1515
- proceduralTexture.setMatrix("textureTransformMat", babylonTexture.getTextureMatrix());
1516
- // isReady trigger creation of effect if it doesnt exist yet
1517
- if (proceduralTexture.isReady()) {
1518
- proceduralTexture.render();
1519
- resolve(proceduralTexture);
1468
+ core_Misc_tools__WEBPACK_IMPORTED_MODULE_0__.Tools.Warn("".concat(context, ": Texture ").concat(babylonTexture.name, " with rotation not centered at the origin cannot be exported with ").concat(NAME));
1469
+ resolve(null);
1520
1470
  }
1521
1471
  else {
1522
- proceduralTexture.getEffect().executeWhenCompiled(function () {
1523
- proceduralTexture.render();
1524
- resolve(proceduralTexture);
1525
- });
1472
+ resolve(babylonTexture);
1526
1473
  }
1527
1474
  });
1528
1475
  };
@@ -3356,8 +3303,8 @@ var _Exporter = /** @class */ (function () {
3356
3303
  imageData = _this._imageData[image.uri];
3357
3304
  _this._orderedImageData.push(imageData);
3358
3305
  imageName = image.uri.split(".")[0] + " image";
3359
- bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__._GLTFUtilities._CreateBufferView(0, byteOffset, imageData.data.length, undefined, imageName);
3360
- byteOffset += imageData.data.buffer.byteLength;
3306
+ bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__._GLTFUtilities._CreateBufferView(0, byteOffset, imageData.data.byteLength, undefined, imageName);
3307
+ byteOffset += imageData.data.byteLength;
3361
3308
  _this._bufferViews.push(bufferView);
3362
3309
  image.bufferView = _this._bufferViews.length - 1;
3363
3310
  image.name = imageName;
@@ -3514,7 +3461,7 @@ var _Exporter = /** @class */ (function () {
3514
3461
  var glbData = [headerBuffer, jsonChunkBuffer, binaryChunkBuffer, binaryBuffer];
3515
3462
  // binary data
3516
3463
  for (var i = 0; i < _this._orderedImageData.length; ++i) {
3517
- glbData.push(_this._orderedImageData[i].data.buffer);
3464
+ glbData.push(_this._orderedImageData[i].data);
3518
3465
  }
3519
3466
  glbData.push(binPaddingBuffer);
3520
3467
  glbData.push(imagePaddingBuffer);
@@ -4610,7 +4557,7 @@ __webpack_require__.r(__webpack_exports__);
4610
4557
  /* harmony export */ "_GLTFMaterialExporter": () => (/* binding */ _GLTFMaterialExporter)
4611
4558
  /* harmony export */ });
4612
4559
  /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../../../node_modules/tslib/tslib.es6.js");
4613
- /* harmony import */ var core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! core/Engines/constants */ "core/Maths/math.vector");
4560
+ /* harmony import */ var core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! core/Misc/dumpTools */ "core/Maths/math.vector");
4614
4561
  /* harmony import */ var core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
4615
4562
 
4616
4563
 
@@ -4621,6 +4568,17 @@ __webpack_require__.r(__webpack_exports__);
4621
4568
 
4622
4569
 
4623
4570
 
4571
+
4572
+ function getFileExtensionFromMimeType(mimeType) {
4573
+ switch (mimeType) {
4574
+ case "image/jpeg" /* JPEG */:
4575
+ return ".jpg";
4576
+ case "image/png" /* PNG */:
4577
+ return ".png";
4578
+ case "image/webp" /* WEBP */:
4579
+ return ".webp";
4580
+ }
4581
+ }
4624
4582
  /**
4625
4583
  * Utility methods for working with glTF material conversion properties. This class should only be used internally
4626
4584
  * @internal
@@ -4631,6 +4589,8 @@ var _GLTFMaterialExporter = /** @class */ (function () {
4631
4589
  * Mapping to store textures
4632
4590
  */
4633
4591
  this._textureMap = {};
4592
+ // Mapping of internal textures to images to avoid exporting duplicate images.
4593
+ this._internalTextureToImage = {};
4634
4594
  this._textureMap = {};
4635
4595
  this._exporter = exporter;
4636
4596
  }
@@ -4815,68 +4775,68 @@ var _GLTFMaterialExporter = /** @class */ (function () {
4815
4775
  var materialMap = this._exporter._materialMap;
4816
4776
  var materials = this._exporter._materials;
4817
4777
  var promises = [];
4818
- var glTFPbrMetallicRoughness = this._convertToGLTFPBRMetallicRoughness(babylonStandardMaterial);
4819
- var glTFMaterial = { name: babylonStandardMaterial.name };
4778
+ var pbrMetallicRoughness = this._convertToGLTFPBRMetallicRoughness(babylonStandardMaterial);
4779
+ var material = { name: babylonStandardMaterial.name };
4820
4780
  if (babylonStandardMaterial.backFaceCulling != null && !babylonStandardMaterial.backFaceCulling) {
4821
4781
  if (!babylonStandardMaterial.twoSidedLighting) {
4822
4782
  core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Tools.Warn(babylonStandardMaterial.name + ": Back-face culling disabled and two-sided lighting disabled is not supported in glTF.");
4823
4783
  }
4824
- glTFMaterial.doubleSided = true;
4784
+ material.doubleSided = true;
4825
4785
  }
4826
4786
  if (hasTextureCoords) {
4827
4787
  if (babylonStandardMaterial.diffuseTexture) {
4828
- promises.push(this._exportTextureAsync(babylonStandardMaterial.diffuseTexture, mimeType).then(function (glTFTexture) {
4829
- if (glTFTexture) {
4830
- glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
4788
+ promises.push(this._exportTextureAsync(babylonStandardMaterial.diffuseTexture, mimeType).then(function (textureInfo) {
4789
+ if (textureInfo) {
4790
+ pbrMetallicRoughness.baseColorTexture = textureInfo;
4831
4791
  }
4832
4792
  }));
4833
4793
  }
4834
- if (babylonStandardMaterial.bumpTexture) {
4835
- promises.push(this._exportTextureAsync(babylonStandardMaterial.bumpTexture, mimeType).then(function (glTFTexture) {
4836
- if (glTFTexture) {
4837
- glTFMaterial.normalTexture = glTFTexture;
4838
- if (babylonStandardMaterial.bumpTexture != null && babylonStandardMaterial.bumpTexture.level !== 1) {
4839
- glTFMaterial.normalTexture.scale = babylonStandardMaterial.bumpTexture.level;
4794
+ var bumpTexture_1 = babylonStandardMaterial.bumpTexture;
4795
+ if (bumpTexture_1) {
4796
+ promises.push(this._exportTextureAsync(bumpTexture_1, mimeType).then(function (textureInfo) {
4797
+ if (textureInfo) {
4798
+ material.normalTexture = textureInfo;
4799
+ if (bumpTexture_1.level !== 1) {
4800
+ material.normalTexture.scale = bumpTexture_1.level;
4840
4801
  }
4841
4802
  }
4842
4803
  }));
4843
4804
  }
4844
4805
  if (babylonStandardMaterial.emissiveTexture) {
4845
- glTFMaterial.emissiveFactor = [1.0, 1.0, 1.0];
4846
- promises.push(this._exportTextureAsync(babylonStandardMaterial.emissiveTexture, mimeType).then(function (glTFEmissiveTexture) {
4847
- if (glTFEmissiveTexture) {
4848
- glTFMaterial.emissiveTexture = glTFEmissiveTexture;
4806
+ material.emissiveFactor = [1.0, 1.0, 1.0];
4807
+ promises.push(this._exportTextureAsync(babylonStandardMaterial.emissiveTexture, mimeType).then(function (textureInfo) {
4808
+ if (textureInfo) {
4809
+ material.emissiveTexture = textureInfo;
4849
4810
  }
4850
4811
  }));
4851
4812
  }
4852
4813
  if (babylonStandardMaterial.ambientTexture) {
4853
- promises.push(this._exportTextureAsync(babylonStandardMaterial.ambientTexture, mimeType).then(function (glTFTexture) {
4854
- if (glTFTexture) {
4814
+ promises.push(this._exportTextureAsync(babylonStandardMaterial.ambientTexture, mimeType).then(function (textureInfo) {
4815
+ if (textureInfo) {
4855
4816
  var occlusionTexture = {
4856
- index: glTFTexture.index,
4817
+ index: textureInfo.index,
4857
4818
  };
4858
- glTFMaterial.occlusionTexture = occlusionTexture;
4859
- occlusionTexture.strength = 1.0;
4819
+ material.occlusionTexture = occlusionTexture;
4860
4820
  }
4861
4821
  }));
4862
4822
  }
4863
4823
  }
4864
4824
  if (babylonStandardMaterial.alpha < 1.0 || babylonStandardMaterial.opacityTexture) {
4865
4825
  if (babylonStandardMaterial.alphaMode === core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Constants.ALPHA_COMBINE) {
4866
- glTFMaterial.alphaMode = "BLEND" /* BLEND */;
4826
+ material.alphaMode = "BLEND" /* BLEND */;
4867
4827
  }
4868
4828
  else {
4869
4829
  core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Tools.Warn(babylonStandardMaterial.name + ": glTF 2.0 does not support alpha mode: " + babylonStandardMaterial.alphaMode.toString());
4870
4830
  }
4871
4831
  }
4872
4832
  if (babylonStandardMaterial.emissiveColor && !_GLTFMaterialExporter._FuzzyEquals(babylonStandardMaterial.emissiveColor, core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Color3.Black(), _GLTFMaterialExporter._Epsilon)) {
4873
- glTFMaterial.emissiveFactor = babylonStandardMaterial.emissiveColor.asArray();
4833
+ material.emissiveFactor = babylonStandardMaterial.emissiveColor.asArray();
4874
4834
  }
4875
- glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
4876
- _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonStandardMaterial);
4877
- materials.push(glTFMaterial);
4835
+ material.pbrMetallicRoughness = pbrMetallicRoughness;
4836
+ _GLTFMaterialExporter._SetAlphaMode(material, babylonStandardMaterial);
4837
+ materials.push(material);
4878
4838
  materialMap[babylonStandardMaterial.uniqueId] = materials.length - 1;
4879
- return this._finishMaterial(promises, glTFMaterial, babylonStandardMaterial, mimeType);
4839
+ return this._finishMaterial(promises, material, babylonStandardMaterial, mimeType);
4880
4840
  };
4881
4841
  _GLTFMaterialExporter.prototype._finishMaterial = function (promises, glTFMaterial, babylonMaterial, mimeType) {
4882
4842
  var _this = this;
@@ -4910,11 +4870,9 @@ var _GLTFMaterialExporter = /** @class */ (function () {
4910
4870
  * @param mimeType mimetype of the image
4911
4871
  * @returns base64 image string
4912
4872
  */
4913
- _GLTFMaterialExporter.prototype._createBase64FromCanvasAsync = function (buffer, width, height, mimeType) {
4914
- var _this = this;
4915
- // eslint-disable-next-line no-async-promise-executor
4916
- return new Promise(function (resolve) { return (0,tslib__WEBPACK_IMPORTED_MODULE_0__.__awaiter)(_this, void 0, void 0, function () {
4917
- var textureType, hostingScene, engine, tempTexture, data, base64;
4873
+ _GLTFMaterialExporter.prototype._getImageDataAsync = function (buffer, width, height, mimeType) {
4874
+ return (0,tslib__WEBPACK_IMPORTED_MODULE_0__.__awaiter)(this, void 0, void 0, function () {
4875
+ var textureType, hostingScene, engine, tempTexture, data;
4918
4876
  return (0,tslib__WEBPACK_IMPORTED_MODULE_0__.__generator)(this, function (_a) {
4919
4877
  switch (_a.label) {
4920
4878
  case 0:
@@ -4928,14 +4886,11 @@ var _GLTFMaterialExporter = /** @class */ (function () {
4928
4886
  return [4 /*yield*/, engine._readTexturePixels(tempTexture, width, height)];
4929
4887
  case 2:
4930
4888
  data = _a.sent();
4931
- return [4 /*yield*/, core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Tools.DumpDataAsync(width, height, data, mimeType, undefined, true, false)];
4932
- case 3:
4933
- base64 = _a.sent();
4934
- resolve(base64);
4935
- return [2 /*return*/];
4889
+ return [4 /*yield*/, core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.DumpTools.DumpDataAsync(width, height, data, mimeType, undefined, true, true)];
4890
+ case 3: return [2 /*return*/, (_a.sent())];
4936
4891
  }
4937
4892
  });
4938
- }); });
4893
+ });
4939
4894
  };
4940
4895
  /**
4941
4896
  * Generates a white texture based on the specified width and height
@@ -5026,11 +4981,11 @@ var _GLTFMaterialExporter = /** @class */ (function () {
5026
4981
  _GLTFMaterialExporter.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync = function (diffuseTexture, specularGlossinessTexture, factors, mimeType) {
5027
4982
  var _a;
5028
4983
  return (0,tslib__WEBPACK_IMPORTED_MODULE_0__.__awaiter)(this, void 0, void 0, function () {
5029
- var promises, scene, resizedTextures, diffuseSize, diffuseBuffer, specularGlossinessBuffer, width, height, diffusePixels, specularPixels, byteLength, metallicRoughnessBuffer, baseColorBuffer, strideSize, maxBaseColor, maxMetallic, maxRoughness, h, w, offset, diffuseColor, specularColor, glossiness, specularGlossiness, metallicRoughness, metallicRoughnessFactors_1, writeOutMetallicRoughnessTexture, writeOutBaseColorTexture, h, w, destinationOffset, linearBaseColorPixel, sRGBBaseColorPixel, metallicRoughnessPixel, promise, promise;
4984
+ var promises, scene, resizedTextures, diffuseSize, diffuseBuffer, specularGlossinessBuffer, width, height, diffusePixels, specularPixels, byteLength, metallicRoughnessBuffer, baseColorBuffer, strideSize, maxBaseColor, maxMetallic, maxRoughness, h, w, offset, diffuseColor, specularColor, glossiness, specularGlossiness, metallicRoughness, metallicRoughnessFactors_1, writeOutMetallicRoughnessTexture, writeOutBaseColorTexture, h, w, destinationOffset, linearBaseColorPixel, sRGBBaseColorPixel, metallicRoughnessPixel;
5030
4985
  return (0,tslib__WEBPACK_IMPORTED_MODULE_0__.__generator)(this, function (_b) {
5031
4986
  switch (_b.label) {
5032
4987
  case 0:
5033
- promises = [];
4988
+ promises = new Array();
5034
4989
  if (!(diffuseTexture || specularGlossinessTexture)) {
5035
4990
  return [2 /*return*/, Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!")];
5036
4991
  }
@@ -5127,16 +5082,14 @@ var _GLTFMaterialExporter = /** @class */ (function () {
5127
5082
  }
5128
5083
  }
5129
5084
  if (writeOutMetallicRoughnessTexture) {
5130
- promise = this._createBase64FromCanvasAsync(metallicRoughnessBuffer, width, height, mimeType).then(function (metallicRoughnessBase64) {
5131
- metallicRoughnessFactors_1.metallicRoughnessTextureBase64 = metallicRoughnessBase64;
5132
- });
5133
- promises.push(promise);
5085
+ promises.push(this._getImageDataAsync(metallicRoughnessBuffer, width, height, mimeType).then(function (data) {
5086
+ metallicRoughnessFactors_1.metallicRoughnessTextureData = data;
5087
+ }));
5134
5088
  }
5135
5089
  if (writeOutBaseColorTexture) {
5136
- promise = this._createBase64FromCanvasAsync(baseColorBuffer, width, height, mimeType).then(function (baseColorBase64) {
5137
- metallicRoughnessFactors_1.baseColorTextureBase64 = baseColorBase64;
5138
- });
5139
- promises.push(promise);
5090
+ promises.push(this._getImageDataAsync(baseColorBuffer, width, height, mimeType).then(function (data) {
5091
+ metallicRoughnessFactors_1.baseColorTextureData = data;
5092
+ }));
5140
5093
  }
5141
5094
  return [2 /*return*/, Promise.all(promises).then(function () {
5142
5095
  return metallicRoughnessFactors_1;
@@ -5231,71 +5184,79 @@ var _GLTFMaterialExporter = /** @class */ (function () {
5231
5184
  return metallicRoughness;
5232
5185
  });
5233
5186
  };
5234
- _GLTFMaterialExporter.prototype._getGLTFTextureSampler = function (texture) {
5235
- var sampler = this._getGLTFTextureWrapModesSampler(texture);
5236
- var samplingMode = texture instanceof core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture ? texture.samplingMode : null;
5237
- if (samplingMode != null) {
5238
- switch (samplingMode) {
5239
- case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.LINEAR_LINEAR: {
5240
- sampler.magFilter = 9729 /* LINEAR */;
5241
- sampler.minFilter = 9729 /* LINEAR */;
5242
- break;
5243
- }
5244
- case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.LINEAR_NEAREST: {
5245
- sampler.magFilter = 9729 /* LINEAR */;
5246
- sampler.minFilter = 9728 /* NEAREST */;
5247
- break;
5248
- }
5249
- case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.NEAREST_LINEAR: {
5250
- sampler.magFilter = 9728 /* NEAREST */;
5251
- sampler.minFilter = 9729 /* LINEAR */;
5252
- break;
5253
- }
5254
- case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.NEAREST_LINEAR_MIPLINEAR: {
5255
- sampler.magFilter = 9728 /* NEAREST */;
5256
- sampler.minFilter = 9987 /* LINEAR_MIPMAP_LINEAR */;
5257
- break;
5258
- }
5259
- case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.NEAREST_NEAREST: {
5260
- sampler.magFilter = 9728 /* NEAREST */;
5261
- sampler.minFilter = 9728 /* NEAREST */;
5262
- break;
5263
- }
5264
- case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.NEAREST_LINEAR_MIPNEAREST: {
5265
- sampler.magFilter = 9728 /* NEAREST */;
5266
- sampler.minFilter = 9985 /* LINEAR_MIPMAP_NEAREST */;
5267
- break;
5268
- }
5269
- case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.LINEAR_NEAREST_MIPNEAREST: {
5270
- sampler.magFilter = 9729 /* LINEAR */;
5271
- sampler.minFilter = 9984 /* NEAREST_MIPMAP_NEAREST */;
5272
- break;
5273
- }
5274
- case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.LINEAR_NEAREST_MIPLINEAR: {
5275
- sampler.magFilter = 9729 /* LINEAR */;
5276
- sampler.minFilter = 9986 /* NEAREST_MIPMAP_LINEAR */;
5277
- break;
5278
- }
5279
- case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.NEAREST_NEAREST_MIPLINEAR: {
5280
- sampler.magFilter = 9728 /* NEAREST */;
5281
- sampler.minFilter = 9986 /* NEAREST_MIPMAP_LINEAR */;
5282
- break;
5283
- }
5284
- case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.LINEAR_LINEAR_MIPLINEAR: {
5285
- sampler.magFilter = 9729 /* LINEAR */;
5286
- sampler.minFilter = 9987 /* LINEAR_MIPMAP_LINEAR */;
5287
- break;
5288
- }
5289
- case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.LINEAR_LINEAR_MIPNEAREST: {
5290
- sampler.magFilter = 9729 /* LINEAR */;
5291
- sampler.minFilter = 9985 /* LINEAR_MIPMAP_NEAREST */;
5292
- break;
5293
- }
5294
- case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.NEAREST_NEAREST_MIPNEAREST: {
5295
- sampler.magFilter = 9728 /* NEAREST */;
5296
- sampler.minFilter = 9984 /* NEAREST_MIPMAP_NEAREST */;
5297
- break;
5298
- }
5187
+ _GLTFMaterialExporter.prototype._getTextureSampler = function (texture) {
5188
+ var sampler = {};
5189
+ if (!texture || !(texture instanceof core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture)) {
5190
+ return sampler;
5191
+ }
5192
+ var wrapS = this._getGLTFTextureWrapMode(texture.wrapU);
5193
+ if (wrapS !== 10497 /* REPEAT */) {
5194
+ sampler.wrapS = wrapS;
5195
+ }
5196
+ var wrapT = this._getGLTFTextureWrapMode(texture.wrapV);
5197
+ if (wrapT !== 10497 /* REPEAT */) {
5198
+ sampler.wrapT = wrapT;
5199
+ }
5200
+ switch (texture.samplingMode) {
5201
+ case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.LINEAR_LINEAR: {
5202
+ sampler.magFilter = 9729 /* LINEAR */;
5203
+ sampler.minFilter = 9729 /* LINEAR */;
5204
+ break;
5205
+ }
5206
+ case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.LINEAR_NEAREST: {
5207
+ sampler.magFilter = 9729 /* LINEAR */;
5208
+ sampler.minFilter = 9728 /* NEAREST */;
5209
+ break;
5210
+ }
5211
+ case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.NEAREST_LINEAR: {
5212
+ sampler.magFilter = 9728 /* NEAREST */;
5213
+ sampler.minFilter = 9729 /* LINEAR */;
5214
+ break;
5215
+ }
5216
+ case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.NEAREST_LINEAR_MIPLINEAR: {
5217
+ sampler.magFilter = 9728 /* NEAREST */;
5218
+ sampler.minFilter = 9987 /* LINEAR_MIPMAP_LINEAR */;
5219
+ break;
5220
+ }
5221
+ case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.NEAREST_NEAREST: {
5222
+ sampler.magFilter = 9728 /* NEAREST */;
5223
+ sampler.minFilter = 9728 /* NEAREST */;
5224
+ break;
5225
+ }
5226
+ case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.NEAREST_LINEAR_MIPNEAREST: {
5227
+ sampler.magFilter = 9728 /* NEAREST */;
5228
+ sampler.minFilter = 9985 /* LINEAR_MIPMAP_NEAREST */;
5229
+ break;
5230
+ }
5231
+ case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.LINEAR_NEAREST_MIPNEAREST: {
5232
+ sampler.magFilter = 9729 /* LINEAR */;
5233
+ sampler.minFilter = 9984 /* NEAREST_MIPMAP_NEAREST */;
5234
+ break;
5235
+ }
5236
+ case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.LINEAR_NEAREST_MIPLINEAR: {
5237
+ sampler.magFilter = 9729 /* LINEAR */;
5238
+ sampler.minFilter = 9986 /* NEAREST_MIPMAP_LINEAR */;
5239
+ break;
5240
+ }
5241
+ case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.NEAREST_NEAREST_MIPLINEAR: {
5242
+ sampler.magFilter = 9728 /* NEAREST */;
5243
+ sampler.minFilter = 9986 /* NEAREST_MIPMAP_LINEAR */;
5244
+ break;
5245
+ }
5246
+ case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.LINEAR_LINEAR_MIPLINEAR: {
5247
+ sampler.magFilter = 9729 /* LINEAR */;
5248
+ sampler.minFilter = 9987 /* LINEAR_MIPMAP_LINEAR */;
5249
+ break;
5250
+ }
5251
+ case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.LINEAR_LINEAR_MIPNEAREST: {
5252
+ sampler.magFilter = 9729 /* LINEAR */;
5253
+ sampler.minFilter = 9985 /* LINEAR_MIPMAP_NEAREST */;
5254
+ break;
5255
+ }
5256
+ case core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.NEAREST_NEAREST_MIPNEAREST: {
5257
+ sampler.magFilter = 9728 /* NEAREST */;
5258
+ sampler.minFilter = 9984 /* NEAREST_MIPMAP_NEAREST */;
5259
+ break;
5299
5260
  }
5300
5261
  }
5301
5262
  return sampler;
@@ -5317,15 +5278,6 @@ var _GLTFMaterialExporter = /** @class */ (function () {
5317
5278
  }
5318
5279
  }
5319
5280
  };
5320
- _GLTFMaterialExporter.prototype._getGLTFTextureWrapModesSampler = function (texture) {
5321
- var wrapS = this._getGLTFTextureWrapMode(texture instanceof core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture ? texture.wrapU : core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.WRAP_ADDRESSMODE);
5322
- var wrapT = this._getGLTFTextureWrapMode(texture instanceof core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture ? texture.wrapV : core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Texture.WRAP_ADDRESSMODE);
5323
- if (wrapS === 10497 /* REPEAT */ && wrapT === 10497 /* REPEAT */) {
5324
- // default wrapping mode in glTF, so omitting
5325
- return {};
5326
- }
5327
- return { wrapS: wrapS, wrapT: wrapT };
5328
- };
5329
5281
  /**
5330
5282
  * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors
5331
5283
  * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
@@ -5334,46 +5286,31 @@ var _GLTFMaterialExporter = /** @class */ (function () {
5334
5286
  * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
5335
5287
  * @returns glTF PBR Metallic Roughness factors
5336
5288
  */
5337
- _GLTFMaterialExporter.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync = function (babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords) {
5289
+ _GLTFMaterialExporter.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync = function (babylonPBRMaterial, mimeType, pbrMetallicRoughness, hasTextureCoords) {
5338
5290
  var _this = this;
5339
5291
  return Promise.resolve().then(function () {
5340
- var samplers = _this._exporter._samplers;
5341
- var textures = _this._exporter._textures;
5342
- var diffuseColor = babylonPBRMaterial._albedoColor;
5343
- var specularColor = babylonPBRMaterial._reflectivityColor;
5344
- var glossiness = babylonPBRMaterial._microSurface;
5345
5292
  var specGloss = {
5346
- diffuseColor: diffuseColor,
5347
- specularColor: specularColor,
5348
- glossiness: glossiness,
5293
+ diffuseColor: babylonPBRMaterial._albedoColor,
5294
+ specularColor: babylonPBRMaterial._reflectivityColor,
5295
+ glossiness: babylonPBRMaterial._microSurface,
5349
5296
  };
5350
- var samplerIndex = null;
5351
5297
  var albedoTexture = babylonPBRMaterial._albedoTexture;
5352
5298
  var reflectivityTexture = babylonPBRMaterial._reflectivityTexture;
5353
- if (albedoTexture) {
5354
- var sampler = _this._getGLTFTextureSampler(albedoTexture);
5355
- if (sampler.magFilter != null && sampler.minFilter != null && sampler.wrapS != null && sampler.wrapT != null) {
5356
- samplers.push(sampler);
5357
- samplerIndex = samplers.length - 1;
5358
- }
5359
- }
5360
5299
  var useMicrosurfaceFromReflectivityMapAlpha = babylonPBRMaterial._useMicroSurfaceFromReflectivityMapAlpha;
5361
5300
  if (reflectivityTexture && !useMicrosurfaceFromReflectivityMapAlpha) {
5362
5301
  return Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported");
5363
5302
  }
5364
5303
  if ((albedoTexture || reflectivityTexture) && hasTextureCoords) {
5304
+ var samplerIndex_1 = _this._exportTextureSampler(albedoTexture || reflectivityTexture);
5365
5305
  return _this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(albedoTexture, reflectivityTexture, specGloss, mimeType).then(function (metallicRoughnessFactors) {
5366
- if (metallicRoughnessFactors.baseColorTextureBase64) {
5367
- var glTFBaseColorTexture = _this._getTextureInfoFromBase64(metallicRoughnessFactors.baseColorTextureBase64, "bjsBaseColorTexture_" + textures.length + ".png", mimeType, albedoTexture ? albedoTexture.coordinatesIndex : null, samplerIndex);
5368
- if (glTFBaseColorTexture) {
5369
- glTFPbrMetallicRoughness.baseColorTexture = glTFBaseColorTexture;
5370
- }
5306
+ var textures = _this._exporter._textures;
5307
+ if (metallicRoughnessFactors.baseColorTextureData) {
5308
+ var imageIndex = _this._exportImage("baseColor".concat(textures.length), mimeType, metallicRoughnessFactors.baseColorTextureData);
5309
+ pbrMetallicRoughness.baseColorTexture = _this._exportTextureInfo(imageIndex, samplerIndex_1, albedoTexture === null || albedoTexture === void 0 ? void 0 : albedoTexture.coordinatesIndex);
5371
5310
  }
5372
- if (metallicRoughnessFactors.metallicRoughnessTextureBase64) {
5373
- var glTFMRColorTexture = _this._getTextureInfoFromBase64(metallicRoughnessFactors.metallicRoughnessTextureBase64, "bjsMetallicRoughnessTexture_" + textures.length + ".png", mimeType, reflectivityTexture ? reflectivityTexture.coordinatesIndex : null, samplerIndex);
5374
- if (glTFMRColorTexture) {
5375
- glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFMRColorTexture;
5376
- }
5311
+ if (metallicRoughnessFactors.metallicRoughnessTextureData) {
5312
+ var imageIndex = _this._exportImage("metallicRoughness".concat(textures.length), mimeType, metallicRoughnessFactors.metallicRoughnessTextureData);
5313
+ pbrMetallicRoughness.metallicRoughnessTexture = _this._exportTextureInfo(imageIndex, samplerIndex_1, reflectivityTexture === null || reflectivityTexture === void 0 ? void 0 : reflectivityTexture.coordinatesIndex);
5377
5314
  }
5378
5315
  return metallicRoughnessFactors;
5379
5316
  });
@@ -5435,13 +5372,13 @@ var _GLTFMaterialExporter = /** @class */ (function () {
5435
5372
  glTFMaterial.doubleSided = true;
5436
5373
  }
5437
5374
  if (hasTextureCoords) {
5438
- var bumpTexture_1 = babylonPBRMaterial._bumpTexture;
5439
- if (bumpTexture_1) {
5440
- var promise = this._exportTextureAsync(bumpTexture_1, mimeType).then(function (glTFTexture) {
5375
+ var bumpTexture_2 = babylonPBRMaterial._bumpTexture;
5376
+ if (bumpTexture_2) {
5377
+ var promise = this._exportTextureAsync(bumpTexture_2, mimeType).then(function (glTFTexture) {
5441
5378
  if (glTFTexture) {
5442
5379
  glTFMaterial.normalTexture = glTFTexture;
5443
- if (bumpTexture_1.level !== 1) {
5444
- glTFMaterial.normalTexture.scale = bumpTexture_1.level;
5380
+ if (bumpTexture_2.level !== 1) {
5381
+ glTFMaterial.normalTexture.scale = bumpTexture_2.level;
5445
5382
  }
5446
5383
  }
5447
5384
  });
@@ -5510,10 +5447,8 @@ var _GLTFMaterialExporter = /** @class */ (function () {
5510
5447
  });
5511
5448
  };
5512
5449
  _GLTFMaterialExporter.prototype._exportTextureInfoAsync = function (babylonTexture, mimeType) {
5513
- var _this = this;
5514
- return Promise.resolve().then(function () { return (0,tslib__WEBPACK_IMPORTED_MODULE_0__.__awaiter)(_this, void 0, void 0, function () {
5515
- var textureUid, pixels, samplers, sampler, samplerIndex_1, foundSamplerIndex, i, s, size;
5516
- var _this = this;
5450
+ return (0,tslib__WEBPACK_IMPORTED_MODULE_0__.__awaiter)(this, void 0, void 0, function () {
5451
+ var textureUid, pixels, samplerIndex, textureMimeType, internalTextureToImage, internalTextureUniqueId, imageIndex, size, data, textureInfo;
5517
5452
  return (0,tslib__WEBPACK_IMPORTED_MODULE_0__.__generator)(this, function (_a) {
5518
5453
  switch (_a.label) {
5519
5454
  case 0:
@@ -5526,118 +5461,86 @@ var _GLTFMaterialExporter = /** @class */ (function () {
5526
5461
  if (!pixels) {
5527
5462
  return [2 /*return*/, null];
5528
5463
  }
5529
- samplers = this._exporter._samplers;
5530
- sampler = this._getGLTFTextureSampler(babylonTexture);
5531
- samplerIndex_1 = null;
5532
- foundSamplerIndex = null;
5533
- for (i = 0; i < samplers.length; ++i) {
5534
- s = samplers[i];
5535
- if (s.minFilter === sampler.minFilter && s.magFilter === sampler.magFilter && s.wrapS === sampler.wrapS && s.wrapT === sampler.wrapT) {
5536
- foundSamplerIndex = i;
5537
- break;
5538
- }
5539
- }
5540
- if (foundSamplerIndex == null) {
5541
- samplers.push(sampler);
5542
- samplerIndex_1 = samplers.length - 1;
5543
- }
5544
- else {
5545
- samplerIndex_1 = foundSamplerIndex;
5546
- }
5547
- size = babylonTexture.getSize();
5548
- // Preserve texture mime type if defined
5549
- if (babylonTexture.mimeType) {
5550
- switch (babylonTexture.mimeType) {
5464
+ samplerIndex = this._exportTextureSampler(babylonTexture);
5465
+ textureMimeType = babylonTexture.mimeType;
5466
+ if (textureMimeType) {
5467
+ switch (textureMimeType) {
5551
5468
  case "image/jpeg":
5552
- mimeType = "image/jpeg" /* JPEG */;
5553
- break;
5554
5469
  case "image/png":
5555
- mimeType = "image/png" /* PNG */;
5556
- break;
5557
5470
  case "image/webp":
5558
- mimeType = "image/webp" /* WEBP */;
5471
+ mimeType = textureMimeType;
5472
+ break;
5473
+ default:
5474
+ core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Tools.Warn("Unsupported media type: ${textureMimeType}");
5559
5475
  break;
5560
5476
  }
5561
5477
  }
5562
- return [2 /*return*/, this._createBase64FromCanvasAsync(pixels, size.width, size.height, mimeType).then(function (base64Data) {
5563
- var textureInfo = _this._getTextureInfoFromBase64(base64Data, babylonTexture.name.replace(/\.\/|\/|\.\\|\\/g, "_"), mimeType, babylonTexture.coordinatesIndex, samplerIndex_1);
5564
- if (textureInfo) {
5565
- _this._textureMap[textureUid] = textureInfo;
5566
- _this._exporter._extensionsPostExportTextures("linkTextureInfo", textureInfo, babylonTexture);
5567
- }
5568
- return textureInfo;
5569
- })];
5478
+ internalTextureToImage = this._internalTextureToImage;
5479
+ internalTextureUniqueId = babylonTexture.getInternalTexture().uniqueId;
5480
+ internalTextureToImage[internalTextureUniqueId] || (internalTextureToImage[internalTextureUniqueId] = {});
5481
+ imageIndex = internalTextureToImage[internalTextureUniqueId][mimeType];
5482
+ if (!(imageIndex === undefined)) return [3 /*break*/, 4];
5483
+ size = babylonTexture.getSize();
5484
+ return [4 /*yield*/, this._getImageDataAsync(pixels, size.width, size.height, mimeType)];
5485
+ case 3:
5486
+ data = _a.sent();
5487
+ imageIndex = this._exportImage(babylonTexture.name, mimeType, data);
5488
+ internalTextureToImage[internalTextureUniqueId][mimeType] = imageIndex;
5489
+ _a.label = 4;
5490
+ case 4:
5491
+ textureInfo = this._exportTextureInfo(imageIndex, samplerIndex, babylonTexture.coordinatesIndex);
5492
+ this._textureMap[textureUid] = textureInfo;
5493
+ return [2 /*return*/, textureInfo];
5570
5494
  }
5571
5495
  });
5572
- }); });
5496
+ });
5573
5497
  };
5574
- /**
5575
- * Builds a texture from base64 string
5576
- * @param base64Texture base64 texture string
5577
- * @param baseTextureName Name to use for the texture
5578
- * @param mimeType image mime type for the texture
5579
- * @param texCoordIndex
5580
- * @param samplerIndex
5581
- * @returns glTF texture info, or null if the texture format is not supported
5582
- */
5583
- _GLTFMaterialExporter.prototype._getTextureInfoFromBase64 = function (base64Texture, baseTextureName, mimeType, texCoordIndex, samplerIndex) {
5584
- var textures = this._exporter._textures;
5585
- var images = this._exporter._images;
5498
+ _GLTFMaterialExporter.prototype._exportImage = function (name, mimeType, data) {
5586
5499
  var imageData = this._exporter._imageData;
5587
- var textureInfo = null;
5588
- var glTFTexture = {
5589
- source: images.length,
5590
- name: baseTextureName,
5500
+ var baseName = name.replace(/\.\/|\/|\.\\|\\/g, "_");
5501
+ var extension = getFileExtensionFromMimeType(mimeType);
5502
+ var fileName = baseName + extension;
5503
+ if (fileName in imageData) {
5504
+ fileName = "".concat(baseName, "_").concat(core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Tools.RandomId()).concat(extension);
5505
+ }
5506
+ imageData[fileName] = {
5507
+ data: data,
5508
+ mimeType: mimeType,
5591
5509
  };
5592
- if (samplerIndex != null) {
5593
- glTFTexture.sampler = samplerIndex;
5594
- }
5595
- var binStr = atob(base64Texture.split(",")[1]);
5596
- var arrBuff = new ArrayBuffer(binStr.length);
5597
- var arr = new Uint8Array(arrBuff);
5598
- for (var i = 0, length_2 = binStr.length; i < length_2; ++i) {
5599
- arr[i] = binStr.charCodeAt(i);
5600
- }
5601
- var imageValues = { data: arr, mimeType: mimeType };
5602
- var extension = mimeType === "image/jpeg" /* JPEG */ ? ".jpeg" : ".png";
5603
- var textureName = baseTextureName + extension;
5604
- var originalTextureName = textureName;
5605
- if (textureName in imageData) {
5606
- textureName = "".concat(baseTextureName, "_").concat(core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Tools.RandomId()).concat(extension);
5607
- }
5608
- imageData[textureName] = imageValues;
5609
- if (mimeType === "image/jpeg" /* JPEG */ || mimeType === "image/png" /* PNG */ || mimeType === "image/webp" /* WEBP */) {
5610
- var glTFImage = {
5611
- name: baseTextureName,
5612
- uri: textureName,
5613
- };
5614
- var foundIndex = null;
5615
- for (var i = 0; i < images.length; ++i) {
5616
- if (images[i].uri === originalTextureName) {
5617
- foundIndex = i;
5618
- break;
5619
- }
5620
- }
5621
- if (foundIndex == null) {
5622
- images.push(glTFImage);
5623
- glTFTexture.source = images.length - 1;
5624
- }
5625
- else {
5626
- glTFTexture.source = foundIndex;
5627
- }
5628
- textures.push(glTFTexture);
5629
- textureInfo = {
5630
- index: textures.length - 1,
5631
- };
5632
- if (texCoordIndex != null) {
5633
- textureInfo.texCoord = texCoordIndex;
5634
- }
5510
+ var images = this._exporter._images;
5511
+ images.push({
5512
+ name: name,
5513
+ uri: fileName,
5514
+ });
5515
+ return images.length - 1;
5516
+ };
5517
+ _GLTFMaterialExporter.prototype._exportTextureInfo = function (imageIndex, samplerIndex, coordinatesIndex) {
5518
+ var textures = this._exporter._textures;
5519
+ var textureIndex = textures.findIndex(function (t) { return t.sampler == samplerIndex && t.source === imageIndex; });
5520
+ if (textureIndex === -1) {
5521
+ textureIndex = textures.length;
5522
+ textures.push({
5523
+ source: imageIndex,
5524
+ sampler: samplerIndex,
5525
+ });
5635
5526
  }
5636
- else {
5637
- core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Tools.Error("Unsupported texture mime type ".concat(mimeType));
5527
+ var textureInfo = { index: textureIndex };
5528
+ if (coordinatesIndex) {
5529
+ textureInfo.texCoord = coordinatesIndex;
5638
5530
  }
5639
5531
  return textureInfo;
5640
5532
  };
5533
+ _GLTFMaterialExporter.prototype._exportTextureSampler = function (texture) {
5534
+ var sampler = this._getTextureSampler(texture);
5535
+ // if a pre-existing sampler with identical parameters exists, then reuse the previous sampler
5536
+ var samplers = this._exporter._samplers;
5537
+ var samplerIndex = samplers.findIndex(function (s) { return s.minFilter === sampler.minFilter && s.magFilter === sampler.magFilter && s.wrapS === sampler.wrapS && s.wrapT === sampler.wrapT; });
5538
+ if (samplerIndex !== -1) {
5539
+ return samplerIndex;
5540
+ }
5541
+ samplers.push(sampler);
5542
+ return samplers.length - 1;
5543
+ };
5641
5544
  /**
5642
5545
  * Represents the dielectric specular values for R, G and B
5643
5546
  */
@@ -5993,30 +5896,6 @@ __webpack_require__.r(__webpack_exports__);
5993
5896
 
5994
5897
 
5995
5898
 
5996
- /***/ }),
5997
-
5998
- /***/ "../../../lts/serializers/dist/glTF/2.0/shaders/textureTransform.fragment.js":
5999
- /*!***********************************************************************************!*\
6000
- !*** ../../../lts/serializers/dist/glTF/2.0/shaders/textureTransform.fragment.js ***!
6001
- \***********************************************************************************/
6002
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
6003
-
6004
- __webpack_require__.r(__webpack_exports__);
6005
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
6006
- /* harmony export */ "textureTransformPixelShader": () => (/* binding */ textureTransformPixelShader)
6007
- /* harmony export */ });
6008
- /* harmony import */ var core_Engines_shaderStore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! core/Engines/shaderStore */ "core/Maths/math.vector");
6009
- /* harmony import */ var core_Engines_shaderStore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(core_Engines_shaderStore__WEBPACK_IMPORTED_MODULE_0__);
6010
- // Do not edit.
6011
-
6012
- var name = "textureTransformPixelShader";
6013
- var shader = "precision highp float;varying vec2 vUV;uniform sampler2D textureSampler;uniform mat4 textureTransformMat;void main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\nvec2 uvTransformed=(textureTransformMat*vec4(vUV.xy,1,1)).xy;gl_FragColor=texture2D(textureSampler,uvTransformed);\n#define CUSTOM_FRAGMENT_MAIN_END\n}";
6014
- // Sideeffect
6015
- core_Engines_shaderStore__WEBPACK_IMPORTED_MODULE_0__.ShaderStore.ShadersStore[name] = shader;
6016
- /** @internal */
6017
- var textureTransformPixelShader = { name: name, shader: shader };
6018
-
6019
-
6020
5899
  /***/ }),
6021
5900
 
6022
5901
  /***/ "../../../lts/serializers/dist/glTF/glTFFileExporter.js":