Pārlūkot izejas kodu

Adding IncrementalLoading to disable or enable incremental loading (gltf)
Removing unused code to make Yup in animations

Julien Moreau-Mathis 8 gadi atpakaļ
vecāks
revīzija
ea3a0d7f75

+ 2 - 1
dist/preview release/loaders/babylon.glTFFileLoader.d.ts

@@ -347,6 +347,7 @@ declare module BABYLON {
         */
         static MakeYUP: boolean;
         static HomogeneousCoordinates: boolean;
+        static IncrementalLoading: boolean;
         static Extensions: {
             [name: string]: GLTFFileLoaderExtension;
         };
@@ -427,7 +428,7 @@ declare module BABYLON {
         static DecodeBufferToText(view: ArrayBufferView): string;
         /**
          * Returns the default material of gltf. Related to
-         *
+         * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
          * @param scene: the Babylon.js scene
          */
         static GetDefaultMaterial(scene: Scene): ShaderMaterial;

+ 28 - 22
dist/preview release/loaders/babylon.glTFFileLoader.js

@@ -311,10 +311,6 @@ var BABYLON;
                         }
                         else if (targetPath === "rotationQuaternion") {
                             rotationQuaternion = value;
-                            // Y is Up
-                            if (GLTFFileLoader.MakeYUP) {
-                                rotationQuaternion = rotationQuaternion.multiply(new BABYLON.Quaternion(-0.707107, 0, 0, 0.707107));
-                            }
                         }
                         else {
                             scaling = value;
@@ -352,9 +348,11 @@ var BABYLON;
             var rotation = BABYLON.Quaternion.FromArray(node.rotation || [0, 0, 0, 1]);
             var position = BABYLON.Vector3.FromArray(node.translation || [0, 0, 0]);
             // Y is Up
+            /*
             if (GLTFFileLoader.MakeYUP) {
-                rotation = rotation.multiply(new BABYLON.Quaternion(-0.707107, 0, 0, 0.707107));
+                rotation = rotation.multiply(new Quaternion(-0.707107, 0, 0, 0.707107));
             }
+            */
             mat = BABYLON.Matrix.Compose(scale, rotation, position);
         }
         else {
@@ -733,7 +731,7 @@ var BABYLON;
     /**
     * Configures node from transformation matrix
     */
-    var configureNodeFromMatrix = function (newNode, node) {
+    var configureNodeFromMatrix = function (newNode, node, parent) {
         if (node.matrix) {
             var position = new BABYLON.Vector3(0, 0, 0);
             var rotation = new BABYLON.Quaternion();
@@ -741,7 +739,7 @@ var BABYLON;
             var mat = BABYLON.Matrix.FromArray(node.matrix);
             mat.decompose(scaling, rotation, position);
             // Y is Up
-            if (GLTFFileLoader.MakeYUP) {
+            if (GLTFFileLoader.MakeYUP && !parent) {
                 rotation = rotation.multiply(new BABYLON.Quaternion(-0.707107, 0, 0, 0.707107));
             }
             configureNode(newNode, position, rotation, scaling);
@@ -756,7 +754,7 @@ var BABYLON;
     /**
     * Imports a node
     */
-    var importNode = function (gltfRuntime, node, id) {
+    var importNode = function (gltfRuntime, node, id, parent) {
         var lastNode = null;
         if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
             if (gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name) === -1) {
@@ -775,8 +773,6 @@ var BABYLON;
                         skin.babylonSkeleton = newMesh.skeleton;
                     }
                 }
-                if (newMesh.skeleton !== null) {
-                }
                 lastNode = newMesh;
             }
         }
@@ -874,7 +870,7 @@ var BABYLON;
         }
         if (lastNode !== null) {
             if (node.matrix) {
-                configureNodeFromMatrix(lastNode, node);
+                configureNodeFromMatrix(lastNode, node, parent);
             }
             else {
                 var translation = node.translation || [0, 0, 0];
@@ -905,7 +901,7 @@ var BABYLON;
             meshIncluded = true;
         }
         if (!node.jointName && meshIncluded) {
-            newNode = importNode(gltfRuntime, node, id);
+            newNode = importNode(gltfRuntime, node, id, parent);
             if (newNode !== null) {
                 newNode.id = id;
                 newNode.parent = parent;
@@ -1424,9 +1420,12 @@ var BABYLON;
                     _this._loadShadersAsync(gltfRuntime, function () {
                         importMaterials(gltfRuntime);
                         postLoad(gltfRuntime);
+                        if (!GLTFFileLoader.IncrementalLoading && onSuccess) {
+                            onSuccess(meshes, null, skeletons);
+                        }
                     });
                 });
-                if (onSuccess) {
+                if (GLTFFileLoader.IncrementalLoading && onSuccess) {
                     onSuccess(meshes, null, skeletons);
                 }
             }, onError);
@@ -1446,9 +1445,14 @@ var BABYLON;
                     _this._loadShadersAsync(gltfRuntime, function () {
                         importMaterials(gltfRuntime);
                         postLoad(gltfRuntime);
+                        if (!GLTFFileLoader.IncrementalLoading) {
+                            onSuccess();
+                        }
                     });
                 });
-                onSuccess();
+                if (GLTFFileLoader.IncrementalLoading) {
+                    onSuccess();
+                }
             }, onError);
             return true;
         };
@@ -1544,6 +1548,7 @@ var BABYLON;
     */
     GLTFFileLoader.MakeYUP = false;
     GLTFFileLoader.HomogeneousCoordinates = false;
+    GLTFFileLoader.IncrementalLoading = true;
     GLTFFileLoader.Extensions = {};
     BABYLON.GLTFFileLoader = GLTFFileLoader;
     ;
@@ -1750,25 +1755,25 @@ var BABYLON;
         };
         /**
          * Returns the default material of gltf. Related to
-         *
+         * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
          * @param scene: the Babylon.js scene
          */
         GLTFUtils.GetDefaultMaterial = function (scene) {
             if (!GLTFUtils._DefaultMaterial) {
-                BABYLON.Effect.ShadersStore["GLTFDefaultVertexShader"] = [
+                BABYLON.Effect.ShadersStore["GLTFDefaultMaterialVertexShader"] = [
                     "precision highp float;",
                     "",
-                    "uniform mat4 u_modelViewMatrix;",
-                    "uniform mat4 u_projectionMatrix;",
+                    "uniform mat4 worldView;",
+                    "uniform mat4 projection;",
                     "",
-                    "attribute vec3 a_position;",
+                    "attribute vec3 position;",
                     "",
                     "void main(void)",
                     "{",
-                    "    gl_Position = u_projectionMatrix * u_modelViewMatrix * vec4(a_position,1.0);",
+                    "    gl_Position = projection * worldView * vec4(position, 1.0);",
                     "}"
                 ].join("\n");
-                BABYLON.Effect.ShadersStore["GLTFDefaultVertexShader"] = [
+                BABYLON.Effect.ShadersStore["GLTFDefaultMaterialPixelShader"] = [
                     "precision highp float;",
                     "",
                     "uniform vec4 u_emission;",
@@ -1784,7 +1789,7 @@ var BABYLON;
                 };
                 var options = {
                     attributes: ["position"],
-                    uniforms: ["modelView", "projection", "u_emission"],
+                    uniforms: ["worldView", "projection", "u_emission"],
                     samplers: [],
                     needAlphaBlending: false
                 };
@@ -1795,6 +1800,7 @@ var BABYLON;
         };
         return GLTFUtils;
     }());
+    // The GLTF default material
     GLTFUtils._DefaultMaterial = null;
     BABYLON.GLTFUtils = GLTFUtils;
 })(BABYLON || (BABYLON = {}));

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 2 - 2
dist/preview release/loaders/babylon.glTFFileLoader.min.js


+ 7 - 0
loaders/src/glTF/README.md

@@ -29,6 +29,13 @@ In order the fix the UP vector (Y with Babylon.js) if you want to play with phys
 BABYLON.GLTFFileLoader.MakeYUP = true; // false by default
 ```
 
+If you want to disable incremental loading (which is the default behavior), you can set the property IncrementalLoading to false.
+Then, you'll be able to be called back with all geometries and shaders loaded.
+For example, you can retrieve the real bounding infos of a mesh loaded using the loader.
+```
+BABYLON.GLTFFileLoader.IncrementalLoading = false; // true by default
+```
+
 In order to work with homogeneous coordinates (that can be available with some converters and exporters):
 ```
 BABYLON.GLTFFileLoader.HomogeneousCoordinates = true; // false by default

+ 23 - 14
loaders/src/glTF/babylon.glTFFileLoader.ts

@@ -265,9 +265,11 @@ module BABYLON {
                         else if (targetPath === "rotationQuaternion") {
                             rotationQuaternion = value;
                             // Y is Up
+                            /*
                             if (GLTFFileLoader.MakeYUP) {
                                 rotationQuaternion = rotationQuaternion.multiply(new Quaternion(-0.707107, 0, 0, 0.707107));
                             }
+                            */
                         }
                         else {
                             scaling = value;
@@ -313,9 +315,11 @@ module BABYLON {
             var position = Vector3.FromArray(node.translation || [0, 0, 0]);
 
             // Y is Up
+            /*
             if (GLTFFileLoader.MakeYUP) {
                 rotation = rotation.multiply(new Quaternion(-0.707107, 0, 0, 0.707107));
             }
+            */
 
             mat = Matrix.Compose(scale, rotation, position);
         }
@@ -737,7 +741,6 @@ module BABYLON {
 
         // Apply geometry
         geometry.setAllVerticesData(vertexData, false);
-
         newMesh.computeWorldMatrix(true);
 
         // Apply submeshes
@@ -785,7 +788,7 @@ module BABYLON {
     /**
     * Configures node from transformation matrix
     */
-    var configureNodeFromMatrix = (newNode: any, node: IGLTFNode) => {
+    var configureNodeFromMatrix = (newNode: any, node: IGLTFNode, parent: Node) => {
         if (node.matrix) {
             var position = new Vector3(0, 0, 0);
             var rotation = new Quaternion();
@@ -794,7 +797,7 @@ module BABYLON {
             mat.decompose(scaling, rotation, position);
 
             // Y is Up
-            if (GLTFFileLoader.MakeYUP) {
+            if (GLTFFileLoader.MakeYUP && !parent) {
                 rotation = rotation.multiply(new Quaternion(-0.707107, 0, 0, 0.707107));
             }
 
@@ -812,7 +815,7 @@ module BABYLON {
     /**
     * Imports a node
     */
-    var importNode = (gltfRuntime: IGLTFRuntime, node: IGLTFNode, id: string): Node => {
+    var importNode = (gltfRuntime: IGLTFRuntime, node: IGLTFNode, id: string, parent: Node): Node => {
         var lastNode: Node = null;
 
         if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
@@ -836,11 +839,7 @@ module BABYLON {
                         skin.babylonSkeleton = newMesh.skeleton;
                     }
                 }
-
-                if (newMesh.skeleton !== null) {
-                    //newMesh.useBones = true;
-                }
-
+                
                 lastNode = newMesh;
             }
         }
@@ -960,7 +959,7 @@ module BABYLON {
 
         if (lastNode !== null) {
             if (node.matrix) {
-                configureNodeFromMatrix(lastNode, node);
+                configureNodeFromMatrix(lastNode, node, parent);
             }
             else {
                 var translation = node.translation || [0, 0, 0];
@@ -970,7 +969,6 @@ module BABYLON {
             }
 
             lastNode.updateCache(true);
-
             node.babylonNode = lastNode;
         }
 
@@ -997,7 +995,7 @@ module BABYLON {
         }
 
         if (!node.jointName && meshIncluded) {
-            newNode = importNode(gltfRuntime, node, id);
+            newNode = importNode(gltfRuntime, node, id, parent);
 
             if (newNode !== null) {
                 newNode.id = id;
@@ -1573,6 +1571,7 @@ module BABYLON {
         */
         public static MakeYUP: boolean = false;
         public static HomogeneousCoordinates: boolean = false;
+        public static IncrementalLoading: boolean = true;
 
         public static Extensions: { [name: string]: GLTFFileLoaderExtension } = {};
 
@@ -1636,10 +1635,14 @@ module BABYLON {
                     this._loadShadersAsync(gltfRuntime, () => {
                         importMaterials(gltfRuntime);
                         postLoad(gltfRuntime);
+
+                        if (!GLTFFileLoader.IncrementalLoading && onSuccess) {
+                            onSuccess(meshes, null, skeletons);
+                        }
                     });
                 });
 
-                if (onSuccess) {
+                if (GLTFFileLoader.IncrementalLoading && onSuccess) {
                     onSuccess(meshes, null, skeletons);
                 }
             }, onError);
@@ -1662,10 +1665,16 @@ module BABYLON {
                     this._loadShadersAsync(gltfRuntime, () => {
                         importMaterials(gltfRuntime);
                         postLoad(gltfRuntime);
+
+                        if (!GLTFFileLoader.IncrementalLoading) {
+                            onSuccess();
+                        }
                     });
                 });
 
-                onSuccess();
+                if (GLTFFileLoader.IncrementalLoading) {
+                    onSuccess();
+                }
             }, onError);
 
             return true;