David Catuhe 5 سال پیش
والد
کامیت
0621f7b3e6
3فایلهای تغییر یافته به همراه37 افزوده شده و 32 حذف شده
  1. 32 23
      src/Materials/material.ts
  2. 0 7
      src/Materials/pushMaterial.ts
  3. 5 2
      src/Meshes/subMesh.ts

+ 32 - 23
src/Materials/material.ts

@@ -165,6 +165,13 @@ export class Material implements IAnimatable {
     public shadowDepthWrapper: Nullable<ShadowDepthWrapper> = null;
 
     /**
+     * Gets or sets a boolean indicating that the material is allowed (if supported) to do shader hot swapping.
+     * This means that the material can keep using a previous shader while a new one is being compiled.
+     * This is mostly used when shader parallel compilation is supported (true by default)
+     */
+    public allowShaderHotSwapping = true;    
+
+    /**
      * The ID of the material
      */
     @serialize()
@@ -1045,6 +1052,8 @@ export class Material implements IAnimatable {
         };
 
         var scene = this.getScene();
+        let currentHotSwapingState = this.allowShaderHotSwapping;
+        this.allowShaderHotSwapping = false; // Turned off to let us evaluate the real compilation state
 
         var checkReady = () => {
             if (!this._scene || !this._scene.getEngine()) {
@@ -1060,34 +1069,33 @@ export class Material implements IAnimatable {
             if (this._storeEffectOnSubMeshes) {
                 var allDone = true, lastError = null;
                 if (mesh.subMeshes) {
-                    for (var subMesh of mesh.subMeshes) {
-                        let effectiveMaterial = subMesh.getMaterial();
-                        if (effectiveMaterial) {
-                            if (effectiveMaterial._storeEffectOnSubMeshes) {
-                                if (!effectiveMaterial.isReadyForSubMesh(mesh, subMesh, localOptions.useInstances)) {
-                                    if (subMesh.effect && subMesh.effect.getCompilationError() && subMesh.effect.allFallbacksProcessed()) {
-                                        lastError = subMesh.effect.getCompilationError();
-                                    } else {
-                                        allDone = false;
-                                        setTimeout(checkReady, 16);
-                                        break;
-                                    }
-                                }
+                    let tempSubMesh = new SubMesh(0, 0, 0, 0, 0, mesh, undefined, false, false);
+                    if (this._storeEffectOnSubMeshes) {
+                        if (tempSubMesh._materialDefines) {
+                            tempSubMesh._materialDefines._renderId = -1;
+                        }
+                        if (!this.isReadyForSubMesh(mesh, tempSubMesh, localOptions.useInstances)) {
+                            if (tempSubMesh.effect && tempSubMesh.effect.getCompilationError() && tempSubMesh.effect.allFallbacksProcessed()) {
+                                lastError = tempSubMesh.effect.getCompilationError();
+                            } else {
+                                allDone = false;
+                                setTimeout(checkReady, 16);
+                            }
+                        }
+                    } else {
+                        tempSubMesh._renderId = -1;
+                        if (!this.isReady(mesh, localOptions.useInstances)) {
+                            if (this.getEffect() && this.getEffect()!.getCompilationError() && this.getEffect()!.allFallbacksProcessed()) {
+                                lastError = this.getEffect()!.getCompilationError();
                             } else {
-                                if (!effectiveMaterial.isReady(mesh, localOptions.useInstances)) {
-                                    if (effectiveMaterial.getEffect() && effectiveMaterial.getEffect()!.getCompilationError() && effectiveMaterial.getEffect()!.allFallbacksProcessed()) {
-                                        lastError = effectiveMaterial.getEffect()!.getCompilationError();
-                                    } else {
-                                        allDone = false;
-                                        setTimeout(checkReady, 16);
-                                        break;
-                                    }
-                                }
+                                allDone = false;
+                                setTimeout(checkReady, 16);
                             }
                         }
                     }
                 }
-                if (allDone) {
+                if (allDone) {                    
+                    this.allowShaderHotSwapping = currentHotSwapingState;
                     if (lastError) {
                         if (onError) {
                             onError(lastError);
@@ -1099,6 +1107,7 @@ export class Material implements IAnimatable {
                 }
             } else {
                 if (this.isReady()) {
+                    this.allowShaderHotSwapping = currentHotSwapingState;
                     if (onCompiled) {
                         onCompiled(this);
                     }

+ 0 - 7
src/Materials/pushMaterial.ts

@@ -16,13 +16,6 @@ export class PushMaterial extends Material {
 
     protected _normalMatrix: Matrix = new Matrix();
 
-    /**
-     * Gets or sets a boolean indicating that the material is allowed to do shader hot swapping.
-     * This means that the material can keep using a previous shader while a new one is being compiled.
-     * This is mostly used when shader parallel compilation is supported (true by default)
-     */
-    public allowShaderHotSwapping = true;
-
     constructor(name: string, scene: Scene) {
         super(name, scene);
         this._storeEffectOnSubMeshes = true;

+ 5 - 2
src/Meshes/subMesh.ts

@@ -117,6 +117,7 @@ export class SubMesh implements ICullable {
      * @param mesh defines the parent mesh
      * @param renderingMesh defines an optional rendering mesh
      * @param createBoundingBox defines if bounding box should be created for this submesh
+     * @param addToMesh defines a boolean indicating that the submesh must be added to the mesh.subMeshes array (true by default)
      */
     constructor(
         /** the material index to use */
@@ -128,10 +129,12 @@ export class SubMesh implements ICullable {
         /** index start */
         public indexStart: number,
         /** indices count */
-        public indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh, createBoundingBox: boolean = true) {
+        public indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh, createBoundingBox: boolean = true, addToMesh = true) {
         this._mesh = mesh;
         this._renderingMesh = renderingMesh || <Mesh>mesh;
-        mesh.subMeshes.push(this);
+        if (addToMesh) {
+            mesh.subMeshes.push(this);
+        }
 
         this._trianglePlanes = [];