index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var sceneReadyBehavior = require('../../behavior-scene/scene-ready');
  2. var handleDecodedXML = require('../../behavior-scene/util').handleDecodedXML;
  3. var xmlCode = `<xr-scene ar-system="modes:Marker" id="xr-scene" bind:ready="handleReady" bind:arReady="handleARReady" bind:log="handleLog">
  4. <xr-assets bind:progress="handleAssetsProgress" bind:loaded="handleAssetsLoaded">
  5. <xr-asset-material asset-id="ar-anchor" effect="standrand" uniforms="u_baseColorFactor:0 1 0 1"></xr-asset-material>
  6. </xr-assets>
  7. <xr-node>
  8. <xr-node node-id="id2" scale="2 2 2" position="0 0 0"></xr-node>
  9. <xr-ar-tracker mode="Marker" src="{{markerImg}}">
  10. <xr-mesh geometry="cylinder" material="ar-anchor" />
  11. </xr-ar-tracker>
  12. <xr-camera
  13. id="camera" node-id="camera" position="0.8 2.2 -5" clear-color="0.925 0.925 0.925 1"
  14. target="id2" background="ar" is-ar-camera
  15. camera-orbit-control
  16. ></xr-camera>
  17. </xr-node>
  18. <xr-node node-id="lights">
  19. <xr-light type="ambient" color="1 1 1" intensity="1" />
  20. <xr-light type="directional" rotation="180 0 0" color="1 1 1" intensity="3" />
  21. </xr-node>
  22. </xr-scene>
  23. `;
  24. Page({
  25. behaviors: [sceneReadyBehavior],
  26. data: {
  27. xmlCode: '<div class="codeWrap">' + handleDecodedXML(xmlCode) + '</div>',
  28. markerImg: 'https://mmbizwxaminiprogram-1258344707.cos.ap-guangzhou.myqcloud.com/xr-frame/demo/marker/2dmarker-test.jpg'
  29. },
  30. handleChangeMarkerImg: function() {
  31. wx.chooseMedia({
  32. count: 1,
  33. sizeType: ['compressed'],
  34. mediaType: ['image'],
  35. sourceType: ['album'],
  36. success: res => {
  37. const fp = res.tempFiles[0].tempFilePath;
  38. this.setData({markerImg: fp});
  39. },
  40. fail: err => {
  41. console.error('[xr-demo]chooseImage failed', err);
  42. }
  43. });
  44. }
  45. });