* Adds the given 3D object as a child of this 3D object, while maintaining the object's world * transform. This method does not support scene graphs having non-uniformly-scaled nodes(s). * * @fires Object3D#added * @fires Object3D#childadded * @param {Object3D} object - The 3D object to at
( object )
| 872 | * @return {Object3D} A reference to this instance. |
| 873 | */ |
| 874 | attach( object ) { |
| 875 | |
| 876 | // adds object as a child of this, while maintaining the object's world transform |
| 877 | |
| 878 | // Note: This method does not support scene graphs having non-uniformly-scaled nodes(s) |
| 879 | |
| 880 | this.updateWorldMatrix( true, false ); |
| 881 | |
| 882 | _m1.copy( this.matrixWorld ).invert(); |
| 883 | |
| 884 | if ( object.parent !== null ) { |
| 885 | |
| 886 | object.parent.updateWorldMatrix( true, false ); |
| 887 | |
| 888 | _m1.multiply( object.parent.matrixWorld ); |
| 889 | |
| 890 | } |
| 891 | |
| 892 | object.applyMatrix4( _m1 ); |
| 893 | |
| 894 | object.removeFromParent(); |
| 895 | object.parent = this; |
| 896 | this.children.push( object ); |
| 897 | |
| 898 | object.updateWorldMatrix( false, true ); |
| 899 | |
| 900 | object.dispatchEvent( _addedEvent ); |
| 901 | |
| 902 | _childaddedEvent.child = object; |
| 903 | this.dispatchEvent( _childaddedEvent ); |
| 904 | _childaddedEvent.child = null; |
| 905 | |
| 906 | return this; |
| 907 | |
| 908 | } |
| 909 | |
| 910 | /** |
| 911 | * Searches through the 3D object and its children, starting with the 3D object |
no test coverage detected