Преглед изворни кода

Merge pull request #16880 from Mugen87/dev35

Object3D: Dispatch event in .add()/.remove() when operation is done.
Mr.doob пре 6 година
родитељ
комит
127b3f2dd8
1 измењених фајлова са 3 додато и 4 уклоњено
  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.parent = this;
-			object.dispatchEvent( { type: 'added' } );
-
 			this.children.push( object );
 			this.children.push( object );
 
 
+			object.dispatchEvent( { type: 'added' } );
+
 		} else {
 		} else {
 
 
 			console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
 			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 ) {
 		if ( index !== - 1 ) {
 
 
 			object.parent = null;
 			object.parent = null;
+			this.children.splice( index, 1 );
 
 
 			object.dispatchEvent( { type: 'removed' } );
 			object.dispatchEvent( { type: 'removed' } );
 
 
-			this.children.splice( index, 1 );
-
 		}
 		}
 
 
 		return this;
 		return this;