index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. var sceneReadyBehavior = require('../../behavior-scene/scene-ready');
  2. var handleDecodedXML = require('../../behavior-scene/util').handleDecodedXML;
  3. var escapeMarkup = require('../../behavior-scene/util').escapeMarkup;
  4. var xmlCode = escapeMarkup(`<xr-scene id="xr-scene" bind:ready="handleReady" bind:tick="handleTick">
  5. <xr-shadow id="shadow-root"></xr-shadow>
  6. </xr-scene>`);
  7. var jsCode = `
  8. ...<br>
  9. addOne() {
  10. <div class="ml20">
  11. const xrFrameSystem = wx.getXrFrameSystem();<br>
  12. const pos = [Math.random(), Math.random(), Math.random()].map(v => (v * 2 - 1) * 6);<br>
  13. const gltfElement = this.scene.createElement(xrFrameSystem.XRGLTF);<br>
  14. this.shadowRoot.addChild(gltfElement);<br>
  15. gltfElement.getComponent(xrFrameSystem.Transform).position.setArray(pos);<br>
  16. gltfElement.getComponent(xrFrameSystem.GLTF).setData({model: this.gltfModle});<br>
  17. this.meshList.push(gltfElement);<br>
  18. </div>
  19. },
  20. removeOne() {
  21. <div class="ml20">
  22. const element = this.meshList.pop();<br>
  23. if (element) {<br>
  24. this.shadowRoot.removeChild(element);
  25. }
  26. </div>
  27. },
  28. handleTick: function({detail}) {
  29. <div class="ml20">
  30. const {el, value} = detail;
  31. </div>
  32. },<br>
  33. ...
  34. `;
  35. Page({
  36. behaviors:[sceneReadyBehavior],
  37. data: {
  38. xmlCode: '<div class="codeWrap">' + handleDecodedXML(xmlCode) + '</div>',
  39. jsCode: jsCode,
  40. meshCount: 0
  41. },
  42. handleIncMeshCount: function() {
  43. if (this.data.meshCount > 16) {
  44. return;
  45. }
  46. this.setData({meshCount: this.data.meshCount + 1});
  47. },
  48. handleDecMeshCount: function() {
  49. if (this.data.meshCount <= 0) {
  50. return;
  51. }
  52. this.setData({meshCount: this.data.meshCount - 1});
  53. }
  54. });