index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. var sceneReadyBehavior = require('../../behavior-scene/scene-ready');
  2. var handleDecodedXML = require('../../behavior-scene/util').handleDecodedXML;
  3. var xmlCode = `<xr-scene id="xr-scene">
  4. <xr-assets bind:progress="handleAssetsProgress" bind:loaded="handleAssetsLoaded">
  5. <xr-asset-load asset-id="basic-anim" type="keyframe" src="/assets/animation/basic-animation.json"/>
  6. <xr-asset-material asset-id="standard-mat" effect="standard" />
  7. </xr-assets>
  8. <xr-node>
  9. <xr-node node-id="camera-target" position="0 0 0"></xr-node>
  10. <xr-mesh
  11. node-id="mesh-plane" position="0 -0.8 0" rotation="0 0 0" scale="10 1 8" geometry="plane" material="standard-mat" uniforms="u_baseColorFactor:0.48 0.78 0.64 1"
  12. anim-keyframe="basic-anim" anim-autoplay="clip:plane, speed:4"
  13. ></xr-mesh>
  14. <xr-mesh
  15. node-id="mesh-cube" position="-3 0 2" scale="1 1 1" rotation="0 0 0" geometry="cube" material="standard-mat" uniforms="u_baseColorFactor:0.298 0.764 0.85 1"
  16. anim-keyframe="basic-anim" anim-clipmap="default:cube" anim-autoplay="clip:cube, speed:2"
  17. ></xr-mesh>
  18. <xr-mesh
  19. node-id="mesh-sphere" position="-3 0 0" scale="0.8 0.8 0.8" geometry="sphere" material="standard-mat" uniforms="u_baseColorFactor:0.937 0.176 0.368 1"
  20. anim-keyframe="basic-anim" anim-autoplay="clip:sphere, speed:2"
  21. ></xr-mesh>
  22. <xr-mesh
  23. node-id="mesh-cylinder" position="-3 0 -2" scale="1 0.6 1" geometry="cylinder" material="standard-mat" uniforms="u_baseColorFactor:1 0.776 0.364 1"
  24. anim-keyframe="basic-anim" anim-autoplay="clip:cylinder, speed:2"
  25. ></xr-mesh>
  26. <xr-mesh node-id="mesh-light-cube" position="-5 1 0" scale="0.5 2 10" rotation="0 0 0" geometry="cube" material="standard-mat" uniforms="u_baseColorFactor:0.3 0.3 0.3 1"></xr-mesh>
  27. <xr-camera
  28. id="camera" node-id="camera" position="5 3 0" clear-color="0.925 0.925 0.925 1"
  29. target="camera-target"
  30. camera-orbit-control=""
  31. ></xr-camera>
  32. </xr-node>
  33. <xr-node node-id="lights">
  34. <xr-light type="ambient" color="1 1 1" intensity="1" />
  35. <xr-light type="directional" rotation="30 230 0" color="1 1 1" intensity="3" />
  36. <xr-light
  37. type="spot" position="-4 1 0" rotation="0 -90 0" color="0 0 1" range="20" intensity="100" inner-cone-angle="30" outer-cone-angle="40"
  38. anim-keyframe="basic-anim" anim-autoplay="clip:spotLight, speed:2"
  39. />
  40. </xr-node>
  41. </xr-scene>
  42. `;
  43. const json = `
  44. {
  45. <div class="ml20">
  46. "keyframe": {
  47. <div class="ml20">
  48. "cube": {
  49. <div class="ml20">
  50. "0": {
  51. <div class="ml20">
  52. "position": [-3, 0, 2]
  53. </div>
  54. },<br>
  55. "50": {
  56. <div class="ml20">
  57. "rotation": [0, 0, 0],
  58. "scale": [1, 1, 1]
  59. </div>
  60. },<br>
  61. "100": {
  62. <div class="ml20">
  63. "position": [3, 0, 2],
  64. "rotation": [0, 3.14, 0],
  65. "scale": [1.4, 1.4, 1.4]
  66. </div>
  67. }
  68. </div>
  69. }
  70. </div>
  71. ...<br>
  72. },<br>
  73. "animation": {
  74. <div class="ml20">
  75. "default": {
  76. <div class="ml20">
  77. "keyframe": "cube",<br>
  78. "duration": 1,<br>
  79. "ease": "ease-in-out",<br>
  80. "loop": 400000,<br>
  81. "delay": 1,<br>
  82. "direction": "both"<br>
  83. </div>
  84. }
  85. </div>
  86. ...<br>
  87. }
  88. </div>
  89. }`;
  90. Page({
  91. behaviors:[sceneReadyBehavior],
  92. data: {
  93. xmlCode: '<div class="codeWrap">' + handleDecodedXML(xmlCode) + '</div>',
  94. json: json
  95. }
  96. });