浏览代码

merge multimat dispose

David Catuhe 6 年之前
父节点
当前提交
24562b7c2b
共有 2 个文件被更改,包括 12 次插入1 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 11 1
      src/Materials/multiMaterial.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -90,6 +90,7 @@
 - Added InputsManager and keyboard bindings for FollowCamera. ([mrdunk](https://github.com))
 - Added per solid particle culling possibility : `solidParticle.isInFrustum()`  ([jerome](https://github.com/jbousquie))
 - Added transparency support to `GlowLayer` ([Sebavan](https://github.com/Sebavan))
+- Added option `forceDisposeChildren` to multiMaterial.dispose ([danjpar](https://github.com/danjpar))
 
 ### OBJ Loader
 - Add color vertex support (not part of standard) ([brianzinn](https://github.com/brianzinn))

+ 11 - 1
src/Materials/multiMaterial.ts

@@ -191,13 +191,23 @@ export class MultiMaterial extends Material {
      * Dispose the material and release its associated resources
      * @param forceDisposeEffect Define if we want to force disposing the associated effect (if false the shader is not released and could be reuse later on)
      * @param forceDisposeTextures Define if we want to force disposing the associated textures (if false, they will not be disposed and can still be use elsewhere in the app)
+     * @param forceDisposeChildren Define if we want to force disposing the associated submaterials (if false, they will not be disposed and can still be use elsewhere in the app)
      */
-    public dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean): void {
+    public dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean, forceDisposeChildren?: boolean): void {
         var scene = this.getScene();
         if (!scene) {
             return;
         }
 
+        if (forceDisposeChildren === true) {
+            for (var index = 0; index < this.subMaterials.length; index++) {
+                var subMaterial = this.subMaterials[index];
+                if (subMaterial) {
+                    subMaterial.dispose(forceDisposeEffect, forceDisposeTextures);
+                }
+            }
+        }
+
         var index = scene.multiMaterials.indexOf(this);
         if (index >= 0) {
             scene.multiMaterials.splice(index, 1);