index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. Component({
  2. behaviors: [require('../common/share-behavior').default],
  3. wxball: null,
  4. wxballTransform: null,
  5. wxballAnimator: null,
  6. animationRuning: false,
  7. properties: {
  8. },
  9. data: {
  10. loaded: false,
  11. arReady: false,
  12. },
  13. lifetimes: {
  14. async attached() {
  15. console.log('data', this.data);
  16. }
  17. },
  18. methods: {
  19. handleReady({
  20. detail
  21. }) {
  22. const xrScene = this.scene = detail.value;
  23. console.log('xr-scene', xrScene);
  24. const xrFrameSystem = wx.getXrFrameSystem();
  25. this.wxball = xrScene.getElementById('wxball');
  26. this.wxballTransform = this.wxball.getComponent(xrFrameSystem.Transform);
  27. this.wxballTransform.visible = false;
  28. },
  29. handleAssetsProgress: function ({
  30. detail
  31. }) {
  32. console.log('assets progress', detail.value);
  33. },
  34. handleAssetsLoaded: function ({
  35. detail
  36. }) {
  37. console.log('assets loaded', detail.value);
  38. this.setData({
  39. loaded: true
  40. });
  41. },
  42. handleGltfLoaded: function() {
  43. const xrScene = this.scene;
  44. const xrFrameSystem = wx.getXrFrameSystem();
  45. this.wxball = xrScene.getElementById('wxball');
  46. this.wxballAnimator = this.wxball.getComponent(xrFrameSystem.Animator);
  47. this.wxballAnimator.play('gltfAnimation', {
  48. loop: -1,
  49. });
  50. this.wxballAnimator.play('gltfAnimation#0', {
  51. loop: -1,
  52. });
  53. this.wxballTransform.visible = true;
  54. },
  55. handleTouchWXball: function() {
  56. if (!this.animationRuning) {
  57. console.log('WXBALL TOUCH');
  58. this.animationRuning = true;
  59. this.wxballAnimator.pauseToFrame('gltfAnimation', 1);
  60. this.wxballAnimator.pauseToFrame('gltfAnimation#0', 1);
  61. this.wxballAnimator.resume('gltfAnimation');
  62. this.wxballAnimator.resume('gltfAnimation#0');
  63. }
  64. },handleARTrackerState({detail}) {
  65. // 事件的值即为`ARTracker`实例
  66. const tracker = detail.value;
  67. // 获取当前状态和错误信息
  68. const {state, errorMessage} = tracker;
  69. },
  70. handleAnimationStop: function() {
  71. console.log('animation Stop');
  72. }
  73. }
  74. })