Browse Source

fix LOD support

David Catuhe 7 years ago
parent
commit
29301ab69e

+ 1 - 1
.vscode/launch.json

@@ -142,7 +142,7 @@
             "name": "Launch Build Validation (Chrome)",
             "type": "chrome",
             "request": "launch",
-            "url": "http://localhost:1338/tests/validation/index.html?Reflection%20probes",
+            "url": "http://localhost:1338/tests/validation/index.html?LOD",
             "webRoot": "${workspaceRoot}/",
             "sourceMaps": true,
             "preLaunchTask": "run",

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


+ 13 - 5
src/Mesh/babylon.instancedMesh.ts

@@ -35,9 +35,9 @@
          */
         public getClassName(): string {
             return "InstancedMesh";
-        }          
+        }
 
-        // Methods
+        // Methods      
         public get receiveShadows(): boolean {
             return this._sourceMesh.receiveShadows;
         }
@@ -70,6 +70,14 @@
         }
 
         /**
+         * Is this node ready to be used/rendered
+         * @return {boolean} is it ready
+         */
+        public isReady(): boolean {
+            return this._sourceMesh.isReady(true);
+        }
+
+        /**
          * Returns a float array or a Float32Array of the requested kind of data : positons, normals, uvs, etc.  
          */
         public getVerticesData(kind: string, copyWhenShared?: boolean): Nullable<FloatArray> {
@@ -103,7 +111,7 @@
          */
         public setVerticesData(kind: string, data: FloatArray, updatable?: boolean, stride?: number): Mesh {
             if (this.sourceMesh) {
-               this.sourceMesh.setVerticesData(kind, data, updatable, stride);
+                this.sourceMesh.setVerticesData(kind, data, updatable, stride);
             }
             return this.sourceMesh;
         }
@@ -134,7 +142,7 @@
          */
         public updateVerticesData(kind: string, data: FloatArray, updateExtends?: boolean, makeItUnique?: boolean): Mesh {
             if (this.sourceMesh) {
-               this.sourceMesh.updateVerticesData(kind, data, updateExtends, makeItUnique);
+                this.sourceMesh.updateVerticesData(kind, data, updateExtends, makeItUnique);
             }
             return this.sourceMesh;
         }
@@ -148,7 +156,7 @@
          */
         public setIndices(indices: IndicesArray, totalVertices: Nullable<number> = null): Mesh {
             if (this.sourceMesh) {
-               this.sourceMesh.setIndices(indices, totalVertices);
+                this.sourceMesh.setIndices(indices, totalVertices);
             }
             return this.sourceMesh;
         }

+ 63 - 6
src/Mesh/babylon.mesh.ts

@@ -191,10 +191,10 @@
                 // Metadata
                 if (source.metadata && source.metadata.clone) {
                     this.metadata = source.metadata.clone();
-                 } else {
+                } else {
                     this.metadata = source.metadata;
-                 }                
-                
+                }
+
                 // Tags
                 if (Tags && Tags.HasTags(source)) {
                     Tags.AddTagsTo(this, Tags.GetTags(source, true));
@@ -598,14 +598,71 @@
         }
 
         /**
-         * Boolean : true once the mesh is ready after all the delayed process (loading, etc) are complete.
+         * Determine if the current mesh is ready to be rendered
+         * @returns true if all associated assets are ready (material, textures, shaders)
          */
-        public isReady(): boolean {
+        public isReady(forceInstanceSupport = false): boolean {
             if (this.delayLoadState === Engine.DELAYLOADSTATE_LOADING) {
                 return false;
             }
 
-            return super.isReady();
+            if (!super.isReady()) {
+                return false;
+            }
+
+            let engine = this.getEngine();
+            let scene = this.getScene();
+            let hardwareInstancedRendering = forceInstanceSupport || engine.getCaps().instancedArrays && this.instances.length > 0;
+
+            this.computeWorldMatrix();
+
+            let mat = this.material || scene.defaultMaterial;
+            if (mat) {
+                let currentAlphaTestingState = engine.getAlphaTesting();
+
+                if (mat.storeEffectOnSubMeshes) {
+                    for (var subMesh of this.subMeshes) {
+                        let effectiveMaterial = subMesh.getMaterial();
+                        if (effectiveMaterial) {
+                            engine.setAlphaTesting(effectiveMaterial.needAlphaTesting() && !effectiveMaterial.needAlphaBlendingForMesh(this));
+                            if (!effectiveMaterial.isReadyForSubMesh(this, subMesh, hardwareInstancedRendering)) {
+                                engine.setAlphaTesting(currentAlphaTestingState);
+                                return false;
+                            }
+                        }
+                    }
+                } else {
+                    engine.setAlphaTesting(mat.needAlphaTesting() && !mat.needAlphaBlendingForMesh(this));
+                    if (!mat.isReady(this, hardwareInstancedRendering)) {
+                        engine.setAlphaTesting(currentAlphaTestingState);
+                        return false;
+                    }
+                }
+
+                engine.setAlphaTesting(currentAlphaTestingState);
+            }
+
+            // Shadows
+            for (var light of this._lightSources) {
+                let generator = light.getShadowGenerator();
+
+                if (generator) {
+                    for (var subMesh of this.subMeshes) {
+                        if (!generator.isReady(subMesh, hardwareInstancedRendering)) {
+                            return false;
+                        }
+                    }
+                }
+            }
+
+            // LOD
+            for (var lod of this._LODLevels) {
+                if (lod.mesh && !lod.mesh.isReady(hardwareInstancedRendering)) {
+                    return false;
+                }
+            }
+
+            return true;
         }
 
         /**

+ 1 - 46
src/babylon.scene.ts

@@ -1896,53 +1896,8 @@
                     return false;
                 }
 
-                mesh.computeWorldMatrix();
-
-                let hardwareInstancedRendering = mesh.getClassName() === "InstancedMesh";
-                if (mesh.getClassName() === "Mesh") {
-                    hardwareInstancedRendering = engine.getCaps().instancedArrays && (<Mesh>mesh).instances.length > 0;
-                }
-
-                let mat = mesh.material || this.defaultMaterial;
-                if (mat) {
-                    let currentAlphaTestingState = engine.getAlphaTesting();
-
-                    if (mat.storeEffectOnSubMeshes) {
-                        for (var subMesh of mesh.subMeshes) {
-                            let effectiveMaterial = subMesh.getMaterial();
-                            if (effectiveMaterial) {
-                                engine.setAlphaTesting(effectiveMaterial.needAlphaTesting() && !effectiveMaterial.needAlphaBlendingForMesh(mesh));
-                                if (!effectiveMaterial.isReadyForSubMesh(mesh, subMesh, hardwareInstancedRendering)) {
-                                    engine.setAlphaTesting(currentAlphaTestingState);
-                                    return false;
-                                }
-                            }
-                        }
-                    } else {
-                        engine.setAlphaTesting(mat.needAlphaTesting() && !mat.needAlphaBlendingForMesh(mesh));
-                        if (!mat.isReady(mesh, hardwareInstancedRendering)) {
-                            engine.setAlphaTesting(currentAlphaTestingState);
-                            return false;
-                        }
-                    }
-
-                    engine.setAlphaTesting(currentAlphaTestingState);
-                }
-
-                // Shadows
-                for (var light of mesh._lightSources) {
-                    let generator = light.getShadowGenerator();
-
-                    if (generator) {
-                        for (var subMesh of mesh.subMeshes) {
-                            if (!generator.isReady(subMesh, hardwareInstancedRendering)) {
-                                return false;
-                            }
-                        }
-                    }
-                }
-
                 // Highlight layers
+                let hardwareInstancedRendering = mesh.getClassName() === "InstancedMesh" || engine.getCaps().instancedArrays && (<Mesh>mesh).instances.length > 0;
                 for (var layer of this.highlightLayers) {
                     if (!layer.hasMesh(mesh)) {
                         continue;

BIN
tests/validation/ReferenceImages/lod.png


+ 1 - 0
tests/validation/config.json

@@ -129,6 +129,7 @@
     },
     {
       "title": "LOD",
+      "renderCount": 10,
       "scriptToRun": "/Demos/LOD/lod.js",
       "functionToCall": "CreateLODTestScene",
       "referenceImage": "lod.png"