Skip to content

Commit

Permalink
attach varargs
Browse files Browse the repository at this point in the history
  • Loading branch information
ycw committed Aug 22, 2023
1 parent 0d02218 commit 31320f0
Showing 1 changed file with 42 additions and 16 deletions.
58 changes: 42 additions & 16 deletions src/core/Object3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,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 );

Expand Down Expand Up @@ -411,27 +406,58 @@ class Object3D extends EventDispatcher {

attach( object ) {

// adds object as a child of this, while maintaining the object's world transform
if ( arguments.length > 1 ) {

for ( let i = 0; i < arguments.length; i ++ ) {

// Note: This method does not support scene graphs having non-uniformly-scaled nodes(s)
this.attach( arguments[ i ] );

this.updateWorldMatrix( true, false );
}

_m1.copy( this.matrixWorld ).invert();
return this;

if ( object.parent !== null ) {
}

object.parent.updateWorldMatrix( true, false );
if ( object === this ) {

_m1.multiply( object.parent.matrixWorld );
console.error( 'THREE.Object3D.attach: object can\'t be attached as a child of itself.', object );
return this;

}

object.applyMatrix4( _m1 );
if ( object && object.isObject3D ) {

// adds object as a child of this, while maintaining the object's world transform

// Note: This method does not support scene graphs having non-uniformly-scaled node(s)

this.updateWorldMatrix( true, false );

this.add( object );
_m1.copy( this.matrixWorld ).invert();

object.updateWorldMatrix( false, true );
if ( object.parent !== null ) {

object.parent.updateWorldMatrix( true, false );

_m1.multiply( object.parent.matrixWorld );

}

object.applyMatrix4( _m1 );

object.removeFromParent();
object.parent = this;
this.children.push( object );

object.updateWorldMatrix( false, true );

object.dispatchEvent( _addedEvent );

} else {

console.error( 'THREE.Object3D.attach: object not an instance of THREE.Object3D.', object );

}

return this;

Expand Down

0 comments on commit 31320f0

Please sign in to comment.