ar-tracker.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // components/ar-tracker/ar-tracker.ts
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. },
  8. /**
  9. * 组件的初始数据
  10. */
  11. data: {
  12. },
  13. /**
  14. * 组件的方法列表
  15. */
  16. methods: {
  17. handleReady({
  18. detail
  19. }) {
  20. const xrScene = this.scene = detail.value;
  21. this.mat = new(wx.getXrFrameSystem().Matrix4)();
  22. console.log('xr-scene', xrScene)
  23. this.triggerEvent('ready')
  24. },
  25. handleARReady() {
  26. console.log('handleARReady')
  27. },
  28. handleAssetsProgress: function ({
  29. detail
  30. }) {
  31. const progress =
  32. Math.floor(detail.value.progress * 100)
  33. console.log('progress', progress)
  34. this.triggerEvent('progress', progress)
  35. },
  36. handleAssetsLoaded({
  37. detail
  38. }) {
  39. console.log('assets loaded', detail.value);
  40. this.triggerEvent('loaded')
  41. },
  42. handleItem1Loaded({
  43. detail
  44. }) {
  45. const el = detail.value.target;
  46. console.warn('item1 load')
  47. const gltf = el.getComponent("gltf");
  48. const video = this.scene.assets.getAsset("video-texture", "item1-v");
  49. const newMat = this.scene.assets.getAsset("material", "item1-m");
  50. this.video1 = video
  51. this.video1.onEnd = () => {}
  52. const animator = el.getComponent("animator");
  53. this.animator1 = animator
  54. console.log('animator', this.animator)
  55. for (const mesh of gltf.getPrimitivesByNodeName("video")) {
  56. mesh.material = newMat
  57. }
  58. },
  59. handleItem2Loaded() {
  60. },
  61. handleItem3Loaded() {
  62. },
  63. play(type) {
  64. if (type === 1) {
  65. this.scene.getNodeById('setitem1').visible = true;
  66. if (this.video1) {
  67. this.video1.play()
  68. }
  69. if (this.animator1) {
  70. this.animator1.play('Animation')
  71. }
  72. }
  73. },
  74. handleARTrackerState({
  75. detail
  76. }) {
  77. // 事件的值即为`ARTracker`实例
  78. const tracker = detail.value;
  79. // 获取当前状态和错误信息
  80. const {
  81. state,
  82. errorMessage
  83. } = tracker;
  84. if (state == 2) {
  85. wx.showToast({
  86. title: '1',
  87. })
  88. this.play(1)
  89. }
  90. },
  91. handleARTrackerState1({
  92. detail
  93. }) {
  94. // 事件的值即为`ARTracker`实例
  95. const tracker = detail.value;
  96. // 获取当前状态和错误信息
  97. const {
  98. state,
  99. errorMessage
  100. } = tracker;
  101. if (state == 2) {
  102. }
  103. },
  104. handleARTrackerState2({
  105. detail
  106. }) {
  107. // 事件的值即为`ARTracker`实例
  108. const tracker = detail.value;
  109. // 获取当前状态和错误信息
  110. const {
  111. state,
  112. errorMessage
  113. } = tracker;
  114. if (state == 2) {}
  115. }
  116. }
  117. })