Explorar el Código

Object3D: Fix `added` event in `attach()`. (#27917)

Michael Herzog hace 1 año
padre
commit
74252e6e95
Se han modificado 1 ficheros con 10 adiciones y 7 borrados
  1. 10 7
      src/core/Object3D.js

+ 10 - 7
src/core/Object3D.js

@@ -333,12 +333,7 @@ class Object3D extends EventDispatcher {
 
 		if ( object && object.isObject3D ) {
 
-			if ( object.parent !== null ) {
-
-				object.parent.remove( object );
-
-			}
-
+			object.removeFromParent();
 			object.parent = this;
 			this.children.push( object );
 
@@ -431,10 +426,18 @@ class Object3D extends EventDispatcher {
 
 		object.applyMatrix4( _m1 );
 
-		this.add( object );
+		object.removeFromParent();
+		object.parent = this;
+		this.children.push( object );
 
 		object.updateWorldMatrix( false, true );
 
+		object.dispatchEvent( _addedEvent );
+
+		_childaddedEvent.child = object;
+		this.dispatchEvent( _childaddedEvent );
+		_childaddedEvent.child = null;
+
 		return this;
 
 	}