index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. Component({
  2. behaviors: [require('../../common/share-behavior').default],
  3. properties: {
  4. a: Number,
  5. },
  6. data: {
  7. loaded: false
  8. },
  9. lifetimes: {},
  10. methods: {
  11. handleReady({detail}) {
  12. const xrScene = this.scene = detail.value;
  13. console.log('xr-scene', xrScene);
  14. },
  15. handleAssetsProgress: function({detail}) {
  16. console.log('assets progress', detail.value);
  17. },
  18. handleAssetsLoaded: function({detail}) {
  19. console.log('assets loaded', detail.value);
  20. this.setData({loaded: true});
  21. },
  22. handleGLTFLoaded({ detail }) {
  23. const xrFrameSystem = wx.getXrFrameSystem();
  24. const wrapElement = this.scene.getElementById("wrap");
  25. this.wrapTRS = wrapElement.getComponent(xrFrameSystem.Transform);
  26. const gltfElement = this.scene.getElementById("gltf");
  27. this.gltfTRS = gltfElement.getComponent(xrFrameSystem.Transform);
  28. this.editGLTF = gltfElement.getComponent(xrFrameSystem.GLTF);
  29. console.log(this.wrapTRS, this.gltfTRS)
  30. // Birds
  31. const brid = this.editGLTF.getInternalNodeByName("Birds");
  32. this.bridTRS = brid.getComponent(xrFrameSystem.Transform);
  33. // TurtleAndCastle
  34. const turtle = this.editGLTF.getInternalNodeByName("TurtleAndCastle");
  35. this.turtleTRS = turtle.getComponent(xrFrameSystem.Transform);
  36. // 都用四元数
  37. this.rotation = this.turtleTRS.quaternion.toEulerAngles();
  38. this.scene.event.add('tick', this.handleTick.bind(this));
  39. },
  40. handleTick: function (time) {
  41. const xrSystem = wx.getXrFrameSystem();
  42. this.wrapTRS.position.x -= 0.002;
  43. // this.wrapTRS.rotation.y += Math.PI * 0.0001;
  44. // 比例尺不一样,需要放大改变数值
  45. this.bridTRS.position.x += 1;
  46. this.bridTRS.position.y += Math.random() * 4 - 2;
  47. // 欧拉角直接设置有误 v2.31.0
  48. // this.turtleTRS.rotation.y += Math.PI * 0.0004;
  49. // 目前使用四元数兼容
  50. this.rotation.y += Math.PI * 0.0004;
  51. xrSystem.Quaternion.fromEulerAngles(this.rotation, this.turtleTRS.quaternion);
  52. }
  53. }
  54. })