index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. const blurData = {
  2. cullMask: 0b101,
  3. aIntensity: 1,
  4. dIntensity: 2,
  5. env: "",
  6. background: "default",
  7. cameraPosition: 1.3,
  8. clearColor: "0 0 0 1",
  9. cameraTarget: "camera-target",
  10. pp: "blur",
  11. // blurRadius: 0
  12. };
  13. const bloomData = {
  14. cullMask: 0b11,
  15. aIntensity: 0,
  16. dIntensity: 0,
  17. env: "",
  18. background: "default",
  19. cameraPosition: 10,
  20. clearColor: "0 0 0 1",
  21. cameraTarget: "camera-target",
  22. pp: "bloom2",
  23. // bloomRadius_0: 0,
  24. // bloomRadius_1: 0
  25. };
  26. const fxaaData = {
  27. cullMask: 0b1001,
  28. aIntensity: 1,
  29. dIntensity: 3,
  30. env: "",
  31. background: "default",
  32. cameraPosition: 1,
  33. clearColor: "0.925 0.925 0.925 1",
  34. cameraTarget: "mesh-sphere"
  35. };
  36. const vignetteData = {
  37. cullMask: 0b101,
  38. aIntensity: 1,
  39. dIntensity: 2,
  40. env: "",
  41. background: "default",
  42. cameraPosition: 1.3,
  43. clearColor: "0 0 0 1",
  44. cameraTarget: "camera-target",
  45. pp: "vignette",
  46. };
  47. Component({
  48. behaviors: [require('../common/share-behavior').default],
  49. properties: {
  50. type: {
  51. type: Number,
  52. value: 0,
  53. observer: function (newVal, oldVal) {
  54. if (newVal !== oldVal) {
  55. if (newVal === 0) {
  56. this.activeBlur();
  57. } else if (newVal === 1) {
  58. this.activeBloom();
  59. } else if (newVal === 2) {
  60. this.activeVignette();
  61. } else if (newVal === 3) {
  62. this.activeFXAA();
  63. }
  64. }
  65. }
  66. },
  67. blurRadius: {
  68. type: Number,
  69. value: 0
  70. },
  71. bloomRadius: {
  72. type: Number,
  73. value: 0,
  74. observer(newVal, oldVal) {
  75. this.setData({
  76. bloomRadius_0: newVal * 0.2,
  77. bloomRadius_1: newVal * 0.8
  78. });
  79. }
  80. },
  81. bloomIntensity: {
  82. type: Number,
  83. value: 1,
  84. },
  85. bloomThreshold: {
  86. type: Number,
  87. value: 0.5,
  88. },
  89. vignetteIntensity: {
  90. type: Number,
  91. value: 1,
  92. },
  93. vignetteSmoothness: {
  94. type: Number,
  95. value: 2,
  96. },
  97. vignetteRoundness: {
  98. type: Number,
  99. value: 1,
  100. },
  101. fxaaEnabled: {
  102. type: Boolean,
  103. value: false,
  104. observer(newVal, oldVal) {
  105. this.setData({
  106. fxaaEnabled: newVal
  107. });
  108. if (this.data.type === 3) {
  109. this.activeFXAA();
  110. }
  111. }
  112. }
  113. },
  114. data: {
  115. loaded: false,
  116. env: "",
  117. cullMask: 0,
  118. background: "default",
  119. aIntensity: 0,
  120. dIntensity: 0,
  121. pp: "",
  122. cameraPosition: 1,
  123. cameraTarget: "camera-target",
  124. //---bloom---
  125. bloomRadius_0: 0,
  126. bloomRadius_1: 1,
  127. //---fxaa---
  128. fxaaEnabled: false
  129. },
  130. lifetimes: {
  131. attached() {
  132. console.log('data.a', this.data.a) // expected 123
  133. }
  134. },
  135. methods: {
  136. handleReady: function({detail}) {
  137. this.scene = detail.value;
  138. console.log('scene', detail.value);
  139. this.activeBlur();
  140. },
  141. handleTick: function() {
  142. // const camera = this.scene.getNodeById("camera");
  143. // const transform = camera.el._components.transform;
  144. // if (transform.rotation.y > Math.PI * 0.25) {
  145. // transform.rotation.y = Math.PI * 0.25;
  146. // } else if (transform.rotation.y < -Math.PI * 0.25) {
  147. // transform.rotation.y = -Math.PI * 0.25;
  148. // }
  149. },
  150. handleAssetsProgress: function({detail}) {
  151. this.triggerEvent('assetsProgress', detail.value);
  152. },
  153. handleAssetsLoaded: function({detail}) {
  154. this.triggerEvent('assetsLoaded', detail.value);
  155. this.setData({loaded: true});
  156. },
  157. activeBlur() {
  158. this.setData(blurData);
  159. },
  160. activeBloom() {
  161. this.setData(bloomData);
  162. },
  163. activeVignette() {
  164. this.setData(vignetteData);
  165. },
  166. activeFXAA() {
  167. this.setData(fxaaData);
  168. this.setData({
  169. pp: this.data.fxaaEnabled ? "fxaa" : ""
  170. });
  171. }
  172. }
  173. })