scene-ready.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. windowHeight
  34. });
  35. },
  36. methods: {
  37. onLoad(options) {
  38. wx.reportEvent("xr_frame", {
  39. "xr_page_path": options.path
  40. });
  41. },
  42. onShareAppMessage() {
  43. try {
  44. if (wx.xrScene) {
  45. const buffer = wx.xrScene.share.captureToArrayBuffer({quality: 0.5});
  46. const fp = `${wx.env.USER_DATA_PATH}/xr-frame-share.jpg`;
  47. wx.getFileSystemManager().writeFileSync(fp, buffer, 'binary');
  48. return {
  49. title: this.getTitle(),
  50. imageUrl: fp
  51. };
  52. }
  53. } catch (e) {
  54. return {
  55. title: this.getTitle()
  56. };
  57. }
  58. },
  59. onShareTimeline() {
  60. try {
  61. if (wx.xrScene) {
  62. const buffer = wx.xrScene.share.captureToArrayBuffer({quality: 0.5});
  63. const fp = `${wx.env.USER_DATA_PATH}/xr-frame-share.jpg`;
  64. wx.getFileSystemManager().writeFileSync(fp, buffer, 'binary');
  65. return {
  66. title: this.getTitle(),
  67. imageUrl: fp
  68. };
  69. }
  70. } catch (e) {
  71. return {
  72. title: this.getTitle()
  73. }
  74. }
  75. },
  76. getTitle() {
  77. return wx.xrTitle ? `XR - ${wx.xrTitle}` : 'XR-FRAME官方示例';
  78. },
  79. handleARTrackerState({detail}) {
  80. const {state, error} = detail;
  81. this.setData({
  82. arTrackerShow: true,
  83. arTrackerState: wx.getXrFrameSystem().EARTrackerState[state],
  84. arTrackerError: error
  85. });
  86. }
  87. }
  88. })