Explorar o código

Object3D: Dispatch event in .add()/.remove() when operation is done.

Mugen87 %!s(int64=6) %!d(string=hai) anos
pai
achega
87f6fed4a3
Modificáronse 1 ficheiros con 3 adicións e 4 borrados
  1. 3 4
      src/core/Object3D.js

+ 3 - 4
src/core/Object3D.js

@@ -389,10 +389,10 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 			}
 
 			object.parent = this;
-			object.dispatchEvent( { type: 'added' } );
-
 			this.children.push( object );
 
+			object.dispatchEvent( { type: 'added' } );
+
 		} else {
 
 			console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
@@ -422,11 +422,10 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 		if ( index !== - 1 ) {
 
 			object.parent = null;
+			this.children.splice( index, 1 );
 
 			object.dispatchEvent( { type: 'removed' } );
 
-			this.children.splice( index, 1 );
-
 		}
 
 		return this;

粤ICP备19079148号