From 914e1c4e959696545f44c3257e42576feff80d20 Mon Sep 17 00:00:00 2001 From: Justin Sermeno Date: Sun, 11 Sep 2011 00:29:30 -0700 Subject: [PATCH 1/2] Remove Object3D child from scene too --- src/core/Object3D.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/core/Object3D.js b/src/core/Object3D.js index d2d6bfe8..1c827e34 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -130,14 +130,29 @@ THREE.Object3D.prototype = { }, remove: function ( object ) { + var scene = this; - var childIndex = this.children.indexOf( object ); + var childIndex = this.children.indexOf( child ); if ( childIndex !== - 1 ) { - object.parent = undefined; + 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 ); + + } + } }, From 2f234a2ac8b2fbac49997050caf9adcd896ca35d Mon Sep 17 00:00:00 2001 From: Justin Sermeno Date: Sun, 11 Sep 2011 00:30:43 -0700 Subject: [PATCH 2/2] change child reference to object reference --- src/core/Object3D.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/Object3D.js b/src/core/Object3D.js index 1c827e34..cae9880b 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -132,11 +132,11 @@ THREE.Object3D.prototype = { remove: function ( object ) { var scene = this; - var childIndex = this.children.indexOf( child ); + var childIndex = this.children.indexOf( object ); if ( childIndex !== - 1 ) { - child.parent = undefined; + object.parent = undefined; this.children.splice( childIndex, 1 ); // remove from scene @@ -149,7 +149,7 @@ THREE.Object3D.prototype = { if ( scene !== undefined && scene instanceof THREE.Scene ) { - scene.removeChildRecurse( child ); + scene.removeChildRecurse( object ); }