index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.setBlend();
  21. },
  22. setBlend() {
  23. const scene = this.scene;
  24. const xrSystem = wx.getXrFrameSystem();
  25. // 替换状态
  26. const blendElm = this.scene.getElementById('blend');
  27. const blendGLTF = blendElm.getComponent(xrSystem.GLTF);
  28. // 延时保证glTF解析完毕
  29. setTimeout(()=>{
  30. const frontMesh = blendGLTF.getPrimitivesByMeshName('柱体')[0].primitives[0];
  31. const frontMat = frontMesh.material;
  32. // 正面
  33. // 改变 RenderQueue 先绘制
  34. frontMat.setRenderState('renderQueue', 2500);
  35. // 开启剔除,去掉背面
  36. frontMat.setRenderState('cullOn', true);
  37. frontMat.setRenderState('cullFace', xrSystem.ECullMode.BACK);
  38. const backMesh = blendGLTF.getPrimitivesByMeshName('柱体.001')[0].primitives[0];
  39. const backMat = backMesh.material;
  40. // 背面
  41. // 改变 RenderQueue 后绘制
  42. backMat.setRenderState('renderQueue', 2501);
  43. // 开启剔除,去掉正面
  44. backMat.setRenderState('cullOn', true);
  45. backMat.setRenderState('cullFace', xrSystem.ECullMode.FRONT);
  46. }, 200);
  47. }
  48. }
  49. })