index.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const STATE = {
  2. NONE: -1,
  3. MOVE: 0,
  4. ZOOM_OR_PAN: 1
  5. }
  6. Component({
  7. behaviors: [require('../../common/share-behavior').default],
  8. properties: {
  9. a: Number,
  10. },
  11. data: {
  12. loaded: false,
  13. arReady: false,
  14. },
  15. lifetimes: {
  16. async attached() {
  17. console.log('data', this.data)
  18. }
  19. },
  20. methods: {
  21. handleReady({detail}) {
  22. const xrScene = this.scene = detail.value;
  23. const xrSystem = wx.getXrFrameSystem();
  24. this.mat = new (xrSystem.Matrix4)();
  25. console.log('xr-scene', xrScene);
  26. const { width, height } = this.scene
  27. this.cameraTrs = this.scene.getElementById('camera').getComponent(xrSystem.Transform);
  28. this.leftTRS = this.scene.getElementById('l').getComponent(xrSystem.Transform);
  29. this.rightTRS = this.scene.getElementById('r').getComponent(xrSystem.Transform);
  30. this.frontTRS = this.scene.getElementById('f').getComponent(xrSystem.Transform);
  31. this.backTRS = this.scene.getElementById('b').getComponent(xrSystem.Transform);
  32. this.FACING = xrSystem.Vector3.createFromNumber(0, 0, 0);
  33. this.UP = xrSystem.Vector3.createFromNumber(0, 1, 0);
  34. xrScene.event.add('tick', this.handleTick.bind(this));
  35. },
  36. handleTick: function () {
  37. const xrSystem = wx.getXrFrameSystem();
  38. if (this.leftTRS) {
  39. console.log()
  40. const quaternion = this.leftTRS.quaternion;
  41. // 算出从物体到相机的向量
  42. this.FACING.set(this.cameraTrs.position).sub(this.leftTRS.position, this.FACING);
  43. xrSystem.Quaternion.lookRotation(this.FACING, this.UP, quaternion);
  44. }
  45. if (this.rightTRS) {
  46. const quaternion = this.rightTRS.quaternion;
  47. // 算出从物体到相机的向量
  48. this.FACING.set(this.cameraTrs.position).sub(this.rightTRS.position, this.FACING);
  49. xrSystem.Quaternion.lookRotation(this.FACING, this.UP, quaternion);
  50. }
  51. if (this.frontTRS) {
  52. const quaternion = this.frontTRS.quaternion;
  53. // // 算出从物体到相机的向量
  54. this.FACING.set(this.cameraTrs.position).sub(this.frontTRS.position, this.FACING);
  55. xrSystem.Quaternion.lookRotation(this.FACING, this.UP, quaternion);
  56. }
  57. if (this.backTRS) {
  58. const quaternion = this.backTRS.quaternion;
  59. // 算出从物体到相机的向量
  60. this.FACING.set(this.cameraTrs.position).sub(this.backTRS.position, this.FACING);
  61. xrSystem.Quaternion.lookRotation(this.FACING, this.UP, quaternion);
  62. }
  63. },
  64. }
  65. })