index.js 1.6 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. // 延时保证 glTF 解析完毕
  21. setTimeout(() => {
  22. this.setToon();
  23. }, 200);
  24. },
  25. setToon() {
  26. const scene = this.scene;
  27. const xrFrameSystem = wx.getXrFrameSystem()
  28. const gltfElement = scene.getElementById("gltf");
  29. const gltf = gltfElement.getComponent(xrFrameSystem.GLTF);
  30. console.log('toon gltf', gltf);
  31. for(const mesh of gltf.meshes) {
  32. // console.log('toon mesh', mesh)
  33. console.log('toon mesh material', mesh.material)
  34. console.log('toon effect', scene.assets.getAsset('effect', 'toon-user'));
  35. const toonMaterial = scene.createMaterial(
  36. // 使用定制的效果
  37. scene.assets.getAsset('effect', 'toon-user'),
  38. {
  39. u_baseColorMap: mesh.material.getTexture('u_baseColorMap')
  40. }
  41. );
  42. console.log('toon toonMaterial', toonMaterial);
  43. // 接管渲染状态
  44. // toonMaterial.setRenderState('cullFace', xrFrameSystem.ECullMode.BACK);
  45. toonMaterial.setRenderState('cullOn', false);
  46. mesh.material = toonMaterial;
  47. }
  48. }
  49. }
  50. })