@babylonjs/core 8.11.0 → 8.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (391) hide show
  1. package/Cameras/arcRotateCamera.js +8 -0
  2. package/Cameras/arcRotateCamera.js.map +1 -1
  3. package/Cameras/targetCamera.js +2 -0
  4. package/Cameras/targetCamera.js.map +1 -1
  5. package/Collisions/gpuPicker.d.ts +4 -0
  6. package/Collisions/gpuPicker.js +6 -0
  7. package/Collisions/gpuPicker.js.map +1 -1
  8. package/Engines/abstractEngine.js +2 -2
  9. package/Engines/abstractEngine.js.map +1 -1
  10. package/Engines/constants.d.ts +4 -0
  11. package/Engines/constants.js +4 -0
  12. package/Engines/constants.js.map +1 -1
  13. package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.d.ts +1 -0
  14. package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.js +2 -0
  15. package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.js.map +1 -1
  16. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.d.ts +6 -1
  17. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js +29 -0
  18. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js.map +1 -1
  19. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.d.ts +6 -0
  20. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.js +36 -9
  21. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.js.map +1 -1
  22. package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js +1 -0
  23. package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js.map +1 -1
  24. package/FrameGraph/Node/Blocks/inputBlock.js +1 -0
  25. package/FrameGraph/Node/Blocks/inputBlock.js.map +1 -1
  26. package/FrameGraph/Node/Types/nodeRenderGraphTypes.d.ts +2 -0
  27. package/FrameGraph/Node/Types/nodeRenderGraphTypes.js +2 -0
  28. package/FrameGraph/Node/Types/nodeRenderGraphTypes.js.map +1 -1
  29. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.d.ts +23 -0
  30. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js +126 -21
  31. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js.map +1 -1
  32. package/FrameGraph/Tasks/Rendering/geometryRendererTask.d.ts +5 -0
  33. package/FrameGraph/Tasks/Rendering/geometryRendererTask.js +4 -0
  34. package/FrameGraph/Tasks/Rendering/geometryRendererTask.js.map +1 -1
  35. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.d.ts +2 -4
  36. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js +4 -17
  37. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js.map +1 -1
  38. package/FrameGraph/frameGraph.js +1 -1
  39. package/FrameGraph/frameGraph.js.map +1 -1
  40. package/FrameGraph/frameGraphContext.d.ts +30 -0
  41. package/FrameGraph/frameGraphContext.js +47 -0
  42. package/FrameGraph/frameGraphContext.js.map +1 -1
  43. package/FrameGraph/frameGraphRenderContext.d.ts +1 -4
  44. package/FrameGraph/frameGraphRenderContext.js +2 -5
  45. package/FrameGraph/frameGraphRenderContext.js.map +1 -1
  46. package/Lights/Shadows/cascadedShadowGenerator.d.ts +0 -1
  47. package/Lights/Shadows/cascadedShadowGenerator.js +0 -12
  48. package/Lights/Shadows/cascadedShadowGenerator.js.map +1 -1
  49. package/Materials/Node/Blocks/Dual/clipPlanesBlock.d.ts +1 -1
  50. package/Materials/Node/Blocks/Dual/clipPlanesBlock.js +4 -1
  51. package/Materials/Node/Blocks/Dual/clipPlanesBlock.js.map +1 -1
  52. package/Materials/Node/Blocks/Dual/currentScreenBlock.d.ts +2 -3
  53. package/Materials/Node/Blocks/Dual/currentScreenBlock.js +1 -1
  54. package/Materials/Node/Blocks/Dual/currentScreenBlock.js.map +1 -1
  55. package/Materials/Node/Blocks/Dual/fogBlock.d.ts +1 -1
  56. package/Materials/Node/Blocks/Dual/fogBlock.js +4 -1
  57. package/Materials/Node/Blocks/Dual/fogBlock.js.map +1 -1
  58. package/Materials/Node/Blocks/Dual/lightBlock.d.ts +1 -1
  59. package/Materials/Node/Blocks/Dual/lightBlock.js +2 -2
  60. package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
  61. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.d.ts +1 -2
  62. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js +1 -1
  63. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js.map +1 -1
  64. package/Materials/Node/Blocks/Dual/smartFilterTextureBlock.js +3 -4
  65. package/Materials/Node/Blocks/Dual/smartFilterTextureBlock.js.map +1 -1
  66. package/Materials/Node/Blocks/Dual/textureBlock.d.ts +2 -3
  67. package/Materials/Node/Blocks/Dual/textureBlock.js +2 -2
  68. package/Materials/Node/Blocks/Dual/textureBlock.js.map +1 -1
  69. package/Materials/Node/Blocks/Fragment/TBNBlock.d.ts +1 -1
  70. package/Materials/Node/Blocks/Fragment/TBNBlock.js +4 -1
  71. package/Materials/Node/Blocks/Fragment/TBNBlock.js.map +1 -1
  72. package/Materials/Node/Blocks/Fragment/fragCoordBlock.js +2 -2
  73. package/Materials/Node/Blocks/Fragment/fragCoordBlock.js.map +1 -1
  74. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.d.ts +1 -2
  75. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js +1 -1
  76. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
  77. package/Materials/Node/Blocks/Fragment/frontFacingBlock.js +2 -2
  78. package/Materials/Node/Blocks/Fragment/frontFacingBlock.js.map +1 -1
  79. package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js +1 -2
  80. package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js.map +1 -1
  81. package/Materials/Node/Blocks/Fragment/imageProcessingBlock.d.ts +1 -1
  82. package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js +1 -1
  83. package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js.map +1 -1
  84. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.d.ts +1 -2
  85. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js +1 -1
  86. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
  87. package/Materials/Node/Blocks/Fragment/screenSizeBlock.js +2 -2
  88. package/Materials/Node/Blocks/Fragment/screenSizeBlock.js.map +1 -1
  89. package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.d.ts +3 -3
  90. package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.js +6 -3
  91. package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.js.map +1 -1
  92. package/Materials/Node/Blocks/PBR/anisotropyBlock.d.ts +1 -2
  93. package/Materials/Node/Blocks/PBR/anisotropyBlock.js +2 -4
  94. package/Materials/Node/Blocks/PBR/anisotropyBlock.js.map +1 -1
  95. package/Materials/Node/Blocks/PBR/clearCoatBlock.d.ts +1 -2
  96. package/Materials/Node/Blocks/PBR/clearCoatBlock.js +1 -2
  97. package/Materials/Node/Blocks/PBR/clearCoatBlock.js.map +1 -1
  98. package/Materials/Node/Blocks/PBR/iridescenceBlock.d.ts +2 -3
  99. package/Materials/Node/Blocks/PBR/iridescenceBlock.js +1 -2
  100. package/Materials/Node/Blocks/PBR/iridescenceBlock.js.map +1 -1
  101. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.d.ts +1 -1
  102. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +5 -2
  103. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  104. package/Materials/Node/Blocks/PBR/reflectionBlock.d.ts +1 -2
  105. package/Materials/Node/Blocks/PBR/reflectionBlock.js +2 -2
  106. package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
  107. package/Materials/Node/Blocks/PBR/refractionBlock.d.ts +1 -2
  108. package/Materials/Node/Blocks/PBR/refractionBlock.js +1 -2
  109. package/Materials/Node/Blocks/PBR/refractionBlock.js.map +1 -1
  110. package/Materials/Node/Blocks/PBR/sheenBlock.d.ts +2 -3
  111. package/Materials/Node/Blocks/PBR/sheenBlock.js +1 -2
  112. package/Materials/Node/Blocks/PBR/sheenBlock.js.map +1 -1
  113. package/Materials/Node/Blocks/PBR/subSurfaceBlock.d.ts +2 -3
  114. package/Materials/Node/Blocks/PBR/subSurfaceBlock.js +1 -2
  115. package/Materials/Node/Blocks/PBR/subSurfaceBlock.js.map +1 -1
  116. package/Materials/Node/Blocks/Particle/particleTextureBlock.d.ts +1 -2
  117. package/Materials/Node/Blocks/Particle/particleTextureBlock.js +1 -1
  118. package/Materials/Node/Blocks/Particle/particleTextureBlock.js.map +1 -1
  119. package/Materials/Node/Blocks/Vertex/bonesBlock.d.ts +2 -2
  120. package/Materials/Node/Blocks/Vertex/bonesBlock.js +3 -3
  121. package/Materials/Node/Blocks/Vertex/bonesBlock.js.map +1 -1
  122. package/Materials/Node/Blocks/Vertex/instancesBlock.d.ts +1 -1
  123. package/Materials/Node/Blocks/Vertex/instancesBlock.js +1 -1
  124. package/Materials/Node/Blocks/Vertex/instancesBlock.js.map +1 -1
  125. package/Materials/Node/Blocks/Vertex/lightInformationBlock.d.ts +1 -2
  126. package/Materials/Node/Blocks/Vertex/lightInformationBlock.js +1 -1
  127. package/Materials/Node/Blocks/Vertex/lightInformationBlock.js.map +1 -1
  128. package/Materials/Node/Blocks/Vertex/morphTargetsBlock.d.ts +2 -2
  129. package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js +8 -2
  130. package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js.map +1 -1
  131. package/Materials/Node/Blocks/transformBlock.d.ts +3 -3
  132. package/Materials/Node/Blocks/transformBlock.js +4 -5
  133. package/Materials/Node/Blocks/transformBlock.js.map +1 -1
  134. package/Materials/Node/Blocks/triPlanarBlock.d.ts +1 -3
  135. package/Materials/Node/Blocks/triPlanarBlock.js +1 -1
  136. package/Materials/Node/Blocks/triPlanarBlock.js.map +1 -1
  137. package/Materials/Node/nodeMaterial.d.ts +1 -1
  138. package/Materials/Node/nodeMaterial.js +28 -42
  139. package/Materials/Node/nodeMaterial.js.map +1 -1
  140. package/Materials/Node/nodeMaterialBlock.d.ts +8 -12
  141. package/Materials/Node/nodeMaterialBlock.js +10 -12
  142. package/Materials/Node/nodeMaterialBlock.js.map +1 -1
  143. package/Materials/Node/nodeMaterialBuildState.js +3 -1
  144. package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
  145. package/Materials/Node/nodeMaterialBuildStateSharedData.d.ts +7 -3
  146. package/Materials/Node/nodeMaterialBuildStateSharedData.js +17 -6
  147. package/Materials/Node/nodeMaterialBuildStateSharedData.js.map +1 -1
  148. package/Materials/PBR/pbrBaseMaterial.d.ts +2 -0
  149. package/Materials/PBR/pbrBaseMaterial.js +11 -0
  150. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  151. package/Materials/Textures/Loaders/exrTextureLoader.d.ts +10 -0
  152. package/Materials/Textures/Loaders/exrTextureLoader.js +28 -1
  153. package/Materials/Textures/Loaders/exrTextureLoader.js.map +1 -1
  154. package/Materials/materialHelper.functions.js +1 -1
  155. package/Materials/materialHelper.functions.js.map +1 -1
  156. package/Materials/materialHelper.geometryrendering.js +7 -0
  157. package/Materials/materialHelper.geometryrendering.js.map +1 -1
  158. package/Materials/standardMaterial.d.ts +2 -0
  159. package/Materials/standardMaterial.js +11 -0
  160. package/Materials/standardMaterial.js.map +1 -1
  161. package/Meshes/Node/Blocks/Textures/geometryTextureBlock.d.ts +7 -0
  162. package/Meshes/Node/Blocks/Textures/geometryTextureBlock.js +11 -5
  163. package/Meshes/Node/Blocks/Textures/geometryTextureBlock.js.map +1 -1
  164. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.d.ts +6 -0
  165. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js +42 -4
  166. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js.map +1 -1
  167. package/Meshes/Node/Blocks/geometryOptimizeBlock.js +8 -0
  168. package/Meshes/Node/Blocks/geometryOptimizeBlock.js.map +1 -1
  169. package/Misc/environmentTextureTools.js +1 -1
  170. package/Misc/environmentTextureTools.js.map +1 -1
  171. package/Misc/minMaxReducer.d.ts +8 -6
  172. package/Misc/minMaxReducer.js +57 -90
  173. package/Misc/minMaxReducer.js.map +1 -1
  174. package/Misc/observable.d.ts +1 -1
  175. package/Misc/observable.js.map +1 -1
  176. package/Misc/thinMinMaxReducer.d.ts +47 -0
  177. package/Misc/thinMinMaxReducer.js +148 -0
  178. package/Misc/thinMinMaxReducer.js.map +1 -0
  179. package/Particles/EmitterTypes/customParticleEmitter.d.ts +5 -0
  180. package/Particles/EmitterTypes/customParticleEmitter.js +9 -1
  181. package/Particles/EmitterTypes/customParticleEmitter.js.map +1 -1
  182. package/Particles/IParticleSystem.d.ts +8 -0
  183. package/Particles/IParticleSystem.js.map +1 -1
  184. package/Particles/Node/Blocks/Conditions/particleConditionBlock.d.ts +75 -0
  185. package/Particles/Node/Blocks/Conditions/particleConditionBlock.js +179 -0
  186. package/Particles/Node/Blocks/Conditions/particleConditionBlock.js.map +1 -0
  187. package/Particles/Node/Blocks/Emitters/boxShapeBlock.d.ts +47 -0
  188. package/Particles/Node/Blocks/Emitters/boxShapeBlock.js +107 -0
  189. package/Particles/Node/Blocks/Emitters/boxShapeBlock.js.map +1 -0
  190. package/Particles/Node/Blocks/Emitters/createParticleBlock.d.ts +46 -0
  191. package/Particles/Node/Blocks/Emitters/createParticleBlock.js +97 -0
  192. package/Particles/Node/Blocks/Emitters/createParticleBlock.js.map +1 -0
  193. package/Particles/Node/Blocks/Emitters/customShapeBlock.d.ts +39 -0
  194. package/Particles/Node/Blocks/Emitters/customShapeBlock.js +84 -0
  195. package/Particles/Node/Blocks/Emitters/customShapeBlock.js.map +1 -0
  196. package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.d.ts +48 -0
  197. package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.js +120 -0
  198. package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.js.map +1 -0
  199. package/Particles/Node/Blocks/Emitters/index.d.ts +7 -0
  200. package/Particles/Node/Blocks/Emitters/index.js +8 -0
  201. package/Particles/Node/Blocks/Emitters/index.js.map +1 -0
  202. package/Particles/Node/Blocks/Emitters/pointShapeBlock.d.ts +39 -0
  203. package/Particles/Node/Blocks/Emitters/pointShapeBlock.js +86 -0
  204. package/Particles/Node/Blocks/Emitters/pointShapeBlock.js.map +1 -0
  205. package/Particles/Node/Blocks/Emitters/setupSpriteSheetBlock.d.ts +53 -0
  206. package/Particles/Node/Blocks/Emitters/setupSpriteSheetBlock.js +111 -0
  207. package/Particles/Node/Blocks/Emitters/setupSpriteSheetBlock.js.map +1 -0
  208. package/Particles/Node/Blocks/Emitters/sphereShapeBlock.d.ts +43 -0
  209. package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js +108 -0
  210. package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js.map +1 -0
  211. package/Particles/Node/Blocks/Teleport/particleTeleportInBlock.d.ts +48 -0
  212. package/Particles/Node/Blocks/Teleport/particleTeleportInBlock.js +100 -0
  213. package/Particles/Node/Blocks/Teleport/particleTeleportInBlock.js.map +1 -0
  214. package/Particles/Node/Blocks/Teleport/particleTeleportOutBlock.d.ts +47 -0
  215. package/Particles/Node/Blocks/Teleport/particleTeleportOutBlock.js +82 -0
  216. package/Particles/Node/Blocks/Teleport/particleTeleportOutBlock.js.map +1 -0
  217. package/Particles/Node/Blocks/Triggers/particleTriggerBlock.d.ts +48 -0
  218. package/Particles/Node/Blocks/Triggers/particleTriggerBlock.js +133 -0
  219. package/Particles/Node/Blocks/Triggers/particleTriggerBlock.js.map +1 -0
  220. package/Particles/Node/Blocks/Triggers/triggerTools.d.ts +9 -0
  221. package/Particles/Node/Blocks/Triggers/triggerTools.js +16 -0
  222. package/Particles/Node/Blocks/Triggers/triggerTools.js.map +1 -0
  223. package/Particles/Node/Blocks/Update/basicPositionUpdateBlock.d.ts +31 -0
  224. package/Particles/Node/Blocks/Update/basicPositionUpdateBlock.js +64 -0
  225. package/Particles/Node/Blocks/Update/basicPositionUpdateBlock.js.map +1 -0
  226. package/Particles/Node/Blocks/Update/basicSpriteUpdateBlock.d.ts +31 -0
  227. package/Particles/Node/Blocks/Update/basicSpriteUpdateBlock.js +63 -0
  228. package/Particles/Node/Blocks/Update/basicSpriteUpdateBlock.js.map +1 -0
  229. package/Particles/Node/Blocks/Update/updateAngleBlock.d.ts +35 -0
  230. package/Particles/Node/Blocks/Update/updateAngleBlock.js +73 -0
  231. package/Particles/Node/Blocks/Update/updateAngleBlock.js.map +1 -0
  232. package/Particles/Node/Blocks/Update/updateColorBlock.d.ts +35 -0
  233. package/Particles/Node/Blocks/Update/updateColorBlock.js +73 -0
  234. package/Particles/Node/Blocks/Update/updateColorBlock.js.map +1 -0
  235. package/Particles/Node/Blocks/Update/updateDirectionBlock.d.ts +35 -0
  236. package/Particles/Node/Blocks/Update/updateDirectionBlock.js +73 -0
  237. package/Particles/Node/Blocks/Update/updateDirectionBlock.js.map +1 -0
  238. package/Particles/Node/Blocks/Update/updateFlowMapBlock.d.ts +41 -0
  239. package/Particles/Node/Blocks/Update/updateFlowMapBlock.js +102 -0
  240. package/Particles/Node/Blocks/Update/updateFlowMapBlock.js.map +1 -0
  241. package/Particles/Node/Blocks/Update/updatePositionBlock.d.ts +35 -0
  242. package/Particles/Node/Blocks/Update/updatePositionBlock.js +73 -0
  243. package/Particles/Node/Blocks/Update/updatePositionBlock.js.map +1 -0
  244. package/Particles/Node/Blocks/Update/updateScaleBlock.d.ts +35 -0
  245. package/Particles/Node/Blocks/Update/updateScaleBlock.js +73 -0
  246. package/Particles/Node/Blocks/Update/updateScaleBlock.js.map +1 -0
  247. package/Particles/Node/Blocks/Update/updateSpriteCellIndexBlock.d.ts +35 -0
  248. package/Particles/Node/Blocks/Update/updateSpriteCellIndexBlock.js +74 -0
  249. package/Particles/Node/Blocks/Update/updateSpriteCellIndexBlock.js.map +1 -0
  250. package/Particles/Node/Blocks/index.d.ts +27 -0
  251. package/Particles/Node/Blocks/index.js +29 -0
  252. package/Particles/Node/Blocks/index.js.map +1 -0
  253. package/Particles/Node/Blocks/particleConverterBlock.d.ts +85 -0
  254. package/Particles/Node/Blocks/particleConverterBlock.js +267 -0
  255. package/Particles/Node/Blocks/particleConverterBlock.js.map +1 -0
  256. package/Particles/Node/Blocks/particleDebugBlock.d.ts +37 -0
  257. package/Particles/Node/Blocks/particleDebugBlock.js +109 -0
  258. package/Particles/Node/Blocks/particleDebugBlock.js.map +1 -0
  259. package/Particles/Node/Blocks/particleElbowBlock.d.ts +27 -0
  260. package/Particles/Node/Blocks/particleElbowBlock.js +47 -0
  261. package/Particles/Node/Blocks/particleElbowBlock.js.map +1 -0
  262. package/Particles/Node/Blocks/particleGradientBlock.d.ts +28 -0
  263. package/Particles/Node/Blocks/particleGradientBlock.js +118 -0
  264. package/Particles/Node/Blocks/particleGradientBlock.js.map +1 -0
  265. package/Particles/Node/Blocks/particleGradientValueBlock.d.ts +32 -0
  266. package/Particles/Node/Blocks/particleGradientValueBlock.js +79 -0
  267. package/Particles/Node/Blocks/particleGradientValueBlock.js.map +1 -0
  268. package/Particles/Node/Blocks/particleInputBlock.d.ts +87 -0
  269. package/Particles/Node/Blocks/particleInputBlock.js +279 -0
  270. package/Particles/Node/Blocks/particleInputBlock.js.map +1 -0
  271. package/Particles/Node/Blocks/particleLerpBlock.d.ts +34 -0
  272. package/Particles/Node/Blocks/particleLerpBlock.js +92 -0
  273. package/Particles/Node/Blocks/particleLerpBlock.js.map +1 -0
  274. package/Particles/Node/Blocks/particleMathBlock.d.ts +64 -0
  275. package/Particles/Node/Blocks/particleMathBlock.js +321 -0
  276. package/Particles/Node/Blocks/particleMathBlock.js.map +1 -0
  277. package/Particles/Node/Blocks/particleRandomBlock.d.ts +52 -0
  278. package/Particles/Node/Blocks/particleRandomBlock.js +161 -0
  279. package/Particles/Node/Blocks/particleRandomBlock.js.map +1 -0
  280. package/Particles/Node/Blocks/particleSourceTextureBlock.d.ts +65 -0
  281. package/Particles/Node/Blocks/particleSourceTextureBlock.js +173 -0
  282. package/Particles/Node/Blocks/particleSourceTextureBlock.js.map +1 -0
  283. package/Particles/Node/Blocks/particleTrigonometryBlock.d.ts +80 -0
  284. package/Particles/Node/Blocks/particleTrigonometryBlock.js +272 -0
  285. package/Particles/Node/Blocks/particleTrigonometryBlock.js.map +1 -0
  286. package/Particles/Node/Blocks/randomRangeBlock.d.ts +45 -0
  287. package/Particles/Node/Blocks/randomRangeBlock.js +151 -0
  288. package/Particles/Node/Blocks/randomRangeBlock.js.map +1 -0
  289. package/Particles/Node/Blocks/systemBlock.d.ts +71 -0
  290. package/Particles/Node/Blocks/systemBlock.js +193 -0
  291. package/Particles/Node/Blocks/systemBlock.js.map +1 -0
  292. package/Particles/Node/Enums/nodeParticleBlockConnectionPointTypes.d.ts +39 -0
  293. package/Particles/Node/Enums/nodeParticleBlockConnectionPointTypes.js +41 -0
  294. package/Particles/Node/Enums/nodeParticleBlockConnectionPointTypes.js.map +1 -0
  295. package/Particles/Node/Enums/nodeParticleContextualSources.d.ts +31 -0
  296. package/Particles/Node/Enums/nodeParticleContextualSources.js +34 -0
  297. package/Particles/Node/Enums/nodeParticleContextualSources.js.map +1 -0
  298. package/Particles/Node/Enums/nodeParticleSystemSources.d.ts +13 -0
  299. package/Particles/Node/Enums/nodeParticleSystemSources.js +15 -0
  300. package/Particles/Node/Enums/nodeParticleSystemSources.js.map +1 -0
  301. package/Particles/Node/index.d.ts +8 -0
  302. package/Particles/Node/index.js +10 -0
  303. package/Particles/Node/index.js.map +1 -0
  304. package/Particles/Node/nodeParticleBlock.d.ts +154 -0
  305. package/Particles/Node/nodeParticleBlock.js +355 -0
  306. package/Particles/Node/nodeParticleBlock.js.map +1 -0
  307. package/Particles/Node/nodeParticleBlockConnectionPoint.d.ts +188 -0
  308. package/Particles/Node/nodeParticleBlockConnectionPoint.js +337 -0
  309. package/Particles/Node/nodeParticleBlockConnectionPoint.js.map +1 -0
  310. package/Particles/Node/nodeParticleBuildState.d.ts +89 -0
  311. package/Particles/Node/nodeParticleBuildState.js +170 -0
  312. package/Particles/Node/nodeParticleBuildState.js.map +1 -0
  313. package/Particles/Node/nodeParticleSystemSet.d.ts +121 -0
  314. package/Particles/Node/nodeParticleSystemSet.js +383 -0
  315. package/Particles/Node/nodeParticleSystemSet.js.map +1 -0
  316. package/Particles/Queue/executionQueue.d.ts +2 -0
  317. package/Particles/Queue/executionQueue.js +10 -0
  318. package/Particles/Queue/executionQueue.js.map +1 -1
  319. package/Particles/baseParticleSystem.d.ts +6 -1
  320. package/Particles/baseParticleSystem.js +7 -0
  321. package/Particles/baseParticleSystem.js.map +1 -1
  322. package/Particles/flowMap.d.ts +7 -0
  323. package/Particles/flowMap.js +32 -0
  324. package/Particles/flowMap.js.map +1 -1
  325. package/Particles/gpuParticleSystem.d.ts +4 -0
  326. package/Particles/gpuParticleSystem.js +4 -0
  327. package/Particles/gpuParticleSystem.js.map +1 -1
  328. package/Particles/index.d.ts +1 -0
  329. package/Particles/index.js +1 -0
  330. package/Particles/index.js.map +1 -1
  331. package/Particles/particleSystem.d.ts +12 -0
  332. package/Particles/particleSystem.js +22 -1
  333. package/Particles/particleSystem.js.map +1 -1
  334. package/Particles/thinParticleSystem.d.ts +32 -11
  335. package/Particles/thinParticleSystem.js +62 -36
  336. package/Particles/thinParticleSystem.js.map +1 -1
  337. package/PostProcesses/postProcessManager.d.ts +2 -1
  338. package/PostProcesses/postProcessManager.js +3 -2
  339. package/PostProcesses/postProcessManager.js.map +1 -1
  340. package/Shaders/ShadersInclude/defaultUboDeclaration.js +1 -1
  341. package/Shaders/ShadersInclude/defaultUboDeclaration.js.map +1 -1
  342. package/Shaders/ShadersInclude/defaultVertexDeclaration.js +1 -0
  343. package/Shaders/ShadersInclude/defaultVertexDeclaration.js.map +1 -1
  344. package/Shaders/ShadersInclude/lightFragment.js +5 -2
  345. package/Shaders/ShadersInclude/lightFragment.js.map +1 -1
  346. package/Shaders/ShadersInclude/morphTargetsVertexDeclaration.js +3 -0
  347. package/Shaders/ShadersInclude/morphTargetsVertexDeclaration.js.map +1 -1
  348. package/Shaders/ShadersInclude/pbrBlockPrePass.js +3 -0
  349. package/Shaders/ShadersInclude/pbrBlockPrePass.js.map +1 -1
  350. package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js +1 -1
  351. package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
  352. package/Shaders/ShadersInclude/pbrUboDeclaration.js +1 -1
  353. package/Shaders/ShadersInclude/pbrUboDeclaration.js.map +1 -1
  354. package/Shaders/ShadersInclude/pbrVertexDeclaration.js +1 -0
  355. package/Shaders/ShadersInclude/pbrVertexDeclaration.js.map +1 -1
  356. package/Shaders/ShadersInclude/prePassDeclaration.js +3 -0
  357. package/Shaders/ShadersInclude/prePassDeclaration.js.map +1 -1
  358. package/Shaders/ShadersInclude/prePassVertex.js +3 -0
  359. package/Shaders/ShadersInclude/prePassVertex.js.map +1 -1
  360. package/Shaders/ShadersInclude/prePassVertexDeclaration.js +3 -0
  361. package/Shaders/ShadersInclude/prePassVertexDeclaration.js.map +1 -1
  362. package/Shaders/default.fragment.js +3 -0
  363. package/Shaders/default.fragment.js.map +1 -1
  364. package/Shaders/minmaxRedux.fragment.js +13 -5
  365. package/Shaders/minmaxRedux.fragment.js.map +1 -1
  366. package/ShadersWGSL/ShadersInclude/defaultUboDeclaration.js +1 -1
  367. package/ShadersWGSL/ShadersInclude/defaultUboDeclaration.js.map +1 -1
  368. package/ShadersWGSL/ShadersInclude/lightFragment.js +5 -2
  369. package/ShadersWGSL/ShadersInclude/lightFragment.js.map +1 -1
  370. package/ShadersWGSL/ShadersInclude/morphTargetsVertexDeclaration.js +3 -0
  371. package/ShadersWGSL/ShadersInclude/morphTargetsVertexDeclaration.js.map +1 -1
  372. package/ShadersWGSL/ShadersInclude/pbrBlockPrePass.js +3 -0
  373. package/ShadersWGSL/ShadersInclude/pbrBlockPrePass.js.map +1 -1
  374. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js +1 -1
  375. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
  376. package/ShadersWGSL/ShadersInclude/pbrUboDeclaration.js +1 -1
  377. package/ShadersWGSL/ShadersInclude/pbrUboDeclaration.js.map +1 -1
  378. package/ShadersWGSL/ShadersInclude/prePassDeclaration.js +3 -0
  379. package/ShadersWGSL/ShadersInclude/prePassDeclaration.js.map +1 -1
  380. package/ShadersWGSL/ShadersInclude/prePassVertex.js +3 -0
  381. package/ShadersWGSL/ShadersInclude/prePassVertex.js.map +1 -1
  382. package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js +3 -0
  383. package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js.map +1 -1
  384. package/ShadersWGSL/default.fragment.js +3 -0
  385. package/ShadersWGSL/default.fragment.js.map +1 -1
  386. package/ShadersWGSL/minmaxRedux.fragment.js +14 -6
  387. package/ShadersWGSL/minmaxRedux.fragment.js.map +1 -1
  388. package/package.json +1 -1
  389. package/scene.d.ts +5 -0
  390. package/scene.js +8 -0
  391. package/scene.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"minMaxReducer.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/minMaxReducer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAKzE,OAAO,iCAAiC,CAAC;AACzC,OAAO,qCAAq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I,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACvD,OAAO;QACX,CAAC;QAED,IAAI,CAAC,cAAc,CAAC,uBAAuB,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAChF,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACI,OAAO,CAAC,UAAU,GAAG,IAAI;QAC5B,IAAI,UAAU,EAAE,CAAC;YACb,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC;YAEvC,IAAI,IAAI,CAAC,0BAA0B,EAAE,CAAC;gBAClC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,2BAA2B,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;gBAC7F,IAAI,CAAC,0BAA0B,GAAG,IAAI,CAAC;YAC3C,CAAC;QACL,CAAC;QAED,IAAI,CAAC,UAAU,EAAE,CAAC;QAElB,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;gBACnD,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;YACtC,CAAC;YACD,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAChC,CAAC;QAED,IAAI,IAAI,CAAC,mBAAmB,IAAI,UAAU,EAAE,CAAC;YACzC,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;QACvC,CAAC;QAED,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;IAC/B,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Observer } from \"./observable\";\r\nimport { Observable } from \"./observable\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport { PostProcessManager } from \"../PostProcesses/postProcessManager\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\n\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\n\r\nimport \"../Shaders/minmaxRedux.fragment\";\r\nimport \"../ShadersWGSL/minmaxRedux.fragment\";\r\n\r\n/**\r\n * This class computes a min/max reduction from a texture: it means it computes the minimum\r\n * and maximum values from all values of the texture.\r\n * It is performed on the GPU for better performances, thanks to a succession of post processes.\r\n * The source values are read from the red channel of the texture.\r\n */\r\nexport class MinMaxReducer {\r\n /**\r\n * Observable triggered when the computation has been performed\r\n */\r\n public onAfterReductionPerformed = new Observable<{ min: number; max: number }>();\r\n\r\n protected _camera: Camera;\r\n protected _sourceTexture: Nullable<RenderTargetTexture>;\r\n protected _reductionSteps: Nullable<Array<PostProcess>>;\r\n protected _postProcessManager: PostProcessManager;\r\n protected _onAfterUnbindObserver: Nullable<Observer<RenderTargetTexture>>;\r\n protected _forceFullscreenViewport = true;\r\n protected _onContextRestoredObserver: Nullable<Observer<AbstractEngine>>;\r\n\r\n /**\r\n * Creates a min/max reducer\r\n * @param camera The camera to use for the post processes\r\n */\r\n constructor(camera: Camera) {\r\n this._camera = camera;\r\n this._postProcessManager = new PostProcessManager(camera.getScene());\r\n\r\n this._onContextRestoredObserver = camera.getEngine().onContextRestoredObservable.add(() => {\r\n this._postProcessManager._rebuild();\r\n });\r\n }\r\n\r\n /**\r\n * Gets the texture used to read the values from.\r\n */\r\n public get sourceTexture(): Nullable<RenderTargetTexture> {\r\n return this._sourceTexture;\r\n }\r\n\r\n /**\r\n * Sets the source texture to read the values from.\r\n * One must indicate if the texture is a depth texture or not through the depthRedux parameter\r\n * because in such textures '1' value must not be taken into account to compute the maximum\r\n * as this value is used to clear the texture.\r\n * Note that the computation is not activated by calling this function, you must call activate() for that!\r\n * @param sourceTexture The texture to read the values from. The values should be in the red channel.\r\n * @param depthRedux Indicates if the texture is a depth texture or not\r\n * @param type The type of the textures created for the reduction (defaults to TEXTURETYPE_HALF_FLOAT)\r\n * @param forceFullscreenViewport Forces the post processes used for the reduction to be applied without taking into account viewport (defaults to true)\r\n */\r\n public setSourceTexture(sourceTexture: RenderTargetTexture, depthRedux: boolean, type: number = Constants.TEXTURETYPE_HALF_FLOAT, forceFullscreenViewport = true): void {\r\n if (sourceTexture === this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this.dispose(false);\r\n\r\n this._sourceTexture = sourceTexture;\r\n this._reductionSteps = [];\r\n this._forceFullscreenViewport = forceFullscreenViewport;\r\n\r\n const scene = this._camera.getScene();\r\n\r\n // create the first step\r\n const reductionInitial = new PostProcess(\r\n \"Initial reduction phase\",\r\n \"minmaxRedux\", // shader\r\n [\"texSize\"],\r\n [\"sourceTexture\"], // textures\r\n 1.0, // options\r\n null, // camera\r\n Constants.TEXTURE_NEAREST_NEAREST, // sampling\r\n scene.getEngine(), // engine\r\n false, // reusable\r\n \"#define INITIAL\" + (depthRedux ? \"\\n#define DEPTH_REDUX\" : \"\"), // defines\r\n type,\r\n undefined,\r\n undefined,\r\n undefined,\r\n Constants.TEXTUREFORMAT_RG,\r\n scene.getEngine().isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL\r\n );\r\n\r\n reductionInitial.autoClear = false;\r\n reductionInitial.forceFullscreenViewport = forceFullscreenViewport;\r\n\r\n let w = this._sourceTexture.getRenderWidth(),\r\n h = this._sourceTexture.getRenderHeight();\r\n\r\n reductionInitial.onApply = ((w: number, h: number) => {\r\n return (effect: Effect) => {\r\n effect.setTexture(\"sourceTexture\", this._sourceTexture);\r\n effect.setFloat2(\"texSize\", w, h);\r\n };\r\n })(w, h);\r\n\r\n this._reductionSteps.push(reductionInitial);\r\n\r\n let index = 1;\r\n\r\n // create the additional steps\r\n while (w > 1 || h > 1) {\r\n w = Math.max(Math.round(w / 2), 1);\r\n h = Math.max(Math.round(h / 2), 1);\r\n\r\n const reduction = new PostProcess(\r\n \"Reduction phase \" + index,\r\n \"minmaxRedux\", // shader\r\n [\"texSize\"],\r\n null,\r\n { width: w, height: h }, // options\r\n null, // camera\r\n Constants.TEXTURE_NEAREST_NEAREST, // sampling\r\n scene.getEngine(), // engine\r\n false, // reusable\r\n \"#define \" + (w == 1 && h == 1 ? \"LAST\" : w == 1 || h == 1 ? \"ONEBEFORELAST\" : \"MAIN\"), // defines\r\n type,\r\n undefined,\r\n undefined,\r\n undefined,\r\n Constants.TEXTUREFORMAT_RG,\r\n scene.getEngine().isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL\r\n );\r\n\r\n reduction.autoClear = false;\r\n reduction.forceFullscreenViewport = forceFullscreenViewport;\r\n\r\n reduction.onApply = ((w: number, h: number) => {\r\n return (effect: Effect) => {\r\n if (w == 1 || h == 1) {\r\n effect.setInt2(\"texSize\", w, h);\r\n } else {\r\n effect.setFloat2(\"texSize\", w, h);\r\n }\r\n };\r\n })(w, h);\r\n\r\n this._reductionSteps.push(reduction);\r\n\r\n index++;\r\n\r\n if (w == 1 && h == 1) {\r\n const func = (w: number, h: number, reduction: PostProcess) => {\r\n const buffer = new Float32Array(4 * w * h),\r\n minmax = { min: 0, max: 0 };\r\n return () => {\r\n // Note that we should normally await the call to _readTexturePixels!\r\n // But because WebGL does the read synchronously, we know the values will be updated without waiting for the promise to be resolved, which will let us get the updated values\r\n // in the current frame, whereas in WebGPU, the read is asynchronous and we should normally wait for the promise to be resolved to get the updated values.\r\n // However, it's safe to avoid waiting for the promise to be resolved in WebGPU as well, because we will simply use the current values until \"buffer\" is updated later on.\r\n // Note that it means we can suffer some rendering artifacts in WebGPU because we may use previous min/max values for the current frame.\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n scene.getEngine()._readTexturePixels(reduction.inputTexture.texture!, w, h, -1, 0, buffer, false);\r\n minmax.min = buffer[0];\r\n minmax.max = buffer[1];\r\n this.onAfterReductionPerformed.notifyObservers(minmax);\r\n };\r\n };\r\n reduction.onAfterRenderObservable.add(func(w, h, reduction));\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Defines the refresh rate of the computation.\r\n * Use 0 to compute just once, 1 to compute on every frame, 2 to compute every two frames and so on...\r\n */\r\n public get refreshRate(): number {\r\n return this._sourceTexture ? this._sourceTexture.refreshRate : -1;\r\n }\r\n\r\n public set refreshRate(value: number) {\r\n if (this._sourceTexture) {\r\n this._sourceTexture.refreshRate = value;\r\n }\r\n }\r\n\r\n protected _activated = false;\r\n\r\n /**\r\n * Gets the activation status of the reducer\r\n */\r\n public get activated(): boolean {\r\n return this._activated;\r\n }\r\n\r\n /**\r\n * Activates the reduction computation.\r\n * When activated, the observers registered in onAfterReductionPerformed are\r\n * called after the computation is performed\r\n */\r\n public activate(): void {\r\n if (this._onAfterUnbindObserver || !this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this._onAfterUnbindObserver = this._sourceTexture.onAfterUnbindObservable.add(() => {\r\n const engine = this._camera.getScene().getEngine();\r\n engine._debugPushGroup?.(`min max reduction`, 1);\r\n this._reductionSteps![0].activate(this._camera);\r\n this._postProcessManager.directRender(this._reductionSteps!, this._reductionSteps![0].inputTexture, this._forceFullscreenViewport);\r\n engine.unBindFramebuffer(this._reductionSteps![0].inputTexture, false);\r\n engine._debugPopGroup?.(1);\r\n });\r\n\r\n this._activated = true;\r\n }\r\n\r\n /**\r\n * Deactivates the reduction computation.\r\n */\r\n public deactivate(): void {\r\n if (!this._onAfterUnbindObserver || !this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this._sourceTexture.onAfterUnbindObservable.remove(this._onAfterUnbindObserver);\r\n this._onAfterUnbindObserver = null;\r\n this._activated = false;\r\n }\r\n\r\n /**\r\n * Disposes the min/max reducer\r\n * @param disposeAll true to dispose all the resources. You should always call this function with true as the parameter (or without any parameter as it is the default one). This flag is meant to be used internally.\r\n */\r\n public dispose(disposeAll = true): void {\r\n if (disposeAll) {\r\n this.onAfterReductionPerformed.clear();\r\n\r\n if (this._onContextRestoredObserver) {\r\n this._camera.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n this._onContextRestoredObserver = null;\r\n }\r\n }\r\n\r\n this.deactivate();\r\n\r\n if (this._reductionSteps) {\r\n for (let i = 0; i < this._reductionSteps.length; ++i) {\r\n this._reductionSteps[i].dispose();\r\n }\r\n this._reductionSteps = null;\r\n }\r\n\r\n if (this._postProcessManager && disposeAll) {\r\n this._postProcessManager.dispose();\r\n }\r\n\r\n this._sourceTexture = null;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"minMaxReducer.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/minMaxReducer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAGzE,OAAO,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAEtF,OAAO,iCAAiC,CAAC;AACzC,OAAO,qCAAqC,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IACtB;;OAEG;IACH,IAAW,yBAAyB;QAChC,OAAO,IAAI,CAAC,kBAAkB,CAAC,yBAAyB,CAAC;IAC7D,CAAC;IAWD;;;OAGG;IACH,YAAY,MAAc;QARhB,2BAAsB,GAA4C,IAAI,CAAC;QACvE,6BAAwB,GAAG,IAAI,CAAC;QAoGhC,eAAU,GAAG,KAAK,CAAC;QA5FzB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,mBAAmB,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QACrE,IAAI,CAAC,kBAAkB,GAAG,IAA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,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACvD,OAAO;QACX,CAAC;QAED,IAAI,CAAC,cAAc,CAAC,uBAAuB,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAChF,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACI,OAAO,CAAC,UAAU,GAAG,IAAI;QAC5B,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,OAAO;QACX,CAAC;QAED,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC;QAEvC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,2BAA2B,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QAC5F,IAAI,CAAC,0BAAkC,GAAG,SAAS,CAAC;QAErD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAE7B,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;QAClC,IAAI,CAAC,mBAA2B,GAAG,SAAgB,CAAC;QACrD,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC;QACjC,IAAI,CAAC,kBAA0B,GAAG,SAAS,CAAC;QAC7C,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;IAC/B,CAAC;IAEO,qBAAqB;QACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;YACnD,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACtC,CAAC;QACD,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC;IACpC,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Observer } from \"./observable\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport { PostProcessManager } from \"../PostProcesses/postProcessManager\";\r\n\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport { ThinMinMaxReducer, ThinMinMaxReducerPostProcess } from \"./thinMinMaxReducer\";\r\n\r\nimport \"../Shaders/minmaxRedux.fragment\";\r\nimport \"../ShadersWGSL/minmaxRedux.fragment\";\r\n\r\n/**\r\n * This class computes a min/max reduction from a texture: it means it computes the minimum\r\n * and maximum values from all values of the texture.\r\n * It is performed on the GPU for better performances, thanks to a succession of post processes.\r\n * The source values are read from the red channel of the texture.\r\n */\r\nexport class MinMaxReducer {\r\n /**\r\n * Observable triggered when the computation has been performed\r\n */\r\n public get onAfterReductionPerformed() {\r\n return this._thinMinMaxReducer.onAfterReductionPerformed;\r\n }\r\n\r\n protected readonly _camera: Camera;\r\n protected readonly _thinMinMaxReducer: ThinMinMaxReducer;\r\n protected _sourceTexture: Nullable<RenderTargetTexture>;\r\n protected readonly _reductionSteps: Array<PostProcess>;\r\n protected readonly _postProcessManager: PostProcessManager;\r\n protected _onAfterUnbindObserver: Nullable<Observer<RenderTargetTexture>> = null;\r\n protected _forceFullscreenViewport = true;\r\n protected readonly _onContextRestoredObserver: Observer<AbstractEngine>;\r\n\r\n /**\r\n * Creates a min/max reducer\r\n * @param camera The camera to use for the post processes\r\n */\r\n constructor(camera: Camera) {\r\n this._camera = camera;\r\n this._postProcessManager = new PostProcessManager(camera.getScene());\r\n this._thinMinMaxReducer = new ThinMinMaxReducer(camera.getScene());\r\n this._reductionSteps = [];\r\n\r\n this._onContextRestoredObserver = camera.getEngine().onContextRestoredObservable.add(() => {\r\n this._postProcessManager._rebuild();\r\n });\r\n }\r\n\r\n /**\r\n * Gets the texture used to read the values from.\r\n */\r\n public get sourceTexture(): Nullable<RenderTargetTexture> {\r\n return this._sourceTexture;\r\n }\r\n\r\n /**\r\n * Sets the source texture to read the values from.\r\n * One must indicate if the texture is a depth texture or not through the depthRedux parameter\r\n * because in such textures '1' value must not be taken into account to compute the maximum\r\n * as this value is used to clear the texture.\r\n * Note that the computation is not activated by calling this function, you must call activate() for that!\r\n * @param sourceTexture The texture to read the values from. The values should be in the red channel.\r\n * @param depthRedux Indicates if the texture is a depth texture or not\r\n * @param type The type of the textures created for the reduction (defaults to TEXTURETYPE_HALF_FLOAT)\r\n * @param forceFullscreenViewport Forces the post processes used for the reduction to be applied without taking into account viewport (defaults to true)\r\n */\r\n public setSourceTexture(sourceTexture: RenderTargetTexture, depthRedux: boolean, type: number = Constants.TEXTURETYPE_HALF_FLOAT, forceFullscreenViewport = true): void {\r\n if (sourceTexture === this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this._thinMinMaxReducer.depthRedux = depthRedux;\r\n\r\n this.deactivate();\r\n\r\n this._sourceTexture = sourceTexture;\r\n this._forceFullscreenViewport = forceFullscreenViewport;\r\n\r\n if (this._thinMinMaxReducer.setTextureDimensions(sourceTexture.getRenderWidth(), sourceTexture.getRenderHeight())) {\r\n this._disposePostProcesses();\r\n\r\n const reductionSteps = this._thinMinMaxReducer.reductionSteps;\r\n\r\n for (let i = 0; i < reductionSteps.length; ++i) {\r\n const reductionStep = reductionSteps[i];\r\n\r\n const postProcess = new PostProcess(reductionStep.name, ThinMinMaxReducerPostProcess.FragmentUrl, {\r\n effectWrapper: reductionStep,\r\n samplingMode: Constants.TEXTURE_NEAREST_NEAREST,\r\n engine: this._camera.getScene().getEngine(),\r\n textureType: type,\r\n textureFormat: Constants.TEXTUREFORMAT_RG,\r\n size: { width: reductionStep.textureWidth, height: reductionStep.textureHeight },\r\n });\r\n\r\n this._reductionSteps.push(postProcess);\r\n\r\n postProcess.autoClear = false;\r\n postProcess.forceFullscreenViewport = forceFullscreenViewport;\r\n\r\n if (i === 0) {\r\n postProcess.externalTextureSamplerBinding = true;\r\n postProcess.onApplyObservable.add((effect: Effect) => {\r\n effect.setTexture(\"textureSampler\", this._sourceTexture);\r\n });\r\n }\r\n\r\n if (i === reductionSteps.length - 1) {\r\n this._reductionSteps[i - 1].onAfterRenderObservable.add(() => {\r\n this._thinMinMaxReducer.readMinMax(postProcess.inputTexture.texture!);\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Defines the refresh rate of the computation.\r\n * Use 0 to compute just once, 1 to compute on every frame, 2 to compute every two frames and so on...\r\n */\r\n public get refreshRate(): number {\r\n return this._sourceTexture ? this._sourceTexture.refreshRate : -1;\r\n }\r\n\r\n public set refreshRate(value: number) {\r\n if (this._sourceTexture) {\r\n this._sourceTexture.refreshRate = value;\r\n }\r\n }\r\n\r\n protected _activated = false;\r\n\r\n /**\r\n * Gets the activation status of the reducer\r\n */\r\n public get activated(): boolean {\r\n return this._activated;\r\n }\r\n\r\n /**\r\n * Activates the reduction computation.\r\n * When activated, the observers registered in onAfterReductionPerformed are\r\n * called after the computation is performed\r\n */\r\n public activate(): void {\r\n if (this._onAfterUnbindObserver || !this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this._onAfterUnbindObserver = this._sourceTexture.onAfterUnbindObservable.add(() => {\r\n const engine = this._camera.getScene().getEngine();\r\n engine._debugPushGroup?.(`min max reduction`, 1);\r\n this._reductionSteps![0].activate(this._camera);\r\n this._postProcessManager.directRender(\r\n this._reductionSteps!,\r\n this._reductionSteps![0].inputTexture,\r\n this._forceFullscreenViewport,\r\n 0,\r\n 0,\r\n true,\r\n this._reductionSteps.length - 1\r\n );\r\n engine.unBindFramebuffer(this._reductionSteps![this._reductionSteps.length - 1].inputTexture, false);\r\n engine._debugPopGroup?.(1);\r\n });\r\n\r\n this._activated = true;\r\n }\r\n\r\n /**\r\n * Deactivates the reduction computation.\r\n */\r\n public deactivate(): void {\r\n if (!this._onAfterUnbindObserver || !this._sourceTexture) {\r\n return;\r\n }\r\n\r\n this._sourceTexture.onAfterUnbindObservable.remove(this._onAfterUnbindObserver);\r\n this._onAfterUnbindObserver = null;\r\n this._activated = false;\r\n }\r\n\r\n /**\r\n * Disposes the min/max reducer\r\n * @param disposeAll true to dispose all the resources. You should always call this function with true as the parameter (or without any parameter as it is the default one). This flag is meant to be used internally.\r\n */\r\n public dispose(disposeAll = true): void {\r\n if (!disposeAll) {\r\n return;\r\n }\r\n\r\n this.onAfterReductionPerformed.clear();\r\n\r\n this._camera.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver);\r\n (this._onContextRestoredObserver as any) = undefined;\r\n\r\n this._disposePostProcesses();\r\n\r\n this._postProcessManager.dispose();\r\n (this._postProcessManager as any) = undefined as any;\r\n this._thinMinMaxReducer.dispose();\r\n (this._thinMinMaxReducer as any) = undefined;\r\n this._sourceTexture = null;\r\n }\r\n\r\n private _disposePostProcesses() {\r\n for (let i = 0; i < this._reductionSteps.length; ++i) {\r\n this._reductionSteps[i].dispose();\r\n }\r\n this._reductionSteps.length = 0;\r\n }\r\n}\r\n"]}
@@ -113,7 +113,7 @@ export declare class Observer<T> implements IObserver {
113
113
  /**
114
114
  * An interface that defines the reader side of an Observable (receive notifications).
115
115
  */
116
- export interface IReadonlyObservable<T> {
116
+ export interface IReadonlyObservable<T = unknown> {
117
117
  /**
118
118
  * Create a new Observer with the specified callback
119
119
  * @param callback the callback that will be executed for that Observer
@@ -1 +1 @@
1
- {"version":3,"file":"observable.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/observable.ts"],"names":[],"mappings":"AAIA,MAAM,kBAAkB,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB;;;;;;OAMG;IACH,YAAY,IAAY,EAAE,iBAAiB,GAAG,KAAK,EAAE,MAAY,EAAE,aAAmB;QAClF,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;IACp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AI,KAAK,IAAI,EAAE,CAAC;gBACvC,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\n\r\ndeclare const WeakRef: any;\r\n\r\nconst IsWeakRefSupported = typeof WeakRef !== \"undefined\";\r\n\r\n/**\r\n * A class serves as a medium between the observable and its observers\r\n */\r\nexport class EventState {\r\n /**\r\n * Create a new EventState\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n */\r\n constructor(mask: number, skipNextObservers = false, target?: any, currentTarget?: any) {\r\n this.initialize(mask, skipNextObservers, target, currentTarget);\r\n }\r\n\r\n /**\r\n * Initialize the current event state\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @returns the current event state\r\n */\r\n public initialize(mask: number, skipNextObservers = false, target?: any, currentTarget?: any): EventState {\r\n this.mask = mask;\r\n this.skipNextObservers = skipNextObservers;\r\n this.target = target;\r\n this.currentTarget = currentTarget;\r\n return this;\r\n }\r\n\r\n /**\r\n * An Observer can set this property to true to prevent subsequent observers of being notified\r\n */\r\n public skipNextObservers: boolean;\r\n\r\n /**\r\n * Get the mask value that were used to trigger the event corresponding to this EventState object\r\n */\r\n public mask: number;\r\n\r\n /**\r\n * The object that originally notified the event\r\n */\r\n public target?: any;\r\n\r\n /**\r\n * The current object in the bubbling phase\r\n */\r\n public currentTarget?: any;\r\n\r\n /**\r\n * This will be populated with the return value of the last function that was executed.\r\n * If it is the first function in the callback chain it will be the event data.\r\n */\r\n public lastReturnValue?: any;\r\n\r\n /**\r\n * User defined information that will be sent to observers\r\n */\r\n public userInfo?: any;\r\n}\r\n\r\n/**\r\n * Represent an observer registered to a given IObservable object.\r\n */\r\nexport interface IObserver {\r\n /**\r\n * Remove the observer from its observable\r\n * @param defer if true, the removal will be deferred to avoid callback skipping (default: false)\r\n */\r\n remove(defer?: boolean): void;\r\n}\r\n\r\n/**\r\n * Represent an observer registered to a given Observable object.\r\n */\r\nexport class Observer<T> implements IObserver {\r\n /** @internal */\r\n public _willBeUnregistered = false;\r\n /**\r\n * Gets or sets a property defining that the observer as to be unregistered after the next notification\r\n */\r\n public unregisterOnNextCall = false;\r\n\r\n /**\r\n * this function can be used to remove the observer from the observable.\r\n * It will be set by the observable that the observer belongs to.\r\n * @internal\r\n */\r\n public _remove: Nullable<(defer?: boolean) => void> = null;\r\n\r\n /**\r\n * Creates a new observer\r\n * @param callback defines the callback to call when the observer is notified\r\n * @param mask defines the mask of the observer (used to filter notifications)\r\n * @param scope defines the current scope used to restore the JS context\r\n */\r\n constructor(\r\n /**\r\n * Defines the callback to call when the observer is notified\r\n */\r\n public callback: (eventData: T, eventState: EventState) => void,\r\n /**\r\n * Defines the mask of the observer (used to filter notifications)\r\n */\r\n public mask: number,\r\n /**\r\n * [null] Defines the current scope used to restore the JS context\r\n */\r\n public scope: any = null\r\n ) {}\r\n\r\n /**\r\n * Remove the observer from its observable\r\n * This can be used instead of using the observable's remove function.\r\n * @param defer if true, the removal will be deferred to avoid callback skipping (default: false)\r\n */\r\n public remove(defer = false) {\r\n if (this._remove) {\r\n this._remove(defer);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * An interface that defines the reader side of an Observable (receive notifications).\r\n */\r\nexport interface IReadonlyObservable<T> {\r\n /**\r\n * Create a new Observer with the specified callback\r\n * @param callback the callback that will be executed for that Observer\r\n * @param mask the mask used to filter observers\r\n * @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.\r\n * @param scope optional scope for the callback to be called from\r\n * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification\r\n * @returns the new observer created for the callback\r\n */\r\n add(callback: (eventData: T, eventState: EventState) => void, mask?: number, insertFirst?: boolean, scope?: unknown, unregisterOnFirstCall?: boolean): IObserver;\r\n\r\n /**\r\n * Create a new Observer with the specified callback and unregisters after the next notification\r\n * @param callback the callback that will be executed for that Observer\r\n * @returns the new observer created for the callback\r\n */\r\n addOnce(callback: (eventData: T, eventState: EventState) => void): IObserver;\r\n}\r\n\r\n/**\r\n * The Observable class is a simple implementation of the Observable pattern.\r\n *\r\n * There's one slight particularity though: a given Observable can notify its observer using a particular mask value, only the Observers registered with this mask value will be notified.\r\n * This enable a more fine grained execution without having to rely on multiple different Observable objects.\r\n * For instance you may have a given Observable that have four different types of notifications: Move (mask = 0x01), Stop (mask = 0x02), Turn Right (mask = 0X04), Turn Left (mask = 0X08).\r\n * A given observer can register itself with only Move and Stop (mask = 0x03), then it will only be notified when one of these two occurs and will never be for Turn Left/Right.\r\n */\r\nexport class Observable<T> implements IReadonlyObservable<T> {\r\n private _observers = new Array<Observer<T>>();\r\n private _numObserversMarkedAsDeleted = 0;\r\n private _hasNotified = false;\r\n private _lastNotifiedValue?: T;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _eventState: EventState;\r\n\r\n private _onObserverAdded: Nullable<(observer: Observer<T>) => void>;\r\n\r\n /**\r\n * Create an observable from a Promise.\r\n * @param promise a promise to observe for fulfillment.\r\n * @param onErrorObservable an observable to notify if a promise was rejected.\r\n * @returns the new Observable\r\n */\r\n public static FromPromise<T, E = Error>(promise: Promise<T>, onErrorObservable?: Observable<E>): Observable<T> {\r\n const observable = new Observable<T>();\r\n\r\n promise\r\n // eslint-disable-next-line github/no-then\r\n .then((ret: T) => {\r\n observable.notifyObservers(ret);\r\n })\r\n // eslint-disable-next-line github/no-then\r\n .catch((err) => {\r\n if (onErrorObservable) {\r\n onErrorObservable.notifyObservers(err as E);\r\n } else {\r\n throw err;\r\n }\r\n });\r\n\r\n return observable;\r\n }\r\n\r\n /**\r\n * Gets the list of observers\r\n * Note that observers that were recently deleted may still be present in the list because they are only really deleted on the next javascript tick!\r\n */\r\n public get observers(): Array<Observer<T>> {\r\n return this._observers;\r\n }\r\n\r\n /**\r\n * Creates a new observable\r\n * @param onObserverAdded defines a callback to call when a new observer is added\r\n * @param notifyIfTriggered If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n */\r\n constructor(\r\n onObserverAdded?: (observer: Observer<T>) => void,\r\n /**\r\n * [false] If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n * This is helpful to single-state observables like the scene onReady or the dispose observable.\r\n */\r\n public notifyIfTriggered = false\r\n ) {\r\n this._eventState = new EventState(0);\r\n\r\n if (onObserverAdded) {\r\n this._onObserverAdded = onObserverAdded;\r\n }\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback\r\n * @param callback the callback that will be executed for that Observer\r\n * @param mask the mask used to filter observers\r\n * @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.\r\n * @param scope optional scope for the callback to be called from\r\n * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification\r\n * @returns the new observer created for the callback\r\n */\r\n public add(callback?: null, mask?: number, insertFirst?: boolean, scope?: any, unregisterOnFirstCall?: boolean): null;\r\n public add(callback: (eventData: T, eventState: EventState) => void, mask?: number, insertFirst?: boolean, scope?: any, unregisterOnFirstCall?: boolean): Observer<T>;\r\n public add(\r\n callback?: ((eventData: T, eventState: EventState) => void) | null,\r\n mask?: number,\r\n insertFirst?: boolean,\r\n scope?: any,\r\n unregisterOnFirstCall?: boolean\r\n ): Nullable<Observer<T>>;\r\n public add(\r\n callback?: ((eventData: T, eventState: EventState) => void) | null,\r\n mask: number = -1,\r\n insertFirst = false,\r\n scope: any = null,\r\n unregisterOnFirstCall = false\r\n ): Nullable<Observer<T>> {\r\n if (!callback) {\r\n return null;\r\n }\r\n\r\n const observer = new Observer(callback, mask, scope);\r\n observer.unregisterOnNextCall = unregisterOnFirstCall;\r\n\r\n if (insertFirst) {\r\n this._observers.unshift(observer);\r\n } else {\r\n this._observers.push(observer);\r\n }\r\n\r\n if (this._onObserverAdded) {\r\n this._onObserverAdded(observer);\r\n }\r\n\r\n // If the observable was already triggered and the observable is set to notify if triggered, notify the new observer\r\n if (this._hasNotified && this.notifyIfTriggered) {\r\n if (this._lastNotifiedValue !== undefined) {\r\n this.notifyObserver(observer, this._lastNotifiedValue);\r\n }\r\n }\r\n\r\n // attach the remove function to the observer\r\n const observableWeakRef = IsWeakRefSupported ? new WeakRef(this) : { deref: () => this };\r\n observer._remove = (defer = false) => {\r\n const observable = observableWeakRef.deref();\r\n if (observable) {\r\n defer ? observable.remove(observer) : observable._remove(observer);\r\n }\r\n };\r\n\r\n return observer;\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback and unregisters after the next notification\r\n * @param callback the callback that will be executed for that Observer\r\n * @returns the new observer created for the callback\r\n */\r\n public addOnce(callback?: null): null;\r\n public addOnce(callback: (eventData: T, eventState: EventState) => void): Observer<T>;\r\n public addOnce(callback?: ((eventData: T, eventState: EventState) => void) | null): Nullable<Observer<T>>;\r\n public addOnce(callback?: ((eventData: T, eventState: EventState) => void) | null): Nullable<Observer<T>> {\r\n return this.add(callback, undefined, undefined, undefined, true);\r\n }\r\n\r\n /**\r\n * Remove an Observer from the Observable object\r\n * @param observer the instance of the Observer to remove\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public remove(observer: Nullable<Observer<T>>): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n observer._remove = null;\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Remove a callback from the Observable object\r\n * @param callback the callback to remove\r\n * @param scope optional scope. If used only the callbacks with this scope will be removed\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public removeCallback(callback: (eventData: T, eventState: EventState) => void, scope?: any): boolean {\r\n for (let index = 0; index < this._observers.length; index++) {\r\n const observer = this._observers[index];\r\n if (observer._willBeUnregistered) {\r\n continue;\r\n }\r\n if (observer.callback === callback && (!scope || scope === observer.scope)) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _deferUnregister(observer: Observer<T>): void {\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n this._numObserversMarkedAsDeleted++;\r\n observer.unregisterOnNextCall = false;\r\n observer._willBeUnregistered = true;\r\n setTimeout(() => {\r\n this._remove(observer);\r\n }, 0);\r\n }\r\n\r\n // This should only be called when not iterating over _observers to avoid callback skipping.\r\n // Removes an observer from the _observer Array.\r\n private _remove(observer: Nullable<Observer<T>>, updateCounter = true): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n if (updateCounter) {\r\n this._numObserversMarkedAsDeleted--;\r\n }\r\n this._observers.splice(index, 1);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Moves the observable to the top of the observer list making it get called first when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverTopPriority(observer: Observer<T>) {\r\n this._remove(observer, false);\r\n this._observers.unshift(observer);\r\n }\r\n\r\n /**\r\n * Moves the observable to the bottom of the observer list making it get called last when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverBottomPriority(observer: Observer<T>) {\r\n this._remove(observer, false);\r\n this._observers.push(observer);\r\n }\r\n\r\n /**\r\n * Notify all Observers by calling their respective callback with the given data\r\n * Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute\r\n * @param eventData defines the data to send to all observers\r\n * @param mask defines the mask of the current notification (observers with incompatible mask (ie mask & observer.mask === 0) will not be notified)\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @param userInfo defines any user info to send to observers\r\n * @returns false if the complete observer chain was not processed (because one observer set the skipNextObservers to true)\r\n */\r\n public notifyObservers(eventData: T, mask: number = -1, target?: any, currentTarget?: any, userInfo?: any): boolean {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (!this._observers.length) {\r\n return true;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.target = target;\r\n state.currentTarget = currentTarget;\r\n state.skipNextObservers = false;\r\n state.lastReturnValue = eventData;\r\n state.userInfo = userInfo;\r\n\r\n for (const obs of this._observers) {\r\n if (obs._willBeUnregistered) {\r\n continue;\r\n }\r\n\r\n if (obs.mask & mask) {\r\n if (obs.unregisterOnNextCall) {\r\n this._deferUnregister(obs);\r\n }\r\n\r\n if (obs.scope) {\r\n state.lastReturnValue = obs.callback.apply(obs.scope, [eventData, state]);\r\n } else {\r\n state.lastReturnValue = obs.callback(eventData, state);\r\n }\r\n }\r\n if (state.skipNextObservers) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Notify a specific observer\r\n * @param observer defines the observer to notify\r\n * @param eventData defines the data to be sent to each callback\r\n * @param mask is used to filter observers defaults to -1\r\n */\r\n public notifyObserver(observer: Observer<T>, eventData: T, mask: number = -1): void {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.skipNextObservers = false;\r\n\r\n if (observer.unregisterOnNextCall) {\r\n this._deferUnregister(observer);\r\n }\r\n\r\n observer.callback(eventData, state);\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the observable has at least one observer\r\n * @returns true is the Observable has at least one Observer registered\r\n */\r\n public hasObservers(): boolean {\r\n return this._observers.length - this._numObserversMarkedAsDeleted > 0;\r\n }\r\n\r\n /**\r\n * Clear the list of observers\r\n */\r\n public clear(): void {\r\n while (this._observers.length) {\r\n const o = this._observers.pop();\r\n if (o) {\r\n o._remove = null;\r\n }\r\n }\r\n this._onObserverAdded = null;\r\n this._numObserversMarkedAsDeleted = 0;\r\n this.cleanLastNotifiedState();\r\n }\r\n\r\n /**\r\n * Clean the last notified state - both the internal last value and the has-notified flag\r\n */\r\n public cleanLastNotifiedState(): void {\r\n this._hasNotified = false;\r\n this._lastNotifiedValue = undefined;\r\n }\r\n\r\n /**\r\n * Clone the current observable\r\n * @returns a new observable\r\n */\r\n public clone(): Observable<T> {\r\n const result = new Observable<T>();\r\n\r\n result._observers = this._observers.slice(0);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Does this observable handles observer registered with a given mask\r\n * @param mask defines the mask to be tested\r\n * @returns whether or not one observer registered with the given mask is handled\r\n **/\r\n public hasSpecificMask(mask: number = -1): boolean {\r\n for (const obs of this._observers) {\r\n if (obs.mask & mask || obs.mask === mask) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"observable.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/observable.ts"],"names":[],"mappings":"AAIA,MAAM,kBAAkB,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB;;;;;;OAMG;IACH,YAAY,IAAY,EAAE,iBAAiB,GAAG,KAAK,EAAE,MAAY,EAAE,aAAmB;QAClF,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;;OAOG;IACI,UAAU,CAAC,IAAY,EAAE,iBAAiB,GAAG,KAAK,EAAE,MAAY,EAAE,aAAmB;QACxF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,MAAM,G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CAAC,CAAC;IACxC,CAAC;IAED;;;OAGG;IACI,YAAY;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,4BAA4B,GAAG,CAAC,CAAC;IAC1E,CAAC;IAED;;OAEG;IACI,KAAK;QACR,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;YAChC,IAAI,CAAC,EAAE,CAAC;gBACJ,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC;YACrB,CAAC;QACL,CAAC;QACD,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,IAAI,CAAC,4BAA4B,GAAG,CAAC,CAAC;QACtC,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAClC,CAAC;IAED;;OAEG;IACI,sBAAsB;QACzB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;IACxC,CAAC;IAED;;;OAGG;IACI,KAAK;QACR,MAAM,MAAM,GAAG,IAAI,UAAU,EAAK,CAAC;QAEnC,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAE7C,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;QAII;IACG,eAAe,CAAC,OAAe,CAAC,CAAC;QACpC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAChC,IAAI,GAAG,CAAC,IAAI,GAAG,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;gBACvC,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\n\r\ndeclare const WeakRef: any;\r\n\r\nconst IsWeakRefSupported = typeof WeakRef !== \"undefined\";\r\n\r\n/**\r\n * A class serves as a medium between the observable and its observers\r\n */\r\nexport class EventState {\r\n /**\r\n * Create a new EventState\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n */\r\n constructor(mask: number, skipNextObservers = false, target?: any, currentTarget?: any) {\r\n this.initialize(mask, skipNextObservers, target, currentTarget);\r\n }\r\n\r\n /**\r\n * Initialize the current event state\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @returns the current event state\r\n */\r\n public initialize(mask: number, skipNextObservers = false, target?: any, currentTarget?: any): EventState {\r\n this.mask = mask;\r\n this.skipNextObservers = skipNextObservers;\r\n this.target = target;\r\n this.currentTarget = currentTarget;\r\n return this;\r\n }\r\n\r\n /**\r\n * An Observer can set this property to true to prevent subsequent observers of being notified\r\n */\r\n public skipNextObservers: boolean;\r\n\r\n /**\r\n * Get the mask value that were used to trigger the event corresponding to this EventState object\r\n */\r\n public mask: number;\r\n\r\n /**\r\n * The object that originally notified the event\r\n */\r\n public target?: any;\r\n\r\n /**\r\n * The current object in the bubbling phase\r\n */\r\n public currentTarget?: any;\r\n\r\n /**\r\n * This will be populated with the return value of the last function that was executed.\r\n * If it is the first function in the callback chain it will be the event data.\r\n */\r\n public lastReturnValue?: any;\r\n\r\n /**\r\n * User defined information that will be sent to observers\r\n */\r\n public userInfo?: any;\r\n}\r\n\r\n/**\r\n * Represent an observer registered to a given IObservable object.\r\n */\r\nexport interface IObserver {\r\n /**\r\n * Remove the observer from its observable\r\n * @param defer if true, the removal will be deferred to avoid callback skipping (default: false)\r\n */\r\n remove(defer?: boolean): void;\r\n}\r\n\r\n/**\r\n * Represent an observer registered to a given Observable object.\r\n */\r\nexport class Observer<T> implements IObserver {\r\n /** @internal */\r\n public _willBeUnregistered = false;\r\n /**\r\n * Gets or sets a property defining that the observer as to be unregistered after the next notification\r\n */\r\n public unregisterOnNextCall = false;\r\n\r\n /**\r\n * this function can be used to remove the observer from the observable.\r\n * It will be set by the observable that the observer belongs to.\r\n * @internal\r\n */\r\n public _remove: Nullable<(defer?: boolean) => void> = null;\r\n\r\n /**\r\n * Creates a new observer\r\n * @param callback defines the callback to call when the observer is notified\r\n * @param mask defines the mask of the observer (used to filter notifications)\r\n * @param scope defines the current scope used to restore the JS context\r\n */\r\n constructor(\r\n /**\r\n * Defines the callback to call when the observer is notified\r\n */\r\n public callback: (eventData: T, eventState: EventState) => void,\r\n /**\r\n * Defines the mask of the observer (used to filter notifications)\r\n */\r\n public mask: number,\r\n /**\r\n * [null] Defines the current scope used to restore the JS context\r\n */\r\n public scope: any = null\r\n ) {}\r\n\r\n /**\r\n * Remove the observer from its observable\r\n * This can be used instead of using the observable's remove function.\r\n * @param defer if true, the removal will be deferred to avoid callback skipping (default: false)\r\n */\r\n public remove(defer = false) {\r\n if (this._remove) {\r\n this._remove(defer);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * An interface that defines the reader side of an Observable (receive notifications).\r\n */\r\nexport interface IReadonlyObservable<T = unknown> {\r\n /**\r\n * Create a new Observer with the specified callback\r\n * @param callback the callback that will be executed for that Observer\r\n * @param mask the mask used to filter observers\r\n * @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.\r\n * @param scope optional scope for the callback to be called from\r\n * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification\r\n * @returns the new observer created for the callback\r\n */\r\n add(callback: (eventData: T, eventState: EventState) => void, mask?: number, insertFirst?: boolean, scope?: unknown, unregisterOnFirstCall?: boolean): IObserver;\r\n\r\n /**\r\n * Create a new Observer with the specified callback and unregisters after the next notification\r\n * @param callback the callback that will be executed for that Observer\r\n * @returns the new observer created for the callback\r\n */\r\n addOnce(callback: (eventData: T, eventState: EventState) => void): IObserver;\r\n}\r\n\r\n/**\r\n * The Observable class is a simple implementation of the Observable pattern.\r\n *\r\n * There's one slight particularity though: a given Observable can notify its observer using a particular mask value, only the Observers registered with this mask value will be notified.\r\n * This enable a more fine grained execution without having to rely on multiple different Observable objects.\r\n * For instance you may have a given Observable that have four different types of notifications: Move (mask = 0x01), Stop (mask = 0x02), Turn Right (mask = 0X04), Turn Left (mask = 0X08).\r\n * A given observer can register itself with only Move and Stop (mask = 0x03), then it will only be notified when one of these two occurs and will never be for Turn Left/Right.\r\n */\r\nexport class Observable<T> implements IReadonlyObservable<T> {\r\n private _observers = new Array<Observer<T>>();\r\n private _numObserversMarkedAsDeleted = 0;\r\n private _hasNotified = false;\r\n private _lastNotifiedValue?: T;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _eventState: EventState;\r\n\r\n private _onObserverAdded: Nullable<(observer: Observer<T>) => void>;\r\n\r\n /**\r\n * Create an observable from a Promise.\r\n * @param promise a promise to observe for fulfillment.\r\n * @param onErrorObservable an observable to notify if a promise was rejected.\r\n * @returns the new Observable\r\n */\r\n public static FromPromise<T, E = Error>(promise: Promise<T>, onErrorObservable?: Observable<E>): Observable<T> {\r\n const observable = new Observable<T>();\r\n\r\n promise\r\n // eslint-disable-next-line github/no-then\r\n .then((ret: T) => {\r\n observable.notifyObservers(ret);\r\n })\r\n // eslint-disable-next-line github/no-then\r\n .catch((err) => {\r\n if (onErrorObservable) {\r\n onErrorObservable.notifyObservers(err as E);\r\n } else {\r\n throw err;\r\n }\r\n });\r\n\r\n return observable;\r\n }\r\n\r\n /**\r\n * Gets the list of observers\r\n * Note that observers that were recently deleted may still be present in the list because they are only really deleted on the next javascript tick!\r\n */\r\n public get observers(): Array<Observer<T>> {\r\n return this._observers;\r\n }\r\n\r\n /**\r\n * Creates a new observable\r\n * @param onObserverAdded defines a callback to call when a new observer is added\r\n * @param notifyIfTriggered If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n */\r\n constructor(\r\n onObserverAdded?: (observer: Observer<T>) => void,\r\n /**\r\n * [false] If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n * This is helpful to single-state observables like the scene onReady or the dispose observable.\r\n */\r\n public notifyIfTriggered = false\r\n ) {\r\n this._eventState = new EventState(0);\r\n\r\n if (onObserverAdded) {\r\n this._onObserverAdded = onObserverAdded;\r\n }\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback\r\n * @param callback the callback that will be executed for that Observer\r\n * @param mask the mask used to filter observers\r\n * @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.\r\n * @param scope optional scope for the callback to be called from\r\n * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification\r\n * @returns the new observer created for the callback\r\n */\r\n public add(callback?: null, mask?: number, insertFirst?: boolean, scope?: any, unregisterOnFirstCall?: boolean): null;\r\n public add(callback: (eventData: T, eventState: EventState) => void, mask?: number, insertFirst?: boolean, scope?: any, unregisterOnFirstCall?: boolean): Observer<T>;\r\n public add(\r\n callback?: ((eventData: T, eventState: EventState) => void) | null,\r\n mask?: number,\r\n insertFirst?: boolean,\r\n scope?: any,\r\n unregisterOnFirstCall?: boolean\r\n ): Nullable<Observer<T>>;\r\n public add(\r\n callback?: ((eventData: T, eventState: EventState) => void) | null,\r\n mask: number = -1,\r\n insertFirst = false,\r\n scope: any = null,\r\n unregisterOnFirstCall = false\r\n ): Nullable<Observer<T>> {\r\n if (!callback) {\r\n return null;\r\n }\r\n\r\n const observer = new Observer(callback, mask, scope);\r\n observer.unregisterOnNextCall = unregisterOnFirstCall;\r\n\r\n if (insertFirst) {\r\n this._observers.unshift(observer);\r\n } else {\r\n this._observers.push(observer);\r\n }\r\n\r\n if (this._onObserverAdded) {\r\n this._onObserverAdded(observer);\r\n }\r\n\r\n // If the observable was already triggered and the observable is set to notify if triggered, notify the new observer\r\n if (this._hasNotified && this.notifyIfTriggered) {\r\n if (this._lastNotifiedValue !== undefined) {\r\n this.notifyObserver(observer, this._lastNotifiedValue);\r\n }\r\n }\r\n\r\n // attach the remove function to the observer\r\n const observableWeakRef = IsWeakRefSupported ? new WeakRef(this) : { deref: () => this };\r\n observer._remove = (defer = false) => {\r\n const observable = observableWeakRef.deref();\r\n if (observable) {\r\n defer ? observable.remove(observer) : observable._remove(observer);\r\n }\r\n };\r\n\r\n return observer;\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback and unregisters after the next notification\r\n * @param callback the callback that will be executed for that Observer\r\n * @returns the new observer created for the callback\r\n */\r\n public addOnce(callback?: null): null;\r\n public addOnce(callback: (eventData: T, eventState: EventState) => void): Observer<T>;\r\n public addOnce(callback?: ((eventData: T, eventState: EventState) => void) | null): Nullable<Observer<T>>;\r\n public addOnce(callback?: ((eventData: T, eventState: EventState) => void) | null): Nullable<Observer<T>> {\r\n return this.add(callback, undefined, undefined, undefined, true);\r\n }\r\n\r\n /**\r\n * Remove an Observer from the Observable object\r\n * @param observer the instance of the Observer to remove\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public remove(observer: Nullable<Observer<T>>): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n observer._remove = null;\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Remove a callback from the Observable object\r\n * @param callback the callback to remove\r\n * @param scope optional scope. If used only the callbacks with this scope will be removed\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public removeCallback(callback: (eventData: T, eventState: EventState) => void, scope?: any): boolean {\r\n for (let index = 0; index < this._observers.length; index++) {\r\n const observer = this._observers[index];\r\n if (observer._willBeUnregistered) {\r\n continue;\r\n }\r\n if (observer.callback === callback && (!scope || scope === observer.scope)) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _deferUnregister(observer: Observer<T>): void {\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n this._numObserversMarkedAsDeleted++;\r\n observer.unregisterOnNextCall = false;\r\n observer._willBeUnregistered = true;\r\n setTimeout(() => {\r\n this._remove(observer);\r\n }, 0);\r\n }\r\n\r\n // This should only be called when not iterating over _observers to avoid callback skipping.\r\n // Removes an observer from the _observer Array.\r\n private _remove(observer: Nullable<Observer<T>>, updateCounter = true): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n if (updateCounter) {\r\n this._numObserversMarkedAsDeleted--;\r\n }\r\n this._observers.splice(index, 1);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Moves the observable to the top of the observer list making it get called first when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverTopPriority(observer: Observer<T>) {\r\n this._remove(observer, false);\r\n this._observers.unshift(observer);\r\n }\r\n\r\n /**\r\n * Moves the observable to the bottom of the observer list making it get called last when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverBottomPriority(observer: Observer<T>) {\r\n this._remove(observer, false);\r\n this._observers.push(observer);\r\n }\r\n\r\n /**\r\n * Notify all Observers by calling their respective callback with the given data\r\n * Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute\r\n * @param eventData defines the data to send to all observers\r\n * @param mask defines the mask of the current notification (observers with incompatible mask (ie mask & observer.mask === 0) will not be notified)\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @param userInfo defines any user info to send to observers\r\n * @returns false if the complete observer chain was not processed (because one observer set the skipNextObservers to true)\r\n */\r\n public notifyObservers(eventData: T, mask: number = -1, target?: any, currentTarget?: any, userInfo?: any): boolean {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (!this._observers.length) {\r\n return true;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.target = target;\r\n state.currentTarget = currentTarget;\r\n state.skipNextObservers = false;\r\n state.lastReturnValue = eventData;\r\n state.userInfo = userInfo;\r\n\r\n for (const obs of this._observers) {\r\n if (obs._willBeUnregistered) {\r\n continue;\r\n }\r\n\r\n if (obs.mask & mask) {\r\n if (obs.unregisterOnNextCall) {\r\n this._deferUnregister(obs);\r\n }\r\n\r\n if (obs.scope) {\r\n state.lastReturnValue = obs.callback.apply(obs.scope, [eventData, state]);\r\n } else {\r\n state.lastReturnValue = obs.callback(eventData, state);\r\n }\r\n }\r\n if (state.skipNextObservers) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Notify a specific observer\r\n * @param observer defines the observer to notify\r\n * @param eventData defines the data to be sent to each callback\r\n * @param mask is used to filter observers defaults to -1\r\n */\r\n public notifyObserver(observer: Observer<T>, eventData: T, mask: number = -1): void {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.skipNextObservers = false;\r\n\r\n if (observer.unregisterOnNextCall) {\r\n this._deferUnregister(observer);\r\n }\r\n\r\n observer.callback(eventData, state);\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the observable has at least one observer\r\n * @returns true is the Observable has at least one Observer registered\r\n */\r\n public hasObservers(): boolean {\r\n return this._observers.length - this._numObserversMarkedAsDeleted > 0;\r\n }\r\n\r\n /**\r\n * Clear the list of observers\r\n */\r\n public clear(): void {\r\n while (this._observers.length) {\r\n const o = this._observers.pop();\r\n if (o) {\r\n o._remove = null;\r\n }\r\n }\r\n this._onObserverAdded = null;\r\n this._numObserversMarkedAsDeleted = 0;\r\n this.cleanLastNotifiedState();\r\n }\r\n\r\n /**\r\n * Clean the last notified state - both the internal last value and the has-notified flag\r\n */\r\n public cleanLastNotifiedState(): void {\r\n this._hasNotified = false;\r\n this._lastNotifiedValue = undefined;\r\n }\r\n\r\n /**\r\n * Clone the current observable\r\n * @returns a new observable\r\n */\r\n public clone(): Observable<T> {\r\n const result = new Observable<T>();\r\n\r\n result._observers = this._observers.slice(0);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Does this observable handles observer registered with a given mask\r\n * @param mask defines the mask to be tested\r\n * @returns whether or not one observer registered with the given mask is handled\r\n **/\r\n public hasSpecificMask(mask: number = -1): boolean {\r\n for (const obs of this._observers) {\r\n if (obs.mask & mask || obs.mask === mask) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,47 @@
1
+ import type { Nullable, EffectWrapperCreationOptions, AbstractEngine, InternalTexture, Scene } from "../index.js";
2
+ import { Observable } from "./observable.js";
3
+ import { EffectWrapper } from "../Materials/effectRenderer.js";
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare enum DepthTextureType {
8
+ NormalizedViewDepth = 0,
9
+ ViewDepth = 1,
10
+ ScreenDepth = 2
11
+ }
12
+ /**
13
+ * @internal
14
+ */
15
+ export declare class ThinMinMaxReducerPostProcess extends EffectWrapper {
16
+ static readonly FragmentUrl = "minmaxRedux";
17
+ static readonly Uniforms: string[];
18
+ protected _gatherImports(useWebGPU: boolean, list: Promise<any>[]): void;
19
+ textureWidth: number;
20
+ textureHeight: number;
21
+ constructor(name: string, engine?: Nullable<AbstractEngine>, defines?: string, options?: EffectWrapperCreationOptions);
22
+ bind(noDefaultBindings?: boolean): void;
23
+ }
24
+ /**
25
+ * @internal
26
+ */
27
+ export declare class ThinMinMaxReducer {
28
+ readonly onAfterReductionPerformed: Observable<{
29
+ min: number;
30
+ max: number;
31
+ }>;
32
+ readonly reductionSteps: Array<ThinMinMaxReducerPostProcess>;
33
+ private _depthRedux;
34
+ private _depthTextureType;
35
+ get depthRedux(): boolean;
36
+ set depthRedux(value: boolean);
37
+ protected readonly _scene: Scene;
38
+ private _textureWidth;
39
+ private _textureHeight;
40
+ get textureWidth(): number;
41
+ get textureHeight(): number;
42
+ constructor(scene: Scene, depthRedux?: boolean);
43
+ setTextureDimensions(width: number, height: number, depthTextureType?: DepthTextureType): boolean;
44
+ readMinMax(texture: InternalTexture): void;
45
+ dispose(disposeAll?: boolean): void;
46
+ private _recreatePostProcesses;
47
+ }
@@ -0,0 +1,148 @@
1
+ import { Observable } from "./observable.js";
2
+ import { EffectWrapper } from "../Materials/effectRenderer.js";
3
+ import { Engine } from "../Engines/engine.js";
4
+ /**
5
+ * @internal
6
+ */
7
+ export var DepthTextureType;
8
+ (function (DepthTextureType) {
9
+ DepthTextureType[DepthTextureType["NormalizedViewDepth"] = 0] = "NormalizedViewDepth";
10
+ DepthTextureType[DepthTextureType["ViewDepth"] = 1] = "ViewDepth";
11
+ DepthTextureType[DepthTextureType["ScreenDepth"] = 2] = "ScreenDepth";
12
+ })(DepthTextureType || (DepthTextureType = {}));
13
+ /**
14
+ * @internal
15
+ */
16
+ export class ThinMinMaxReducerPostProcess extends EffectWrapper {
17
+ _gatherImports(useWebGPU, list) {
18
+ if (useWebGPU) {
19
+ this._webGPUReady = true;
20
+ list.push(import("../ShadersWGSL/minmaxRedux.fragment.js"));
21
+ }
22
+ else {
23
+ list.push(import("../Shaders/minmaxRedux.fragment.js"));
24
+ }
25
+ }
26
+ constructor(name, engine = null, defines = "", options) {
27
+ super({
28
+ ...options,
29
+ name,
30
+ engine: engine || Engine.LastCreatedEngine,
31
+ useShaderStore: true,
32
+ useAsPostProcess: true,
33
+ fragmentShader: ThinMinMaxReducerPostProcess.FragmentUrl,
34
+ uniforms: ThinMinMaxReducerPostProcess.Uniforms,
35
+ defines,
36
+ });
37
+ this.textureWidth = 0;
38
+ this.textureHeight = 0;
39
+ }
40
+ bind(noDefaultBindings = false) {
41
+ super.bind(noDefaultBindings);
42
+ const effect = this.drawWrapper.effect;
43
+ if (this.textureWidth === 1 || this.textureHeight === 1) {
44
+ effect.setInt2("texSize", this.textureWidth, this.textureHeight);
45
+ }
46
+ else {
47
+ effect.setFloat2("texSize", this.textureWidth, this.textureHeight);
48
+ }
49
+ }
50
+ }
51
+ ThinMinMaxReducerPostProcess.FragmentUrl = "minmaxRedux";
52
+ ThinMinMaxReducerPostProcess.Uniforms = ["texSize"];
53
+ const BufferFloat = new Float32Array(4 * 1 * 1);
54
+ const BufferUint8 = new Uint8Array(4 * 1 * 1);
55
+ const MinMax = { min: 0, max: 0 };
56
+ /**
57
+ * @internal
58
+ */
59
+ export class ThinMinMaxReducer {
60
+ get depthRedux() {
61
+ return this._depthRedux;
62
+ }
63
+ set depthRedux(value) {
64
+ if (this._depthRedux === value) {
65
+ return;
66
+ }
67
+ this._depthRedux = value;
68
+ this._recreatePostProcesses();
69
+ }
70
+ get textureWidth() {
71
+ return this._textureWidth;
72
+ }
73
+ get textureHeight() {
74
+ return this._textureHeight;
75
+ }
76
+ constructor(scene, depthRedux = true) {
77
+ this.onAfterReductionPerformed = new Observable();
78
+ this._textureWidth = 0;
79
+ this._textureHeight = 0;
80
+ this._scene = scene;
81
+ this._depthRedux = depthRedux;
82
+ this.reductionSteps = [];
83
+ }
84
+ setTextureDimensions(width, height, depthTextureType = 0 /* DepthTextureType.NormalizedViewDepth */) {
85
+ if (width === this._textureWidth && height === this._textureHeight && depthTextureType === this._depthTextureType) {
86
+ return false;
87
+ }
88
+ this._textureWidth = width;
89
+ this._textureHeight = height;
90
+ this._depthTextureType = depthTextureType;
91
+ this._recreatePostProcesses();
92
+ return true;
93
+ }
94
+ readMinMax(texture) {
95
+ // Note that we should normally await the call to _readTexturePixels!
96
+ // But because WebGL does the read synchronously, we know the values will be updated without waiting for the promise to be resolved, which will let us get the updated values
97
+ // in the current frame, whereas in WebGPU, the read is asynchronous and we should normally wait for the promise to be resolved to get the updated values.
98
+ // However, it's safe to avoid waiting for the promise to be resolved in WebGPU as well, because we will simply use the current values until "buffer" is updated later on.
99
+ // Note that it means we can suffer some rendering artifacts in WebGPU because we may use previous min/max values for the current frame.
100
+ const isFloat = texture.type === Engine.TEXTURETYPE_FLOAT || texture.type === Engine.TEXTURETYPE_HALF_FLOAT;
101
+ const buffer = isFloat ? BufferFloat : BufferUint8;
102
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
103
+ this._scene.getEngine()._readTexturePixels(texture, 1, 1, -1, 0, buffer, false);
104
+ MinMax.min = buffer[0];
105
+ MinMax.max = buffer[1];
106
+ if (!isFloat) {
107
+ MinMax.min = MinMax.min / 255.0;
108
+ MinMax.max = MinMax.max / 255.0;
109
+ }
110
+ if (MinMax.min >= MinMax.max) {
111
+ MinMax.min = 0;
112
+ MinMax.max = 1;
113
+ }
114
+ this.onAfterReductionPerformed.notifyObservers(MinMax);
115
+ }
116
+ dispose(disposeAll = true) {
117
+ if (disposeAll) {
118
+ this.onAfterReductionPerformed.clear();
119
+ this._textureWidth = 0;
120
+ this._textureHeight = 0;
121
+ }
122
+ for (let i = 0; i < this.reductionSteps.length; ++i) {
123
+ this.reductionSteps[i].dispose();
124
+ }
125
+ this.reductionSteps.length = 0;
126
+ }
127
+ _recreatePostProcesses() {
128
+ this.dispose(false);
129
+ const scene = this._scene;
130
+ let w = this.textureWidth, h = this.textureHeight;
131
+ const reductionInitial = new ThinMinMaxReducerPostProcess("Initial reduction phase", scene.getEngine(), "#define INITIAL" + (this._depthRedux ? "\n#define DEPTH_REDUX" : "") + (this._depthTextureType === 1 /* DepthTextureType.ViewDepth */ ? "\n#define VIEW_DEPTH" : ""));
132
+ reductionInitial.textureWidth = w;
133
+ reductionInitial.textureHeight = h;
134
+ this.reductionSteps.push(reductionInitial);
135
+ let index = 1;
136
+ // create the additional steps
137
+ while (w > 1 || h > 1) {
138
+ w = Math.max(Math.round(w / 2), 1);
139
+ h = Math.max(Math.round(h / 2), 1);
140
+ const reduction = new ThinMinMaxReducerPostProcess("Reduction phase " + index, scene.getEngine(), "#define " + (w == 1 && h == 1 ? "LAST" : w == 1 || h == 1 ? "ONEBEFORELAST" : "MAIN"));
141
+ reduction.textureWidth = w;
142
+ reduction.textureHeight = h;
143
+ this.reductionSteps.push(reduction);
144
+ index++;
145
+ }
146
+ }
147
+ }
148
+ //# sourceMappingURL=thinMinMaxReducer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thinMinMaxReducer.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/thinMinMaxReducer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,6BAA4B;AAE7C;;GAEG;AACH,MAAM,CAAN,IAAkB,gBAIjB;AAJD,WAAkB,gBAAgB;IAC9B,qFAAuB,CAAA;IACvB,iEAAa,CAAA;IACb,qEAAe,CAAA;AACnB,CAAC,EAJiB,gBAAgB,KAAhB,gBAAgB,QAIjC;AAED;;GAEG;AACH,MAAM,OAAO,4BAA6B,SAAQ,aAAa;IAKxC,cAAc,CAAC,SAAkB,EAAE,IAAoB;QACtE,IAAI,SAAS,EAAE,CAAC;YACZ,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,qCAAqC,CAAC,CAAC,CAAC;QAC7D,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,iCAAiC,CAAC,CAAC,CAAC;QACzD,CAAC;IACL,CAAC;IAMD,YAAY,IAAY,EAAE,SAAmC,IAAI,EAAE,OAAO,GAAG,EAAE,EAAE,OAAsC;QACnH,KAAK,CAAC;YACF,GAAG,OAAO;YACV,IAAI;YACJ,MAAM,EAAE,MAAM,IAAI,MAAM,CAAC,iBAAkB;YAC3C,cAAc,EAAE,IAAI;YACpB,gBAAgB,EAAE,IAAI;YACtB,cAAc,EAAE,4BAA4B,CAAC,WAAW;YACxD,QAAQ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CACzF,CAAC;YAEF,SAAS,CAAC,YAAY,GAAG,CAAC,CAAC;YAC3B,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC;YAE5B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAEpC,KAAK,EAAE,CAAC;QACZ,CAAC;IACL,CAAC;CACJ","sourcesContent":["/* eslint-disable import/no-internal-modules */\r\nimport type { Nullable, EffectWrapperCreationOptions, AbstractEngine, InternalTexture, Scene } from \"core/index\";\r\nimport { Observable } from \"./observable\";\r\nimport { EffectWrapper } from \"../Materials/effectRenderer\";\r\nimport { Engine } from \"core/Engines/engine\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport const enum DepthTextureType {\r\n NormalizedViewDepth = 0,\r\n ViewDepth = 1,\r\n ScreenDepth = 2,\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class ThinMinMaxReducerPostProcess extends EffectWrapper {\r\n public static readonly FragmentUrl = \"minmaxRedux\";\r\n\r\n public static readonly Uniforms = [\"texSize\"];\r\n\r\n protected override _gatherImports(useWebGPU: boolean, list: Promise<any>[]) {\r\n if (useWebGPU) {\r\n this._webGPUReady = true;\r\n list.push(import(\"../ShadersWGSL/minmaxRedux.fragment\"));\r\n } else {\r\n list.push(import(\"../Shaders/minmaxRedux.fragment\"));\r\n }\r\n }\r\n\r\n public textureWidth = 0;\r\n\r\n public textureHeight = 0;\r\n\r\n constructor(name: string, engine: Nullable<AbstractEngine> = null, defines = \"\", options?: EffectWrapperCreationOptions) {\r\n super({\r\n ...options,\r\n name,\r\n engine: engine || Engine.LastCreatedEngine!,\r\n useShaderStore: true,\r\n useAsPostProcess: true,\r\n fragmentShader: ThinMinMaxReducerPostProcess.FragmentUrl,\r\n uniforms: ThinMinMaxReducerPostProcess.Uniforms,\r\n defines,\r\n });\r\n }\r\n\r\n public override bind(noDefaultBindings = false) {\r\n super.bind(noDefaultBindings);\r\n\r\n const effect = this.drawWrapper.effect!;\r\n\r\n if (this.textureWidth === 1 || this.textureHeight === 1) {\r\n effect.setInt2(\"texSize\", this.textureWidth, this.textureHeight);\r\n } else {\r\n effect.setFloat2(\"texSize\", this.textureWidth, this.textureHeight);\r\n }\r\n }\r\n}\r\n\r\nconst BufferFloat = new Float32Array(4 * 1 * 1);\r\nconst BufferUint8 = new Uint8Array(4 * 1 * 1);\r\nconst MinMax = { min: 0, max: 0 };\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class ThinMinMaxReducer {\r\n public readonly onAfterReductionPerformed = new Observable<{ min: number; max: number }>();\r\n\r\n public readonly reductionSteps: Array<ThinMinMaxReducerPostProcess>;\r\n\r\n private _depthRedux: boolean;\r\n private _depthTextureType: DepthTextureType;\r\n\r\n public get depthRedux() {\r\n return this._depthRedux;\r\n }\r\n\r\n public set depthRedux(value: boolean) {\r\n if (this._depthRedux === value) {\r\n return;\r\n }\r\n\r\n this._depthRedux = value;\r\n\r\n this._recreatePostProcesses();\r\n }\r\n\r\n protected readonly _scene: Scene;\r\n\r\n private _textureWidth = 0;\r\n private _textureHeight = 0;\r\n\r\n public get textureWidth() {\r\n return this._textureWidth;\r\n }\r\n\r\n public get textureHeight() {\r\n return this._textureHeight;\r\n }\r\n\r\n constructor(scene: Scene, depthRedux = true) {\r\n this._scene = scene;\r\n this._depthRedux = depthRedux;\r\n this.reductionSteps = [];\r\n }\r\n\r\n public setTextureDimensions(width: number, height: number, depthTextureType: DepthTextureType = DepthTextureType.NormalizedViewDepth) {\r\n if (width === this._textureWidth && height === this._textureHeight && depthTextureType === this._depthTextureType) {\r\n return false;\r\n }\r\n\r\n this._textureWidth = width;\r\n this._textureHeight = height;\r\n this._depthTextureType = depthTextureType;\r\n\r\n this._recreatePostProcesses();\r\n\r\n return true;\r\n }\r\n\r\n public readMinMax(texture: InternalTexture) {\r\n // Note that we should normally await the call to _readTexturePixels!\r\n // But because WebGL does the read synchronously, we know the values will be updated without waiting for the promise to be resolved, which will let us get the updated values\r\n // in the current frame, whereas in WebGPU, the read is asynchronous and we should normally wait for the promise to be resolved to get the updated values.\r\n // However, it's safe to avoid waiting for the promise to be resolved in WebGPU as well, because we will simply use the current values until \"buffer\" is updated later on.\r\n // Note that it means we can suffer some rendering artifacts in WebGPU because we may use previous min/max values for the current frame.\r\n const isFloat = texture.type === Engine.TEXTURETYPE_FLOAT || texture.type === Engine.TEXTURETYPE_HALF_FLOAT;\r\n const buffer = isFloat ? BufferFloat : BufferUint8;\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n this._scene.getEngine()._readTexturePixels(texture, 1, 1, -1, 0, buffer, false);\r\n\r\n MinMax.min = buffer[0];\r\n MinMax.max = buffer[1];\r\n\r\n if (!isFloat) {\r\n MinMax.min = MinMax.min / 255.0;\r\n MinMax.max = MinMax.max / 255.0;\r\n }\r\n\r\n if (MinMax.min >= MinMax.max) {\r\n MinMax.min = 0;\r\n MinMax.max = 1;\r\n }\r\n\r\n this.onAfterReductionPerformed.notifyObservers(MinMax);\r\n }\r\n\r\n public dispose(disposeAll = true): void {\r\n if (disposeAll) {\r\n this.onAfterReductionPerformed.clear();\r\n this._textureWidth = 0;\r\n this._textureHeight = 0;\r\n }\r\n\r\n for (let i = 0; i < this.reductionSteps.length; ++i) {\r\n this.reductionSteps[i].dispose();\r\n }\r\n this.reductionSteps.length = 0;\r\n }\r\n\r\n private _recreatePostProcesses() {\r\n this.dispose(false);\r\n\r\n const scene = this._scene;\r\n\r\n let w = this.textureWidth,\r\n h = this.textureHeight;\r\n\r\n const reductionInitial = new ThinMinMaxReducerPostProcess(\r\n \"Initial reduction phase\",\r\n scene.getEngine(),\r\n \"#define INITIAL\" + (this._depthRedux ? \"\\n#define DEPTH_REDUX\" : \"\") + (this._depthTextureType === DepthTextureType.ViewDepth ? \"\\n#define VIEW_DEPTH\" : \"\")\r\n );\r\n\r\n reductionInitial.textureWidth = w;\r\n reductionInitial.textureHeight = h;\r\n\r\n this.reductionSteps.push(reductionInitial);\r\n\r\n let index = 1;\r\n\r\n // create the additional steps\r\n while (w > 1 || h > 1) {\r\n w = Math.max(Math.round(w / 2), 1);\r\n h = Math.max(Math.round(h / 2), 1);\r\n\r\n const reduction = new ThinMinMaxReducerPostProcess(\r\n \"Reduction phase \" + index,\r\n scene.getEngine(),\r\n \"#define \" + (w == 1 && h == 1 ? \"LAST\" : w == 1 || h == 1 ? \"ONEBEFORELAST\" : \"MAIN\")\r\n );\r\n\r\n reduction.textureWidth = w;\r\n reduction.textureHeight = h;\r\n\r\n this.reductionSteps.push(reduction);\r\n\r\n index++;\r\n }\r\n }\r\n}\r\n"]}
@@ -19,6 +19,11 @@ export declare class CustomParticleEmitter implements IParticleEmitterType {
19
19
  * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles
20
20
  */
21
21
  particleDestinationGenerator: (index: number, particle: Nullable<Particle>, outDestination: Vector3) => void;
22
+ /**
23
+ * Gets or sets the direction generator that will create the initial direction of each particle.
24
+ * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles
25
+ */
26
+ particleDirectionGenerator: (index: number, particle: Nullable<Particle>, outDestination: Vector3) => void;
22
27
  /**
23
28
  * Creates a new instance CustomParticleEmitter
24
29
  */
@@ -18,6 +18,11 @@ export class CustomParticleEmitter {
18
18
  * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles
19
19
  */
20
20
  this.particleDestinationGenerator = () => { };
21
+ /**
22
+ * Gets or sets the direction generator that will create the initial direction of each particle.
23
+ * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles
24
+ */
25
+ this.particleDirectionGenerator = () => { };
21
26
  }
22
27
  /**
23
28
  * Called by the particle System when the direction is computed for the created particle.
@@ -28,7 +33,10 @@ export class CustomParticleEmitter {
28
33
  */
29
34
  startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {
30
35
  const tmpVector = TmpVectors.Vector3[0];
31
- if (this.particleDestinationGenerator) {
36
+ if (this.particleDirectionGenerator) {
37
+ this.particleDirectionGenerator(-1, particle, tmpVector);
38
+ }
39
+ else if (this.particleDestinationGenerator) {
32
40
  this.particleDestinationGenerator(-1, particle, tmpVector);
33
41
  // Get direction
34
42
  const diffVector = TmpVectors.Vector3[1];
@@ -1 +1 @@
1
- {"version":3,"file":"customParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/customParticleEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM9D;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAa9B;;OAEG;IACH;QAfA;;;WAGG;QACI,8BAAyB,GAAgF,GAAG,EAAE,GAAE,CAAC,CAAC;QAEzH;;;WAGG;QACI,iCAA4B,GAAmF,GAAG,EAAE,GAAE,CAAC,CAAC;IAKhH,CAAC;IAEhB;;;;;;OAMG;IACI,sBAAsB,CAAC,WAAmB,EAAE,iBAA0B,EAAE,QAAkB,EAAE,OAAgB;QAC/G,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAExC,IAAI,IAAI,CAAC,4BAA4B,EAAE,CAAC;YACpC,IAAI,CAAC,4BAA4B,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;YAE3D,gBAAgB;YAChB,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACzC,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YAEvD,UAAU,CAAC,UAAU,CAAC,CAAC,GAAG,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC5D,CAAC;aAAM,CAAC;YACJ,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3B,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACV,iBAAiB,CAAC,QAAQ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AC,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAC/C,mBAAmB,CAAC,yBAAyB,GAAG,IAAI,CAAC,yBAAyB,CAAC;QAC/E,mBAAmB,CAAC,4BAA4B,GAAG,IAAI,CAAC,4BAA4B,CAAC;QAErF,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,mBAAwB;QACjC,IAAI,mBAAmB,CAAC,yBAAyB,EAAE,CAAC;YAChD,IAAI,CAAC,yBAAyB,GAAG,mBAAmB,CAAC,yBAAyB,CAAC;QACnF,CAAC;QAED,IAAI,mBAAmB,CAAC,4BAA4B,EAAE,CAAC;YACnD,IAAI,CAAC,4BAA4B,GAAG,mBAAmB,CAAC,4BAA4B,CAAC;QACzF,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3, TmpVectors } from \"../../Maths/math.vector\";\r\nimport type { Particle } from \"../particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from a custom list of positions.\r\n */\r\nexport class CustomParticleEmitter implements IParticleEmitterType {\r\n /**\r\n * Gets or sets the position generator that will create the initial position of each particle.\r\n * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\r\n */\r\n public particlePositionGenerator: (index: number, particle: Nullable<Particle>, outPosition: Vector3) => void = () => {};\r\n\r\n /**\r\n * Gets or sets the destination generator that will create the final destination of each particle.\r\n * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\r\n */\r\n public particleDestinationGenerator: (index: number, particle: Nullable<Particle>, outDestination: Vector3) => void = () => {};\r\n\r\n /**\r\n * Creates a new instance CustomParticleEmitter\r\n */\r\n constructor() {}\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const tmpVector = TmpVectors.Vector3[0];\r\n\r\n if (this.particleDestinationGenerator) {\r\n this.particleDestinationGenerator(-1, particle, tmpVector);\r\n\r\n // Get direction\r\n const diffVector = TmpVectors.Vector3[1];\r\n tmpVector.subtractToRef(particle.position, diffVector);\r\n\r\n diffVector.scaleToRef(1 / particle.lifeTime, tmpVector);\r\n } else {\r\n tmpVector.set(0, 0, 0);\r\n }\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFrom(tmpVector);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalToRef(tmpVector, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const tmpVector = TmpVectors.Vector3[0];\r\n\r\n if (this.particlePositionGenerator) {\r\n this.particlePositionGenerator(-1, particle, tmpVector);\r\n } else {\r\n tmpVector.set(0, 0, 0);\r\n }\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFrom(tmpVector);\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesToRef(tmpVector, worldMatrix, positionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): CustomParticleEmitter {\r\n const newOne = new CustomParticleEmitter();\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {}\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public buildUniformLayout(ubo: UniformBuffer): void {}\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define CUSTOMEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"PointParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"CustomParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.type = this.getClassName();\r\n serializationObject.particlePositionGenerator = this.particlePositionGenerator;\r\n serializationObject.particleDestinationGenerator = this.particleDestinationGenerator;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n if (serializationObject.particlePositionGenerator) {\r\n this.particlePositionGenerator = serializationObject.particlePositionGenerator;\r\n }\r\n\r\n if (serializationObject.particleDestinationGenerator) {\r\n this.particleDestinationGenerator = serializationObject.particleDestinationGenerator;\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"customParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/customParticleEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAA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mBAAmB,CAAC,4BAA4B,GAAG,IAAI,CAAC,4BAA4B,CAAC;QAErF,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,mBAAwB;QACjC,IAAI,mBAAmB,CAAC,yBAAyB,EAAE,CAAC;YAChD,IAAI,CAAC,yBAAyB,GAAG,mBAAmB,CAAC,yBAAyB,CAAC;QACnF,CAAC;QAED,IAAI,mBAAmB,CAAC,4BAA4B,EAAE,CAAC;YACnD,IAAI,CAAC,4BAA4B,GAAG,mBAAmB,CAAC,4BAA4B,CAAC;QACzF,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3, TmpVectors } from \"../../Maths/math.vector\";\r\nimport type { Particle } from \"../particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from a custom list of positions.\r\n */\r\nexport class CustomParticleEmitter implements IParticleEmitterType {\r\n /**\r\n * Gets or sets the position generator that will create the initial position of each particle.\r\n * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\r\n */\r\n public particlePositionGenerator: (index: number, particle: Nullable<Particle>, outPosition: Vector3) => void = () => {};\r\n\r\n /**\r\n * Gets or sets the destination generator that will create the final destination of each particle.\r\n * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\r\n */\r\n public particleDestinationGenerator: (index: number, particle: Nullable<Particle>, outDestination: Vector3) => void = () => {};\r\n\r\n /**\r\n * Gets or sets the direction generator that will create the initial direction of each particle.\r\n * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\r\n */\r\n public particleDirectionGenerator: (index: number, particle: Nullable<Particle>, outDestination: Vector3) => void = () => {};\r\n\r\n /**\r\n * Creates a new instance CustomParticleEmitter\r\n */\r\n constructor() {}\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const tmpVector = TmpVectors.Vector3[0];\r\n\r\n if (this.particleDirectionGenerator) {\r\n this.particleDirectionGenerator(-1, particle, tmpVector);\r\n } else if (this.particleDestinationGenerator) {\r\n this.particleDestinationGenerator(-1, particle, tmpVector);\r\n\r\n // Get direction\r\n const diffVector = TmpVectors.Vector3[1];\r\n tmpVector.subtractToRef(particle.position, diffVector);\r\n\r\n diffVector.scaleToRef(1 / particle.lifeTime, tmpVector);\r\n } else {\r\n tmpVector.set(0, 0, 0);\r\n }\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFrom(tmpVector);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalToRef(tmpVector, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const tmpVector = TmpVectors.Vector3[0];\r\n\r\n if (this.particlePositionGenerator) {\r\n this.particlePositionGenerator(-1, particle, tmpVector);\r\n } else {\r\n tmpVector.set(0, 0, 0);\r\n }\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFrom(tmpVector);\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesToRef(tmpVector, worldMatrix, positionToUpdate);\r\n }\r\n\r\n /**\r\n * Clones the current emitter and returns a copy of it\r\n * @returns the new emitter\r\n */\r\n public clone(): CustomParticleEmitter {\r\n const newOne = new CustomParticleEmitter();\r\n\r\n DeepCopier.DeepCopy(this, newOne);\r\n\r\n return newOne;\r\n }\r\n\r\n /**\r\n * Called by the GPUParticleSystem to setup the update shader\r\n * @param uboOrEffect defines the update shader\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {}\r\n\r\n /**\r\n * Creates the structure of the ubo for this particle emitter\r\n * @param ubo ubo to create the structure for\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public buildUniformLayout(ubo: UniformBuffer): void {}\r\n\r\n /**\r\n * Returns a string to use to update the GPU particles update shader\r\n * @returns a string containing the defines string\r\n */\r\n public getEffectDefines(): string {\r\n return \"#define CUSTOMEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"PointParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"CustomParticleEmitter\";\r\n }\r\n\r\n /**\r\n * Serializes the particle system to a JSON object.\r\n * @returns the JSON object\r\n */\r\n public serialize(): any {\r\n const serializationObject: any = {};\r\n\r\n serializationObject.type = this.getClassName();\r\n serializationObject.particlePositionGenerator = this.particlePositionGenerator;\r\n serializationObject.particleDestinationGenerator = this.particleDestinationGenerator;\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Parse properties from a JSON object\r\n * @param serializationObject defines the JSON object\r\n */\r\n public parse(serializationObject: any): void {\r\n if (serializationObject.particlePositionGenerator) {\r\n this.particlePositionGenerator = serializationObject.particlePositionGenerator;\r\n }\r\n\r\n if (serializationObject.particleDestinationGenerator) {\r\n this.particleDestinationGenerator = serializationObject.particleDestinationGenerator;\r\n }\r\n }\r\n}\r\n"]}
@@ -241,6 +241,10 @@ export interface IParticleSystem {
241
241
  updateInAnimate: boolean;
242
242
  /** @internal */
243
243
  _wasDispatched: boolean;
244
+ /**
245
+ * Returns true if the particle system was generated by a node particle system set
246
+ */
247
+ isNodeGenerated: boolean;
244
248
  /**
245
249
  * Gets the maximum number of particles active at the same time.
246
250
  * @returns The max number of active particles.
@@ -280,6 +284,10 @@ export interface IParticleSystem {
280
284
  * An event triggered when the system is stopped
281
285
  */
282
286
  onStoppedObservable: Observable<IParticleSystem>;
287
+ /**
288
+ * An event triggered when the system is started
289
+ */
290
+ onStartedObservable: Observable<IParticleSystem>;
283
291
  /**
284
292
  * Clones the particle system.
285
293
  * @param name The name of the cloned object