瀏覽代碼

dispose of emitter for subemitters automatically

Trevor Baron 7 年之前
父節點
當前提交
0f0b2f61a3
共有 1 個文件被更改,包括 13 次插入1 次删除
  1. 13 1
      src/Particles/babylon.subEmitter.ts

+ 13 - 1
src/Particles/babylon.subEmitter.ts

@@ -38,7 +38,19 @@ module BABYLON {
             /**
              * the particle system to be used by the sub emitter
              */
-            public particleSystem: ParticleSystem) {
+            public particleSystem: ParticleSystem
+        ) {
+            // Create mesh as emitter to support rotation
+            if(!particleSystem.emitter || !(<AbstractMesh>particleSystem.emitter).dispose){
+                particleSystem.emitter = new BABYLON.AbstractMesh("SubemitterSystemEmitter", particleSystem.getScene());
+            }
+
+            // Automatically dispose of subemitter when system is disposed
+            particleSystem.onDisposeObservable.add(()=>{
+                if(particleSystem.emitter && (<AbstractMesh>particleSystem.emitter).dispose){
+                    (<AbstractMesh>particleSystem.emitter).dispose();
+                }
+            })
         }
         /**
          * Clones the sub emitter