@babylonjs/loaders 5.11.0 → 5.13.0
Sign up to get free protection for your applications and to get access to all the features.
package/glTF/2.0/glTFLoader.js
CHANGED
@@ -55,6 +55,30 @@ var ArrayItem = /** @class */ (function () {
|
|
55
55
|
return ArrayItem;
|
56
56
|
}());
|
57
57
|
export { ArrayItem };
|
58
|
+
// https://stackoverflow.com/a/48218209
|
59
|
+
function mergeDeep() {
|
60
|
+
var objects = [];
|
61
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
62
|
+
objects[_i] = arguments[_i];
|
63
|
+
}
|
64
|
+
var isObject = function (obj) { return obj && typeof obj === "object"; };
|
65
|
+
return objects.reduce(function (prev, obj) {
|
66
|
+
Object.keys(obj).forEach(function (key) {
|
67
|
+
var pVal = prev[key];
|
68
|
+
var oVal = obj[key];
|
69
|
+
if (Array.isArray(pVal) && Array.isArray(oVal)) {
|
70
|
+
prev[key] = pVal.concat.apply(pVal, oVal);
|
71
|
+
}
|
72
|
+
else if (isObject(pVal) && isObject(oVal)) {
|
73
|
+
prev[key] = mergeDeep(pVal, oVal);
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
prev[key] = oVal;
|
77
|
+
}
|
78
|
+
});
|
79
|
+
return prev;
|
80
|
+
}, {});
|
81
|
+
}
|
58
82
|
/**
|
59
83
|
* The glTF 2.0 loader
|
60
84
|
*/
|
@@ -643,6 +667,8 @@ var GLTFLoader = /** @class */ (function () {
|
|
643
667
|
var mesh = ArrayItem.Get("".concat(context, "/mesh"), this._gltf.meshes, node.mesh);
|
644
668
|
promises.push(this._loadMeshAsync("/meshes/".concat(mesh.index), node, mesh, function (babylonTransformNode) {
|
645
669
|
var babylonTransformNodeForSkin = node._babylonTransformNodeForSkin;
|
670
|
+
// Merge the metadata from the skin node to the skinned mesh in case a loader extension added metadata.
|
671
|
+
babylonTransformNode.metadata = mergeDeep(babylonTransformNodeForSkin.metadata, babylonTransformNode.metadata);
|
646
672
|
var skin = ArrayItem.Get("".concat(context, "/skin"), _this._gltf.skins, node.skin);
|
647
673
|
promises.push(_this._loadSkinAsync("/skins/".concat(skin.index), node, skin, function (babylonSkeleton) {
|
648
674
|
_this._forEachPrimitive(node, function (babylonMesh) {
|
@@ -655,7 +681,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
655
681
|
// Handle special case when the parent of the skeleton root is the skinned mesh.
|
656
682
|
var parentNode = ArrayItem.Get("/skins/".concat(skin.index, "/skeleton"), _this._gltf.nodes, skin.skeleton).parent;
|
657
683
|
if (node.index === parentNode.index) {
|
658
|
-
babylonTransformNode.parent =
|
684
|
+
babylonTransformNode.parent = babylonTransformNodeForSkin.parent;
|
659
685
|
}
|
660
686
|
else {
|
661
687
|
babylonTransformNode.parent = parentNode._babylonTransformNode;
|