Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/api/en/core/Object3D.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ <h3>[method:null applyMatrix]( [param:Matrix4 matrix] )</h3>
<h3>[method:this applyQuaternion]( [param:Quaternion quaternion] )</h3>
<p>Applies the rotation represented by the quaternion to the object.</p>

<h3>[method:this attach]( [param:Object3D object] )</h3>
<p>Adds *object* as a child of this, while maintaining the object's world transform.</p>

<h3>[method:Object3D clone]( [param:Boolean recursive] )</h3>
<p>
recursive -- if true, descendants of the object are also cloned. Default is true.<br /><br />
Expand Down
5 changes: 5 additions & 0 deletions src/core/Object3D.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ export class Object3D extends EventDispatcher {
*/
remove(...object: Object3D[]): this;

/**
* Adds object as a child of this, while maintaining the object's world transform.
*/
attach(object: Object3D): this;

/**
* Searches through the object's children and returns the first with a matching id.
* @param id Unique number of the object instance
Expand Down
32 changes: 32 additions & 0 deletions src/core/Object3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,38 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),

},

attach: function () {

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

var m = new Matrix4();

return function attach( object ) {

this.updateWorldMatrix( true, false );

m.getInverse( this.matrixWorld );

if ( object.parent !== null ) {

object.parent.updateWorldMatrix( true, false );

m.multiply( object.parent.matrixWorld );

}

object.applyMatrix( m );

object.updateWorldMatrix( false, false );

this.add( object );

return this;

};

}(),

getObjectById: function ( id ) {

return this.getObjectByProperty( 'id', id );
Expand Down