Browse Source

Improved control over material compilation for gltf

David Catuhe 8 years ago
parent
commit
6d55c04478

File diff suppressed because it is too large
+ 7947 - 7947
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 7947 - 7947
dist/preview release/babylon.module.d.ts


File diff suppressed because it is too large
+ 4372 - 4372
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


File diff suppressed because it is too large
+ 2 - 2
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 7 - 12
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -52279,19 +52279,14 @@ var BABYLON;
                                         if (isNew && _this._parent.onMaterialLoaded) {
                                         if (isNew && _this._parent.onMaterialLoaded) {
                                             _this._parent.onMaterialLoaded(babylonMaterial);
                                             _this._parent.onMaterialLoaded(babylonMaterial);
                                         }
                                         }
-                                        var needToCompile = false;
-                                        if (_this._parent.onMaterialReady) {
-                                            needToCompile = _this._parent.onMaterialReady(babylonMaterial, babylonMultiMaterial.subMaterials[i] != null);
-                                        }
-                                        if (!needToCompile) {
-                                            babylonMultiMaterial.subMaterials[i] = babylonMaterial;
-                                        }
-                                        else {
-                                            // Let's compile first to avoid jittering
-                                            babylonMaterial.forceCompilation(babylonMesh, function (babylonMaterial) {
+                                        if (_this._parent.onBeforeMaterialReadyAsync) {
+                                            _this._parent.onBeforeMaterialReadyAsync(babylonMaterial, babylonMesh, babylonMultiMaterial.subMaterials[i] != null, function () {
                                                 babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                                 babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                             });
                                             });
                                         }
                                         }
+                                        else {
+                                            babylonMultiMaterial.subMaterials[i] = babylonMaterial;
+                                        }
                                     });
                                     });
                                 }
                                 }
                             }
                             }
@@ -52747,7 +52742,7 @@ var BABYLON;
                 else if (--this._loaderPendingCount === 0) {
                 else if (--this._loaderPendingCount === 0) {
                     this._onLoaderFirstLODComplete();
                     this._onLoaderFirstLODComplete();
                 }
                 }
-                if ((!this._nonBlockingData || this._nonBlockingData.length === 0) && this._loaderPendingCount <= 0) {
+                if ((!this._nonBlockingData || this._nonBlockingData.length === 0) && this._loaderPendingCount === 0) {
                     this._onLoaderComplete();
                     this._onLoaderComplete();
                     this.dispose();
                     this.dispose();
                 }
                 }
@@ -53109,7 +53104,7 @@ var BABYLON;
                     // Tell the loader not to clear its state until the highest LOD is loaded.
                     // Tell the loader not to clear its state until the highest LOD is loaded.
                     var materialLODs = [material.index].concat(properties.ids);
                     var materialLODs = [material.index].concat(properties.ids);
                     loader.addLoaderPendingData(material);
                     loader.addLoaderPendingData(material);
-                    for (var index = 0; index < materialLODs.length - 1; index++) {
+                    for (var index = 0; index < materialLODs.length; index++) {
                         loader.addLoaderNonBlockingPendingData(index);
                         loader.addLoaderNonBlockingPendingData(index);
                     }
                     }
                     // Start with the lowest quality LOD.
                     // Start with the lowest quality LOD.

File diff suppressed because it is too large
+ 4372 - 4372
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


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

@@ -22,9 +22,9 @@ declare module BABYLON {
         onTextureLoaded: (texture: BaseTexture) => void;
         onTextureLoaded: (texture: BaseTexture) => void;
         onMaterialLoaded: (material: Material) => void;
         onMaterialLoaded: (material: Material) => void;
         /**
         /**
-         * Let the user decides if he needs to precompile a material before affecting it to meshes
+         * Let the user decides if he needs to process the material (like precompilation) before affecting it to meshes
          */
          */
-        onMaterialReady: (material: Material, isLOD: boolean) => boolean;
+        onBeforeMaterialReadyAsync: (material: Material, targetMesh: AbstractMesh, isLOD: boolean, callback: () => void) => void;
         /**
         /**
          * Raised when all LODs are complete (or if there is no LOD and model is complete)
          * Raised when all LODs are complete (or if there is no LOD and model is complete)
          */
          */

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

@@ -22,9 +22,9 @@ declare module BABYLON {
         onTextureLoaded: (texture: BaseTexture) => void;
         onTextureLoaded: (texture: BaseTexture) => void;
         onMaterialLoaded: (material: Material) => void;
         onMaterialLoaded: (material: Material) => void;
         /**
         /**
-         * Let the user decides if he needs to precompile a material before affecting it to meshes
+         * Let the user decides if he needs to process the material (like precompilation) before affecting it to meshes
          */
          */
-        onMaterialReady: (material: Material, isLOD: boolean) => boolean;
+        onBeforeMaterialReadyAsync: (material: Material, targetMesh: AbstractMesh, isLOD: boolean, callback: () => void) => void;
         /**
         /**
          * Raised when all LODs are complete (or if there is no LOD and model is complete)
          * Raised when all LODs are complete (or if there is no LOD and model is complete)
          */
          */

+ 7 - 12
dist/preview release/loaders/babylon.glTF2FileLoader.js

@@ -647,19 +647,14 @@ var BABYLON;
                                         if (isNew && _this._parent.onMaterialLoaded) {
                                         if (isNew && _this._parent.onMaterialLoaded) {
                                             _this._parent.onMaterialLoaded(babylonMaterial);
                                             _this._parent.onMaterialLoaded(babylonMaterial);
                                         }
                                         }
-                                        var needToCompile = false;
-                                        if (_this._parent.onMaterialReady) {
-                                            needToCompile = _this._parent.onMaterialReady(babylonMaterial, babylonMultiMaterial.subMaterials[i] != null);
-                                        }
-                                        if (!needToCompile) {
-                                            babylonMultiMaterial.subMaterials[i] = babylonMaterial;
-                                        }
-                                        else {
-                                            // Let's compile first to avoid jittering
-                                            babylonMaterial.forceCompilation(babylonMesh, function (babylonMaterial) {
+                                        if (_this._parent.onBeforeMaterialReadyAsync) {
+                                            _this._parent.onBeforeMaterialReadyAsync(babylonMaterial, babylonMesh, babylonMultiMaterial.subMaterials[i] != null, function () {
                                                 babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                                 babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                             });
                                             });
                                         }
                                         }
+                                        else {
+                                            babylonMultiMaterial.subMaterials[i] = babylonMaterial;
+                                        }
                                     });
                                     });
                                 }
                                 }
                             }
                             }
@@ -1115,7 +1110,7 @@ var BABYLON;
                 else if (--this._loaderPendingCount === 0) {
                 else if (--this._loaderPendingCount === 0) {
                     this._onLoaderFirstLODComplete();
                     this._onLoaderFirstLODComplete();
                 }
                 }
-                if ((!this._nonBlockingData || this._nonBlockingData.length === 0) && this._loaderPendingCount <= 0) {
+                if ((!this._nonBlockingData || this._nonBlockingData.length === 0) && this._loaderPendingCount === 0) {
                     this._onLoaderComplete();
                     this._onLoaderComplete();
                     this.dispose();
                     this.dispose();
                 }
                 }
@@ -1486,7 +1481,7 @@ var BABYLON;
                     // Tell the loader not to clear its state until the highest LOD is loaded.
                     // Tell the loader not to clear its state until the highest LOD is loaded.
                     var materialLODs = [material.index].concat(properties.ids);
                     var materialLODs = [material.index].concat(properties.ids);
                     loader.addLoaderPendingData(material);
                     loader.addLoaderPendingData(material);
-                    for (var index = 0; index < materialLODs.length - 1; index++) {
+                    for (var index = 0; index < materialLODs.length; index++) {
                         loader.addLoaderNonBlockingPendingData(index);
                         loader.addLoaderNonBlockingPendingData(index);
                     }
                     }
                     // Start with the lowest quality LOD.
                     // Start with the lowest quality LOD.

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/loaders/babylon.glTF2FileLoader.min.js


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

@@ -22,9 +22,9 @@ declare module BABYLON {
         onTextureLoaded: (texture: BaseTexture) => void;
         onTextureLoaded: (texture: BaseTexture) => void;
         onMaterialLoaded: (material: Material) => void;
         onMaterialLoaded: (material: Material) => void;
         /**
         /**
-         * Let the user decides if he needs to precompile a material before affecting it to meshes
+         * Let the user decides if he needs to process the material (like precompilation) before affecting it to meshes
          */
          */
-        onMaterialReady: (material: Material, isLOD: boolean) => boolean;
+        onBeforeMaterialReadyAsync: (material: Material, targetMesh: AbstractMesh, isLOD: boolean, callback: () => void) => void;
         /**
         /**
          * Raised when all LODs are complete (or if there is no LOD and model is complete)
          * Raised when all LODs are complete (or if there is no LOD and model is complete)
          */
          */

+ 7 - 12
dist/preview release/loaders/babylon.glTFFileLoader.js

@@ -2805,19 +2805,14 @@ var BABYLON;
                                         if (isNew && _this._parent.onMaterialLoaded) {
                                         if (isNew && _this._parent.onMaterialLoaded) {
                                             _this._parent.onMaterialLoaded(babylonMaterial);
                                             _this._parent.onMaterialLoaded(babylonMaterial);
                                         }
                                         }
-                                        var needToCompile = false;
-                                        if (_this._parent.onMaterialReady) {
-                                            needToCompile = _this._parent.onMaterialReady(babylonMaterial, babylonMultiMaterial.subMaterials[i] != null);
-                                        }
-                                        if (!needToCompile) {
-                                            babylonMultiMaterial.subMaterials[i] = babylonMaterial;
-                                        }
-                                        else {
-                                            // Let's compile first to avoid jittering
-                                            babylonMaterial.forceCompilation(babylonMesh, function (babylonMaterial) {
+                                        if (_this._parent.onBeforeMaterialReadyAsync) {
+                                            _this._parent.onBeforeMaterialReadyAsync(babylonMaterial, babylonMesh, babylonMultiMaterial.subMaterials[i] != null, function () {
                                                 babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                                 babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                             });
                                             });
                                         }
                                         }
+                                        else {
+                                            babylonMultiMaterial.subMaterials[i] = babylonMaterial;
+                                        }
                                     });
                                     });
                                 }
                                 }
                             }
                             }
@@ -3273,7 +3268,7 @@ var BABYLON;
                 else if (--this._loaderPendingCount === 0) {
                 else if (--this._loaderPendingCount === 0) {
                     this._onLoaderFirstLODComplete();
                     this._onLoaderFirstLODComplete();
                 }
                 }
-                if ((!this._nonBlockingData || this._nonBlockingData.length === 0) && this._loaderPendingCount <= 0) {
+                if ((!this._nonBlockingData || this._nonBlockingData.length === 0) && this._loaderPendingCount === 0) {
                     this._onLoaderComplete();
                     this._onLoaderComplete();
                     this.dispose();
                     this.dispose();
                 }
                 }
@@ -3644,7 +3639,7 @@ var BABYLON;
                     // Tell the loader not to clear its state until the highest LOD is loaded.
                     // Tell the loader not to clear its state until the highest LOD is loaded.
                     var materialLODs = [material.index].concat(properties.ids);
                     var materialLODs = [material.index].concat(properties.ids);
                     loader.addLoaderPendingData(material);
                     loader.addLoaderPendingData(material);
-                    for (var index = 0; index < materialLODs.length - 1; index++) {
+                    for (var index = 0; index < materialLODs.length; index++) {
                         loader.addLoaderNonBlockingPendingData(index);
                         loader.addLoaderNonBlockingPendingData(index);
                     }
                     }
                     // Start with the lowest quality LOD.
                     // Start with the lowest quality LOD.

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/loaders/babylon.glTFFileLoader.min.js


+ 4 - 10
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -413,18 +413,12 @@ module BABYLON.GLTF2 {
                                         this._parent.onMaterialLoaded(babylonMaterial);
                                         this._parent.onMaterialLoaded(babylonMaterial);
                                     }
                                     }
                                     
                                     
-                                    let needToCompile = false;
-                                    if (this._parent.onMaterialReady) {
-                                        needToCompile = this._parent.onMaterialReady(babylonMaterial, babylonMultiMaterial.subMaterials[i] != null);
-                                    }
-
-                                    if (!needToCompile) {
-                                        babylonMultiMaterial.subMaterials[i] = babylonMaterial;
-                                    } else {
-                                        // Let's compile first to avoid jittering
-                                        babylonMaterial.forceCompilation(babylonMesh, babylonMaterial => {
+                                    if (this._parent.onBeforeMaterialReadyAsync) {
+                                        this._parent.onBeforeMaterialReadyAsync(babylonMaterial, babylonMesh, babylonMultiMaterial.subMaterials[i] != null, () => {
                                             babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                             babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                         });
                                         });
+                                    } else {
+                                        babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                     }
                                     }
                                 });
                                 });
                             }
                             }

+ 2 - 2
loaders/src/glTF/babylon.glTFFileLoader.ts

@@ -36,9 +36,9 @@ module BABYLON {
         public onTextureLoaded: (texture: BaseTexture) => void;
         public onTextureLoaded: (texture: BaseTexture) => void;
         public onMaterialLoaded: (material: Material) => void;
         public onMaterialLoaded: (material: Material) => void;
         /**
         /**
-         * Let the user decides if he needs to precompile a material before affecting it to meshes
+         * Let the user decides if he needs to process the material (like precompilation) before affecting it to meshes
          */
          */
-        public onMaterialReady: (material: Material, isLOD: boolean) => boolean;
+        public onBeforeMaterialReadyAsync: (material: Material, targetMesh: AbstractMesh, isLOD: boolean, callback: () => void) => void;
         /**
         /**
          * Raised when all LODs are complete (or if there is no LOD and model is complete)
          * Raised when all LODs are complete (or if there is no LOD and model is complete)
          */
          */

+ 6 - 2
sandbox/index.js

@@ -27,8 +27,12 @@
         if (plugin.name !== "gltf") {
         if (plugin.name !== "gltf") {
             return;
             return;
         }
         }
-        plugin.onMaterialReady = function(material, isLOD) {
-            return isLOD; // We want precompilation for LOD levels
+        plugin.onBeforeMaterialReadyAsync = function(material, mesh, isLOD, callback) {
+            if (!isLOD) {
+                callback();
+                return;
+            }
+            material.forceCompilation(mesh, callback);
         }
         }
     });
     });