Gyroscope.js 1.2 KB

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