scene-ready.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. module.exports = Behavior({
  2. behaviors: [],
  3. properties: {
  4. },
  5. data: {
  6. left: 0,
  7. top: 0,
  8. width: 0,
  9. height: 0,
  10. renderWidth: 0,
  11. renderHeight: 0,
  12. windowHeight: 1000,
  13. heightScale: 0.75,
  14. dpiScale: 1,
  15. showBackBtn: false,
  16. activeValues: [1],
  17. arTrackerShow: false,
  18. arTrackerState: 'Init',
  19. arTrackerError: ''
  20. },
  21. attached: function(){},
  22. ready() {
  23. const info = wx.getSystemInfoSync();
  24. const width = info.windowWidth;
  25. const windowHeight = info.windowHeight;
  26. const height = windowHeight * this.data.heightScale;
  27. const dpi = info.pixelRatio;
  28. this.setData({
  29. width,
  30. height,
  31. renderWidth: width * dpi * this.data.dpiScale,
  32. renderHeight: height * dpi * this.data.dpiScale,
  33. testw: 100011,
  34. windowHeight
  35. });
  36. },
  37. methods: {
  38. onLoad(options) {
  39. wx.reportEvent("xr_frame", {
  40. "xr_page_path": options.path
  41. });
  42. },
  43. onShareAppMessage() {
  44. try {
  45. if (wx.xrScene) {
  46. const buffer = wx.xrScene.share.captureToArrayBuffer({quality: 0.5});
  47. const fp = `${wx.env.USER_DATA_PATH}/xr-frame-share.jpg`;
  48. wx.getFileSystemManager().writeFileSync(fp, buffer, 'binary');
  49. return {
  50. title: this.getTitle(),
  51. imageUrl: fp
  52. };
  53. }
  54. } catch (e) {
  55. return {
  56. title: this.getTitle()
  57. };
  58. }
  59. },
  60. onShareTimeline() {
  61. try {
  62. if (wx.xrScene) {
  63. const buffer = wx.xrScene.share.captureToArrayBuffer({quality: 0.5});
  64. const fp = `${wx.env.USER_DATA_PATH}/xr-frame-share.jpg`;
  65. wx.getFileSystemManager().writeFileSync(fp, buffer, 'binary');
  66. return {
  67. title: this.getTitle(),
  68. imageUrl: fp
  69. };
  70. }
  71. } catch (e) {
  72. return {
  73. title: this.getTitle()
  74. }
  75. }
  76. },
  77. getTitle() {
  78. return wx.xrTitle ? `XR - ${wx.xrTitle}` : 'XR-FRAME官方示例';
  79. },
  80. handleARTrackerState({detail}) {
  81. const {state, error} = detail;
  82. this.setData({
  83. arTrackerShow: true,
  84. arTrackerState: wx.getXrFrameSystem().EARTrackerState[state],
  85. arTrackerError: error
  86. });
  87. }
  88. }
  89. })