index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. const xrFrameSystem = wx.getXrFrameSystem();
  2. Component({
  3. // behaviors: [require('../common/share-behavior').default],
  4. properties: {
  5. fromScan: Boolean
  6. },
  7. data: {
  8. loaded: false,
  9. arReady: false,
  10. isPlay: false
  11. },
  12. lifetimes: {
  13. async attached() {
  14. console.log('data', this.data)
  15. },
  16. async detached() {
  17. console.error('detached', this.video)
  18. this.animator && (this.animator = null);
  19. this.setData({
  20. isPlay: false
  21. })
  22. }
  23. },
  24. methods: {
  25. handleReady({
  26. detail
  27. }) {
  28. const xrScene = this.scene = detail.value;
  29. this.mat = new(wx.getXrFrameSystem().Matrix4)();
  30. console.log('xr-scene', xrScene)
  31. this.triggerEvent('ready')
  32. },
  33. handleAssetsProgress: function ({
  34. detail
  35. }) {
  36. const progress =
  37. Math.floor(detail.value.progress * 100)
  38. this.triggerEvent('progress', progress)
  39. },
  40. handleAssetsLoaded: function ({
  41. detail
  42. }) {
  43. console.log('assets loaded', detail.value);
  44. const el = detail.value.target;
  45. // this.setData({loaded: true});
  46. this.scene.event.addOnce('touchstart', this.placeNode.bind(this));
  47. this.triggerEvent('loaded')
  48. },
  49. handleARReady: function ({
  50. detail
  51. }) {
  52. console.log('arReady', this.scene.ar.arVersion);
  53. },
  54. placeNode(event) {
  55. const {
  56. clientX,
  57. clientY
  58. } = event.touches[0];
  59. const {
  60. frameWidth: width,
  61. frameHeight: height
  62. } = this.scene;
  63. if (clientY / height > 0.8 && clientX / width < 0.2) {
  64. this.scene.getNodeById('setitem').visible = false;
  65. this.scene.ar.resetPlane();
  66. } else {
  67. console.error('show-gltf', this.data.isPlay)
  68. this.showAndPlay();
  69. }
  70. this.scene.event.addOnce('touchstart', this.placeNode.bind(this));
  71. },
  72. handleGLTFLoaded({
  73. detail
  74. }) {
  75. const el = detail.value.target;
  76. const animator = el.getComponent("animator");
  77. this.animator = animator
  78. console.warn('handleGLTFLoaded', animator)
  79. if (this.data.fromScan) {
  80. console.log('fromScan', this.data.fromScan);
  81. this.showAndPlay();
  82. }
  83. },
  84. handleARTrackerState({
  85. detail
  86. }) {
  87. const tracker = detail.value;
  88. // 获取当前状态和错误信息
  89. const {
  90. state,
  91. errorMessage
  92. } = tracker;
  93. console.log('tracker-state', tracker)
  94. if (state == 2) {
  95. wx.showToast({
  96. title: "tracker"
  97. })
  98. this.showAndPlay();
  99. }
  100. },
  101. showAndPlay() {
  102. console.log('showAndPlay');
  103. this.scene.ar.placeHere('setitem', true);
  104. if (!this.data.isPlay) {
  105. this.scene.getNodeById('setitem').visible = true;
  106. this.setData({
  107. isPlay: true
  108. }, () => {
  109. if (this.animator) {
  110. if (this.animator) {
  111. this.animator.play('Group21137Action', {
  112. loop: 0
  113. });
  114. this.animator.play('polySurface1Action', {
  115. loop: 0
  116. });
  117. this.animator.play('vlAction', {
  118. loop: 0
  119. });
  120. }
  121. }
  122. })
  123. }
  124. }
  125. }
  126. })