Ver código fonte

Merge pull request #2359 from mohamedmansour/patch-2

glTF2 - Adding null checks for skins and nodes
David Catuhe 8 anos atrás
pai
commit
0c21ee8587
1 arquivos alterados com 12 adições e 8 exclusões
  1. 12 8
      loaders/src/glTF/2.0/babylon.glTFLoader.ts

+ 12 - 8
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -44,18 +44,22 @@ module BABYLON.GLTF2 {
         public importMeshAsync(meshesNames: any, scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onError: () => void): void {
             this._loadAsync(meshesNames, scene, data, rootUrl, () => {
                 var meshes = [];
-                for (var i = 0; i < this._gltf.nodes.length; i++) {
-                    var node = this._gltf.nodes[i];
-                    if (node.babylonNode instanceof AbstractMesh) {
-                        meshes.push(<AbstractMesh>node.babylonNode);
+                if (this._gltf.nodes) {
+                    for (var i = 0; i < this._gltf.nodes.length; i++) {
+                        var node = this._gltf.nodes[i];
+                        if (node.babylonNode instanceof AbstractMesh) {
+                            meshes.push(<AbstractMesh>node.babylonNode);
+                        }
                     }
                 }
 
                 var skeletons = [];
-                for (var i = 0; i < this._gltf.skins.length; i++) {
-                    var skin = this._gltf.skins[i];
-                    if (skin.babylonSkeleton instanceof Skeleton) {
-                        skeletons.push(skin.babylonSkeleton);
+                if (this._gltf.skins) {
+                    for (var i = 0; i < this._gltf.skins.length; i++) {
+                        var skin = this._gltf.skins[i];
+                        if (skin.babylonSkeleton instanceof Skeleton) {
+                            skeletons.push(skin.babylonSkeleton);
+                        }
                     }
                 }