index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. this.setBallon();
  22. },
  23. async setBallon() {
  24. const scene = this.scene;
  25. const xrSystem = wx.getXrFrameSystem();
  26. // 替换贴图
  27. const ballonElm = this.scene.getElementById('ballon');
  28. const ballonGLTF = ballonElm.getComponent(xrSystem.GLTF);
  29. const textureAsset = await scene.assets.loadAsset({
  30. type: 'texture',
  31. assetId: `texture-1`,
  32. src: 'https://webar.hereto.cn/asset/fe/ast-show/BalloonTEXc1.png',
  33. });
  34. for(const mesh of ballonGLTF.meshes) {
  35. console.log('textureAsset', textureAsset.value);
  36. mesh.material.setVector('u_specularFactor', xrSystem.Vector3.createFromNumber(0, 0, 0));
  37. mesh.material.setTexture('u_baseColorMap', textureAsset.value);
  38. }
  39. // 替换状态
  40. const ballonBlendElm = this.scene.getElementById('ballonBlend');
  41. const ballonBlendGLTF = ballonBlendElm.getComponent(xrSystem.GLTF);
  42. for(const mesh of ballonBlendGLTF.meshes) {
  43. // 清理模型金属度
  44. mesh.material.setVector('u_specularFactor', xrSystem.Vector3.createFromNumber(0, 0, 0));
  45. // 通过alphaMode 的 Setter 设置,或者写入renderState,但需要手动控制宏
  46. mesh.material.alphaMode = "BLEND";
  47. mesh.material.setVector('u_baseColorFactor', xrSystem.Vector4.createFromNumber(0, 0.5, 0, 0.5));
  48. }
  49. }
  50. }
  51. })