index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. Component({
  2. behaviors: [require('../common/share-behavior').default],
  3. properties: {
  4. a: Number,
  5. },
  6. data: {
  7. loaded: false,
  8. arReady: false,
  9. },
  10. lifetimes: {
  11. async attached() {
  12. console.log('data', this.data)
  13. }
  14. },
  15. methods: {
  16. handleReady({detail}) {
  17. const xrScene = this.scene = detail.value;
  18. this.mat = new (wx.getXrFrameSystem().Matrix4)();
  19. console.log('xr-scene', xrScene);
  20. },
  21. handleAssetsProgress: function({detail}) {
  22. console.log('assets progress', detail.value);
  23. },
  24. handleAssetsLoaded: function({detail}) {
  25. console.log('assets loaded', detail.value);
  26. // this.setData({loaded: true});
  27. this.scene.event.addOnce('touchstart', this.placeNode.bind(this));
  28. },
  29. handleARReady: function({detail}) {
  30. console.log('arReady', this.scene.ar.arVersion);
  31. },
  32. placeNode(event) {
  33. const {clientX, clientY} = event.touches[0];
  34. const {frameWidth: width, frameHeight: height} = this.scene;
  35. if (clientY / height > 0.8 && clientX / width < 0.2) {
  36. this.scene.getNodeById('setitem').visible = false;
  37. this.scene.ar.resetPlane();
  38. } else {
  39. this.scene.ar.placeHere('setitem', true);
  40. }
  41. this.scene.event.addOnce('touchstart', this.placeNode.bind(this));
  42. }
  43. }
  44. })