babylonjs-loaders 5.2.0 → 5.5.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.
@@ -1287,16 +1287,16 @@ var KHR_materials_iridescence = /** @class */ (function () {
1287
1287
  });
1288
1288
  };
1289
1289
  KHR_materials_iridescence.prototype._loadIridescencePropertiesAsync = function (context, properties, babylonMaterial) {
1290
- var _a, _b, _c, _d;
1290
+ var _a, _b, _c, _d, _e;
1291
1291
  if (!(babylonMaterial instanceof core_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__.PBRMaterial)) {
1292
1292
  throw new Error("".concat(context, ": Material type not supported"));
1293
1293
  }
1294
1294
  var promises = new Array();
1295
1295
  babylonMaterial.iridescence.isEnabled = true;
1296
1296
  babylonMaterial.iridescence.intensity = (_a = properties.iridescenceFactor) !== null && _a !== void 0 ? _a : 0;
1297
- babylonMaterial.iridescence.indexOfRefraction = (_b = properties.iridescenceIOR) !== null && _b !== void 0 ? _b : 1.3;
1298
- babylonMaterial.iridescence.minimumThickness = (_c = properties.iridescenceThicknessMinimum) !== null && _c !== void 0 ? _c : 100;
1299
- babylonMaterial.iridescence.maximumThickness = (_d = properties.iridescenceThicknessMaximum) !== null && _d !== void 0 ? _d : 400;
1297
+ babylonMaterial.iridescence.indexOfRefraction = (_c = (_b = properties.iridescenceIor) !== null && _b !== void 0 ? _b : properties.iridescenceIOR) !== null && _c !== void 0 ? _c : 1.3;
1298
+ babylonMaterial.iridescence.minimumThickness = (_d = properties.iridescenceThicknessMinimum) !== null && _d !== void 0 ? _d : 100;
1299
+ babylonMaterial.iridescence.maximumThickness = (_e = properties.iridescenceThicknessMaximum) !== null && _e !== void 0 ? _e : 400;
1300
1300
  if (properties.iridescenceTexture) {
1301
1301
  promises.push(this._loader.loadTextureInfoAsync("".concat(context, "/iridescenceTexture"), properties.iridescenceTexture, function (texture) {
1302
1302
  texture.name = "".concat(babylonMaterial.name, " (Iridescence Intensity)");
@@ -1402,8 +1402,8 @@ var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
1402
1402
  promises.push(this._loader.loadTextureInfoAsync("".concat(context, "/specularGlossinessTexture"), properties.specularGlossinessTexture, function (texture) {
1403
1403
  texture.name = "".concat(babylonMaterial.name, " (Specular Glossiness)");
1404
1404
  babylonMaterial.reflectivityTexture = texture;
1405
+ babylonMaterial.reflectivityTexture.hasAlpha = true;
1405
1406
  }));
1406
- babylonMaterial.reflectivityTexture.hasAlpha = true;
1407
1407
  babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
1408
1408
  }
1409
1409
  return Promise.all(promises).then(function () { });
@@ -4221,12 +4221,18 @@ var GLTFLoader = /** @class */ (function () {
4221
4221
  _this._forEachPrimitive(node, function (babylonMesh) {
4222
4222
  babylonMesh.skeleton = babylonSkeleton;
4223
4223
  });
4224
- // Wait until the scene is loaded to ensure the skeleton root node has been loaded.
4224
+ // Wait until all the nodes are parented before parenting the skinned mesh.
4225
4225
  _this._postSceneLoadActions.push(function () {
4226
4226
  if (skin.skeleton != undefined) {
4227
4227
  // Place the skinned mesh node as a sibling of the skeleton root node.
4228
- var skeletonRootNode = ArrayItem.Get("/skins/".concat(skin.index, "/skeleton"), _this._gltf.nodes, skin.skeleton);
4229
- babylonTransformNode.parent = skeletonRootNode.parent._babylonTransformNode;
4228
+ // Handle special case when the parent of the skeleton root is the skinned mesh.
4229
+ var parentNode = ArrayItem.Get("/skins/".concat(skin.index, "/skeleton"), _this._gltf.nodes, skin.skeleton).parent;
4230
+ if (node.index === parentNode.index) {
4231
+ babylonTransformNode.parent = node._babylonTransformNodeForSkin.parent;
4232
+ }
4233
+ else {
4234
+ babylonTransformNode.parent = parentNode._babylonTransformNode;
4235
+ }
4230
4236
  }
4231
4237
  else {
4232
4238
  babylonTransformNode.parent = _this._rootBabylonMesh;
@@ -4325,6 +4331,9 @@ var GLTFLoader = /** @class */ (function () {
4325
4331
  this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
4326
4332
  promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
4327
4333
  return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
4334
+ if (_this._disposed) {
4335
+ return;
4336
+ }
4328
4337
  _this._babylonScene._blockEntityCollection = !!_this._assetContainer;
4329
4338
  babylonGeometry.applyToMesh(babylonMesh_1);
4330
4339
  babylonGeometry._parentContainer = _this._assetContainer;
@@ -5147,17 +5156,16 @@ var GLTFLoader = /** @class */ (function () {
5147
5156
  return accessor._data;
5148
5157
  };
5149
5158
  GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView) {
5150
- var _this = this;
5151
5159
  if (bufferView._babylonBuffer) {
5152
5160
  return bufferView._babylonBuffer;
5153
5161
  }
5162
+ var engine = this._babylonScene.getEngine();
5154
5163
  bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView).then(function (data) {
5155
- return new core_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__.Buffer(_this._babylonScene.getEngine(), data, false);
5164
+ return new core_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__.Buffer(engine, data, false);
5156
5165
  });
5157
5166
  return bufferView._babylonBuffer;
5158
5167
  };
5159
5168
  GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
5160
- var _this = this;
5161
5169
  var _a;
5162
5170
  if ((_a = accessor._babylonVertexBuffer) === null || _a === void 0 ? void 0 : _a[kind]) {
5163
5171
  return accessor._babylonVertexBuffer[kind];
@@ -5165,23 +5173,24 @@ var GLTFLoader = /** @class */ (function () {
5165
5173
  if (!accessor._babylonVertexBuffer) {
5166
5174
  accessor._babylonVertexBuffer = {};
5167
5175
  }
5176
+ var engine = this._babylonScene.getEngine();
5168
5177
  if (accessor.sparse) {
5169
5178
  accessor._babylonVertexBuffer[kind] = this._loadFloatAccessorAsync(context, accessor).then(function (data) {
5170
- return new core_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__.VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
5179
+ return new core_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__.VertexBuffer(engine, data, kind, false);
5171
5180
  });
5172
5181
  }
5173
5182
  // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
5174
5183
  // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
5175
5184
  else if (kind === core_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__.VertexBuffer.MatricesIndicesKind || kind === core_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__.VertexBuffer.MatricesIndicesExtraKind) {
5176
5185
  accessor._babylonVertexBuffer[kind] = this._loadFloatAccessorAsync(context, accessor).then(function (data) {
5177
- return new core_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__.VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
5186
+ return new core_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__.VertexBuffer(engine, data, kind, false);
5178
5187
  });
5179
5188
  }
5180
5189
  else {
5181
5190
  var bufferView_2 = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, accessor.bufferView);
5182
5191
  accessor._babylonVertexBuffer[kind] = this._loadVertexBufferViewAsync(bufferView_2).then(function (babylonBuffer) {
5183
5192
  var size = GLTFLoader._GetNumComponents(context, accessor.type);
5184
- return new core_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__.VertexBuffer(_this._babylonScene.getEngine(), babylonBuffer, kind, false, false, bufferView_2.byteStride, false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true, 1, true);
5193
+ return new core_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__.VertexBuffer(engine, babylonBuffer, kind, false, false, bufferView_2.byteStride, false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true, 1, true);
5185
5194
  });
5186
5195
  }
5187
5196
  return accessor._babylonVertexBuffer[kind];
@@ -5339,7 +5348,7 @@ var GLTFLoader = /** @class */ (function () {
5339
5348
  }));
5340
5349
  babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
5341
5350
  babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
5342
- if (material.normalTexture.scale != undefined) {
5351
+ if (material.normalTexture.scale != undefined && babylonMaterial.bumpTexture) {
5343
5352
  babylonMaterial.bumpTexture.level = material.normalTexture.scale;
5344
5353
  }
5345
5354
  babylonMaterial.forceIrradianceInFragment = true;