index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. Component({
  2. // behaviors: [require('../common/share-behavior').default],
  3. properties: {
  4. a: Number,
  5. },
  6. data: {
  7. loaded: false,
  8. arReady: false,
  9. },
  10. lifetimes: {
  11. async attached() {
  12. console.log('data', this.data)
  13. }
  14. },
  15. methods: {
  16. handleReady({
  17. detail
  18. }) {
  19. const xrScene = this.scene = detail.value;
  20. this.mat = new(wx.getXrFrameSystem().Matrix4)();
  21. console.log('xr-scene', xrScene);
  22. wx.showLoading({
  23. title: 'loading...',
  24. })
  25. },
  26. handleAssetsProgress: function ({
  27. detail
  28. }) {
  29. console.log('assets progress', detail.value);
  30. },
  31. handleAssetsLoaded: function ({
  32. detail
  33. }) {
  34. console.log('assets loaded', detail.value);
  35. const el = detail.value.target;
  36. // this.setData({loaded: true});
  37. this.scene.event.addOnce('touchstart', this.placeNode.bind(this));
  38. wx.hideLoading()
  39. },
  40. handleARReady: function ({
  41. detail
  42. }) {
  43. console.log('arReady', this.scene.ar.arVersion);
  44. },
  45. placeNode(event) {
  46. const {
  47. clientX,
  48. clientY
  49. } = event.touches[0];
  50. const {
  51. frameWidth: width,
  52. frameHeight: height
  53. } = this.scene;
  54. if (clientY / height > 0.8 && clientX / width < 0.2) {
  55. this.scene.getNodeById('setitem').visible = false;
  56. this.scene.ar.resetPlane();
  57. } else {
  58. this.scene.ar.placeHere('setitem', true);
  59. console.error('show-gltf')
  60. }
  61. this.scene.event.addOnce('touchstart', this.placeNode.bind(this));
  62. },
  63. handleGLTFLoaded({
  64. detail
  65. }) {
  66. const el = detail.value.target;
  67. console.error('handleGLTFLoaded')
  68. const gltf = el.getComponent("gltf");
  69. const vt = this.scene.assets.getAsset("texture", "video-cat");
  70. const newMat = this.scene.assets.getAsset("material", "catMat");
  71. console.log('vt', vt)
  72. for (const mesh of gltf.getPrimitivesByNodeName("video")) {
  73. mesh.material = newMat
  74. // mesh.material.setTexture("u_baseColorMap", vt);
  75. }
  76. }
  77. }
  78. })