Gyroscope.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ( function () {
  2. const _translationObject = new THREE.Vector3();
  3. const _quaternionObject = new THREE.Quaternion();
  4. const _scaleObject = new THREE.Vector3();
  5. const _translationWorld = new THREE.Vector3();
  6. const _quaternionWorld = new THREE.Quaternion();
  7. const _scaleWorld = new THREE.Vector3();
  8. class Gyroscope extends THREE.Object3D {
  9. constructor() {
  10. super();
  11. }
  12. updateMatrixWorld( force ) {
  13. this.matrixAutoUpdate && this.updateMatrix(); // update matrixWorld
  14. if ( this.matrixWorldNeedsUpdate || force ) {
  15. if ( this.parent !== null ) {
  16. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  17. this.matrixWorld.decompose( _translationWorld, _quaternionWorld, _scaleWorld );
  18. this.matrix.decompose( _translationObject, _quaternionObject, _scaleObject );
  19. this.matrixWorld.compose( _translationWorld, _quaternionObject, _scaleWorld );
  20. } else {
  21. this.matrixWorld.copy( this.matrix );
  22. }
  23. this.matrixWorldNeedsUpdate = false;
  24. force = true;
  25. } // update children
  26. for ( let i = 0, l = this.children.length; i < l; i ++ ) {
  27. this.children[ i ].updateMatrixWorld( force );
  28. }
  29. }
  30. }
  31. THREE.Gyroscope = Gyroscope;
  32. } )();