瀏覽代碼

Object3D removeChild removes child from scene too

Justin Sermeno 14 年之前
父節點
當前提交
d1f77fd776
共有 1 個文件被更改,包括 18 次插入3 次删除
  1. 18 3
      src/core/Object3D.js

+ 18 - 3
src/core/Object3D.js

@@ -130,15 +130,30 @@ THREE.Object3D.prototype = {
 	},
 
 	removeChild: function ( child ) {
+        var scene = this;
 
 		var childIndex = this.children.indexOf( child );
 
 		if ( childIndex !== - 1 ) {
 
-			child.parent = undefined;
-			this.children.splice( childIndex, 1 );
+            child.parent = undefined;
+            this.children.splice( childIndex, 1 );
 
-		}
+            // remove from scene
+
+            while ( scene.parent !== undefined ) {
+
+                scene = scene.parent;
+
+            }
+
+            if ( scene !== undefined && scene instanceof THREE.Scene ) {
+
+                scene.removeChildRecurse( child );
+
+            }
+
+        }
 
 	},