@babylonjs/core 8.36.1 → 8.37.0

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 (132) hide show
  1. package/AudioV2/abstractAudio/audioEngineV2.d.ts +0 -4
  2. package/AudioV2/abstractAudio/audioEngineV2.js +0 -4
  3. package/AudioV2/abstractAudio/audioEngineV2.js.map +1 -1
  4. package/AudioV2/abstractAudio/subNodes/volumeAudioSubNode.js +1 -1
  5. package/AudioV2/abstractAudio/subNodes/volumeAudioSubNode.js.map +1 -1
  6. package/AudioV2/audioParameter.d.ts +5 -1
  7. package/AudioV2/audioParameter.js +4 -0
  8. package/AudioV2/audioParameter.js.map +1 -1
  9. package/AudioV2/webAudio/components/webAudioParameterComponent.d.ts +0 -18
  10. package/AudioV2/webAudio/components/webAudioParameterComponent.js +7 -67
  11. package/AudioV2/webAudio/components/webAudioParameterComponent.js.map +1 -1
  12. package/Cameras/camera.js +1 -0
  13. package/Cameras/camera.js.map +1 -1
  14. package/Cameras/targetCamera.js +0 -4
  15. package/Cameras/targetCamera.js.map +1 -1
  16. package/Culling/ray.core.js +1 -1
  17. package/Culling/ray.core.js.map +1 -1
  18. package/Debug/debugLayer.d.ts +1 -1
  19. package/Debug/debugLayer.js.map +1 -1
  20. package/Engines/WebGPU/webgpuCacheSampler.js +4 -0
  21. package/Engines/WebGPU/webgpuCacheSampler.js.map +1 -1
  22. package/Engines/abstractEngine.js +2 -2
  23. package/Engines/abstractEngine.js.map +1 -1
  24. package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.d.ts +1 -1
  25. package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.js +1 -1
  26. package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.js.map +1 -1
  27. package/FrameGraph/Node/Blocks/PostProcesses/baseWithPropertiesPostProcessBlock.d.ts +1 -1
  28. package/FrameGraph/Node/Blocks/PostProcesses/baseWithPropertiesPostProcessBlock.js +1 -1
  29. package/FrameGraph/Node/Blocks/PostProcesses/baseWithPropertiesPostProcessBlock.js.map +1 -1
  30. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js +1 -1
  31. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js.map +1 -1
  32. package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js +1 -1
  33. package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js.map +1 -1
  34. package/FrameGraph/Node/Blocks/Textures/copyTextureBlock.d.ts +3 -0
  35. package/FrameGraph/Node/Blocks/Textures/copyTextureBlock.js +13 -0
  36. package/FrameGraph/Node/Blocks/Textures/copyTextureBlock.js.map +1 -1
  37. package/FrameGraph/Node/Blocks/index.d.ts +1 -0
  38. package/FrameGraph/Node/Blocks/index.js +1 -0
  39. package/FrameGraph/Node/Blocks/index.js.map +1 -1
  40. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.d.ts +4 -4
  41. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js +3 -4
  42. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js.map +1 -1
  43. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.d.ts +2 -3
  44. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js +1 -2
  45. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js.map +1 -1
  46. package/FrameGraph/Tasks/Rendering/utilityLayerRendererTask.d.ts +3 -1
  47. package/FrameGraph/Tasks/Rendering/utilityLayerRendererTask.js +11 -1
  48. package/FrameGraph/Tasks/Rendering/utilityLayerRendererTask.js.map +1 -1
  49. package/FrameGraph/Tasks/Texture/copyToTextureTask.d.ts +4 -0
  50. package/FrameGraph/Tasks/Texture/copyToTextureTask.js +7 -1
  51. package/FrameGraph/Tasks/Texture/copyToTextureTask.js.map +1 -1
  52. package/FrameGraph/frameGraphRenderContext.d.ts +2 -1
  53. package/FrameGraph/frameGraphRenderContext.js +22 -3
  54. package/FrameGraph/frameGraphRenderContext.js.map +1 -1
  55. package/Materials/PBR/openpbrMaterial.js +2 -1
  56. package/Materials/PBR/openpbrMaterial.js.map +1 -1
  57. package/Materials/floatingOriginMatrixOverrides.js +19 -0
  58. package/Materials/floatingOriginMatrixOverrides.js.map +1 -1
  59. package/Meshes/Node/Blocks/randomBlock.js +11 -11
  60. package/Meshes/Node/Blocks/randomBlock.js.map +1 -1
  61. package/Misc/copyTextureToTexture.d.ts +8 -1
  62. package/Misc/copyTextureToTexture.js +16 -2
  63. package/Misc/copyTextureToTexture.js.map +1 -1
  64. package/Particles/EmitterTypes/coneParticleEmitter.d.ts +3 -3
  65. package/Particles/EmitterTypes/coneParticleEmitter.js +11 -11
  66. package/Particles/EmitterTypes/coneParticleEmitter.js.map +1 -1
  67. package/Particles/EmitterTypes/customParticleEmitter.d.ts +5 -3
  68. package/Particles/EmitterTypes/customParticleEmitter.js +8 -6
  69. package/Particles/EmitterTypes/customParticleEmitter.js.map +1 -1
  70. package/Particles/EmitterTypes/sphereParticleEmitter.d.ts +3 -1
  71. package/Particles/EmitterTypes/sphereParticleEmitter.js +7 -1
  72. package/Particles/EmitterTypes/sphereParticleEmitter.js.map +1 -1
  73. package/Particles/Node/Blocks/Emitters/boxShapeBlock.d.ts +1 -1
  74. package/Particles/Node/Blocks/Emitters/boxShapeBlock.js +2 -1
  75. package/Particles/Node/Blocks/Emitters/boxShapeBlock.js.map +1 -1
  76. package/Particles/Node/Blocks/Emitters/coneShapeBlock.d.ts +6 -4
  77. package/Particles/Node/Blocks/Emitters/coneShapeBlock.js +34 -35
  78. package/Particles/Node/Blocks/Emitters/coneShapeBlock.js.map +1 -1
  79. package/Particles/Node/Blocks/Emitters/createParticleBlock.d.ts +0 -4
  80. package/Particles/Node/Blocks/Emitters/createParticleBlock.js +1 -8
  81. package/Particles/Node/Blocks/Emitters/createParticleBlock.js.map +1 -1
  82. package/Particles/Node/Blocks/Emitters/customShapeBlock.d.ts +13 -9
  83. package/Particles/Node/Blocks/Emitters/customShapeBlock.js +36 -23
  84. package/Particles/Node/Blocks/Emitters/customShapeBlock.js.map +1 -1
  85. package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.d.ts +10 -1
  86. package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.js +50 -17
  87. package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.js.map +1 -1
  88. package/Particles/Node/Blocks/Emitters/emitters.functions.d.ts +6 -0
  89. package/Particles/Node/Blocks/Emitters/emitters.functions.js +13 -0
  90. package/Particles/Node/Blocks/Emitters/emitters.functions.js.map +1 -0
  91. package/Particles/Node/Blocks/Emitters/meshShapeBlock.d.ts +2 -2
  92. package/Particles/Node/Blocks/Emitters/meshShapeBlock.js +5 -1
  93. package/Particles/Node/Blocks/Emitters/meshShapeBlock.js.map +1 -1
  94. package/Particles/Node/Blocks/Emitters/pointShapeBlock.d.ts +1 -1
  95. package/Particles/Node/Blocks/Emitters/pointShapeBlock.js +3 -1
  96. package/Particles/Node/Blocks/Emitters/pointShapeBlock.js.map +1 -1
  97. package/Particles/Node/Blocks/Emitters/sphereShapeBlock.d.ts +16 -1
  98. package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js +67 -14
  99. package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js.map +1 -1
  100. package/Particles/Node/Blocks/particleInputBlock.js +1 -0
  101. package/Particles/Node/Blocks/particleInputBlock.js.map +1 -1
  102. package/Particles/Node/Blocks/particleRandomBlock.js +10 -10
  103. package/Particles/Node/Blocks/particleRandomBlock.js.map +1 -1
  104. package/Particles/Node/Blocks/systemBlock.d.ts +5 -1
  105. package/Particles/Node/Blocks/systemBlock.js +14 -3
  106. package/Particles/Node/Blocks/systemBlock.js.map +1 -1
  107. package/Particles/Node/Enums/nodeParticleContextualSources.d.ts +3 -1
  108. package/Particles/Node/Enums/nodeParticleContextualSources.js +2 -0
  109. package/Particles/Node/Enums/nodeParticleContextualSources.js.map +1 -1
  110. package/Particles/Node/nodeParticleBuildState.js +5 -0
  111. package/Particles/Node/nodeParticleBuildState.js.map +1 -1
  112. package/Particles/Node/nodeParticleSystemSet.helper.js +89 -28
  113. package/Particles/Node/nodeParticleSystemSet.helper.js.map +1 -1
  114. package/Particles/Node/nodeParticleSystemSet.js +1 -1
  115. package/Particles/Node/nodeParticleSystemSet.js.map +1 -1
  116. package/Particles/thinParticleSystem.function.d.ts +2 -2
  117. package/Particles/thinParticleSystem.function.js +2 -2
  118. package/Particles/thinParticleSystem.function.js.map +1 -1
  119. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +2 -1
  120. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -1
  121. package/Rendering/prePassRenderer.js +4 -1
  122. package/Rendering/prePassRenderer.js.map +1 -1
  123. package/Shaders/copyTextureToTexture.fragment.js +2 -2
  124. package/Shaders/copyTextureToTexture.fragment.js.map +1 -1
  125. package/ShadersWGSL/copyTextureToTexture.fragment.js +3 -3
  126. package/ShadersWGSL/copyTextureToTexture.fragment.js.map +1 -1
  127. package/XR/webXRSessionManager.js +4 -0
  128. package/XR/webXRSessionManager.js.map +1 -1
  129. package/package.json +1 -1
  130. package/scene.d.ts +1 -3
  131. package/scene.js +8 -7
  132. package/scene.js.map +1 -1
@@ -116,6 +116,25 @@ function GetOffsetMatrix(uniformName, mat) {
116
116
  case "worldViewProjection":
117
117
  return OffsetWorldViewProjectionToRef(offset, mat, scene.getTransformMatrix(), scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);
118
118
  default:
119
+ // Node material blocks uniforms are formatted u_BlockName, with trailing numbers if there are multiple blocks of the same name
120
+ // Check u_ first so that we can early out for non-node material uniforms
121
+ if (uniformName.startsWith("u_")) {
122
+ if (uniformName.startsWith("u_WorldViewProjection")) {
123
+ return OffsetWorldViewProjectionToRef(offset, mat, scene.getTransformMatrix(), scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);
124
+ }
125
+ if (uniformName.startsWith("u_ViewProjection")) {
126
+ return OffsetViewProjectionToRef(offset, scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);
127
+ }
128
+ if (uniformName.startsWith("u_WorldView")) {
129
+ return OffsetWorldViewToRef(offset, mat, scene.getViewMatrix(), TempFinalMat);
130
+ }
131
+ if (uniformName.startsWith("u_World")) {
132
+ return OffsetWorldToRef(offset, mat, TempFinalMat);
133
+ }
134
+ if (uniformName.startsWith("u_View")) {
135
+ return OffsetViewToRef(offset, mat, TempFinalMat);
136
+ }
137
+ }
119
138
  return mat;
120
139
  }
121
140
  }
@@ -1 +1 @@
1
- {"version":3,"file":"floatingOriginMatrixOverrides.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/floatingOriginMatrixOverrides.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAGxG,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,MAAM,YAAY,GAAW,IAAI,MAAM,EAAE,CAAC;AAC1C,MAAM,QAAQ,GAAW,IAAI,MAAM,EAAE,CAAC;AACtC,MAAM,QAAQ,GAAW,IAAI,MAAM,EAAE,CAAC;AAEtC;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACtC,QAAQ,EAAE,GAAG,EAAE,CAAC,SAA8B;IAC9C,WAAW,EAAE,IAAI,EAAE,+GAA+G;CACrI,CAAC;AAEF,SAAS,gBAAgB,CAAC,MAAoB,EAAE,KAAiC,EAAE,GAAW;IAC1F,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IAC/B,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;IACnC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,E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AM,CAAC,SAAS,CAAC,SAAS,CAAC;AAErD,MAAM,UAAU,oBAAoB;IAChC,MAAM,CAAC,SAAS,CAAC,SAAS,GAAG,iBAAiB,CAAC;IAC/C,cAAc,CAAC,kBAAkB,GAAG,SAAS,CAAC;IAC9C,qBAAqB,CAAC,SAAS,CAAC,uBAAuB,GAAG,8BAA8B,CAAC;IACzF,qBAAqB,CAAC,SAAS,CAAC,+BAA+B,GAAG,SAAS,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,uBAAuB;IACnC,cAAc,CAAC,SAAS,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;IAChE,cAAc,CAAC,SAAS,CAAC,SAAS,GAAG,UAAU,WAAmB,EAAE,MAAmB;QACnF,IAAI,CAAC,kBAAkB,CAAC,WAAW,EAAE,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;QAC3E,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;IACF,qBAAqB,CAAC,SAAS,CAAC,+BAA+B,GAAG,8BAA8B,CAAC;IACjG,qBAAqB,CAAC,SAAS,CAAC,uBAAuB,GAAG,UAAU,WAAmB,EAAE,MAAmB;QACxG,IAAI,CAAC,+BAA+B,CAAC,WAAW,EAAE,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5F,CAAC,CAAC;AACN,CAAC","sourcesContent":["import { Effect } from \"../Materials/effect\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport type { IMatrixLike, IVector3Like } from \"../Maths/math.like\";\r\nimport { InvertMatrixToRef, MultiplyMatricesToRef } from \"../Maths/ThinMaths/thinMath.matrix.functions\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { DeepImmutable } from \"../types\";\r\nimport { UniformBuffer } from \"./uniformBuffer\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\n\r\nconst TempFinalMat: Matrix = new Matrix();\r\nconst TempMat1: Matrix = new Matrix();\r\nconst TempMat2: Matrix = new Matrix();\r\n\r\n/**\r\n * When rendering, each scene will reset this to ensure the correct floating origin offset is when overriding the below functions\r\n */\r\nexport const FloatingOriginCurrentScene = {\r\n getScene: () => undefined as Scene | undefined,\r\n eyeAtCamera: true, // When true, we can assume viewMatrix translation is at origin. Otherwise, we must do full offset calculations\r\n};\r\n\r\nfunction OffsetWorldToRef(offset: IVector3Like, world: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n const refArray = ref.asArray();\r\n const worldArray = world.asArray();\r\n for (let i = 0; i < 16; i++) {\r\n refArray[i] = worldArray[i];\r\n }\r\n refArray[12] -= offset.x;\r\n refArray[13] -= offset.y;\r\n refArray[14] -= offset.z;\r\n ref.markAsUpdated();\r\n return ref;\r\n}\r\n\r\nfunction GetFullOffsetView(offset: IVector3Like, viewMatrix: DeepImmutable<IMatrixLike>, ref: IMatrixLike) {\r\n InvertMatrixToRef(viewMatrix, TempMat1); // TempMat1 = light world matrix (inverse of view)\r\n OffsetWorldToRef(offset, TempMat1, TempMat2); // TempMat2 = offset light world matrix\r\n InvertMatrixToRef(TempMat2, ref); // TempMat1 = offset view matrix\r\n return ref;\r\n}\r\n\r\nexport function OffsetViewToRef(offset: IVector3Like, view: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n // When eye is not at camera, we cannot assume the translation of view matrix is at origin, so we perform full offset calculation\r\n if (!FloatingOriginCurrentScene.eyeAtCamera) {\r\n return GetFullOffsetView(offset, view, ref);\r\n }\r\n const refArray = ref.asArray();\r\n const viewArray = view.asArray();\r\n for (let i = 0; i < 16; i++) {\r\n refArray[i] = viewArray[i];\r\n }\r\n refArray[12] = 0;\r\n refArray[13] = 0;\r\n refArray[14] = 0;\r\n ref.markAsUpdated();\r\n return ref;\r\n}\r\n\r\nfunction OffsetViewProjectionToRef(offset: IVector3Like, view: DeepImmutable<IMatrixLike>, projection: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n MultiplyMatricesToRef(OffsetViewToRef(offset, view, ref), projection, ref);\r\n return ref;\r\n}\r\n\r\nexport function OffsetClipPlaneToRef(offset: Vector3, plane: Plane, ref: Plane): Plane {\r\n // Original clipplane is using equation normal.dot(p) + d = 0\r\n // Assume we have p' = p - offset, that means normal.dot(p') + d' = 0\r\n // So to get the offset plane,\r\n // normal.dot(p' + offset) + d = 0\r\n // normal.dot(p') + normal.dot(offset) + d = 0\r\n // -d' + normal.dot(offset) + d = 0\r\n // d' = d + normal.dot(offset)\r\n ref.normal.copyFrom(plane.normal);\r\n ref.d = plane.d + Vector3.Dot(plane.normal, offset);\r\n return ref;\r\n}\r\n\r\nexport function GetOffsetTransformMatrices(\r\n offset: IVector3Like,\r\n viewMatrices: Array<Matrix>,\r\n projectionMatrices: Array<Matrix>,\r\n length: number,\r\n resultArray: Float32Array\r\n): Float32Array {\r\n for (let cascadeIndex = 0; cascadeIndex < length; ++cascadeIndex) {\r\n GetFullOffsetViewProjectionToRef(offset, viewMatrices[cascadeIndex], projectionMatrices[cascadeIndex], TempMat1);\r\n TempMat1.copyToArray(resultArray, cascadeIndex * 16);\r\n }\r\n return resultArray;\r\n}\r\n\r\nfunction OffsetWorldViewToRef(offset: IVector3Like, worldView: DeepImmutable<IMatrixLike>, view: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n // ( world * view ) * inverse ( view ) = world\r\n InvertMatrixToRef(view, TempMat1); // TempMat1 = inverseView\r\n MultiplyMatricesToRef(worldView, TempMat1, TempMat2); // TempMat2 = world, TempMat1 can be reused\r\n\r\n // ( offsetWorld * offsetView ) = offsetWorldView\r\n OffsetWorldToRef(offset, TempMat2, TempMat1); // TempMat1 = offsetWorld\r\n OffsetViewToRef(offset, view, TempMat2); // TempMat2 = offsetView\r\n MultiplyMatricesToRef(TempMat1, TempMat2, ref);\r\n\r\n return ref;\r\n}\r\n\r\nexport function GetFullOffsetViewProjectionToRef(\r\n offset: IVector3Like,\r\n viewMatrix: DeepImmutable<IMatrixLike>,\r\n projectionMatrix: DeepImmutable<IMatrixLike>,\r\n ref: IMatrixLike\r\n): DeepImmutable<IMatrixLike> {\r\n GetFullOffsetView(offset, viewMatrix, TempMat2);\r\n MultiplyMatricesToRef(TempMat2, projectionMatrix, ref);\r\n return ref;\r\n}\r\n\r\nfunction OffsetWorldViewProjectionToRef(\r\n offset: IVector3Like,\r\n worldViewProjection: DeepImmutable<IMatrixLike>,\r\n viewProjection: DeepImmutable<IMatrixLike>,\r\n view: DeepImmutable<IMatrixLike>,\r\n projection: DeepImmutable<IMatrixLike>,\r\n ref: IMatrixLike\r\n): DeepImmutable<IMatrixLike> {\r\n // ( world * view * projection ) * inverse(projection) * inverse(view) = world\r\n // ( world * view * projection ) * inverse (view * projection) = world\r\n InvertMatrixToRef(viewProjection, TempMat1); // TempMat1 = inverse (view * projection)\r\n MultiplyMatricesToRef(worldViewProjection, TempMat1, TempMat2); // TempMat2 = world, TempMat1 can be reused\r\n\r\n // ( offsetWorld * offsetViewProjection) = offsetWorldViewProjection\r\n OffsetWorldToRef(offset, TempMat2, TempMat1); // TempMat1 = offsetWorld\r\n OffsetViewProjectionToRef(offset, view, projection, TempMat2); // TempMat2 = offsetViewProjection\r\n MultiplyMatricesToRef(TempMat1, TempMat2, ref);\r\n\r\n return ref;\r\n}\r\n\r\nfunction GetOffsetMatrix(uniformName: string, mat: IMatrixLike): IMatrixLike {\r\n const scene = FloatingOriginCurrentScene.getScene();\r\n // Early out for scenes that don't have floatingOriginMode enabled\r\n // Effect.setMatrix will call pipelineContext.setMatrix. In WebGPU, this will in turn call ubo.updateMatrix. To avoid double offset, early out if mat is TempFinalMat\r\n if (!scene || TempFinalMat === mat) {\r\n return mat;\r\n }\r\n TempFinalMat.updateFlag = mat.updateFlag;\r\n const offset = scene.floatingOriginOffset;\r\n switch (uniformName) {\r\n case \"world\":\r\n return OffsetWorldToRef(offset, mat, TempFinalMat);\r\n case \"view\":\r\n return OffsetViewToRef(offset, mat, TempFinalMat);\r\n case \"worldView\":\r\n return OffsetWorldViewToRef(offset, mat, scene.getViewMatrix(), TempFinalMat);\r\n case \"viewProjection\":\r\n return OffsetViewProjectionToRef(offset, scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);\r\n case \"worldViewProjection\":\r\n return OffsetWorldViewProjectionToRef(offset, mat, scene.getTransformMatrix(), scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);\r\n default:\r\n return mat;\r\n }\r\n}\r\n\r\n// ---- Overriding the prototypes of effect and uniformBuffer's setMatrix functions ----\r\nconst UniformBufferInternal = UniformBuffer as any;\r\nconst EffectInternal = Effect as any;\r\nconst OriginalUpdateMatrixForUniform = UniformBufferInternal.prototype._updateMatrixForUniform;\r\nconst OriginalSetMatrix = Effect.prototype.setMatrix;\r\n\r\nexport function ResetMatrixFunctions() {\r\n Effect.prototype.setMatrix = OriginalSetMatrix;\r\n EffectInternal._setMatrixOverride = undefined;\r\n UniformBufferInternal.prototype._updateMatrixForUniform = OriginalUpdateMatrixForUniform;\r\n UniformBufferInternal.prototype._updateMatrixForUniformOverride = undefined;\r\n}\r\n\r\nexport function OverrideMatrixFunctions() {\r\n EffectInternal.prototype._setMatrixOverride = OriginalSetMatrix;\r\n EffectInternal.prototype.setMatrix = function (uniformName: string, matrix: IMatrixLike) {\r\n this._setMatrixOverride(uniformName, GetOffsetMatrix(uniformName, matrix));\r\n return this;\r\n };\r\n UniformBufferInternal.prototype._updateMatrixForUniformOverride = OriginalUpdateMatrixForUniform;\r\n UniformBufferInternal.prototype._updateMatrixForUniform = function (uniformName: string, matrix: IMatrixLike) {\r\n this._updateMatrixForUniformOverride(uniformName, GetOffsetMatrix(uniformName, matrix));\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"floatingOriginMatrixOverrides.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/floatingOriginMatrixOverrides.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,C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AC,+BAA+B,CAAC,WAAW,EAAE,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5F,CAAC,CAAC;AACN,CAAC","sourcesContent":["import { Effect } from \"../Materials/effect\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport type { IMatrixLike, IVector3Like } from \"../Maths/math.like\";\r\nimport { InvertMatrixToRef, MultiplyMatricesToRef } from \"../Maths/ThinMaths/thinMath.matrix.functions\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { DeepImmutable } from \"../types\";\r\nimport { UniformBuffer } from \"./uniformBuffer\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\n\r\nconst TempFinalMat: Matrix = new Matrix();\r\nconst TempMat1: Matrix = new Matrix();\r\nconst TempMat2: Matrix = new Matrix();\r\n\r\n/**\r\n * When rendering, each scene will reset this to ensure the correct floating origin offset is when overriding the below functions\r\n */\r\nexport const FloatingOriginCurrentScene = {\r\n getScene: () => undefined as Scene | undefined,\r\n eyeAtCamera: true, // When true, we can assume viewMatrix translation is at origin. Otherwise, we must do full offset calculations\r\n};\r\n\r\nfunction OffsetWorldToRef(offset: IVector3Like, world: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n const refArray = ref.asArray();\r\n const worldArray = world.asArray();\r\n for (let i = 0; i < 16; i++) {\r\n refArray[i] = worldArray[i];\r\n }\r\n refArray[12] -= offset.x;\r\n refArray[13] -= offset.y;\r\n refArray[14] -= offset.z;\r\n ref.markAsUpdated();\r\n return ref;\r\n}\r\n\r\nfunction GetFullOffsetView(offset: IVector3Like, viewMatrix: DeepImmutable<IMatrixLike>, ref: IMatrixLike) {\r\n InvertMatrixToRef(viewMatrix, TempMat1); // TempMat1 = light world matrix (inverse of view)\r\n OffsetWorldToRef(offset, TempMat1, TempMat2); // TempMat2 = offset light world matrix\r\n InvertMatrixToRef(TempMat2, ref); // TempMat1 = offset view matrix\r\n return ref;\r\n}\r\n\r\nexport function OffsetViewToRef(offset: IVector3Like, view: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n // When eye is not at camera, we cannot assume the translation of view matrix is at origin, so we perform full offset calculation\r\n if (!FloatingOriginCurrentScene.eyeAtCamera) {\r\n return GetFullOffsetView(offset, view, ref);\r\n }\r\n const refArray = ref.asArray();\r\n const viewArray = view.asArray();\r\n for (let i = 0; i < 16; i++) {\r\n refArray[i] = viewArray[i];\r\n }\r\n refArray[12] = 0;\r\n refArray[13] = 0;\r\n refArray[14] = 0;\r\n ref.markAsUpdated();\r\n return ref;\r\n}\r\n\r\nfunction OffsetViewProjectionToRef(offset: IVector3Like, view: DeepImmutable<IMatrixLike>, projection: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n MultiplyMatricesToRef(OffsetViewToRef(offset, view, ref), projection, ref);\r\n return ref;\r\n}\r\n\r\nexport function OffsetClipPlaneToRef(offset: Vector3, plane: Plane, ref: Plane): Plane {\r\n // Original clipplane is using equation normal.dot(p) + d = 0\r\n // Assume we have p' = p - offset, that means normal.dot(p') + d' = 0\r\n // So to get the offset plane,\r\n // normal.dot(p' + offset) + d = 0\r\n // normal.dot(p') + normal.dot(offset) + d = 0\r\n // -d' + normal.dot(offset) + d = 0\r\n // d' = d + normal.dot(offset)\r\n ref.normal.copyFrom(plane.normal);\r\n ref.d = plane.d + Vector3.Dot(plane.normal, offset);\r\n return ref;\r\n}\r\n\r\nexport function GetOffsetTransformMatrices(\r\n offset: IVector3Like,\r\n viewMatrices: Array<Matrix>,\r\n projectionMatrices: Array<Matrix>,\r\n length: number,\r\n resultArray: Float32Array\r\n): Float32Array {\r\n for (let cascadeIndex = 0; cascadeIndex < length; ++cascadeIndex) {\r\n GetFullOffsetViewProjectionToRef(offset, viewMatrices[cascadeIndex], projectionMatrices[cascadeIndex], TempMat1);\r\n TempMat1.copyToArray(resultArray, cascadeIndex * 16);\r\n }\r\n return resultArray;\r\n}\r\n\r\nfunction OffsetWorldViewToRef(offset: IVector3Like, worldView: DeepImmutable<IMatrixLike>, view: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n // ( world * view ) * inverse ( view ) = world\r\n InvertMatrixToRef(view, TempMat1); // TempMat1 = inverseView\r\n MultiplyMatricesToRef(worldView, TempMat1, TempMat2); // TempMat2 = world, TempMat1 can be reused\r\n\r\n // ( offsetWorld * offsetView ) = offsetWorldView\r\n OffsetWorldToRef(offset, TempMat2, TempMat1); // TempMat1 = offsetWorld\r\n OffsetViewToRef(offset, view, TempMat2); // TempMat2 = offsetView\r\n MultiplyMatricesToRef(TempMat1, TempMat2, ref);\r\n\r\n return ref;\r\n}\r\n\r\nexport function GetFullOffsetViewProjectionToRef(\r\n offset: IVector3Like,\r\n viewMatrix: DeepImmutable<IMatrixLike>,\r\n projectionMatrix: DeepImmutable<IMatrixLike>,\r\n ref: IMatrixLike\r\n): DeepImmutable<IMatrixLike> {\r\n GetFullOffsetView(offset, viewMatrix, TempMat2);\r\n MultiplyMatricesToRef(TempMat2, projectionMatrix, ref);\r\n return ref;\r\n}\r\n\r\nfunction OffsetWorldViewProjectionToRef(\r\n offset: IVector3Like,\r\n worldViewProjection: DeepImmutable<IMatrixLike>,\r\n viewProjection: DeepImmutable<IMatrixLike>,\r\n view: DeepImmutable<IMatrixLike>,\r\n projection: DeepImmutable<IMatrixLike>,\r\n ref: IMatrixLike\r\n): DeepImmutable<IMatrixLike> {\r\n // ( world * view * projection ) * inverse(projection) * inverse(view) = world\r\n // ( world * view * projection ) * inverse (view * projection) = world\r\n InvertMatrixToRef(viewProjection, TempMat1); // TempMat1 = inverse (view * projection)\r\n MultiplyMatricesToRef(worldViewProjection, TempMat1, TempMat2); // TempMat2 = world, TempMat1 can be reused\r\n\r\n // ( offsetWorld * offsetViewProjection) = offsetWorldViewProjection\r\n OffsetWorldToRef(offset, TempMat2, TempMat1); // TempMat1 = offsetWorld\r\n OffsetViewProjectionToRef(offset, view, projection, TempMat2); // TempMat2 = offsetViewProjection\r\n MultiplyMatricesToRef(TempMat1, TempMat2, ref);\r\n\r\n return ref;\r\n}\r\n\r\nfunction GetOffsetMatrix(uniformName: string, mat: IMatrixLike): IMatrixLike {\r\n const scene = FloatingOriginCurrentScene.getScene();\r\n // Early out for scenes that don't have floatingOriginMode enabled\r\n // Effect.setMatrix will call pipelineContext.setMatrix. In WebGPU, this will in turn call ubo.updateMatrix. To avoid double offset, early out if mat is TempFinalMat\r\n if (!scene || TempFinalMat === mat) {\r\n return mat;\r\n }\r\n TempFinalMat.updateFlag = mat.updateFlag;\r\n const offset = scene.floatingOriginOffset;\r\n switch (uniformName) {\r\n case \"world\":\r\n return OffsetWorldToRef(offset, mat, TempFinalMat);\r\n case \"view\":\r\n return OffsetViewToRef(offset, mat, TempFinalMat);\r\n case \"worldView\":\r\n return OffsetWorldViewToRef(offset, mat, scene.getViewMatrix(), TempFinalMat);\r\n case \"viewProjection\":\r\n return OffsetViewProjectionToRef(offset, scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);\r\n case \"worldViewProjection\":\r\n return OffsetWorldViewProjectionToRef(offset, mat, scene.getTransformMatrix(), scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);\r\n default:\r\n // Node material blocks uniforms are formatted u_BlockName, with trailing numbers if there are multiple blocks of the same name\r\n // Check u_ first so that we can early out for non-node material uniforms\r\n if (uniformName.startsWith(\"u_\")) {\r\n if (uniformName.startsWith(\"u_WorldViewProjection\")) {\r\n return OffsetWorldViewProjectionToRef(offset, mat, scene.getTransformMatrix(), scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);\r\n }\r\n if (uniformName.startsWith(\"u_ViewProjection\")) {\r\n return OffsetViewProjectionToRef(offset, scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);\r\n }\r\n if (uniformName.startsWith(\"u_WorldView\")) {\r\n return OffsetWorldViewToRef(offset, mat, scene.getViewMatrix(), TempFinalMat);\r\n }\r\n if (uniformName.startsWith(\"u_World\")) {\r\n return OffsetWorldToRef(offset, mat, TempFinalMat);\r\n }\r\n if (uniformName.startsWith(\"u_View\")) {\r\n return OffsetViewToRef(offset, mat, TempFinalMat);\r\n }\r\n }\r\n return mat;\r\n }\r\n}\r\n\r\n// ---- Overriding the prototypes of effect and uniformBuffer's setMatrix functions ----\r\nconst UniformBufferInternal = UniformBuffer as any;\r\nconst EffectInternal = Effect as any;\r\nconst OriginalUpdateMatrixForUniform = UniformBufferInternal.prototype._updateMatrixForUniform;\r\nconst OriginalSetMatrix = Effect.prototype.setMatrix;\r\n\r\nexport function ResetMatrixFunctions() {\r\n Effect.prototype.setMatrix = OriginalSetMatrix;\r\n EffectInternal._setMatrixOverride = undefined;\r\n UniformBufferInternal.prototype._updateMatrixForUniform = OriginalUpdateMatrixForUniform;\r\n UniformBufferInternal.prototype._updateMatrixForUniformOverride = undefined;\r\n}\r\n\r\nexport function OverrideMatrixFunctions() {\r\n EffectInternal.prototype._setMatrixOverride = OriginalSetMatrix;\r\n EffectInternal.prototype.setMatrix = function (uniformName: string, matrix: IMatrixLike) {\r\n this._setMatrixOverride(uniformName, GetOffsetMatrix(uniformName, matrix));\r\n return this;\r\n };\r\n UniformBufferInternal.prototype._updateMatrixForUniformOverride = OriginalUpdateMatrixForUniform;\r\n UniformBufferInternal.prototype._updateMatrixForUniform = function (uniformName: string, matrix: IMatrixLike) {\r\n this._updateMatrixForUniformOverride(uniformName, GetOffsetMatrix(uniformName, matrix));\r\n };\r\n}\r\n"]}
@@ -93,32 +93,32 @@ export class RandomBlock extends NodeGeometryBlock {
93
93
  case NodeGeometryBlockConnectionPointTypes.Int:
94
94
  case NodeGeometryBlockConnectionPointTypes.Float: {
95
95
  func = (state) => {
96
- const min = this.min.getConnectedValue(state) || 0;
97
- const max = this.max.getConnectedValue(state) || 0;
96
+ const min = this.min.getConnectedValue(state) ?? 0;
97
+ const max = this.max.getConnectedValue(state) ?? 0;
98
98
  return min + Math.random() * (max - min);
99
99
  };
100
100
  break;
101
101
  }
102
102
  case NodeGeometryBlockConnectionPointTypes.Vector2: {
103
103
  func = (state) => {
104
- const min = this.min.getConnectedValue(state) || Vector2.Zero();
105
- const max = this.max.getConnectedValue(state) || Vector2.Zero();
104
+ const min = this.min.getConnectedValue(state) ?? Vector2.Zero();
105
+ const max = this.max.getConnectedValue(state) ?? Vector2.Zero();
106
106
  return new Vector2(min.x + Math.random() * (max.x - min.x), min.y + Math.random() * (max.y - min.y));
107
107
  };
108
108
  break;
109
109
  }
110
110
  case NodeGeometryBlockConnectionPointTypes.Vector3: {
111
111
  func = (state) => {
112
- const min = this.min.getConnectedValue(state) || Vector3.Zero();
113
- const max = this.max.getConnectedValue(state) || Vector3.Zero();
112
+ const min = this.min.getConnectedValue(state) ?? Vector3.Zero();
113
+ const max = this.max.getConnectedValue(state) ?? Vector3.Zero();
114
114
  return new Vector3(min.x + Math.random() * (max.x - min.x), min.y + Math.random() * (max.y - min.y), min.z + Math.random() * (max.z - min.z));
115
115
  };
116
116
  break;
117
117
  }
118
118
  case NodeGeometryBlockConnectionPointTypes.Vector4: {
119
119
  func = (state) => {
120
- const min = this.min.getConnectedValue(state) || Vector4.Zero();
121
- const max = this.max.getConnectedValue(state) || Vector4.Zero();
120
+ const min = this.min.getConnectedValue(state) ?? Vector4.Zero();
121
+ const max = this.max.getConnectedValue(state) ?? Vector4.Zero();
122
122
  return new Vector4(min.x + Math.random() * (max.x - min.x), min.y + Math.random() * (max.y - min.y), min.z + Math.random() * (max.z - min.z), min.w + Math.random() * (max.w - min.w));
123
123
  };
124
124
  break;
@@ -132,13 +132,13 @@ export class RandomBlock extends NodeGeometryBlock {
132
132
  let lockId = 0;
133
133
  switch (this.lockMode) {
134
134
  case RandomBlockLocks.InstanceID:
135
- lockId = state.getContextualValue(NodeGeometryContextualSources.InstanceID, true) || 0;
135
+ lockId = state.getContextualValue(NodeGeometryContextualSources.InstanceID, true) ?? 0;
136
136
  break;
137
137
  case RandomBlockLocks.LoopID:
138
- lockId = state.getContextualValue(NodeGeometryContextualSources.LoopID, true) || 0;
138
+ lockId = state.getContextualValue(NodeGeometryContextualSources.LoopID, true) ?? 0;
139
139
  break;
140
140
  case RandomBlockLocks.Once:
141
- lockId = state.buildId || 0;
141
+ lockId = state.buildId ?? 0;
142
142
  break;
143
143
  }
144
144
  if (this._currentLockId !== lockId || this.lockMode === RandomBlockLocks.None) {
@@ -1 +1 @@
1
- {"version":3,"file":"randomBlock.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Meshes/Node/Blocks/randomBlock.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,qCAAqC,EAAE,MAAM,2CAA2C,CAAC;AAElG,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAEvE,OAAO,EAA0B,sBAAsB,EAAE,6CAAsC;AAC/F,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAEvF;;GAEG;AACH,MAAM,CAAN,IAAY,gBAWX;AAXD,WAAY,gBAAgB;IACxB,WAAW;IACX,uDAAI,CAAA;IACJ,aAAa;IACb,gEAAgE;IAChE,2DAAM,CAAA;IACN,iBAAiB;IACjB,gEAAgE;IAChE,mEAAU,CAAA;IACV,WAAW;IACX,uDAAI,CAAA;AACR,CAAC,EAXW,gBAAgB,KAAhB,gBAAgB,QAW3B;AAED;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,iBAAiB;IAiB9C;;;OAGG;IACH,YAAmB,IAAY;QAC3B,KAAK,CAAC,IAAI,CAAC,CAAC;QArBR,mBAAc,GAAG,CAAC,CAAC,CAAC;QAC5B;;WAEG;QAWI,aAAQ,GAAG,gBAAgB,CAAC,IAAI,CAA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AE7C,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAEe,YAAY,CAAC,mBAAwB;QACjD,KAAK,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC;QAExC,IAAI,CAAC,QAAQ,GAAG,mBAAmB,CAAC,QAAQ,CAAC;IACjD,CAAC;CACJ;AAlKU;IAVN,sBAAsB,CAAC,UAAU,uCAA+B,UAAU,EAAE;QACzE,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;QAC5B,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE;YACL,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE;YAC/C,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,CAAC,MAAM,EAAE;YACnD,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,gBAAgB,CAAC,UAAU,EAAE;YAC3D,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE;SAClD;KACJ,CAAC;6CACsC;AAoK5C,aAAa,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC","sourcesContent":["import { NodeGeometryBlock } from \"../nodeGeometryBlock\";\r\nimport type { NodeGeometryConnectionPoint } from \"../nodeGeometryBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport { NodeGeometryBlockConnectionPointTypes } from \"../Enums/nodeGeometryConnectionPointTypes\";\r\nimport type { NodeGeometryBuildState } from \"../nodeGeometryBuildState\";\r\nimport { GeometryInputBlock } from \"./geometryInputBlock\";\r\nimport { Vector2, Vector3, Vector4 } from \"../../../Maths/math.vector\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport { PropertyTypeForEdition, editableInPropertyPage } from \"core/Decorators/nodeDecorator\";\r\nimport { NodeGeometryContextualSources } from \"../Enums/nodeGeometryContextualSources\";\r\n\r\n/**\r\n * Locks supported by the random block\r\n */\r\nexport enum RandomBlockLocks {\r\n /** None */\r\n None,\r\n /** LoopID */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n LoopID,\r\n /** InstanceID */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n InstanceID,\r\n /** Once */\r\n Once,\r\n}\r\n\r\n/**\r\n * Block used to get a random number\r\n */\r\nexport class RandomBlock extends NodeGeometryBlock {\r\n private _currentLockId = -1;\r\n /**\r\n * Gets or sets a value indicating if that block will lock its value for a specific duration\r\n */\r\n @editableInPropertyPage(\"LockMode\", PropertyTypeForEdition.List, \"ADVANCED\", {\r\n notifiers: { rebuild: true },\r\n embedded: true,\r\n options: [\r\n { label: \"None\", value: RandomBlockLocks.None },\r\n { label: \"LoopID\", value: RandomBlockLocks.LoopID },\r\n { label: \"InstanceID\", value: RandomBlockLocks.InstanceID },\r\n { label: \"Once\", value: RandomBlockLocks.Once },\r\n ],\r\n })\r\n public lockMode = RandomBlockLocks.None;\r\n\r\n /**\r\n * Create a new RandomBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name);\r\n\r\n this.registerInput(\"min\", NodeGeometryBlockConnectionPointTypes.AutoDetect);\r\n this.registerInput(\"max\", NodeGeometryBlockConnectionPointTypes.AutoDetect);\r\n\r\n this.registerOutput(\"output\", NodeGeometryBlockConnectionPointTypes.BasedOnInput);\r\n\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Matrix);\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Geometry);\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Texture);\r\n this._inputs[1].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Matrix);\r\n this._inputs[1].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Geometry);\r\n this._inputs[1].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Texture);\r\n\r\n this._outputs[0]._typeConnectionSource = this._inputs[0];\r\n this._linkConnectionTypes(0, 1);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public override getClassName() {\r\n return \"RandomBlock\";\r\n }\r\n\r\n /**\r\n * Gets the min input component\r\n */\r\n public get min(): NodeGeometryConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the max input component\r\n */\r\n public get max(): NodeGeometryConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the geometry output component\r\n */\r\n public get output(): NodeGeometryConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n public override autoConfigure() {\r\n if (!this.min.isConnected) {\r\n const minInput = new GeometryInputBlock(\"Min\");\r\n minInput.value = 0;\r\n minInput.output.connectTo(this.min);\r\n }\r\n\r\n if (!this.max.isConnected) {\r\n const maxInput = new GeometryInputBlock(\"Max\");\r\n maxInput.value = 1;\r\n maxInput.output.connectTo(this.max);\r\n }\r\n }\r\n\r\n protected override _buildBlock() {\r\n let func: Nullable<(state: NodeGeometryBuildState) => any> = null;\r\n this._currentLockId = -1;\r\n\r\n switch (this.min.type) {\r\n case NodeGeometryBlockConnectionPointTypes.Int:\r\n case NodeGeometryBlockConnectionPointTypes.Float: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) || 0;\r\n const max = this.max.getConnectedValue(state) || 0;\r\n return min + Math.random() * (max - min);\r\n };\r\n break;\r\n }\r\n case NodeGeometryBlockConnectionPointTypes.Vector2: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) || Vector2.Zero();\r\n const max = this.max.getConnectedValue(state) || Vector2.Zero();\r\n return new Vector2(min.x + Math.random() * (max.x - min.x), min.y + Math.random() * (max.y - min.y));\r\n };\r\n break;\r\n }\r\n case NodeGeometryBlockConnectionPointTypes.Vector3: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) || Vector3.Zero();\r\n const max = this.max.getConnectedValue(state) || Vector3.Zero();\r\n return new Vector3(min.x + Math.random() * (max.x - min.x), min.y + Math.random() * (max.y - min.y), min.z + Math.random() * (max.z - min.z));\r\n };\r\n break;\r\n }\r\n case NodeGeometryBlockConnectionPointTypes.Vector4: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) || Vector4.Zero();\r\n const max = this.max.getConnectedValue(state) || Vector4.Zero();\r\n return new Vector4(\r\n min.x + Math.random() * (max.x - min.x),\r\n min.y + Math.random() * (max.y - min.y),\r\n min.z + Math.random() * (max.z - min.z),\r\n min.w + Math.random() * (max.w - min.w)\r\n );\r\n };\r\n break;\r\n }\r\n }\r\n\r\n if (this.lockMode === RandomBlockLocks.None || !func) {\r\n this.output._storedFunction = func;\r\n } else {\r\n this.output._storedFunction = (state) => {\r\n let lockId = 0;\r\n\r\n switch (this.lockMode) {\r\n case RandomBlockLocks.InstanceID:\r\n lockId = state.getContextualValue(NodeGeometryContextualSources.InstanceID, true) || 0;\r\n break;\r\n case RandomBlockLocks.LoopID:\r\n lockId = state.getContextualValue(NodeGeometryContextualSources.LoopID, true) || 0;\r\n break;\r\n case RandomBlockLocks.Once:\r\n lockId = state.buildId || 0;\r\n break;\r\n }\r\n\r\n if (this._currentLockId !== lockId || this.lockMode === RandomBlockLocks.None) {\r\n this._currentLockId = lockId;\r\n this.output._storedValue = func(state);\r\n }\r\n return this.output._storedValue;\r\n };\r\n }\r\n }\r\n\r\n protected override _dumpPropertiesCode() {\r\n const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.lockMode = BABYLON.RandomBlockLocks.${RandomBlockLocks[this.lockMode]};\\n`;\r\n return codeString;\r\n }\r\n\r\n /**\r\n * Serializes this block in a JSON representation\r\n * @returns the serialized block object\r\n */\r\n public override serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.lockMode = this.lockMode;\r\n\r\n return serializationObject;\r\n }\r\n\r\n public override _deserialize(serializationObject: any) {\r\n super._deserialize(serializationObject);\r\n\r\n this.lockMode = serializationObject.lockMode;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.RandomBlock\", RandomBlock);\r\n"]}
1
+ {"version":3,"file":"randomBlock.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Meshes/Node/Blocks/randomBlock.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,qCAAqC,EAAE,MAAM,2CAA2C,CAAC;AAElG,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAEvE,OAAO,EAA0B,sBAAsB,EAAE,6CAAsC;AAC/F,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAEvF;;GAEG;AACH,MAAM,CAAN,IAAY,gBAWX;AAXD,WAAY,gBAAgB;IACxB,WAAW;IACX,uDAAI,CAAA;IACJ,aAAa;IACb,gEAAgE;IAChE,2DAAM,CAAA;IACN,iBAAiB;IACjB,gEAAgE;IAChE,mEAAU,CAAA;IACV,WAAW;IACX,uDAAI,CAAA;AACR,CAAC,EAXW,gBAAgB,KAAhB,gBAAgB,QAW3B;AAED;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,iBAAiB;IAiB9C;;;OAGG;IACH,YAAmB,IAAY;QAC3B,KAAK,CAAC,IAAI,CAAC,CAAC;QArBR,mBAAc,GAAG,CAAC,CAAC,CAAC;QAC5B;;WAEG;QAWI,aAAQ,GAAG,gBAAgB,CAAC,IAAI,CAAC;QASpC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,qCAAqC,CAAC,UAAU,CAAC,CAAC;QAC5E,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,qCAAqC,CAAC,UAAU,CAAC,CAAC;QAE5E,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,qCAAqC,CA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BAAsB,CAAC,UAAU,uCAA+B,UAAU,EAAE;QACzE,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;QAC5B,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE;YACL,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE;YAC/C,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,CAAC,MAAM,EAAE;YACnD,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,gBAAgB,CAAC,UAAU,EAAE;YAC3D,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE;SAClD;KACJ,CAAC;6CACsC;AAoK5C,aAAa,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC","sourcesContent":["import { NodeGeometryBlock } from \"../nodeGeometryBlock\";\r\nimport type { NodeGeometryConnectionPoint } from \"../nodeGeometryBlockConnectionPoint\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport { NodeGeometryBlockConnectionPointTypes } from \"../Enums/nodeGeometryConnectionPointTypes\";\r\nimport type { NodeGeometryBuildState } from \"../nodeGeometryBuildState\";\r\nimport { GeometryInputBlock } from \"./geometryInputBlock\";\r\nimport { Vector2, Vector3, Vector4 } from \"../../../Maths/math.vector\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport { PropertyTypeForEdition, editableInPropertyPage } from \"core/Decorators/nodeDecorator\";\r\nimport { NodeGeometryContextualSources } from \"../Enums/nodeGeometryContextualSources\";\r\n\r\n/**\r\n * Locks supported by the random block\r\n */\r\nexport enum RandomBlockLocks {\r\n /** None */\r\n None,\r\n /** LoopID */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n LoopID,\r\n /** InstanceID */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n InstanceID,\r\n /** Once */\r\n Once,\r\n}\r\n\r\n/**\r\n * Block used to get a random number\r\n */\r\nexport class RandomBlock extends NodeGeometryBlock {\r\n private _currentLockId = -1;\r\n /**\r\n * Gets or sets a value indicating if that block will lock its value for a specific duration\r\n */\r\n @editableInPropertyPage(\"LockMode\", PropertyTypeForEdition.List, \"ADVANCED\", {\r\n notifiers: { rebuild: true },\r\n embedded: true,\r\n options: [\r\n { label: \"None\", value: RandomBlockLocks.None },\r\n { label: \"LoopID\", value: RandomBlockLocks.LoopID },\r\n { label: \"InstanceID\", value: RandomBlockLocks.InstanceID },\r\n { label: \"Once\", value: RandomBlockLocks.Once },\r\n ],\r\n })\r\n public lockMode = RandomBlockLocks.None;\r\n\r\n /**\r\n * Create a new RandomBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name);\r\n\r\n this.registerInput(\"min\", NodeGeometryBlockConnectionPointTypes.AutoDetect);\r\n this.registerInput(\"max\", NodeGeometryBlockConnectionPointTypes.AutoDetect);\r\n\r\n this.registerOutput(\"output\", NodeGeometryBlockConnectionPointTypes.BasedOnInput);\r\n\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Matrix);\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Geometry);\r\n this._inputs[0].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Texture);\r\n this._inputs[1].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Matrix);\r\n this._inputs[1].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Geometry);\r\n this._inputs[1].excludedConnectionPointTypes.push(NodeGeometryBlockConnectionPointTypes.Texture);\r\n\r\n this._outputs[0]._typeConnectionSource = this._inputs[0];\r\n this._linkConnectionTypes(0, 1);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public override getClassName() {\r\n return \"RandomBlock\";\r\n }\r\n\r\n /**\r\n * Gets the min input component\r\n */\r\n public get min(): NodeGeometryConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the max input component\r\n */\r\n public get max(): NodeGeometryConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the geometry output component\r\n */\r\n public get output(): NodeGeometryConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n public override autoConfigure() {\r\n if (!this.min.isConnected) {\r\n const minInput = new GeometryInputBlock(\"Min\");\r\n minInput.value = 0;\r\n minInput.output.connectTo(this.min);\r\n }\r\n\r\n if (!this.max.isConnected) {\r\n const maxInput = new GeometryInputBlock(\"Max\");\r\n maxInput.value = 1;\r\n maxInput.output.connectTo(this.max);\r\n }\r\n }\r\n\r\n protected override _buildBlock() {\r\n let func: Nullable<(state: NodeGeometryBuildState) => any> = null;\r\n this._currentLockId = -1;\r\n\r\n switch (this.min.type) {\r\n case NodeGeometryBlockConnectionPointTypes.Int:\r\n case NodeGeometryBlockConnectionPointTypes.Float: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) ?? 0;\r\n const max = this.max.getConnectedValue(state) ?? 0;\r\n return min + Math.random() * (max - min);\r\n };\r\n break;\r\n }\r\n case NodeGeometryBlockConnectionPointTypes.Vector2: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) ?? Vector2.Zero();\r\n const max = this.max.getConnectedValue(state) ?? Vector2.Zero();\r\n return new Vector2(min.x + Math.random() * (max.x - min.x), min.y + Math.random() * (max.y - min.y));\r\n };\r\n break;\r\n }\r\n case NodeGeometryBlockConnectionPointTypes.Vector3: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) ?? Vector3.Zero();\r\n const max = this.max.getConnectedValue(state) ?? Vector3.Zero();\r\n return new Vector3(min.x + Math.random() * (max.x - min.x), min.y + Math.random() * (max.y - min.y), min.z + Math.random() * (max.z - min.z));\r\n };\r\n break;\r\n }\r\n case NodeGeometryBlockConnectionPointTypes.Vector4: {\r\n func = (state) => {\r\n const min = this.min.getConnectedValue(state) ?? Vector4.Zero();\r\n const max = this.max.getConnectedValue(state) ?? Vector4.Zero();\r\n return new Vector4(\r\n min.x + Math.random() * (max.x - min.x),\r\n min.y + Math.random() * (max.y - min.y),\r\n min.z + Math.random() * (max.z - min.z),\r\n min.w + Math.random() * (max.w - min.w)\r\n );\r\n };\r\n break;\r\n }\r\n }\r\n\r\n if (this.lockMode === RandomBlockLocks.None || !func) {\r\n this.output._storedFunction = func;\r\n } else {\r\n this.output._storedFunction = (state) => {\r\n let lockId = 0;\r\n\r\n switch (this.lockMode) {\r\n case RandomBlockLocks.InstanceID:\r\n lockId = state.getContextualValue(NodeGeometryContextualSources.InstanceID, true) ?? 0;\r\n break;\r\n case RandomBlockLocks.LoopID:\r\n lockId = state.getContextualValue(NodeGeometryContextualSources.LoopID, true) ?? 0;\r\n break;\r\n case RandomBlockLocks.Once:\r\n lockId = state.buildId ?? 0;\r\n break;\r\n }\r\n\r\n if (this._currentLockId !== lockId || this.lockMode === RandomBlockLocks.None) {\r\n this._currentLockId = lockId;\r\n this.output._storedValue = func(state);\r\n }\r\n return this.output._storedValue;\r\n };\r\n }\r\n }\r\n\r\n protected override _dumpPropertiesCode() {\r\n const codeString = super._dumpPropertiesCode() + `${this._codeVariableName}.lockMode = BABYLON.RandomBlockLocks.${RandomBlockLocks[this.lockMode]};\\n`;\r\n return codeString;\r\n }\r\n\r\n /**\r\n * Serializes this block in a JSON representation\r\n * @returns the serialized block object\r\n */\r\n public override serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.lockMode = this.lockMode;\r\n\r\n return serializationObject;\r\n }\r\n\r\n public override _deserialize(serializationObject: any) {\r\n super._deserialize(serializationObject);\r\n\r\n this.lockMode = serializationObject.lockMode;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.RandomBlock\", RandomBlock);\r\n"]}
@@ -23,6 +23,7 @@ export declare class CopyTextureToTexture {
23
23
  private _effectWrapper;
24
24
  private _source;
25
25
  private _conversion;
26
+ private _lodLevel;
26
27
  /** Shader language used */
27
28
  protected _shaderLanguage: ShaderLanguage;
28
29
  /**
@@ -38,6 +39,11 @@ export declare class CopyTextureToTexture {
38
39
  */
39
40
  get source(): InternalTexture | ThinTexture;
40
41
  set source(texture: InternalTexture | ThinTexture);
42
+ /**
43
+ * Gets or sets the LOD level to copy from the source texture
44
+ */
45
+ get lodLevel(): number;
46
+ set lodLevel(level: number);
41
47
  private _textureIsInternal;
42
48
  /**
43
49
  * Constructs a new instance of the class
@@ -58,9 +64,10 @@ export declare class CopyTextureToTexture {
58
64
  * @param source The source texture
59
65
  * @param destination The destination texture. If null, copy the source to the currently bound framebuffer
60
66
  * @param conversion The conversion mode that should be applied when copying
67
+ * @param lod The LOD level to copy from the source texture
61
68
  * @returns
62
69
  */
63
- copy(source: InternalTexture | ThinTexture, destination?: Nullable<RenderTargetWrapper | IRenderTargetTexture>, conversion?: ConversionMode): boolean;
70
+ copy(source: InternalTexture | ThinTexture, destination?: Nullable<RenderTargetWrapper | IRenderTargetTexture>, conversion?: ConversionMode, lod?: number): boolean;
64
71
  /**
65
72
  * Releases all the resources used by the class
66
73
  */
@@ -34,6 +34,15 @@ export class CopyTextureToTexture {
34
34
  set source(texture) {
35
35
  this._source = texture;
36
36
  }
37
+ /**
38
+ * Gets or sets the LOD level to copy from the source texture
39
+ */
40
+ get lodLevel() {
41
+ return this._lodLevel;
42
+ }
43
+ set lodLevel(level) {
44
+ this._lodLevel = level;
45
+ }
37
46
  _textureIsInternal(texture) {
38
47
  return texture.getInternalTexture === undefined;
39
48
  }
@@ -49,6 +58,8 @@ export class CopyTextureToTexture {
49
58
  this._shadersLoaded = false;
50
59
  this._engine = engine;
51
60
  this._isDepthTexture = isDepthTexture;
61
+ this._lodLevel = 0;
62
+ this._conversion = 0 /* ConversionMode.None */;
52
63
  this._renderer = new EffectRenderer(engine);
53
64
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
54
65
  this._initShaderSourceAsync(isDepthTexture, sameSizeCopy);
@@ -75,7 +86,7 @@ export class CopyTextureToTexture {
75
86
  name: "CopyTextureToTexture",
76
87
  fragmentShader: "copyTextureToTexture",
77
88
  useShaderStore: true,
78
- uniformNames: ["conversion"],
89
+ uniformNames: ["conversion", "lodLevel"],
79
90
  samplerNames: ["textureSampler"],
80
91
  defines,
81
92
  shaderLanguage: this._shaderLanguage,
@@ -98,6 +109,7 @@ export class CopyTextureToTexture {
98
109
  this._effectWrapper.effect.setTexture("textureSampler", this._source);
99
110
  }
100
111
  this._effectWrapper.effect.setFloat("conversion", this._conversion);
112
+ this._effectWrapper.effect.setFloat("lodLevel", this._lodLevel);
101
113
  });
102
114
  }
103
115
  /**
@@ -112,14 +124,16 @@ export class CopyTextureToTexture {
112
124
  * @param source The source texture
113
125
  * @param destination The destination texture. If null, copy the source to the currently bound framebuffer
114
126
  * @param conversion The conversion mode that should be applied when copying
127
+ * @param lod The LOD level to copy from the source texture
115
128
  * @returns
116
129
  */
117
- copy(source, destination = null, conversion = 0 /* ConversionMode.None */) {
130
+ copy(source, destination = null, conversion = 0 /* ConversionMode.None */, lod = 0) {
118
131
  if (!this.isReady()) {
119
132
  return false;
120
133
  }
121
134
  this._source = source;
122
135
  this._conversion = conversion;
136
+ this._lodLevel = lod;
123
137
  const engineDepthFunc = this._engine.getDepthFunction();
124
138
  const engineDepthMask = this._engine.getDepthWrite(); // for some reasons, depthWrite is not restored by EffectRenderer.restoreStates
125
139
  this._renderer.render(this._effectWrapper, destination);
@@ -1 +1 @@
1
- {"version":3,"file":"copyTextureToTexture.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/copyTextureToTexture.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5E,OAAO,EAAE,SAAS,EAAE,gCAA+B;AAKnD;;GAEG;AACH,MAAM,CAAN,IAAkB,cAIjB;AAJD,WAAkB,cAAc;IAC5B,mDAAQ,CAAA;IACR,qEAAiB,CAAA;IACjB,mEAAgB,CAAA;AACpB,CAAC,EAJi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OAAO,CAAC,CAAC;YAC1E,CAAC;YACD,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACI,OAAO;QACV,OAAO,IAAI,CAAC,cAAc,IAAI,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAC3E,CAAC;IAED;;;;;;OAMG;IACI,IAAI,CAAC,MAAqC,EAAE,cAAoE,IAAI,EAAE,UAAU,8BAAsB;QACzJ,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YAClB,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;QACxD,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,+EAA+E;QAErI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;QAExD,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;QAE5C,IAAI,IAAI,CAAC,eAAe,IAAI,eAAe,EAAE,CAAC;YAC1C,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC;QACnD,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,cAAc,EAAE,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACJ","sourcesContent":["import type { AbstractEngine } from \"core/Engines/abstractEngine\";\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport { EffectRenderer, EffectWrapper } from \"../Materials/effectRenderer\";\r\nimport type { IRenderTargetTexture, RenderTargetWrapper } from \"../Engines/renderTargetWrapper\";\r\nimport type { ThinTexture } from \"../Materials/Textures/thinTexture\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\n\r\n/**\r\n * Conversion modes available when copying a texture into another one\r\n */\r\nexport const enum ConversionMode {\r\n None = 0,\r\n ToLinearSpace = 1,\r\n ToGammaSpace = 2,\r\n}\r\n\r\n/**\r\n * Class used for fast copy from one texture to another\r\n */\r\nexport class CopyTextureToTexture {\r\n private _engine: AbstractEngine;\r\n private _isDepthTexture: boolean;\r\n private _renderer: EffectRenderer;\r\n private _effectWrapper: EffectWrapper;\r\n private _source: InternalTexture | ThinTexture;\r\n private _conversion: number;\r\n\r\n /** Shader language used */\r\n protected _shaderLanguage = ShaderLanguage.GLSL;\r\n\r\n /**\r\n * Gets the shader language\r\n */\r\n public get shaderLanguage(): ShaderLanguage {\r\n return this._shaderLanguage;\r\n }\r\n\r\n /**\r\n * Gets the effect wrapper used for the copy\r\n */\r\n public get effectWrapper() {\r\n return this._effectWrapper;\r\n }\r\n\r\n /**\r\n * Gets or sets the source texture\r\n */\r\n public get source() {\r\n return this._source;\r\n }\r\n\r\n public set source(texture: InternalTexture | ThinTexture) {\r\n this._source = texture;\r\n }\r\n\r\n private _textureIsInternal(texture: InternalTexture | ThinTexture): texture is InternalTexture {\r\n return (texture as ThinTexture).getInternalTexture === undefined;\r\n }\r\n\r\n /**\r\n * Constructs a new instance of the class\r\n * @param engine The engine to use for the copy\r\n * @param isDepthTexture True means that we should write (using gl_FragDepth) into the depth texture attached to the destination (default: false)\r\n * @param sameSizeCopy True means that the copy will be done without any sampling (more efficient, but requires the source and destination to be of the same size) (default: false)\r\n */\r\n constructor(engine: AbstractEngine, isDepthTexture = false, sameSizeCopy = false) {\r\n this._engine = engine;\r\n this._isDepthTexture = isDepthTexture;\r\n\r\n this._renderer = new EffectRenderer(engine);\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n this._initShaderSourceAsync(isDepthTexture, sameSizeCopy);\r\n }\r\n\r\n private _shadersLoaded = false;\r\n private async _initShaderSourceAsync(isDepthTexture: boolean, sameSizeCopy: boolean) {\r\n const engine = this._engine;\r\n\r\n if (engine.isWebGPU) {\r\n this._shaderLanguage = ShaderLanguage.WGSL;\r\n\r\n await import(\"../ShadersWGSL/copyTextureToTexture.fragment\");\r\n } else {\r\n await import(\"../Shaders/copyTextureToTexture.fragment\");\r\n }\r\n\r\n this._shadersLoaded = true;\r\n\r\n const defines: string[] = [];\r\n\r\n if (isDepthTexture) {\r\n defines.push(\"#define DEPTH_TEXTURE\");\r\n }\r\n if (sameSizeCopy) {\r\n defines.push(\"#define NO_SAMPLER\");\r\n }\r\n\r\n this._effectWrapper = new EffectWrapper({\r\n engine: engine,\r\n name: \"CopyTextureToTexture\",\r\n fragmentShader: \"copyTextureToTexture\",\r\n useShaderStore: true,\r\n uniformNames: [\"conversion\"],\r\n samplerNames: [\"textureSampler\"],\r\n defines,\r\n shaderLanguage: this._shaderLanguage,\r\n });\r\n\r\n this._effectWrapper.onApplyObservable.add(() => {\r\n if (isDepthTexture) {\r\n engine.setState(false);\r\n engine.setDepthBuffer(true);\r\n engine.depthCullingState.depthMask = true;\r\n engine.depthCullingState.depthFunc = Constants.ALWAYS;\r\n } else {\r\n engine.depthCullingState.depthMask = false;\r\n // other states are already set by EffectRenderer.applyEffectWrapper\r\n }\r\n\r\n if (this._textureIsInternal(this._source)) {\r\n this._effectWrapper.effect._bindTexture(\"textureSampler\", this._source);\r\n } else {\r\n this._effectWrapper.effect.setTexture(\"textureSampler\", this._source);\r\n }\r\n this._effectWrapper.effect.setFloat(\"conversion\", this._conversion);\r\n });\r\n }\r\n\r\n /**\r\n * Indicates if the effect is ready to be used for the copy\r\n * @returns true if \"copy\" can be called without delay, else false\r\n */\r\n public isReady(): boolean {\r\n return this._shadersLoaded && !!this._effectWrapper?.effect?.isReady();\r\n }\r\n\r\n /**\r\n * Copy one texture into another\r\n * @param source The source texture\r\n * @param destination The destination texture. If null, copy the source to the currently bound framebuffer\r\n * @param conversion The conversion mode that should be applied when copying\r\n * @returns\r\n */\r\n public copy(source: InternalTexture | ThinTexture, destination: Nullable<RenderTargetWrapper | IRenderTargetTexture> = null, conversion = ConversionMode.None): boolean {\r\n if (!this.isReady()) {\r\n return false;\r\n }\r\n\r\n this._source = source;\r\n this._conversion = conversion;\r\n\r\n const engineDepthFunc = this._engine.getDepthFunction();\r\n const engineDepthMask = this._engine.getDepthWrite(); // for some reasons, depthWrite is not restored by EffectRenderer.restoreStates\r\n\r\n this._renderer.render(this._effectWrapper, destination);\r\n\r\n this._engine.setDepthWrite(engineDepthMask);\r\n\r\n if (this._isDepthTexture && engineDepthFunc) {\r\n this._engine.setDepthFunction(engineDepthFunc);\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Releases all the resources used by the class\r\n */\r\n public dispose(): void {\r\n this._effectWrapper?.dispose();\r\n this._renderer.dispose();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"copyTextureToTexture.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/copyTextureToTexture.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5E,OAAO,EAAE,SAAS,EAAE,gCAA+B;AAKnD;;GAEG;AACH,MAAM,CAAN,IAAkB,cAIjB;AAJD,WAAkB,cAAc;IAC5B,mDAAQ,CAAA;IACR,qEAAiB,CAAA;IACjB,mEAAgB,CAAA;AACpB,CAAC,EAJiB,cAAc,KAAd,cAAc,QAI/B;AAED;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAY7B;;OAEG;IACH,IAAW,cAAc;QACrB,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;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,CAAC,CAAC;QACnD,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,cAAc,EAAE,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACJ","sourcesContent":["import type { AbstractEngine } from \"core/Engines/abstractEngine\";\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport { EffectRenderer, EffectWrapper } from \"../Materials/effectRenderer\";\r\nimport type { IRenderTargetTexture, RenderTargetWrapper } from \"../Engines/renderTargetWrapper\";\r\nimport type { ThinTexture } from \"../Materials/Textures/thinTexture\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\n\r\n/**\r\n * Conversion modes available when copying a texture into another one\r\n */\r\nexport const enum ConversionMode {\r\n None = 0,\r\n ToLinearSpace = 1,\r\n ToGammaSpace = 2,\r\n}\r\n\r\n/**\r\n * Class used for fast copy from one texture to another\r\n */\r\nexport class CopyTextureToTexture {\r\n private _engine: AbstractEngine;\r\n private _isDepthTexture: boolean;\r\n private _renderer: EffectRenderer;\r\n private _effectWrapper: EffectWrapper;\r\n private _source: InternalTexture | ThinTexture;\r\n private _conversion: number;\r\n private _lodLevel: number;\r\n\r\n /** Shader language used */\r\n protected _shaderLanguage = ShaderLanguage.GLSL;\r\n\r\n /**\r\n * Gets the shader language\r\n */\r\n public get shaderLanguage(): ShaderLanguage {\r\n return this._shaderLanguage;\r\n }\r\n\r\n /**\r\n * Gets the effect wrapper used for the copy\r\n */\r\n public get effectWrapper() {\r\n return this._effectWrapper;\r\n }\r\n\r\n /**\r\n * Gets or sets the source texture\r\n */\r\n public get source() {\r\n return this._source;\r\n }\r\n\r\n public set source(texture: InternalTexture | ThinTexture) {\r\n this._source = texture;\r\n }\r\n\r\n /**\r\n * Gets or sets the LOD level to copy from the source texture\r\n */\r\n public get lodLevel(): number {\r\n return this._lodLevel;\r\n }\r\n\r\n public set lodLevel(level: number) {\r\n this._lodLevel = level;\r\n }\r\n\r\n private _textureIsInternal(texture: InternalTexture | ThinTexture): texture is InternalTexture {\r\n return (texture as ThinTexture).getInternalTexture === undefined;\r\n }\r\n\r\n /**\r\n * Constructs a new instance of the class\r\n * @param engine The engine to use for the copy\r\n * @param isDepthTexture True means that we should write (using gl_FragDepth) into the depth texture attached to the destination (default: false)\r\n * @param sameSizeCopy True means that the copy will be done without any sampling (more efficient, but requires the source and destination to be of the same size) (default: false)\r\n */\r\n constructor(engine: AbstractEngine, isDepthTexture = false, sameSizeCopy = false) {\r\n this._engine = engine;\r\n this._isDepthTexture = isDepthTexture;\r\n this._lodLevel = 0;\r\n this._conversion = ConversionMode.None;\r\n\r\n this._renderer = new EffectRenderer(engine);\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n this._initShaderSourceAsync(isDepthTexture, sameSizeCopy);\r\n }\r\n\r\n private _shadersLoaded = false;\r\n private async _initShaderSourceAsync(isDepthTexture: boolean, sameSizeCopy: boolean) {\r\n const engine = this._engine;\r\n\r\n if (engine.isWebGPU) {\r\n this._shaderLanguage = ShaderLanguage.WGSL;\r\n\r\n await import(\"../ShadersWGSL/copyTextureToTexture.fragment\");\r\n } else {\r\n await import(\"../Shaders/copyTextureToTexture.fragment\");\r\n }\r\n\r\n this._shadersLoaded = true;\r\n\r\n const defines: string[] = [];\r\n\r\n if (isDepthTexture) {\r\n defines.push(\"#define DEPTH_TEXTURE\");\r\n }\r\n if (sameSizeCopy) {\r\n defines.push(\"#define NO_SAMPLER\");\r\n }\r\n\r\n this._effectWrapper = new EffectWrapper({\r\n engine: engine,\r\n name: \"CopyTextureToTexture\",\r\n fragmentShader: \"copyTextureToTexture\",\r\n useShaderStore: true,\r\n uniformNames: [\"conversion\", \"lodLevel\"],\r\n samplerNames: [\"textureSampler\"],\r\n defines,\r\n shaderLanguage: this._shaderLanguage,\r\n });\r\n\r\n this._effectWrapper.onApplyObservable.add(() => {\r\n if (isDepthTexture) {\r\n engine.setState(false);\r\n engine.setDepthBuffer(true);\r\n engine.depthCullingState.depthMask = true;\r\n engine.depthCullingState.depthFunc = Constants.ALWAYS;\r\n } else {\r\n engine.depthCullingState.depthMask = false;\r\n // other states are already set by EffectRenderer.applyEffectWrapper\r\n }\r\n\r\n if (this._textureIsInternal(this._source)) {\r\n this._effectWrapper.effect._bindTexture(\"textureSampler\", this._source);\r\n } else {\r\n this._effectWrapper.effect.setTexture(\"textureSampler\", this._source);\r\n }\r\n this._effectWrapper.effect.setFloat(\"conversion\", this._conversion);\r\n this._effectWrapper.effect.setFloat(\"lodLevel\", this._lodLevel);\r\n });\r\n }\r\n\r\n /**\r\n * Indicates if the effect is ready to be used for the copy\r\n * @returns true if \"copy\" can be called without delay, else false\r\n */\r\n public isReady(): boolean {\r\n return this._shadersLoaded && !!this._effectWrapper?.effect?.isReady();\r\n }\r\n\r\n /**\r\n * Copy one texture into another\r\n * @param source The source texture\r\n * @param destination The destination texture. If null, copy the source to the currently bound framebuffer\r\n * @param conversion The conversion mode that should be applied when copying\r\n * @param lod The LOD level to copy from the source texture\r\n * @returns\r\n */\r\n public copy(\r\n source: InternalTexture | ThinTexture,\r\n destination: Nullable<RenderTargetWrapper | IRenderTargetTexture> = null,\r\n conversion = ConversionMode.None,\r\n lod = 0\r\n ): boolean {\r\n if (!this.isReady()) {\r\n return false;\r\n }\r\n\r\n this._source = source;\r\n this._conversion = conversion;\r\n this._lodLevel = lod;\r\n\r\n const engineDepthFunc = this._engine.getDepthFunction();\r\n const engineDepthMask = this._engine.getDepthWrite(); // for some reasons, depthWrite is not restored by EffectRenderer.restoreStates\r\n\r\n this._renderer.render(this._effectWrapper, destination);\r\n\r\n this._engine.setDepthWrite(engineDepthMask);\r\n\r\n if (this._isDepthTexture && engineDepthFunc) {\r\n this._engine.setDepthFunction(engineDepthFunc);\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Releases all the resources used by the class\r\n */\r\n public dispose(): void {\r\n this._effectWrapper?.dispose();\r\n this._renderer.dispose();\r\n }\r\n}\r\n"]}
@@ -1,9 +1,9 @@
1
1
  import type { Matrix } from "../../Maths/math.vector.js";
2
- import { Vector3 } from "../../Maths/math.vector.js";
3
- import type { Particle } from "../../Particles/particle.js";
4
- import type { IParticleEmitterType } from "./IParticleEmitterType.js";
2
+ import type { Particle } from "../particle.js";
5
3
  import type { UniformBufferEffectCommonAccessor } from "../../Materials/uniformBufferEffectCommonAccessor.js";
6
4
  import type { UniformBuffer } from "../../Materials/uniformBuffer.js";
5
+ import type { IParticleEmitterType } from "./IParticleEmitterType.js";
6
+ import { Vector3 } from "../../Maths/math.vector.js";
7
7
  /**
8
8
  * Particle emitter emitting particles from the inside of a cone.
9
9
  * It emits the particles alongside the cone volume from the base to the particle.
@@ -1,5 +1,5 @@
1
1
  import { DeepCopier } from "../../Misc/deepCopier.js";
2
- import { Vector3, TmpVectors } from "../../Maths/math.vector.js";
2
+ import { Vector3 } from "../../Maths/math.vector.js";
3
3
  import { RandomRange } from "../../Maths/math.scalar.functions.js";
4
4
  /**
5
5
  * Particle emitter emitting particles from the inside of a cone.
@@ -68,19 +68,19 @@ export class ConeParticleEmitter {
68
68
  * @param isLocal defines if the direction should be set in local space
69
69
  */
70
70
  startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {
71
- if (isLocal) {
72
- TmpVectors.Vector3[0].copyFrom(particle._localPosition).normalize();
73
- }
74
- else {
75
- particle.position.subtractToRef(worldMatrix.getTranslation(), TmpVectors.Vector3[0]).normalize();
76
- }
71
+ const direction = particle.position.subtract(worldMatrix.getTranslation()).normalize();
77
72
  const randX = RandomRange(0, this.directionRandomizer);
78
73
  const randY = RandomRange(0, this.directionRandomizer);
79
74
  const randZ = RandomRange(0, this.directionRandomizer);
80
- directionToUpdate.x = TmpVectors.Vector3[0].x + randX;
81
- directionToUpdate.y = TmpVectors.Vector3[0].y + randY;
82
- directionToUpdate.z = TmpVectors.Vector3[0].z + randZ;
83
- directionToUpdate.normalize();
75
+ direction.x += randX;
76
+ direction.y += randY;
77
+ direction.z += randZ;
78
+ direction.normalize();
79
+ if (isLocal) {
80
+ directionToUpdate.copyFrom(direction);
81
+ return;
82
+ }
83
+ Vector3.TransformNormalFromFloatsToRef(direction.x, direction.y, direction.z, worldMatrix, directionToUpdate);
84
84
  }
85
85
  /**
86
86
  * Called by the particle System when the position is computed for the created particle.
@@ -1 +1 @@
1
- {"version":3,"file":"coneParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/coneParticleEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAKhE;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAoB5B;;OAEG;IACH,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,IAAW,MAAM,CAAC,KAAa;QAC3B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,IAAW,KAAK,CAAC,KAAa;QAC1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;IAEO,YAAY;QAChB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC5D,CAA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C,CAAC;IAC7D,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 { RandomRange } from \"../../Maths/math.scalar.functions\";\r\nimport type { Particle } from \"../../Particles/particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"../../Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\r\n/**\r\n * Particle emitter emitting particles from the inside of a cone.\r\n * It emits the particles alongside the cone volume from the base to the particle.\r\n * The emission direction might be randomized.\r\n */\r\nexport class ConeParticleEmitter implements IParticleEmitterType {\r\n private _radius: number;\r\n private _angle: number;\r\n private _height: number;\r\n\r\n /**\r\n * Gets or sets a value indicating where on the radius the start position should be picked (1 = everywhere, 0 = only surface)\r\n */\r\n public radiusRange = 1;\r\n\r\n /**\r\n * Gets or sets a value indicating where on the height the start position should be picked (1 = everywhere, 0 = only surface)\r\n */\r\n public heightRange = 1;\r\n\r\n /**\r\n * Gets or sets a value indicating if all the particles should be emitted from the spawn point only (the base of the cone)\r\n */\r\n public emitFromSpawnPointOnly = false;\r\n\r\n /**\r\n * Gets or sets the radius of the emission cone\r\n */\r\n public get radius(): number {\r\n return this._radius;\r\n }\r\n\r\n public set radius(value: number) {\r\n this._radius = value;\r\n this._buildHeight();\r\n }\r\n\r\n /**\r\n * Gets or sets the angle of the emission cone\r\n */\r\n public get angle(): number {\r\n return this._angle;\r\n }\r\n\r\n public set angle(value: number) {\r\n this._angle = value;\r\n this._buildHeight();\r\n }\r\n\r\n private _buildHeight() {\r\n if (this._angle !== 0) {\r\n this._height = this._radius / Math.tan(this._angle / 2);\r\n } else {\r\n this._height = 1;\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new instance ConeParticleEmitter\r\n * @param radius the radius of the emission cone (1 by default)\r\n * @param angle the cone base angle (PI by default)\r\n * @param directionRandomizer defines how much to randomize the particle direction [0-1] (default is 0)\r\n */\r\n constructor(\r\n radius = 1,\r\n angle = Math.PI,\r\n /** [0] defines how much to randomize the particle direction [0-1] (default is 0) */\r\n public directionRandomizer = 0\r\n ) {\r\n this.angle = angle;\r\n this.radius = radius;\r\n }\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 if (isLocal) {\r\n TmpVectors.Vector3[0].copyFrom(particle._localPosition!).normalize();\r\n } else {\r\n particle.position.subtractToRef(worldMatrix.getTranslation(), TmpVectors.Vector3[0]).normalize();\r\n }\r\n\r\n const randX = RandomRange(0, this.directionRandomizer);\r\n const randY = RandomRange(0, this.directionRandomizer);\r\n const randZ = RandomRange(0, this.directionRandomizer);\r\n directionToUpdate.x = TmpVectors.Vector3[0].x + randX;\r\n directionToUpdate.y = TmpVectors.Vector3[0].y + randY;\r\n directionToUpdate.z = TmpVectors.Vector3[0].z + randZ;\r\n directionToUpdate.normalize();\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 startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const s = RandomRange(0, Math.PI * 2);\r\n let h: number;\r\n\r\n if (!this.emitFromSpawnPointOnly) {\r\n h = RandomRange(0, this.heightRange);\r\n // Better distribution in a cone at normal angles.\r\n h = 1 - h * h;\r\n } else {\r\n h = 0.0001;\r\n }\r\n let radius = this._radius - RandomRange(0, this._radius * this.radiusRange);\r\n radius = radius * h;\r\n\r\n const randX = radius * Math.sin(s);\r\n const randZ = radius * Math.cos(s);\r\n const randY = h * this._height;\r\n\r\n if (isLocal) {\r\n positionToUpdate.x = randX;\r\n positionToUpdate.y = randY;\r\n positionToUpdate.z = randZ;\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, 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(): ConeParticleEmitter {\r\n const newOne = new ConeParticleEmitter(this._radius, this._angle, this.directionRandomizer);\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 public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat2(\"radius\", this._radius, this.radiusRange);\r\n uboOrEffect.setFloat(\"coneAngle\", this._angle);\r\n uboOrEffect.setFloat2(\"height\", this._height, this.heightRange);\r\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\r\n }\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 public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 2);\r\n ubo.addUniform(\"coneAngle\", 1);\r\n ubo.addUniform(\"height\", 2);\r\n ubo.addUniform(\"directionRandomizer\", 1);\r\n }\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 let defines = \"#define CONEEMITTER\";\r\n\r\n if (this.emitFromSpawnPointOnly) {\r\n defines += \"\\n#define CONEEMITTERSPAWNPOINT\";\r\n }\r\n\r\n return defines;\r\n }\r\n\r\n /**\r\n * Returns the string \"ConeParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"ConeParticleEmitter\";\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.radius = this._radius;\r\n serializationObject.angle = this._angle;\r\n serializationObject.directionRandomizer = this.directionRandomizer;\r\n serializationObject.radiusRange = this.radiusRange;\r\n serializationObject.heightRange = this.heightRange;\r\n serializationObject.emitFromSpawnPointOnly = this.emitFromSpawnPointOnly;\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 this.radius = serializationObject.radius;\r\n this.angle = serializationObject.angle;\r\n this.directionRandomizer = serializationObject.directionRandomizer;\r\n\r\n this.radiusRange = serializationObject.radiusRange !== undefined ? serializationObject.radiusRange : 1;\r\n this.heightRange = serializationObject.radiusRange !== undefined ? serializationObject.heightRange : 1;\r\n this.emitFromSpawnPointOnly = serializationObject.emitFromSpawnPointOnly !== undefined ? serializationObject.emitFromSpawnPointOnly : false;\r\n }\r\n}\r\nexport class ConeDirectedParticleEmitter extends ConeParticleEmitter {\r\n constructor(\r\n radius = 1,\r\n angle = Math.PI,\r\n /**\r\n * [Up vector] The min limit of the emission direction.\r\n */\r\n public direction1 = new Vector3(0, 1, 0),\r\n /**\r\n * [Up vector] The max limit of the emission direction.\r\n */\r\n public direction2 = new Vector3(0, 1, 0)\r\n ) {\r\n super(radius, angle);\r\n }\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 */\r\n public override startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3): void {\r\n const randX = RandomRange(this.direction1.x, this.direction2.x);\r\n const randY = RandomRange(this.direction1.y, this.direction2.y);\r\n const randZ = RandomRange(this.direction1.z, this.direction2.z);\r\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\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 override clone(): ConeDirectedParticleEmitter {\r\n const newOne = new ConeDirectedParticleEmitter(this.radius, this.angle, this.direction1, this.direction2);\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 public override applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\r\n uboOrEffect.setVector3(\"direction1\", this.direction1);\r\n uboOrEffect.setVector3(\"direction2\", this.direction2);\r\n }\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 public override buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\r\n ubo.addUniform(\"direction1\", 3);\r\n ubo.addUniform(\"direction2\", 3);\r\n }\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 override getEffectDefines(): string {\r\n return \"#define CONEEMITTER\\n#define DIRECTEDCONEEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"ConeDirectedParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public override getClassName(): string {\r\n return \"ConeDirectedParticleEmitter\";\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 override serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.direction1 = this.direction1.asArray();\r\n serializationObject.direction2 = this.direction2.asArray();\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 override parse(serializationObject: any): void {\r\n super.parse(serializationObject);\r\n this.direction1.copyFrom(serializationObject.direction1);\r\n this.direction2.copyFrom(serializationObject.direction2);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"coneParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/coneParticleEmitter.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,iCAA6B;AAClD,OAAO,EAAE,OAAO,EAAE,mCAA+B;AACjD,OAAO,EAAE,WAAW,EAAE,6CAAyC;AAE/D;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAoB5B;;OAEG;IACH,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,IAAW,MAAM,CAAC,KAAa;QAC3B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,IAAW,KAAK,CAAC,KAAa;QAC1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;IAEO,YAAY;QAChB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC5D,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;QACrB,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,YACI,MAAM,GAAG,CAAC,EACV,KAAK,GAAG,IAAI,CAAC,EAAE;IACf,oFAAoF;IAC7E,sBAAsB,CAAC;QAAvB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CAAC,GAAkB;QACjD,GAAG,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC5B,GAAG,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;QACjC,GAAG,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;QAChC,GAAG,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACa,gBAAgB;QAC5B,OAAO,kDAAkD,CAAC;IAC9D,CAAC;IAED;;;OAGG;IACa,YAAY;QACxB,OAAO,6BAA6B,CAAC;IACzC,CAAC;IAED;;;OAGG;IACa,SAAS;QACrB,MAAM,mBAAmB,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QAE9C,mBAAmB,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAC3D,mBAAmB,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAE3D,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACa,KAAK,CAAC,mBAAwB;QAC1C,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACjC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;QACzD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC7D,CAAC;CACJ","sourcesContent":["import type { Matrix } from \"core/Maths/math.vector\";\r\nimport type { Particle } from \"core/Particles/particle\";\r\nimport type { UniformBufferEffectCommonAccessor } from \"core/Materials/uniformBufferEffectCommonAccessor\";\r\nimport type { UniformBuffer } from \"core/Materials/uniformBuffer\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\n\r\nimport { DeepCopier } from \"core/Misc/deepCopier\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\nimport { RandomRange } from \"core/Maths/math.scalar.functions\";\r\n\r\n/**\r\n * Particle emitter emitting particles from the inside of a cone.\r\n * It emits the particles alongside the cone volume from the base to the particle.\r\n * The emission direction might be randomized.\r\n */\r\nexport class ConeParticleEmitter implements IParticleEmitterType {\r\n private _radius: number;\r\n private _angle: number;\r\n private _height: number;\r\n\r\n /**\r\n * Gets or sets a value indicating where on the radius the start position should be picked (1 = everywhere, 0 = only surface)\r\n */\r\n public radiusRange = 1;\r\n\r\n /**\r\n * Gets or sets a value indicating where on the height the start position should be picked (1 = everywhere, 0 = only surface)\r\n */\r\n public heightRange = 1;\r\n\r\n /**\r\n * Gets or sets a value indicating if all the particles should be emitted from the spawn point only (the base of the cone)\r\n */\r\n public emitFromSpawnPointOnly = false;\r\n\r\n /**\r\n * Gets or sets the radius of the emission cone\r\n */\r\n public get radius(): number {\r\n return this._radius;\r\n }\r\n\r\n public set radius(value: number) {\r\n this._radius = value;\r\n this._buildHeight();\r\n }\r\n\r\n /**\r\n * Gets or sets the angle of the emission cone\r\n */\r\n public get angle(): number {\r\n return this._angle;\r\n }\r\n\r\n public set angle(value: number) {\r\n this._angle = value;\r\n this._buildHeight();\r\n }\r\n\r\n private _buildHeight() {\r\n if (this._angle !== 0) {\r\n this._height = this._radius / Math.tan(this._angle / 2);\r\n } else {\r\n this._height = 1;\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new instance ConeParticleEmitter\r\n * @param radius the radius of the emission cone (1 by default)\r\n * @param angle the cone base angle (PI by default)\r\n * @param directionRandomizer defines how much to randomize the particle direction [0-1] (default is 0)\r\n */\r\n constructor(\r\n radius = 1,\r\n angle = Math.PI,\r\n /** [0] defines how much to randomize the particle direction [0-1] (default is 0) */\r\n public directionRandomizer = 0\r\n ) {\r\n this.angle = angle;\r\n this.radius = radius;\r\n }\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 direction = particle.position.subtract(worldMatrix.getTranslation()).normalize();\r\n const randX = RandomRange(0, this.directionRandomizer);\r\n const randY = RandomRange(0, this.directionRandomizer);\r\n const randZ = RandomRange(0, this.directionRandomizer);\r\n direction.x += randX;\r\n direction.y += randY;\r\n direction.z += randZ;\r\n direction.normalize();\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFrom(direction);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(direction.x, direction.y, direction.z, 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 startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const s = RandomRange(0, Math.PI * 2);\r\n let h: number;\r\n\r\n if (!this.emitFromSpawnPointOnly) {\r\n h = RandomRange(0, this.heightRange);\r\n // Better distribution in a cone at normal angles.\r\n h = 1 - h * h;\r\n } else {\r\n h = 0.0001;\r\n }\r\n let radius = this._radius - RandomRange(0, this._radius * this.radiusRange);\r\n radius = radius * h;\r\n\r\n const randX = radius * Math.sin(s);\r\n const randZ = radius * Math.cos(s);\r\n const randY = h * this._height;\r\n\r\n if (isLocal) {\r\n positionToUpdate.x = randX;\r\n positionToUpdate.y = randY;\r\n positionToUpdate.z = randZ;\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, 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(): ConeParticleEmitter {\r\n const newOne = new ConeParticleEmitter(this._radius, this._angle, this.directionRandomizer);\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 public applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat2(\"radius\", this._radius, this.radiusRange);\r\n uboOrEffect.setFloat(\"coneAngle\", this._angle);\r\n uboOrEffect.setFloat2(\"height\", this._height, this.heightRange);\r\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\r\n }\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 public buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 2);\r\n ubo.addUniform(\"coneAngle\", 1);\r\n ubo.addUniform(\"height\", 2);\r\n ubo.addUniform(\"directionRandomizer\", 1);\r\n }\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 let defines = \"#define CONEEMITTER\";\r\n\r\n if (this.emitFromSpawnPointOnly) {\r\n defines += \"\\n#define CONEEMITTERSPAWNPOINT\";\r\n }\r\n\r\n return defines;\r\n }\r\n\r\n /**\r\n * Returns the string \"ConeParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"ConeParticleEmitter\";\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.radius = this._radius;\r\n serializationObject.angle = this._angle;\r\n serializationObject.directionRandomizer = this.directionRandomizer;\r\n serializationObject.radiusRange = this.radiusRange;\r\n serializationObject.heightRange = this.heightRange;\r\n serializationObject.emitFromSpawnPointOnly = this.emitFromSpawnPointOnly;\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 this.radius = serializationObject.radius;\r\n this.angle = serializationObject.angle;\r\n this.directionRandomizer = serializationObject.directionRandomizer;\r\n\r\n this.radiusRange = serializationObject.radiusRange !== undefined ? serializationObject.radiusRange : 1;\r\n this.heightRange = serializationObject.radiusRange !== undefined ? serializationObject.heightRange : 1;\r\n this.emitFromSpawnPointOnly = serializationObject.emitFromSpawnPointOnly !== undefined ? serializationObject.emitFromSpawnPointOnly : false;\r\n }\r\n}\r\nexport class ConeDirectedParticleEmitter extends ConeParticleEmitter {\r\n constructor(\r\n radius = 1,\r\n angle = Math.PI,\r\n /**\r\n * [Up vector] The min limit of the emission direction.\r\n */\r\n public direction1 = new Vector3(0, 1, 0),\r\n /**\r\n * [Up vector] The max limit of the emission direction.\r\n */\r\n public direction2 = new Vector3(0, 1, 0)\r\n ) {\r\n super(radius, angle);\r\n }\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 */\r\n public override startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3): void {\r\n const randX = RandomRange(this.direction1.x, this.direction2.x);\r\n const randY = RandomRange(this.direction1.y, this.direction2.y);\r\n const randZ = RandomRange(this.direction1.z, this.direction2.z);\r\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\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 override clone(): ConeDirectedParticleEmitter {\r\n const newOne = new ConeDirectedParticleEmitter(this.radius, this.angle, this.direction1, this.direction2);\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 public override applyToShader(uboOrEffect: UniformBufferEffectCommonAccessor): void {\r\n uboOrEffect.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\r\n uboOrEffect.setVector3(\"direction1\", this.direction1);\r\n uboOrEffect.setVector3(\"direction2\", this.direction2);\r\n }\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 public override buildUniformLayout(ubo: UniformBuffer): void {\r\n ubo.addUniform(\"radius\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\r\n ubo.addUniform(\"direction1\", 3);\r\n ubo.addUniform(\"direction2\", 3);\r\n }\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 override getEffectDefines(): string {\r\n return \"#define CONEEMITTER\\n#define DIRECTEDCONEEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"ConeDirectedParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public override getClassName(): string {\r\n return \"ConeDirectedParticleEmitter\";\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 override serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.direction1 = this.direction1.asArray();\r\n serializationObject.direction2 = this.direction2.asArray();\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 override parse(serializationObject: any): void {\r\n super.parse(serializationObject);\r\n this.direction1.copyFrom(serializationObject.direction1);\r\n this.direction2.copyFrom(serializationObject.direction2);\r\n }\r\n}\r\n"]}
@@ -1,10 +1,12 @@
1
+ import type { Nullable } from "../../types.js";
1
2
  import type { Matrix } from "../../Maths/math.vector.js";
2
- import { Vector3 } from "../../Maths/math.vector.js";
3
3
  import type { Particle } from "../particle.js";
4
- import type { IParticleEmitterType } from "./IParticleEmitterType.js";
5
- import type { Nullable } from "../../types.js";
6
4
  import type { UniformBufferEffectCommonAccessor } from "../../Materials/uniformBufferEffectCommonAccessor.js";
7
5
  import type { UniformBuffer } from "../../Materials/uniformBuffer.js";
6
+ import type { IParticleEmitterType } from "./IParticleEmitterType.js";
7
+ import { Vector3 } from "../../Maths/math.vector.js";
8
+ /** Represents and empty generator function */
9
+ export declare const EmptyGeneratorFunc: () => void;
8
10
  /**
9
11
  * Particle emitter emitting particles from a custom list of positions.
10
12
  */
@@ -1,5 +1,7 @@
1
1
  import { DeepCopier } from "../../Misc/deepCopier.js";
2
2
  import { Vector3, TmpVectors } from "../../Maths/math.vector.js";
3
+ /** Represents and empty generator function */
4
+ export const EmptyGeneratorFunc = () => { };
3
5
  /**
4
6
  * Particle emitter emitting particles from a custom list of positions.
5
7
  */
@@ -12,17 +14,17 @@ export class CustomParticleEmitter {
12
14
  * Gets or sets the position generator that will create the initial position of each particle.
13
15
  * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles
14
16
  */
15
- this.particlePositionGenerator = () => { };
17
+ this.particlePositionGenerator = EmptyGeneratorFunc;
16
18
  /**
17
19
  * Gets or sets the destination generator that will create the final destination of each particle.
18
20
  * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles
19
21
  */
20
- this.particleDestinationGenerator = () => { };
22
+ this.particleDestinationGenerator = EmptyGeneratorFunc;
21
23
  /**
22
24
  * Gets or sets the direction generator that will create the initial direction of each particle.
23
25
  * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles
24
26
  */
25
- this.particleDirectionGenerator = () => { };
27
+ this.particleDirectionGenerator = EmptyGeneratorFunc;
26
28
  }
27
29
  /**
28
30
  * Called by the particle System when the direction is computed for the created particle.
@@ -33,10 +35,10 @@ export class CustomParticleEmitter {
33
35
  */
34
36
  startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {
35
37
  const tmpVector = TmpVectors.Vector3[0];
36
- if (this.particleDirectionGenerator) {
38
+ if (this.particleDirectionGenerator && this.particleDirectionGenerator !== EmptyGeneratorFunc) {
37
39
  this.particleDirectionGenerator(-1, particle, tmpVector);
38
40
  }
39
- else if (this.particleDestinationGenerator) {
41
+ else if (this.particleDestinationGenerator && this.particleDestinationGenerator !== EmptyGeneratorFunc) {
40
42
  this.particleDestinationGenerator(-1, particle, tmpVector);
41
43
  // Get direction
42
44
  const diffVector = TmpVectors.Vector3[1];
@@ -61,7 +63,7 @@ export class CustomParticleEmitter {
61
63
  */
62
64
  startPositionFunction(worldMatrix, positionToUpdate, particle, isLocal) {
63
65
  const tmpVector = TmpVectors.Vector3[0];
64
- if (this.particlePositionGenerator) {
66
+ if (this.particlePositionGenerator && this.particlePositionGenerator !== EmptyGeneratorFunc) {
65
67
  this.particlePositionGenerator(-1, particle, tmpVector);
66
68
  }
67
69
  else {