index.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import cont from './earring'
  2. Component({
  3. behaviors: [require('../common/share-behavior').default],
  4. properties: {
  5. capacity: {
  6. type: Number,
  7. value: 20
  8. },
  9. emitRate: {
  10. type: Number,
  11. value: 5
  12. },
  13. lifeTime:{
  14. type: Number,
  15. value: 3
  16. }
  17. },
  18. data: {
  19. loaded: false
  20. },
  21. lifetimes: {},
  22. methods: {
  23. handleReady({detail}) {
  24. const xrScene = this.scene = detail.value;
  25. console.log('xr-scene', xrScene);
  26. const xrFrameSystem = wx.getXrFrameSystem()
  27. const particle = xrScene.getElementById("human-face");
  28. // // 来自图片数据的二元数组content
  29. var content = cont
  30. // // 影响画作的大小与粒子疏密程度的因子
  31. var step = 0.02
  32. var height = Math.floor(step * content.length)
  33. //设置箱型发射器的发射方向,与粒子初始位置范围
  34. particle.getComponent(xrFrameSystem.Particle).createBoxEmitter(xrFrameSystem.Vector3.createFromNumber(1.0, 0.0, 0), xrFrameSystem.Vector3.createFromNumber(1.0, 0.0, 0),
  35. xrFrameSystem.Vector3.createFromNumber(0, 0, 0.5), xrFrameSystem.Vector3.createFromNumber(0, height, 0.0));
  36. //实现发射器的自定义粒子运作接口
  37. particle.getComponent(xrFrameSystem.Particle).particleEmitter.processInstance = (instance, deltaTime)=> {
  38. var contentTemp = content
  39. var cellNumY = contentTemp.length
  40. var cellNumX = contentTemp[0].length
  41. var width = Math.floor(step * cellNumX)
  42. if(instance.position.x - instance.particleSystem.emitterPosition.x> width){
  43. instance.age = instance.lifeTime;
  44. return;
  45. }
  46. instance.age = 0;
  47. const posX = Math.floor((instance.position.x - instance.particleSystem.emitterPosition.x)/ step);
  48. const posY = Math.floor(instance.position.y/ step);
  49. const speed = contentTemp[cellNumY-1-posY][posX] * 0.97;
  50. instance.position.x += ( 1 - speed * 0.97 ) * 0.03 + Math.random() * 0.007;
  51. instance.color.w = speed * 0.3;
  52. };
  53. },
  54. handleAssetsProgress: function({detail}) {
  55. console.log('assets progress', detail.value);
  56. },
  57. handleAssetsLoaded: function({detail}) {
  58. console.log('assets loaded', detail.value);
  59. this.setData({loaded: true});
  60. }
  61. }
  62. })