Object3D.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. import { Quaternion } from '../math/Quaternion.js';
  2. import { Vector3 } from '../math/Vector3.js';
  3. import { Matrix4 } from '../math/Matrix4.js';
  4. import { EventDispatcher } from './EventDispatcher.js';
  5. import { Euler } from '../math/Euler.js';
  6. import { Layers } from './Layers.js';
  7. import { Matrix3 } from '../math/Matrix3.js';
  8. import * as MathUtils from '../math/MathUtils.js';
  9. let _object3DId = 0;
  10. const _v1 = /*@__PURE__*/ new Vector3();
  11. const _q1 = /*@__PURE__*/ new Quaternion();
  12. const _m1 = /*@__PURE__*/ new Matrix4();
  13. const _target = /*@__PURE__*/ new Vector3();
  14. const _position = /*@__PURE__*/ new Vector3();
  15. const _scale = /*@__PURE__*/ new Vector3();
  16. const _quaternion = /*@__PURE__*/ new Quaternion();
  17. const _xAxis = /*@__PURE__*/ new Vector3( 1, 0, 0 );
  18. const _yAxis = /*@__PURE__*/ new Vector3( 0, 1, 0 );
  19. const _zAxis = /*@__PURE__*/ new Vector3( 0, 0, 1 );
  20. const _addedEvent = { type: 'added' };
  21. const _removedEvent = { type: 'removed' };
  22. class Object3D extends EventDispatcher {
  23. constructor() {
  24. super();
  25. this.isObject3D = true;
  26. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  27. this.uuid = MathUtils.generateUUID();
  28. this.name = '';
  29. this.type = 'Object3D';
  30. this.parent = null;
  31. this.children = [];
  32. this.up = Object3D.DEFAULT_UP.clone();
  33. const position = new Vector3();
  34. const rotation = new Euler();
  35. const quaternion = new Quaternion();
  36. const scale = new Vector3( 1, 1, 1 );
  37. function onRotationChange() {
  38. quaternion.setFromEuler( rotation, false );
  39. }
  40. function onQuaternionChange() {
  41. rotation.setFromQuaternion( quaternion, undefined, false );
  42. }
  43. rotation._onChange( onRotationChange );
  44. quaternion._onChange( onQuaternionChange );
  45. Object.defineProperties( this, {
  46. position: {
  47. configurable: true,
  48. enumerable: true,
  49. value: position
  50. },
  51. rotation: {
  52. configurable: true,
  53. enumerable: true,
  54. value: rotation
  55. },
  56. quaternion: {
  57. configurable: true,
  58. enumerable: true,
  59. value: quaternion
  60. },
  61. scale: {
  62. configurable: true,
  63. enumerable: true,
  64. value: scale
  65. },
  66. modelViewMatrix: {
  67. value: new Matrix4()
  68. },
  69. normalMatrix: {
  70. value: new Matrix3()
  71. }
  72. } );
  73. this.matrix = new Matrix4();
  74. this.matrixWorld = new Matrix4();
  75. this.matrixAutoUpdate = Object3D.DEFAULT_MATRIX_AUTO_UPDATE;
  76. this.matrixWorldNeedsUpdate = false;
  77. this.matrixWorldAutoUpdate = Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE; // checked by the renderer
  78. this.layers = new Layers();
  79. this.visible = true;
  80. this.castShadow = false;
  81. this.receiveShadow = false;
  82. this.frustumCulled = true;
  83. this.renderOrder = 0;
  84. this.animations = [];
  85. this.userData = {};
  86. }
  87. onBeforeShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {}
  88. onAfterShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {}
  89. onBeforeRender( /* renderer, scene, camera, geometry, material, group */ ) {}
  90. onAfterRender( /* renderer, scene, camera, geometry, material, group */ ) {}
  91. applyMatrix4( matrix ) {
  92. if ( this.matrixAutoUpdate ) this.updateMatrix();
  93. this.matrix.premultiply( matrix );
  94. this.matrix.decompose( this.position, this.quaternion, this.scale );
  95. }
  96. applyQuaternion( q ) {
  97. this.quaternion.premultiply( q );
  98. return this;
  99. }
  100. setRotationFromAxisAngle( axis, angle ) {
  101. // assumes axis is normalized
  102. this.quaternion.setFromAxisAngle( axis, angle );
  103. }
  104. setRotationFromEuler( euler ) {
  105. this.quaternion.setFromEuler( euler, true );
  106. }
  107. setRotationFromMatrix( m ) {
  108. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  109. this.quaternion.setFromRotationMatrix( m );
  110. }
  111. setRotationFromQuaternion( q ) {
  112. // assumes q is normalized
  113. this.quaternion.copy( q );
  114. }
  115. rotateOnAxis( axis, angle ) {
  116. // rotate object on axis in object space
  117. // axis is assumed to be normalized
  118. _q1.setFromAxisAngle( axis, angle );
  119. this.quaternion.multiply( _q1 );
  120. return this;
  121. }
  122. rotateOnWorldAxis( axis, angle ) {
  123. // rotate object on axis in world space
  124. // axis is assumed to be normalized
  125. // method assumes no rotated parent
  126. _q1.setFromAxisAngle( axis, angle );
  127. this.quaternion.premultiply( _q1 );
  128. return this;
  129. }
  130. rotateX( angle ) {
  131. return this.rotateOnAxis( _xAxis, angle );
  132. }
  133. rotateY( angle ) {
  134. return this.rotateOnAxis( _yAxis, angle );
  135. }
  136. rotateZ( angle ) {
  137. return this.rotateOnAxis( _zAxis, angle );
  138. }
  139. translateOnAxis( axis, distance ) {
  140. // translate object by distance along axis in object space
  141. // axis is assumed to be normalized
  142. _v1.copy( axis ).applyQuaternion( this.quaternion );
  143. this.position.add( _v1.multiplyScalar( distance ) );
  144. return this;
  145. }
  146. translateX( distance ) {
  147. return this.translateOnAxis( _xAxis, distance );
  148. }
  149. translateY( distance ) {
  150. return this.translateOnAxis( _yAxis, distance );
  151. }
  152. translateZ( distance ) {
  153. return this.translateOnAxis( _zAxis, distance );
  154. }
  155. localToWorld( vector ) {
  156. this.updateWorldMatrix( true, false );
  157. return vector.applyMatrix4( this.matrixWorld );
  158. }
  159. worldToLocal( vector ) {
  160. this.updateWorldMatrix( true, false );
  161. return vector.applyMatrix4( _m1.copy( this.matrixWorld ).invert() );
  162. }
  163. lookAt( x, y, z ) {
  164. // This method does not support objects having non-uniformly-scaled parent(s)
  165. if ( x.isVector3 ) {
  166. _target.copy( x );
  167. } else {
  168. _target.set( x, y, z );
  169. }
  170. const parent = this.parent;
  171. this.updateWorldMatrix( true, false );
  172. _position.setFromMatrixPosition( this.matrixWorld );
  173. if ( this.isCamera || this.isLight ) {
  174. _m1.lookAt( _position, _target, this.up );
  175. } else {
  176. _m1.lookAt( _target, _position, this.up );
  177. }
  178. this.quaternion.setFromRotationMatrix( _m1 );
  179. if ( parent ) {
  180. _m1.extractRotation( parent.matrixWorld );
  181. _q1.setFromRotationMatrix( _m1 );
  182. this.quaternion.premultiply( _q1.invert() );
  183. }
  184. }
  185. add( object ) {
  186. if ( arguments.length > 1 ) {
  187. for ( let i = 0; i < arguments.length; i ++ ) {
  188. this.add( arguments[ i ] );
  189. }
  190. return this;
  191. }
  192. if ( object === this ) {
  193. console.error( 'THREE.Object3D.add: object can\'t be added as a child of itself.', object );
  194. return this;
  195. }
  196. if ( object && object.isObject3D ) {
  197. if ( object.parent !== null ) {
  198. object.parent.remove( object );
  199. }
  200. object.parent = this;
  201. this.children.push( object );
  202. object.dispatchEvent( _addedEvent );
  203. } else {
  204. console.error( 'THREE.Object3D.add: object not an instance of THREE.Object3D.', object );
  205. }
  206. return this;
  207. }
  208. remove( object ) {
  209. if ( arguments.length > 1 ) {
  210. for ( let i = 0; i < arguments.length; i ++ ) {
  211. this.remove( arguments[ i ] );
  212. }
  213. return this;
  214. }
  215. const index = this.children.indexOf( object );
  216. if ( index !== - 1 ) {
  217. object.parent = null;
  218. this.children.splice( index, 1 );
  219. object.dispatchEvent( _removedEvent );
  220. }
  221. return this;
  222. }
  223. removeFromParent() {
  224. const parent = this.parent;
  225. if ( parent !== null ) {
  226. parent.remove( this );
  227. }
  228. return this;
  229. }
  230. clear() {
  231. return this.remove( ... this.children );
  232. }
  233. attach( object ) {
  234. // adds object as a child of this, while maintaining the object's world transform
  235. // Note: This method does not support scene graphs having non-uniformly-scaled nodes(s)
  236. this.updateWorldMatrix( true, false );
  237. _m1.copy( this.matrixWorld ).invert();
  238. if ( object.parent !== null ) {
  239. object.parent.updateWorldMatrix( true, false );
  240. _m1.multiply( object.parent.matrixWorld );
  241. }
  242. object.applyMatrix4( _m1 );
  243. this.add( object );
  244. object.updateWorldMatrix( false, true );
  245. return this;
  246. }
  247. getObjectById( id ) {
  248. return this.getObjectByProperty( 'id', id );
  249. }
  250. getObjectByName( name ) {
  251. return this.getObjectByProperty( 'name', name );
  252. }
  253. getObjectByProperty( name, value ) {
  254. if ( this[ name ] === value ) return this;
  255. for ( let i = 0, l = this.children.length; i < l; i ++ ) {
  256. const child = this.children[ i ];
  257. const object = child.getObjectByProperty( name, value );
  258. if ( object !== undefined ) {
  259. return object;
  260. }
  261. }
  262. return undefined;
  263. }
  264. getObjectsByProperty( name, value, result = [] ) {
  265. if ( this[ name ] === value ) result.push( this );
  266. const children = this.children;
  267. for ( let i = 0, l = children.length; i < l; i ++ ) {
  268. children[ i ].getObjectsByProperty( name, value, result );
  269. }
  270. return result;
  271. }
  272. getWorldPosition( target ) {
  273. this.updateWorldMatrix( true, false );
  274. return target.setFromMatrixPosition( this.matrixWorld );
  275. }
  276. getWorldQuaternion( target ) {
  277. this.updateWorldMatrix( true, false );
  278. this.matrixWorld.decompose( _position, target, _scale );
  279. return target;
  280. }
  281. getWorldScale( target ) {
  282. this.updateWorldMatrix( true, false );
  283. this.matrixWorld.decompose( _position, _quaternion, target );
  284. return target;
  285. }
  286. getWorldDirection( target ) {
  287. this.updateWorldMatrix( true, false );
  288. const e = this.matrixWorld.elements;
  289. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  290. }
  291. raycast( /* raycaster, intersects */ ) {}
  292. traverse( callback ) {
  293. callback( this );
  294. const children = this.children;
  295. for ( let i = 0, l = children.length; i < l; i ++ ) {
  296. children[ i ].traverse( callback );
  297. }
  298. }
  299. traverseVisible( callback ) {
  300. if ( this.visible === false ) return;
  301. callback( this );
  302. const children = this.children;
  303. for ( let i = 0, l = children.length; i < l; i ++ ) {
  304. children[ i ].traverseVisible( callback );
  305. }
  306. }
  307. traverseAncestors( callback ) {
  308. const parent = this.parent;
  309. if ( parent !== null ) {
  310. callback( parent );
  311. parent.traverseAncestors( callback );
  312. }
  313. }
  314. updateMatrix() {
  315. this.matrix.compose( this.position, this.quaternion, this.scale );
  316. this.matrixWorldNeedsUpdate = true;
  317. }
  318. updateMatrixWorld( force ) {
  319. if ( this.matrixAutoUpdate ) this.updateMatrix();
  320. if ( this.matrixWorldNeedsUpdate || force ) {
  321. if ( this.parent === null ) {
  322. this.matrixWorld.copy( this.matrix );
  323. } else {
  324. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  325. }
  326. this.matrixWorldNeedsUpdate = false;
  327. force = true;
  328. }
  329. // update children
  330. const children = this.children;
  331. for ( let i = 0, l = children.length; i < l; i ++ ) {
  332. const child = children[ i ];
  333. if ( child.matrixWorldAutoUpdate === true || force === true ) {
  334. child.updateMatrixWorld( force );
  335. }
  336. }
  337. }
  338. updateWorldMatrix( updateParents, updateChildren ) {
  339. const parent = this.parent;
  340. if ( updateParents === true && parent !== null && parent.matrixWorldAutoUpdate === true ) {
  341. parent.updateWorldMatrix( true, false );
  342. }
  343. if ( this.matrixAutoUpdate ) this.updateMatrix();
  344. if ( this.parent === null ) {
  345. this.matrixWorld.copy( this.matrix );
  346. } else {
  347. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  348. }
  349. // update children
  350. if ( updateChildren === true ) {
  351. const children = this.children;
  352. for ( let i = 0, l = children.length; i < l; i ++ ) {
  353. const child = children[ i ];
  354. if ( child.matrixWorldAutoUpdate === true ) {
  355. child.updateWorldMatrix( false, true );
  356. }
  357. }
  358. }
  359. }
  360. toJSON( meta ) {
  361. // meta is a string when called from JSON.stringify
  362. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  363. const output = {};
  364. // meta is a hash used to collect geometries, materials.
  365. // not providing it implies that this is the root object
  366. // being serialized.
  367. if ( isRootObject ) {
  368. // initialize meta obj
  369. meta = {
  370. geometries: {},
  371. materials: {},
  372. textures: {},
  373. images: {},
  374. shapes: {},
  375. skeletons: {},
  376. animations: {},
  377. nodes: {}
  378. };
  379. output.metadata = {
  380. version: 4.6,
  381. type: 'Object',
  382. generator: 'Object3D.toJSON'
  383. };
  384. }
  385. // standard Object3D serialization
  386. const object = {};
  387. object.uuid = this.uuid;
  388. object.type = this.type;
  389. if ( this.name !== '' ) object.name = this.name;
  390. if ( this.castShadow === true ) object.castShadow = true;
  391. if ( this.receiveShadow === true ) object.receiveShadow = true;
  392. if ( this.visible === false ) object.visible = false;
  393. if ( this.frustumCulled === false ) object.frustumCulled = false;
  394. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  395. if ( Object.keys( this.userData ).length > 0 ) object.userData = this.userData;
  396. object.layers = this.layers.mask;
  397. object.matrix = this.matrix.toArray();
  398. object.up = this.up.toArray();
  399. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  400. // object specific properties
  401. if ( this.isInstancedMesh ) {
  402. object.type = 'InstancedMesh';
  403. object.count = this.count;
  404. object.instanceMatrix = this.instanceMatrix.toJSON();
  405. if ( this.instanceColor !== null ) object.instanceColor = this.instanceColor.toJSON();
  406. }
  407. if ( this.isBatchedMesh ) {
  408. object.type = 'BatchedMesh';
  409. object.perObjectFrustumCulled = this.perObjectFrustumCulled;
  410. object.sortObjects = this.sortObjects;
  411. object.drawRanges = this._drawRanges;
  412. object.reservedRanges = this._reservedRanges;
  413. object.visibility = this._visibility;
  414. object.active = this._active;
  415. object.bounds = this._bounds.map( bound => ( {
  416. boxInitialized: bound.boxInitialized,
  417. boxMin: bound.box.min.toArray(),
  418. boxMax: bound.box.max.toArray(),
  419. sphereInitialized: bound.sphereInitialized,
  420. sphereRadius: bound.sphere.radius,
  421. sphereCenter: bound.sphere.center.toArray()
  422. } ) );
  423. object.maxGeometryCount = this._maxGeometryCount;
  424. object.maxVertexCount = this._maxVertexCount;
  425. object.maxIndexCount = this._maxIndexCount;
  426. object.geometryInitialized = this._geometryInitialized;
  427. object.geometryCount = this._geometryCount;
  428. object.matricesTexture = this._matricesTexture.toJSON( meta );
  429. if ( this.boundingSphere !== null ) {
  430. object.boundingSphere = {
  431. center: object.boundingSphere.center.toArray(),
  432. radius: object.boundingSphere.radius
  433. };
  434. }
  435. if ( this.boundingBox !== null ) {
  436. object.boundingBox = {
  437. min: object.boundingBox.min.toArray(),
  438. max: object.boundingBox.max.toArray()
  439. };
  440. }
  441. }
  442. //
  443. function serialize( library, element ) {
  444. if ( library[ element.uuid ] === undefined ) {
  445. library[ element.uuid ] = element.toJSON( meta );
  446. }
  447. return element.uuid;
  448. }
  449. if ( this.isScene ) {
  450. if ( this.background ) {
  451. if ( this.background.isColor ) {
  452. object.background = this.background.toJSON();
  453. } else if ( this.background.isTexture ) {
  454. object.background = this.background.toJSON( meta ).uuid;
  455. }
  456. }
  457. if ( this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== true ) {
  458. object.environment = this.environment.toJSON( meta ).uuid;
  459. }
  460. } else if ( this.isMesh || this.isLine || this.isPoints ) {
  461. object.geometry = serialize( meta.geometries, this.geometry );
  462. const parameters = this.geometry.parameters;
  463. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  464. const shapes = parameters.shapes;
  465. if ( Array.isArray( shapes ) ) {
  466. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  467. const shape = shapes[ i ];
  468. serialize( meta.shapes, shape );
  469. }
  470. } else {
  471. serialize( meta.shapes, shapes );
  472. }
  473. }
  474. }
  475. if ( this.isSkinnedMesh ) {
  476. object.bindMode = this.bindMode;
  477. object.bindMatrix = this.bindMatrix.toArray();
  478. if ( this.skeleton !== undefined ) {
  479. serialize( meta.skeletons, this.skeleton );
  480. object.skeleton = this.skeleton.uuid;
  481. }
  482. }
  483. if ( this.material !== undefined ) {
  484. if ( Array.isArray( this.material ) ) {
  485. const uuids = [];
  486. for ( let i = 0, l = this.material.length; i < l; i ++ ) {
  487. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  488. }
  489. object.material = uuids;
  490. } else {
  491. object.material = serialize( meta.materials, this.material );
  492. }
  493. }
  494. //
  495. if ( this.children.length > 0 ) {
  496. object.children = [];
  497. for ( let i = 0; i < this.children.length; i ++ ) {
  498. object.children.push( this.children[ i ].toJSON( meta ).object );
  499. }
  500. }
  501. //
  502. if ( this.animations.length > 0 ) {
  503. object.animations = [];
  504. for ( let i = 0; i < this.animations.length; i ++ ) {
  505. const animation = this.animations[ i ];
  506. object.animations.push( serialize( meta.animations, animation ) );
  507. }
  508. }
  509. if ( isRootObject ) {
  510. const geometries = extractFromCache( meta.geometries );
  511. const materials = extractFromCache( meta.materials );
  512. const textures = extractFromCache( meta.textures );
  513. const images = extractFromCache( meta.images );
  514. const shapes = extractFromCache( meta.shapes );
  515. const skeletons = extractFromCache( meta.skeletons );
  516. const animations = extractFromCache( meta.animations );
  517. const nodes = extractFromCache( meta.nodes );
  518. if ( geometries.length > 0 ) output.geometries = geometries;
  519. if ( materials.length > 0 ) output.materials = materials;
  520. if ( textures.length > 0 ) output.textures = textures;
  521. if ( images.length > 0 ) output.images = images;
  522. if ( shapes.length > 0 ) output.shapes = shapes;
  523. if ( skeletons.length > 0 ) output.skeletons = skeletons;
  524. if ( animations.length > 0 ) output.animations = animations;
  525. if ( nodes.length > 0 ) output.nodes = nodes;
  526. }
  527. output.object = object;
  528. return output;
  529. // extract data from the cache hash
  530. // remove metadata on each item
  531. // and return as array
  532. function extractFromCache( cache ) {
  533. const values = [];
  534. for ( const key in cache ) {
  535. const data = cache[ key ];
  536. delete data.metadata;
  537. values.push( data );
  538. }
  539. return values;
  540. }
  541. }
  542. clone( recursive ) {
  543. return new this.constructor().copy( this, recursive );
  544. }
  545. copy( source, recursive = true ) {
  546. this.name = source.name;
  547. this.up.copy( source.up );
  548. this.position.copy( source.position );
  549. this.rotation.order = source.rotation.order;
  550. this.quaternion.copy( source.quaternion );
  551. this.scale.copy( source.scale );
  552. this.matrix.copy( source.matrix );
  553. this.matrixWorld.copy( source.matrixWorld );
  554. this.matrixAutoUpdate = source.matrixAutoUpdate;
  555. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  556. this.matrixWorldAutoUpdate = source.matrixWorldAutoUpdate;
  557. this.layers.mask = source.layers.mask;
  558. this.visible = source.visible;
  559. this.castShadow = source.castShadow;
  560. this.receiveShadow = source.receiveShadow;
  561. this.frustumCulled = source.frustumCulled;
  562. this.renderOrder = source.renderOrder;
  563. this.animations = source.animations.slice();
  564. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  565. if ( recursive === true ) {
  566. for ( let i = 0; i < source.children.length; i ++ ) {
  567. const child = source.children[ i ];
  568. this.add( child.clone() );
  569. }
  570. }
  571. return this;
  572. }
  573. }
  574. Object3D.DEFAULT_UP = /*@__PURE__*/ new Vector3( 0, 1, 0 );
  575. Object3D.DEFAULT_MATRIX_AUTO_UPDATE = true;
  576. Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = true;
  577. export { Object3D };