@babylonjs/core 7.24.0 → 7.25.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.
- package/Animations/animation.js +3 -3
- package/Animations/animation.js.map +1 -1
- package/Audio/sound.js +13 -6
- package/Audio/sound.js.map +1 -1
- package/Behaviors/Meshes/followBehavior.js +3 -3
- package/Behaviors/Meshes/followBehavior.js.map +1 -1
- package/Cameras/Inputs/arcRotateCameraMouseWheelInput.js +2 -2
- package/Cameras/Inputs/arcRotateCameraMouseWheelInput.js.map +1 -1
- package/Compute/computeEffect.js +4 -4
- package/Compute/computeEffect.js.map +1 -1
- package/Engines/Extensions/engine.prefilteredCubeTexture.js +2 -3
- package/Engines/Extensions/engine.prefilteredCubeTexture.js.map +1 -1
- package/Engines/Processors/Expressions/shaderDefineExpression.js +1 -1
- package/Engines/Processors/Expressions/shaderDefineExpression.js.map +1 -1
- package/Engines/WebGPU/webgpuHardwareTexture.js +2 -2
- package/Engines/WebGPU/webgpuHardwareTexture.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessorsGLSL.js +2 -2
- package/Engines/WebGPU/webgpuShaderProcessorsGLSL.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js +12 -10
- package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js.map +1 -1
- package/Engines/WebGPU/webgpuTextureHelper.js +2 -2
- package/Engines/WebGPU/webgpuTextureHelper.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/engineCapabilities.d.ts +2 -0
- package/Engines/engineCapabilities.js.map +1 -1
- package/Engines/nativeEngine.js +3 -2
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/nullEngine.js +1 -0
- package/Engines/nullEngine.js.map +1 -1
- package/Engines/thinEngine.js +2 -0
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +1 -0
- package/Engines/webgpuEngine.js.map +1 -1
- package/LensFlares/lensFlareSystem.js +2 -2
- package/LensFlares/lensFlareSystem.js.map +1 -1
- package/Loading/sceneLoader.js +3 -3
- package/Loading/sceneLoader.js.map +1 -1
- package/Materials/Node/Blocks/Dual/lightBlock.js +17 -8
- package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +2 -2
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/reflectionBlock.js +1 -2
- package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/refractionBlock.js +1 -2
- package/Materials/Node/Blocks/PBR/refractionBlock.js.map +1 -1
- package/Materials/Node/Blocks/colorMergerBlock.js +1 -1
- package/Materials/Node/Blocks/colorMergerBlock.js.map +1 -1
- package/Materials/Node/Blocks/vectorMergerBlock.js +1 -1
- package/Materials/Node/Blocks/vectorMergerBlock.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.js +1 -2
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/PBR/pbrSubSurfaceConfiguration.js +1 -2
- package/Materials/PBR/pbrSubSurfaceConfiguration.js.map +1 -1
- package/Materials/Textures/Filtering/hdrFiltering.d.ts +0 -2
- package/Materials/Textures/Filtering/hdrFiltering.js +12 -4
- package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
- package/Materials/Textures/Loaders/textureLoaderManager.d.ts +14 -1
- package/Materials/Textures/Loaders/textureLoaderManager.js +50 -21
- package/Materials/Textures/Loaders/textureLoaderManager.js.map +1 -1
- package/Materials/Textures/Procedurals/proceduralTexture.d.ts +15 -1
- package/Materials/Textures/Procedurals/proceduralTexture.js +24 -1
- package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
- package/Materials/Textures/index.d.ts +6 -0
- package/Materials/Textures/index.js +8 -0
- package/Materials/Textures/index.js.map +1 -1
- package/Materials/Textures/texture.js +2 -2
- package/Materials/Textures/texture.js.map +1 -1
- package/Materials/effect.functions.js +4 -4
- package/Materials/effect.functions.js.map +1 -1
- package/Maths/math.color.js +6 -7
- package/Maths/math.color.js.map +1 -1
- package/Maths/math.path.js +5 -5
- package/Maths/math.path.js.map +1 -1
- package/Maths/math.scalar.d.ts +33 -191
- package/Maths/math.scalar.functions.d.ts +147 -0
- package/Maths/math.scalar.functions.js +247 -0
- package/Maths/math.scalar.functions.js.map +1 -1
- package/Maths/math.scalar.js +15 -303
- package/Maths/math.scalar.js.map +1 -1
- package/Meshes/Builders/decalBuilder.js +3 -3
- package/Meshes/Builders/decalBuilder.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.d.ts +8 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +30 -13
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
- package/Meshes/Node/Blocks/conditionBlock.js +2 -2
- package/Meshes/Node/Blocks/conditionBlock.js.map +1 -1
- package/Meshes/Node/Blocks/geometryOptimizeBlock.js +4 -4
- package/Meshes/Node/Blocks/geometryOptimizeBlock.js.map +1 -1
- package/Meshes/Node/Blocks/noiseBlock.js +3 -3
- package/Meshes/Node/Blocks/noiseBlock.js.map +1 -1
- package/Meshes/geodesicMesh.js +3 -3
- package/Meshes/geodesicMesh.js.map +1 -1
- package/Meshes/trailMesh.js +4 -4
- package/Meshes/trailMesh.js.map +1 -1
- package/Misc/HighDynamicRange/cubemapToSphericalPolynomial.js +7 -7
- package/Misc/HighDynamicRange/cubemapToSphericalPolynomial.js.map +1 -1
- package/Misc/PerformanceViewer/performanceViewerCollector.js +2 -1
- package/Misc/PerformanceViewer/performanceViewerCollector.js.map +1 -1
- package/Misc/basis.js +2 -3
- package/Misc/basis.js.map +1 -1
- package/Misc/dds.js +9 -9
- package/Misc/dds.js.map +1 -1
- package/Misc/dumpTools.js +2 -2
- package/Misc/dumpTools.js.map +1 -1
- package/Misc/environmentTextureTools.js +4 -4
- package/Misc/environmentTextureTools.js.map +1 -1
- package/Misc/reflector.js +3 -3
- package/Misc/reflector.js.map +1 -1
- package/Misc/screenshotTools.d.ts +2 -1
- package/Misc/screenshotTools.js +3 -2
- package/Misc/screenshotTools.js.map +1 -1
- package/Misc/tools.d.ts +6 -3
- package/Misc/tools.js +5 -3
- package/Misc/tools.js.map +1 -1
- package/Particles/EmitterTypes/coneParticleEmitter.js +10 -10
- package/Particles/EmitterTypes/coneParticleEmitter.js.map +1 -1
- package/Particles/EmitterTypes/cylinderParticleEmitter.js +9 -9
- package/Particles/EmitterTypes/cylinderParticleEmitter.js.map +1 -1
- package/Particles/EmitterTypes/hemisphericParticleEmitter.js +7 -7
- package/Particles/EmitterTypes/hemisphericParticleEmitter.js.map +1 -1
- package/Particles/EmitterTypes/meshParticleEmitter.js +4 -4
- package/Particles/EmitterTypes/meshParticleEmitter.js.map +1 -1
- package/Particles/EmitterTypes/pointParticleEmitter.js +4 -4
- package/Particles/EmitterTypes/pointParticleEmitter.js.map +1 -1
- package/Particles/EmitterTypes/sphereParticleEmitter.js +10 -10
- package/Particles/EmitterTypes/sphereParticleEmitter.js.map +1 -1
- package/Particles/gpuParticleSystem.js +2 -2
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Particles/pointsCloudSystem.js +8 -8
- package/Particles/pointsCloudSystem.js.map +1 -1
- package/Physics/v1/Plugins/ammoJSPlugin.js +2 -2
- package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -1
- package/Physics/v2/physicsAggregate.js +2 -2
- package/Physics/v2/physicsAggregate.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/lensRenderingPipeline.js +2 -2
- package/PostProcesses/RenderPipeline/Pipelines/lensRenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js +2 -2
- package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssaoRenderingPipeline.js +4 -4
- package/PostProcesses/RenderPipeline/Pipelines/ssaoRenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js +2 -2
- package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/postProcessRenderPipeline.d.ts +4 -0
- package/PostProcesses/RenderPipeline/postProcessRenderPipeline.js +6 -0
- package/PostProcesses/RenderPipeline/postProcessRenderPipeline.js.map +1 -1
- package/PostProcesses/postProcess.d.ts +4 -0
- package/PostProcesses/postProcess.js +1 -0
- package/PostProcesses/postProcess.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.d.ts +0 -2
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.js +46 -3
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.d.ts +0 -5
- package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.js +33 -5
- package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.d.ts +8 -3
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +56 -18
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.d.ts +0 -2
- package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.js +20 -2
- package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.d.ts +2 -14
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js +108 -36
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.d.ts +0 -2
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +23 -11
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -1
- package/Rendering/depthPeelingRenderer.d.ts +7 -3
- package/Rendering/depthPeelingRenderer.js +38 -3
- package/Rendering/depthPeelingRenderer.js.map +1 -1
- package/Rendering/index.d.ts +44 -0
- package/Rendering/index.js +46 -0
- package/Rendering/index.js.map +1 -1
- package/Shaders/iblCombineVoxelGrids.fragment.d.ts +5 -0
- package/Shaders/{combineVoxelGrids.fragment.js → iblCombineVoxelGrids.fragment.js} +3 -3
- package/Shaders/iblCombineVoxelGrids.fragment.js.map +1 -0
- package/Shaders/iblGenerateVoxelMip.fragment.d.ts +5 -0
- package/Shaders/{generateVoxelMip.fragment.js → iblGenerateVoxelMip.fragment.js} +3 -3
- package/Shaders/iblGenerateVoxelMip.fragment.js.map +1 -0
- package/Shaders/iblShadowVoxelTracing.fragment.js +18 -10
- package/Shaders/iblShadowVoxelTracing.fragment.js.map +1 -1
- package/Shaders/iblShadowsImportanceSamplingDebug.fragment.js +2 -1
- package/Shaders/iblShadowsImportanceSamplingDebug.fragment.js.map +1 -1
- package/Shaders/{voxelGrid.fragment.d.ts → iblVoxelGrid.fragment.d.ts} +1 -1
- package/Shaders/{voxelGrid.fragment.js → iblVoxelGrid.fragment.js} +3 -3
- package/Shaders/iblVoxelGrid.fragment.js.map +1 -0
- package/Shaders/{voxelSlabDebug.fragment.d.ts → iblVoxelGrid.vertex.d.ts} +1 -1
- package/Shaders/{voxelGrid.vertex.js → iblVoxelGrid.vertex.js} +8 -4
- package/Shaders/iblVoxelGrid.vertex.js.map +1 -0
- package/Shaders/iblVoxelGrid2dArrayDebug.fragment.d.ts +5 -0
- package/Shaders/{voxelGrid2dArrayDebug.fragment.js → iblVoxelGrid2dArrayDebug.fragment.js} +3 -3
- package/Shaders/iblVoxelGrid2dArrayDebug.fragment.js.map +1 -0
- package/Shaders/iblVoxelGrid3dDebug.fragment.d.ts +5 -0
- package/Shaders/{voxelGrid3dDebug.fragment.js → iblVoxelGrid3dDebug.fragment.js} +3 -3
- package/Shaders/iblVoxelGrid3dDebug.fragment.js.map +1 -0
- package/Shaders/{combineVoxelGrids.fragment.d.ts → iblVoxelSlabDebug.fragment.d.ts} +1 -1
- package/Shaders/{voxelSlabDebug.fragment.js → iblVoxelSlabDebug.fragment.js} +3 -3
- package/Shaders/iblVoxelSlabDebug.fragment.js.map +1 -0
- package/Shaders/iblVoxelSlabDebug.vertex.d.ts +5 -0
- package/Shaders/{voxelSlabDebug.vertex.js → iblVoxelSlabDebug.vertex.js} +3 -3
- package/Shaders/iblVoxelSlabDebug.vertex.js.map +1 -0
- package/ShadersWGSL/ShadersInclude/lightFragment.js +7 -7
- package/ShadersWGSL/ShadersInclude/lightFragment.js.map +1 -1
- package/ShadersWGSL/copyTexture3DLayerToTexture.fragment.d.ts +5 -0
- package/ShadersWGSL/copyTexture3DLayerToTexture.fragment.js +10 -0
- package/ShadersWGSL/copyTexture3DLayerToTexture.fragment.js.map +1 -0
- package/ShadersWGSL/default.fragment.js +4 -0
- package/ShadersWGSL/default.fragment.js.map +1 -1
- package/ShadersWGSL/hdrFiltering.fragment.d.ts +9 -0
- package/ShadersWGSL/hdrFiltering.fragment.js +18 -0
- package/ShadersWGSL/hdrFiltering.fragment.js.map +1 -0
- package/ShadersWGSL/hdrFiltering.vertex.d.ts +5 -0
- package/ShadersWGSL/hdrFiltering.vertex.js +16 -0
- package/ShadersWGSL/hdrFiltering.vertex.js.map +1 -0
- package/ShadersWGSL/iblCombineVoxelGrids.fragment.d.ts +5 -0
- package/ShadersWGSL/iblCombineVoxelGrids.fragment.js +10 -0
- package/ShadersWGSL/iblCombineVoxelGrids.fragment.js.map +1 -0
- package/ShadersWGSL/iblGenerateVoxelMip.fragment.d.ts +5 -0
- package/ShadersWGSL/iblGenerateVoxelMip.fragment.js +26 -0
- package/ShadersWGSL/iblGenerateVoxelMip.fragment.js.map +1 -0
- package/ShadersWGSL/iblShadowAccumulation.fragment.d.ts +5 -0
- package/ShadersWGSL/iblShadowAccumulation.fragment.js +24 -0
- package/ShadersWGSL/iblShadowAccumulation.fragment.js.map +1 -0
- package/ShadersWGSL/iblShadowDebug.fragment.d.ts +5 -0
- package/ShadersWGSL/iblShadowDebug.fragment.js +16 -0
- package/ShadersWGSL/iblShadowDebug.fragment.js.map +1 -0
- package/ShadersWGSL/iblShadowGBufferDebug.fragment.d.ts +5 -0
- package/ShadersWGSL/iblShadowGBufferDebug.fragment.js +17 -0
- package/ShadersWGSL/iblShadowGBufferDebug.fragment.js.map +1 -0
- package/ShadersWGSL/iblShadowSpatialBlur.fragment.d.ts +5 -0
- package/ShadersWGSL/iblShadowSpatialBlur.fragment.js +20 -0
- package/ShadersWGSL/iblShadowSpatialBlur.fragment.js.map +1 -0
- package/ShadersWGSL/iblShadowVoxelTracing.fragment.d.ts +5 -0
- package/ShadersWGSL/iblShadowVoxelTracing.fragment.js +163 -0
- package/ShadersWGSL/iblShadowVoxelTracing.fragment.js.map +1 -0
- package/ShadersWGSL/iblShadowsCdfx.fragment.d.ts +5 -0
- package/ShadersWGSL/iblShadowsCdfx.fragment.js +12 -0
- package/ShadersWGSL/iblShadowsCdfx.fragment.js.map +1 -0
- package/ShadersWGSL/iblShadowsCdfy.fragment.d.ts +5 -0
- package/ShadersWGSL/iblShadowsCdfy.fragment.js +33 -0
- package/ShadersWGSL/iblShadowsCdfy.fragment.js.map +1 -0
- package/ShadersWGSL/iblShadowsCombine.fragment.d.ts +5 -0
- package/ShadersWGSL/iblShadowsCombine.fragment.js +10 -0
- package/ShadersWGSL/iblShadowsCombine.fragment.js.map +1 -0
- package/ShadersWGSL/iblShadowsIcdfx.fragment.d.ts +5 -0
- package/ShadersWGSL/iblShadowsIcdfx.fragment.js +18 -0
- package/ShadersWGSL/iblShadowsIcdfx.fragment.js.map +1 -0
- package/ShadersWGSL/iblShadowsIcdfy.fragment.d.ts +5 -0
- package/ShadersWGSL/iblShadowsIcdfy.fragment.js +17 -0
- package/ShadersWGSL/iblShadowsIcdfy.fragment.js.map +1 -0
- package/ShadersWGSL/iblShadowsImportanceSamplingDebug.fragment.d.ts +5 -0
- package/ShadersWGSL/iblShadowsImportanceSamplingDebug.fragment.js +41 -0
- package/ShadersWGSL/iblShadowsImportanceSamplingDebug.fragment.js.map +1 -0
- package/{Shaders/voxelGrid3dDebug.fragment.d.ts → ShadersWGSL/iblVoxelGrid.fragment.d.ts} +1 -1
- package/ShadersWGSL/iblVoxelGrid.fragment.js +15 -0
- package/ShadersWGSL/iblVoxelGrid.fragment.js.map +1 -0
- package/ShadersWGSL/iblVoxelGrid.vertex.d.ts +5 -0
- package/ShadersWGSL/iblVoxelGrid.vertex.js +14 -0
- package/ShadersWGSL/iblVoxelGrid.vertex.js.map +1 -0
- package/ShadersWGSL/iblVoxelGrid2dArrayDebug.fragment.d.ts +5 -0
- package/ShadersWGSL/iblVoxelGrid2dArrayDebug.fragment.js +10 -0
- package/ShadersWGSL/iblVoxelGrid2dArrayDebug.fragment.js.map +1 -0
- package/ShadersWGSL/iblVoxelGrid3dDebug.fragment.d.ts +5 -0
- package/ShadersWGSL/iblVoxelGrid3dDebug.fragment.js +22 -0
- package/ShadersWGSL/iblVoxelGrid3dDebug.fragment.js.map +1 -0
- package/ShadersWGSL/iblVoxelSlabDebug.fragment.d.ts +5 -0
- package/ShadersWGSL/iblVoxelSlabDebug.fragment.js +12 -0
- package/ShadersWGSL/iblVoxelSlabDebug.fragment.js.map +1 -0
- package/ShadersWGSL/iblVoxelSlabDebug.vertex.d.ts +5 -0
- package/ShadersWGSL/iblVoxelSlabDebug.vertex.js +10 -0
- package/ShadersWGSL/iblVoxelSlabDebug.vertex.js.map +1 -0
- package/{Shaders/generateVoxelMip.fragment.d.ts → ShadersWGSL/oitBackBlend.fragment.d.ts} +1 -1
- package/ShadersWGSL/oitBackBlend.fragment.js +11 -0
- package/ShadersWGSL/oitBackBlend.fragment.js.map +1 -0
- package/{Shaders/voxelGrid.vertex.d.ts → ShadersWGSL/oitFinal.fragment.d.ts} +1 -1
- package/ShadersWGSL/oitFinal.fragment.js +14 -0
- package/ShadersWGSL/oitFinal.fragment.js.map +1 -0
- package/ShadersWGSL/pbr.fragment.js +17 -8
- package/ShadersWGSL/pbr.fragment.js.map +1 -1
- package/{Shaders/voxelSlabDebug.vertex.d.ts → ShadersWGSL/procedural.vertex.d.ts} +1 -1
- package/ShadersWGSL/procedural.vertex.js +16 -0
- package/ShadersWGSL/procedural.vertex.js.map +1 -0
- package/XR/features/WebXRHandTracking.d.ts +5 -0
- package/XR/features/WebXRHandTracking.js +34 -12
- package/XR/features/WebXRHandTracking.js.map +1 -1
- package/package.json +2 -2
- package/Shaders/combineVoxelGrids.fragment.js.map +0 -1
- package/Shaders/generateVoxelMip.fragment.js.map +0 -1
- package/Shaders/voxelGrid.fragment.js.map +0 -1
- package/Shaders/voxelGrid.vertex.js.map +0 -1
- package/Shaders/voxelGrid2dArrayDebug.fragment.d.ts +0 -5
- package/Shaders/voxelGrid2dArrayDebug.fragment.js.map +0 -1
- package/Shaders/voxelGrid3dDebug.fragment.js.map +0 -1
- package/Shaders/voxelSlabDebug.fragment.js.map +0 -1
- package/Shaders/voxelSlabDebug.vertex.js.map +0 -1
|
@@ -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,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAKjD;;;;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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AmB,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 { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3, TmpVectors } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\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 = Scalar.RandomRange(0, this.directionRandomizer);\r\n const randY = Scalar.RandomRange(0, this.directionRandomizer);\r\n const randZ = Scalar.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 = Scalar.RandomRange(0, Math.PI * 2);\r\n let h: number;\r\n\r\n if (!this.emitFromSpawnPointOnly) {\r\n h = Scalar.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 - Scalar.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 = Scalar.RandomRange(this.direction1.x, this.direction2.x);\r\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\r\n const randZ = Scalar.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":"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,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GG;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 { 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,5 +1,5 @@
|
|
|
1
1
|
import { Vector3 } from "../../Maths/math.vector.js";
|
|
2
|
-
import {
|
|
2
|
+
import { RandomRange } from "../../Maths/math.scalar.functions.js";
|
|
3
3
|
import { DeepCopier } from "../../Misc/deepCopier.js";
|
|
4
4
|
/**
|
|
5
5
|
* Particle emitter emitting particles from the inside of a cylinder.
|
|
@@ -48,9 +48,9 @@ export class CylinderParticleEmitter {
|
|
|
48
48
|
particle.position.subtractToRef(worldMatrix.getTranslation(), this._tempVector);
|
|
49
49
|
this._tempVector.normalize();
|
|
50
50
|
Vector3.TransformNormalToRef(this._tempVector, inverseWorldMatrix, this._tempVector);
|
|
51
|
-
const randY =
|
|
51
|
+
const randY = RandomRange(-this.directionRandomizer / 2, this.directionRandomizer / 2);
|
|
52
52
|
let angle = Math.atan2(this._tempVector.x, this._tempVector.z);
|
|
53
|
-
angle +=
|
|
53
|
+
angle += RandomRange(-Math.PI / 2, Math.PI / 2) * this.directionRandomizer;
|
|
54
54
|
this._tempVector.y = randY; // set direction y to rand y to mirror normal of cylinder surface
|
|
55
55
|
this._tempVector.x = Math.sin(angle);
|
|
56
56
|
this._tempVector.z = Math.cos(angle);
|
|
@@ -69,10 +69,10 @@ export class CylinderParticleEmitter {
|
|
|
69
69
|
* @param isLocal defines if the position should be set in local space
|
|
70
70
|
*/
|
|
71
71
|
startPositionFunction(worldMatrix, positionToUpdate, particle, isLocal) {
|
|
72
|
-
const yPos =
|
|
73
|
-
const angle =
|
|
72
|
+
const yPos = RandomRange(-this.height / 2, this.height / 2);
|
|
73
|
+
const angle = RandomRange(0, 2 * Math.PI);
|
|
74
74
|
// Pick a properly distributed point within the circle https://programming.guide/random-point-within-circle.html
|
|
75
|
-
const radiusDistribution =
|
|
75
|
+
const radiusDistribution = RandomRange((1 - this.radiusRange) * (1 - this.radiusRange), 1);
|
|
76
76
|
const positionRadius = Math.sqrt(radiusDistribution) * this.radius;
|
|
77
77
|
const xPos = positionRadius * Math.cos(angle);
|
|
78
78
|
const zPos = positionRadius * Math.sin(angle);
|
|
@@ -183,9 +183,9 @@ export class CylinderDirectedParticleEmitter extends CylinderParticleEmitter {
|
|
|
183
183
|
* @param isLocal defines if the direction should be set in local space
|
|
184
184
|
*/
|
|
185
185
|
startDirectionFunction(worldMatrix, directionToUpdate, _particle, isLocal) {
|
|
186
|
-
const randX =
|
|
187
|
-
const randY =
|
|
188
|
-
const randZ =
|
|
186
|
+
const randX = RandomRange(this.direction1.x, this.direction2.x);
|
|
187
|
+
const randY = RandomRange(this.direction1.y, this.direction2.y);
|
|
188
|
+
const randZ = RandomRange(this.direction1.z, this.direction2.z);
|
|
189
189
|
if (isLocal) {
|
|
190
190
|
directionToUpdate.copyFromFloats(randX, randY, randZ);
|
|
191
191
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cylinderParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/cylinderParticleEmitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGjD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAGhC;;;;;;OAM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AAU,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACa,kBAAkB,CAAC,GAAkB;QACjD,GAAG,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC5B,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,0DAA0D,CAAC;IACtE,CAAC;IAED;;;OAGG;IACa,YAAY;QACxB,OAAO,iCAAiC,CAAC;IAC7C,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,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3E,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/E,CAAC;CACJ","sourcesContent":["import type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport type { Particle } from \"../../Particles/particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport { DeepCopier } from \"../../Misc/deepCopier\";\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 cylinder.\r\n * It emits the particles alongside the cylinder radius. The emission direction might be randomized.\r\n */\r\nexport class CylinderParticleEmitter implements IParticleEmitterType {\r\n private _tempVector = Vector3.Zero();\r\n\r\n /**\r\n * Creates a new instance CylinderParticleEmitter\r\n * @param radius the radius of the emission cylinder (1 by default)\r\n * @param height the height of the emission cylinder (1 by default)\r\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\r\n */\r\n constructor(\r\n /**\r\n * [1] The radius of the emission cylinder.\r\n */\r\n public radius = 1,\r\n /**\r\n * [1] The height of the emission cylinder.\r\n */\r\n public height = 1,\r\n /**\r\n * [1] The range of emission [0-1] 0 Surface only, 1 Entire Radius.\r\n */\r\n public radiusRange = 1,\r\n /**\r\n * [0] How much to randomize the particle direction [0-1].\r\n */\r\n public directionRandomizer = 0\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 * @param inverseWorldMatrix defines the inverted world matrix to use if isLocal is false\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean, inverseWorldMatrix: Matrix): void {\r\n particle.position.subtractToRef(worldMatrix.getTranslation(), this._tempVector);\r\n\r\n this._tempVector.normalize();\r\n\r\n Vector3.TransformNormalToRef(this._tempVector, inverseWorldMatrix, this._tempVector);\r\n\r\n const randY = Scalar.RandomRange(-this.directionRandomizer / 2, this.directionRandomizer / 2);\r\n\r\n let angle = Math.atan2(this._tempVector.x, this._tempVector.z);\r\n angle += Scalar.RandomRange(-Math.PI / 2, Math.PI / 2) * this.directionRandomizer;\r\n\r\n this._tempVector.y = randY; // set direction y to rand y to mirror normal of cylinder surface\r\n this._tempVector.x = Math.sin(angle);\r\n this._tempVector.z = Math.cos(angle);\r\n this._tempVector.normalize();\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFrom(this._tempVector);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(this._tempVector.x, this._tempVector.y, this._tempVector.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 public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const yPos = Scalar.RandomRange(-this.height / 2, this.height / 2);\r\n const angle = Scalar.RandomRange(0, 2 * Math.PI);\r\n\r\n // Pick a properly distributed point within the circle https://programming.guide/random-point-within-circle.html\r\n const radiusDistribution = Scalar.RandomRange((1 - this.radiusRange) * (1 - this.radiusRange), 1);\r\n const positionRadius = Math.sqrt(radiusDistribution) * this.radius;\r\n const xPos = positionRadius * Math.cos(angle);\r\n const zPos = positionRadius * Math.sin(angle);\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(xPos, yPos, zPos);\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(xPos, yPos, zPos, 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(): CylinderParticleEmitter {\r\n const newOne = new CylinderParticleEmitter(this.radius, 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.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"height\", this.height);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\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\", 1);\r\n ubo.addUniform(\"height\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\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 return \"#define CYLINDEREMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"CylinderParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"CylinderParticleEmitter\";\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 serializationObject.type = this.getClassName();\r\n serializationObject.radius = this.radius;\r\n serializationObject.height = this.height;\r\n serializationObject.radiusRange = this.radiusRange;\r\n serializationObject.directionRandomizer = this.directionRandomizer;\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.height = serializationObject.height;\r\n this.radiusRange = serializationObject.radiusRange;\r\n this.directionRandomizer = serializationObject.directionRandomizer;\r\n }\r\n}\r\n\r\n/**\r\n * Particle emitter emitting particles from the inside of a cylinder.\r\n * It emits the particles randomly between two vectors.\r\n */\r\nexport class CylinderDirectedParticleEmitter extends CylinderParticleEmitter {\r\n /**\r\n * Creates a new instance CylinderDirectedParticleEmitter\r\n * @param radius the radius of the emission cylinder (1 by default)\r\n * @param height the height of the emission cylinder (1 by default)\r\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param direction1 the min limit of the emission direction (up vector by default)\r\n * @param direction2 the max limit of the emission direction (up vector by default)\r\n */\r\n constructor(\r\n radius = 1,\r\n height = 1,\r\n radiusRange = 1,\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, height, radiusRange);\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 override startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, _particle: Particle, isLocal: boolean): void {\r\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\r\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\r\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\r\n if (isLocal) {\r\n directionToUpdate.copyFromFloats(randX, randY, randZ);\r\n return;\r\n }\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(): CylinderDirectedParticleEmitter {\r\n const newOne = new CylinderDirectedParticleEmitter(this.radius, this.height, this.radiusRange, 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(\"height\", this.height);\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(\"height\", 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 CYLINDEREMITTER\\n#define DIRECTEDCYLINDEREMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"CylinderDirectedParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public override getClassName(): string {\r\n return \"CylinderDirectedParticleEmitter\";\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 Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\r\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"cylinderPartic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U,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/E,CAAC;CACJ","sourcesContent":["import type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3 } 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 { DeepCopier } from \"../../Misc/deepCopier\";\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 cylinder.\r\n * It emits the particles alongside the cylinder radius. The emission direction might be randomized.\r\n */\r\nexport class CylinderParticleEmitter implements IParticleEmitterType {\r\n private _tempVector = Vector3.Zero();\r\n\r\n /**\r\n * Creates a new instance CylinderParticleEmitter\r\n * @param radius the radius of the emission cylinder (1 by default)\r\n * @param height the height of the emission cylinder (1 by default)\r\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\r\n */\r\n constructor(\r\n /**\r\n * [1] The radius of the emission cylinder.\r\n */\r\n public radius = 1,\r\n /**\r\n * [1] The height of the emission cylinder.\r\n */\r\n public height = 1,\r\n /**\r\n * [1] The range of emission [0-1] 0 Surface only, 1 Entire Radius.\r\n */\r\n public radiusRange = 1,\r\n /**\r\n * [0] How much to randomize the particle direction [0-1].\r\n */\r\n public directionRandomizer = 0\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 * @param inverseWorldMatrix defines the inverted world matrix to use if isLocal is false\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean, inverseWorldMatrix: Matrix): void {\r\n particle.position.subtractToRef(worldMatrix.getTranslation(), this._tempVector);\r\n\r\n this._tempVector.normalize();\r\n\r\n Vector3.TransformNormalToRef(this._tempVector, inverseWorldMatrix, this._tempVector);\r\n\r\n const randY = RandomRange(-this.directionRandomizer / 2, this.directionRandomizer / 2);\r\n\r\n let angle = Math.atan2(this._tempVector.x, this._tempVector.z);\r\n angle += RandomRange(-Math.PI / 2, Math.PI / 2) * this.directionRandomizer;\r\n\r\n this._tempVector.y = randY; // set direction y to rand y to mirror normal of cylinder surface\r\n this._tempVector.x = Math.sin(angle);\r\n this._tempVector.z = Math.cos(angle);\r\n this._tempVector.normalize();\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFrom(this._tempVector);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(this._tempVector.x, this._tempVector.y, this._tempVector.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 public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const yPos = RandomRange(-this.height / 2, this.height / 2);\r\n const angle = RandomRange(0, 2 * Math.PI);\r\n\r\n // Pick a properly distributed point within the circle https://programming.guide/random-point-within-circle.html\r\n const radiusDistribution = RandomRange((1 - this.radiusRange) * (1 - this.radiusRange), 1);\r\n const positionRadius = Math.sqrt(radiusDistribution) * this.radius;\r\n const xPos = positionRadius * Math.cos(angle);\r\n const zPos = positionRadius * Math.sin(angle);\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(xPos, yPos, zPos);\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(xPos, yPos, zPos, 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(): CylinderParticleEmitter {\r\n const newOne = new CylinderParticleEmitter(this.radius, 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.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"height\", this.height);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\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\", 1);\r\n ubo.addUniform(\"height\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\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 return \"#define CYLINDEREMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"CylinderParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"CylinderParticleEmitter\";\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 serializationObject.type = this.getClassName();\r\n serializationObject.radius = this.radius;\r\n serializationObject.height = this.height;\r\n serializationObject.radiusRange = this.radiusRange;\r\n serializationObject.directionRandomizer = this.directionRandomizer;\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.height = serializationObject.height;\r\n this.radiusRange = serializationObject.radiusRange;\r\n this.directionRandomizer = serializationObject.directionRandomizer;\r\n }\r\n}\r\n\r\n/**\r\n * Particle emitter emitting particles from the inside of a cylinder.\r\n * It emits the particles randomly between two vectors.\r\n */\r\nexport class CylinderDirectedParticleEmitter extends CylinderParticleEmitter {\r\n /**\r\n * Creates a new instance CylinderDirectedParticleEmitter\r\n * @param radius the radius of the emission cylinder (1 by default)\r\n * @param height the height of the emission cylinder (1 by default)\r\n * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param direction1 the min limit of the emission direction (up vector by default)\r\n * @param direction2 the max limit of the emission direction (up vector by default)\r\n */\r\n constructor(\r\n radius = 1,\r\n height = 1,\r\n radiusRange = 1,\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, height, radiusRange);\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 override startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, _particle: Particle, isLocal: boolean): 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 if (isLocal) {\r\n directionToUpdate.copyFromFloats(randX, randY, randZ);\r\n return;\r\n }\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(): CylinderDirectedParticleEmitter {\r\n const newOne = new CylinderDirectedParticleEmitter(this.radius, this.height, this.radiusRange, 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(\"height\", this.height);\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(\"height\", 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 CYLINDEREMITTER\\n#define DIRECTEDCYLINDEREMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"CylinderDirectedParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public override getClassName(): string {\r\n return \"CylinderDirectedParticleEmitter\";\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 Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\r\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\r\n }\r\n}\r\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepCopier } from "../../Misc/deepCopier.js";
|
|
2
2
|
import { Vector3 } from "../../Maths/math.vector.js";
|
|
3
|
-
import {
|
|
3
|
+
import { RandomRange } from "../../Maths/math.scalar.functions.js";
|
|
4
4
|
/**
|
|
5
5
|
* Particle emitter emitting particles from the inside of a hemisphere.
|
|
6
6
|
* It emits the particles alongside the hemisphere radius. The emission direction might be randomized.
|
|
@@ -38,9 +38,9 @@ export class HemisphericParticleEmitter {
|
|
|
38
38
|
*/
|
|
39
39
|
startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {
|
|
40
40
|
const direction = particle.position.subtract(worldMatrix.getTranslation()).normalize();
|
|
41
|
-
const randX =
|
|
42
|
-
const randY =
|
|
43
|
-
const randZ =
|
|
41
|
+
const randX = RandomRange(0, this.directionRandomizer);
|
|
42
|
+
const randY = RandomRange(0, this.directionRandomizer);
|
|
43
|
+
const randZ = RandomRange(0, this.directionRandomizer);
|
|
44
44
|
direction.x += randX;
|
|
45
45
|
direction.y += randY;
|
|
46
46
|
direction.z += randZ;
|
|
@@ -59,9 +59,9 @@ export class HemisphericParticleEmitter {
|
|
|
59
59
|
* @param isLocal defines if the position should be set in local space
|
|
60
60
|
*/
|
|
61
61
|
startPositionFunction(worldMatrix, positionToUpdate, particle, isLocal) {
|
|
62
|
-
const randRadius = this.radius -
|
|
63
|
-
const v =
|
|
64
|
-
const phi =
|
|
62
|
+
const randRadius = this.radius - RandomRange(0, this.radius * this.radiusRange);
|
|
63
|
+
const v = RandomRange(0, 1.0);
|
|
64
|
+
const phi = RandomRange(0, 2 * Math.PI);
|
|
65
65
|
const theta = Math.acos(2 * v - 1);
|
|
66
66
|
const randX = randRadius * Math.cos(phi) * Math.sin(theta);
|
|
67
67
|
const randY = randRadius * Math.cos(theta);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hemisphericParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/hemisphericParticleEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAKjD;;;GAGG;AACH,MAAM,OAAO,0BAA0B;IACnC;;;;;OAKG;IACH;IACI;;OAEG;IACI,SAAS,CAAC;IACjB;;OAEG;IACI,cAAc,CAAC;IACtB;;OAEG;IACI,sBAAsB,CAAC;QARvB,WAAM,GAAN,MAAM,CAAI;QAIV,gBAAW,GAAX,WAAW,CAAI;QAIf,wBAAmB,GAAnB,mBAAmB,CAAI;IAC/B,CAAC;IAEJ;;;;;;OAMG;IACI,sBAAsB,CAAC,WAAmB,EAAE,iBAA0B,EAAE,QAAkB,EAAE,OAAgB;QAC/G,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,cAAc,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC;QACvF,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC9D,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC9D,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC9D,SAAS,CAAC,CAAC,IAAI,KAAK,CAAC;QACrB,SAAS,CAAC,CAAC,IAAI,KAAK,CAAC;QACrB,SAAS,CAAC,CAAC,IAAI,KAAK,CAAC;QACrB,SAAS,CAAC,SAAS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C;QACnD,mBAAmB,CAAC,mBAAmB,GAAG,IAAI,CAAC,mBAAmB,CAAC;QAEnE,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,mBAAwB;QACjC,IAAI,CAAC,MAAM,GAAG,mBAAmB,CAAC,MAAM,CAAC;QACzC,IAAI,CAAC,WAAW,GAAG,mBAAmB,CAAC,WAAW,CAAC;QACnD,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC,mBAAmB,CAAC;IACvE,CAAC;CACJ","sourcesContent":["import { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\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 hemisphere.\r\n * It emits the particles alongside the hemisphere radius. The emission direction might be randomized.\r\n */\r\nexport class HemisphericParticleEmitter implements IParticleEmitterType {\r\n /**\r\n * Creates a new instance HemisphericParticleEmitter\r\n * @param radius the radius of the emission hemisphere (1 by default)\r\n * @param radiusRange the range of the emission hemisphere [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\r\n */\r\n constructor(\r\n /**\r\n * [1] The radius of the emission hemisphere.\r\n */\r\n public radius = 1,\r\n /**\r\n * [1] The range of emission [0-1] 0 Surface only, 1 Entire Radius.\r\n */\r\n public radiusRange = 1,\r\n /**\r\n * [0] How much to randomize the particle direction [0-1].\r\n */\r\n public directionRandomizer = 0\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 = Scalar.RandomRange(0, this.directionRandomizer);\r\n const randY = Scalar.RandomRange(0, this.directionRandomizer);\r\n const randZ = Scalar.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 public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const randRadius = this.radius - Scalar.RandomRange(0, this.radius * this.radiusRange);\r\n const v = Scalar.RandomRange(0, 1.0);\r\n const phi = Scalar.RandomRange(0, 2 * Math.PI);\r\n const theta = Math.acos(2 * v - 1);\r\n const randX = randRadius * Math.cos(phi) * Math.sin(theta);\r\n const randY = randRadius * Math.cos(theta);\r\n const randZ = randRadius * Math.sin(phi) * Math.sin(theta);\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(randX, Math.abs(randY), randZ);\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(randX, Math.abs(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(): HemisphericParticleEmitter {\r\n const newOne = new HemisphericParticleEmitter(this.radius, 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.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\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\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\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 return \"#define HEMISPHERICEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"HemisphericParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"HemisphericParticleEmitter\";\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 serializationObject.type = this.getClassName();\r\n serializationObject.radius = this.radius;\r\n serializationObject.radiusRange = this.radiusRange;\r\n serializationObject.directionRandomizer = this.directionRandomizer;\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.radiusRange = serializationObject.radiusRange;\r\n this.directionRandomizer = serializationObject.directionRandomizer;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"hemisphericParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/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ACzC,IAAI,CAAC,WAAW,GAAG,mBAAmB,CAAC,WAAW,CAAC;QACnD,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC,mBAAmB,CAAC;IACvE,CAAC;CACJ","sourcesContent":["import { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3 } 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 hemisphere.\r\n * It emits the particles alongside the hemisphere radius. The emission direction might be randomized.\r\n */\r\nexport class HemisphericParticleEmitter implements IParticleEmitterType {\r\n /**\r\n * Creates a new instance HemisphericParticleEmitter\r\n * @param radius the radius of the emission hemisphere (1 by default)\r\n * @param radiusRange the range of the emission hemisphere [0-1] 0 Surface only, 1 Entire Radius (1 by default)\r\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\r\n */\r\n constructor(\r\n /**\r\n * [1] The radius of the emission hemisphere.\r\n */\r\n public radius = 1,\r\n /**\r\n * [1] The range of emission [0-1] 0 Surface only, 1 Entire Radius.\r\n */\r\n public radiusRange = 1,\r\n /**\r\n * [0] How much to randomize the particle direction [0-1].\r\n */\r\n public directionRandomizer = 0\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 public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const randRadius = this.radius - RandomRange(0, this.radius * this.radiusRange);\r\n const v = RandomRange(0, 1.0);\r\n const phi = RandomRange(0, 2 * Math.PI);\r\n const theta = Math.acos(2 * v - 1);\r\n const randX = randRadius * Math.cos(phi) * Math.sin(theta);\r\n const randY = randRadius * Math.cos(theta);\r\n const randZ = randRadius * Math.sin(phi) * Math.sin(theta);\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(randX, Math.abs(randY), randZ);\r\n return;\r\n }\r\n\r\n Vector3.TransformCoordinatesFromFloatsToRef(randX, Math.abs(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(): HemisphericParticleEmitter {\r\n const newOne = new HemisphericParticleEmitter(this.radius, 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.setFloat(\"radius\", this.radius);\r\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\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\", 1);\r\n ubo.addUniform(\"radiusRange\", 1);\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 return \"#define HEMISPHERICEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"HemisphericParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"HemisphericParticleEmitter\";\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 serializationObject.type = this.getClassName();\r\n serializationObject.radius = this.radius;\r\n serializationObject.radiusRange = this.radiusRange;\r\n serializationObject.directionRandomizer = this.directionRandomizer;\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.radiusRange = serializationObject.radiusRange;\r\n this.directionRandomizer = serializationObject.directionRandomizer;\r\n }\r\n}\r\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepCopier } from "../../Misc/deepCopier.js";
|
|
2
2
|
import { Vector3, TmpVectors } from "../../Maths/math.vector.js";
|
|
3
|
-
import {
|
|
3
|
+
import { RandomRange } from "../../Maths/math.scalar.functions.js";
|
|
4
4
|
import { VertexBuffer } from "../../Buffers/buffer.js";
|
|
5
5
|
/**
|
|
6
6
|
* Particle emitter emitting particles from the inside of a box.
|
|
@@ -63,9 +63,9 @@ export class MeshParticleEmitter {
|
|
|
63
63
|
Vector3.TransformNormalToRef(this._storedNormal, worldMatrix, directionToUpdate);
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
const randX =
|
|
67
|
-
const randY =
|
|
68
|
-
const randZ =
|
|
66
|
+
const randX = RandomRange(this.direction1.x, this.direction2.x);
|
|
67
|
+
const randY = RandomRange(this.direction1.y, this.direction2.y);
|
|
68
|
+
const randZ = RandomRange(this.direction1.z, this.direction2.z);
|
|
69
69
|
if (isLocal) {
|
|
70
70
|
directionToUpdate.copyFromFloats(randX, randY, randZ);
|
|
71
71
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meshParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/meshParticleEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAIjD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAKpD;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAqB5B,wCAAwC;IACxC,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,IAAW,IAAI,CAAC,KAA6B;QACzC,IAAI,IAAI,CAAC,KAAK,KAAK,KAAK,EAAE;YACtB,OAAO;SACV;QAED,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,IAAI,KAAK,EAAE;YACP,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;YACnC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,eAAe,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;YACnE,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,eAAe,CAAC,YAAY,CAAC,UA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AAC;IACpC,CAAC;IAED;;;OAGG;IACI,gBAAgB;QACnB,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,YAAY;QACf,OAAO,qBAAqB,CAAC;IACjC,CAAC;IAED;;;OAGG;IACI,SAAS;QACZ,MAAM,mBAAmB,GAAQ,EAAE,CAAC;QAEpC,mBAAmB,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAC/C,mBAAmB,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAC3D,mBAAmB,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAC3D,mBAAmB,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QAC3C,mBAAmB,CAAC,0BAA0B,GAAG,IAAI,CAAC,0BAA0B,CAAC;QAEjF,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,mBAAwB,EAAE,KAAsB;QACzD,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3E,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAE3E,IAAI,mBAAmB,CAAC,MAAM,IAAI,KAAK,EAAE;YACrC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,eAAe,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;SACjE;QAED,IAAI,CAAC,0BAA0B,GAAG,mBAAmB,CAAC,0BAA0B,CAAC;IACrF,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 { Scalar } from \"../../Maths/math.scalar\";\r\nimport type { Particle } from \"../../Particles/particle\";\r\nimport type { IParticleEmitterType } from \"./IParticleEmitterType\";\r\nimport type { IndicesArray, Nullable, FloatArray } from \"../../types\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\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 box.\r\n * It emits the particles randomly between 2 given directions.\r\n */\r\nexport class MeshParticleEmitter implements IParticleEmitterType {\r\n private _indices: Nullable<IndicesArray> = null;\r\n private _positions: Nullable<FloatArray> = null;\r\n private _normals: Nullable<FloatArray> = null;\r\n private _storedNormal = Vector3.Zero();\r\n private _mesh: Nullable<AbstractMesh> = null;\r\n\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n */\r\n public direction1 = new Vector3(0, 1.0, 0);\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n */\r\n public direction2 = new Vector3(0, 1.0, 0);\r\n\r\n /**\r\n * Gets or sets a boolean indicating that particle directions must be built from mesh face normals\r\n */\r\n public useMeshNormalsForDirection = true;\r\n\r\n /** Defines the mesh to use as source */\r\n public get mesh(): Nullable<AbstractMesh> {\r\n return this._mesh;\r\n }\r\n\r\n public set mesh(value: Nullable<AbstractMesh>) {\r\n if (this._mesh === value) {\r\n return;\r\n }\r\n\r\n this._mesh = value;\r\n\r\n if (value) {\r\n this._indices = value.getIndices();\r\n this._positions = value.getVerticesData(VertexBuffer.PositionKind);\r\n this._normals = value.getVerticesData(VertexBuffer.NormalKind);\r\n } else {\r\n this._indices = null;\r\n this._positions = null;\r\n this._normals = null;\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new instance MeshParticleEmitter\r\n * @param mesh defines the mesh to use as source\r\n */\r\n constructor(mesh: Nullable<AbstractMesh> = null) {\r\n this.mesh = mesh;\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 (this.useMeshNormalsForDirection && this._normals) {\r\n Vector3.TransformNormalToRef(this._storedNormal, worldMatrix, directionToUpdate);\r\n return;\r\n }\r\n\r\n const randX = Scalar.RandomRange(this.direction1.x, this.direction2.x);\r\n const randY = Scalar.RandomRange(this.direction1.y, this.direction2.y);\r\n const randZ = Scalar.RandomRange(this.direction1.z, this.direction2.z);\r\n\r\n if (isLocal) {\r\n directionToUpdate.copyFromFloats(randX, randY, randZ);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n if (!this._indices || !this._positions) {\r\n return;\r\n }\r\n\r\n const randomFaceIndex = (3 * Math.random() * (this._indices.length / 3)) | 0;\r\n const bu = Math.random();\r\n const bv = Math.random() * (1.0 - bu);\r\n const bw = 1.0 - bu - bv;\r\n\r\n const faceIndexA = this._indices[randomFaceIndex];\r\n const faceIndexB = this._indices[randomFaceIndex + 1];\r\n const faceIndexC = this._indices[randomFaceIndex + 2];\r\n const vertexA = TmpVectors.Vector3[0];\r\n const vertexB = TmpVectors.Vector3[1];\r\n const vertexC = TmpVectors.Vector3[2];\r\n const randomVertex = TmpVectors.Vector3[3];\r\n\r\n Vector3.FromArrayToRef(this._positions, faceIndexA * 3, vertexA);\r\n Vector3.FromArrayToRef(this._positions, faceIndexB * 3, vertexB);\r\n Vector3.FromArrayToRef(this._positions, faceIndexC * 3, vertexC);\r\n\r\n randomVertex.x = bu * vertexA.x + bv * vertexB.x + bw * vertexC.x;\r\n randomVertex.y = bu * vertexA.y + bv * vertexB.y + bw * vertexC.y;\r\n randomVertex.z = bu * vertexA.z + bv * vertexB.z + bw * vertexC.z;\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(randomVertex.x, randomVertex.y, randomVertex.z);\r\n } else {\r\n Vector3.TransformCoordinatesFromFloatsToRef(randomVertex.x, randomVertex.y, randomVertex.z, worldMatrix, positionToUpdate);\r\n }\r\n\r\n if (this.useMeshNormalsForDirection && this._normals) {\r\n Vector3.FromArrayToRef(this._normals, faceIndexA * 3, vertexA);\r\n Vector3.FromArrayToRef(this._normals, faceIndexB * 3, vertexB);\r\n Vector3.FromArrayToRef(this._normals, faceIndexC * 3, vertexC);\r\n\r\n this._storedNormal.x = bu * vertexA.x + bv * vertexB.x + bw * vertexC.x;\r\n this._storedNormal.y = bu * vertexA.y + bv * vertexB.y + bw * vertexC.y;\r\n this._storedNormal.z = bu * vertexA.z + bv * vertexB.z + bw * vertexC.z;\r\n }\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(): MeshParticleEmitter {\r\n const newOne = new MeshParticleEmitter(this.mesh);\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.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 buildUniformLayout(ubo: UniformBuffer): void {\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 getEffectDefines(): string {\r\n return \"\";\r\n }\r\n\r\n /**\r\n * Returns the string \"BoxParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"MeshParticleEmitter\";\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.direction1 = this.direction1.asArray();\r\n serializationObject.direction2 = this.direction2.asArray();\r\n serializationObject.meshId = this.mesh?.id;\r\n serializationObject.useMeshNormalsForDirection = this.useMeshNormalsForDirection;\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 * @param scene defines the hosting scene\r\n */\r\n public parse(serializationObject: any, scene: Nullable<Scene>): void {\r\n Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\r\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\r\n\r\n if (serializationObject.meshId && scene) {\r\n this.mesh = scene.getLastMeshById(serializationObject.meshId);\r\n }\r\n\r\n this.useMeshNormalsForDirection = serializationObject.useMeshNormalsForDirection;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"meshParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/meshParticleEmitter.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;AA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AAC,UAAU,CAAC,CAAC;QAC3E,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAE3E,IAAI,mBAAmB,CAAC,MAAM,IAAI,KAAK,EAAE;YACrC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,eAAe,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;SACjE;QAED,IAAI,CAAC,0BAA0B,GAAG,mBAAmB,CAAC,0BAA0B,CAAC;IACrF,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 { IndicesArray, Nullable, FloatArray } from \"../../types\";\r\nimport { VertexBuffer } from \"../../Buffers/buffer\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\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 box.\r\n * It emits the particles randomly between 2 given directions.\r\n */\r\nexport class MeshParticleEmitter implements IParticleEmitterType {\r\n private _indices: Nullable<IndicesArray> = null;\r\n private _positions: Nullable<FloatArray> = null;\r\n private _normals: Nullable<FloatArray> = null;\r\n private _storedNormal = Vector3.Zero();\r\n private _mesh: Nullable<AbstractMesh> = null;\r\n\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n */\r\n public direction1 = new Vector3(0, 1.0, 0);\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n */\r\n public direction2 = new Vector3(0, 1.0, 0);\r\n\r\n /**\r\n * Gets or sets a boolean indicating that particle directions must be built from mesh face normals\r\n */\r\n public useMeshNormalsForDirection = true;\r\n\r\n /** Defines the mesh to use as source */\r\n public get mesh(): Nullable<AbstractMesh> {\r\n return this._mesh;\r\n }\r\n\r\n public set mesh(value: Nullable<AbstractMesh>) {\r\n if (this._mesh === value) {\r\n return;\r\n }\r\n\r\n this._mesh = value;\r\n\r\n if (value) {\r\n this._indices = value.getIndices();\r\n this._positions = value.getVerticesData(VertexBuffer.PositionKind);\r\n this._normals = value.getVerticesData(VertexBuffer.NormalKind);\r\n } else {\r\n this._indices = null;\r\n this._positions = null;\r\n this._normals = null;\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new instance MeshParticleEmitter\r\n * @param mesh defines the mesh to use as source\r\n */\r\n constructor(mesh: Nullable<AbstractMesh> = null) {\r\n this.mesh = mesh;\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 (this.useMeshNormalsForDirection && this._normals) {\r\n Vector3.TransformNormalToRef(this._storedNormal, worldMatrix, directionToUpdate);\r\n return;\r\n }\r\n\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\r\n if (isLocal) {\r\n directionToUpdate.copyFromFloats(randX, randY, randZ);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n if (!this._indices || !this._positions) {\r\n return;\r\n }\r\n\r\n const randomFaceIndex = (3 * Math.random() * (this._indices.length / 3)) | 0;\r\n const bu = Math.random();\r\n const bv = Math.random() * (1.0 - bu);\r\n const bw = 1.0 - bu - bv;\r\n\r\n const faceIndexA = this._indices[randomFaceIndex];\r\n const faceIndexB = this._indices[randomFaceIndex + 1];\r\n const faceIndexC = this._indices[randomFaceIndex + 2];\r\n const vertexA = TmpVectors.Vector3[0];\r\n const vertexB = TmpVectors.Vector3[1];\r\n const vertexC = TmpVectors.Vector3[2];\r\n const randomVertex = TmpVectors.Vector3[3];\r\n\r\n Vector3.FromArrayToRef(this._positions, faceIndexA * 3, vertexA);\r\n Vector3.FromArrayToRef(this._positions, faceIndexB * 3, vertexB);\r\n Vector3.FromArrayToRef(this._positions, faceIndexC * 3, vertexC);\r\n\r\n randomVertex.x = bu * vertexA.x + bv * vertexB.x + bw * vertexC.x;\r\n randomVertex.y = bu * vertexA.y + bv * vertexB.y + bw * vertexC.y;\r\n randomVertex.z = bu * vertexA.z + bv * vertexB.z + bw * vertexC.z;\r\n\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(randomVertex.x, randomVertex.y, randomVertex.z);\r\n } else {\r\n Vector3.TransformCoordinatesFromFloatsToRef(randomVertex.x, randomVertex.y, randomVertex.z, worldMatrix, positionToUpdate);\r\n }\r\n\r\n if (this.useMeshNormalsForDirection && this._normals) {\r\n Vector3.FromArrayToRef(this._normals, faceIndexA * 3, vertexA);\r\n Vector3.FromArrayToRef(this._normals, faceIndexB * 3, vertexB);\r\n Vector3.FromArrayToRef(this._normals, faceIndexC * 3, vertexC);\r\n\r\n this._storedNormal.x = bu * vertexA.x + bv * vertexB.x + bw * vertexC.x;\r\n this._storedNormal.y = bu * vertexA.y + bv * vertexB.y + bw * vertexC.y;\r\n this._storedNormal.z = bu * vertexA.z + bv * vertexB.z + bw * vertexC.z;\r\n }\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(): MeshParticleEmitter {\r\n const newOne = new MeshParticleEmitter(this.mesh);\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.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 buildUniformLayout(ubo: UniformBuffer): void {\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 getEffectDefines(): string {\r\n return \"\";\r\n }\r\n\r\n /**\r\n * Returns the string \"BoxParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"MeshParticleEmitter\";\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.direction1 = this.direction1.asArray();\r\n serializationObject.direction2 = this.direction2.asArray();\r\n serializationObject.meshId = this.mesh?.id;\r\n serializationObject.useMeshNormalsForDirection = this.useMeshNormalsForDirection;\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 * @param scene defines the hosting scene\r\n */\r\n public parse(serializationObject: any, scene: Nullable<Scene>): void {\r\n Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\r\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\r\n\r\n if (serializationObject.meshId && scene) {\r\n this.mesh = scene.getLastMeshById(serializationObject.meshId);\r\n }\r\n\r\n this.useMeshNormalsForDirection = serializationObject.useMeshNormalsForDirection;\r\n }\r\n}\r\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepCopier } from "../../Misc/deepCopier.js";
|
|
2
2
|
import { Vector3 } from "../../Maths/math.vector.js";
|
|
3
|
-
import {
|
|
3
|
+
import { RandomRange } from "../../Maths/math.scalar.functions.js";
|
|
4
4
|
/**
|
|
5
5
|
* Particle emitter emitting particles from a point.
|
|
6
6
|
* It emits the particles randomly between 2 given directions.
|
|
@@ -27,9 +27,9 @@ export class PointParticleEmitter {
|
|
|
27
27
|
* @param isLocal defines if the direction should be set in local space
|
|
28
28
|
*/
|
|
29
29
|
startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {
|
|
30
|
-
const randX =
|
|
31
|
-
const randY =
|
|
32
|
-
const randZ =
|
|
30
|
+
const randX = RandomRange(this.direction1.x, this.direction2.x);
|
|
31
|
+
const randY = RandomRange(this.direction1.y, this.direction2.y);
|
|
32
|
+
const randZ = RandomRange(this.direction1.z, this.direction2.z);
|
|
33
33
|
if (isLocal) {
|
|
34
34
|
directionToUpdate.copyFromFloats(randX, randY, randZ);
|
|
35
35
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pointParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/pointParticleEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"pointParticleEmitter.js","sourceRoot":"","sources":["../../../../../dev/core/src/Particles/EmitterTypes/p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AAmB,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3E,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/E,CAAC;CACJ","sourcesContent":["import { DeepCopier } from \"../../Misc/deepCopier\";\r\nimport type { Matrix } from \"../../Maths/math.vector\";\r\nimport { Vector3 } 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 a point.\r\n * It emits the particles randomly between 2 given directions.\r\n */\r\nexport class PointParticleEmitter implements IParticleEmitterType {\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n */\r\n public direction1 = new Vector3(0, 1.0, 0);\r\n /**\r\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\r\n */\r\n public direction2 = new Vector3(0, 1.0, 0);\r\n\r\n /**\r\n * Creates a new instance PointParticleEmitter\r\n */\r\n constructor() {}\r\n\r\n /**\r\n * Called by the particle System when the direction is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param directionToUpdate is the direction vector to update with the result\r\n * @param particle is the particle we are computed the direction for\r\n * @param isLocal defines if the direction should be set in local space\r\n */\r\n public startDirectionFunction(worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n const 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\r\n if (isLocal) {\r\n directionToUpdate.copyFromFloats(randX, randY, randZ);\r\n return;\r\n }\r\n\r\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);\r\n }\r\n\r\n /**\r\n * Called by the particle System when the position is computed for the created particle.\r\n * @param worldMatrix is the world matrix of the particle system\r\n * @param positionToUpdate is the position vector to update with the result\r\n * @param particle is the particle we are computed the position for\r\n * @param isLocal defines if the position should be set in local space\r\n */\r\n public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle, isLocal: boolean): void {\r\n if (isLocal) {\r\n positionToUpdate.copyFromFloats(0, 0, 0);\r\n return;\r\n }\r\n Vector3.TransformCoordinatesFromFloatsToRef(0, 0, 0, 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(): PointParticleEmitter {\r\n const newOne = new PointParticleEmitter();\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.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 buildUniformLayout(ubo: UniformBuffer): void {\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 getEffectDefines(): string {\r\n return \"#define POINTEMITTER\";\r\n }\r\n\r\n /**\r\n * Returns the string \"PointParticleEmitter\"\r\n * @returns a string containing the class name\r\n */\r\n public getClassName(): string {\r\n return \"PointParticleEmitter\";\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.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 parse(serializationObject: any): void {\r\n Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\r\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\r\n }\r\n}\r\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Vector3 } from "../../Maths/math.vector.js";
|
|
2
|
-
import {
|
|
2
|
+
import { RandomRange } from "../../Maths/math.scalar.functions.js";
|
|
3
3
|
import { DeepCopier } from "../../Misc/deepCopier.js";
|
|
4
4
|
/**
|
|
5
5
|
* Particle emitter emitting particles from the inside of a sphere.
|
|
@@ -38,9 +38,9 @@ export class SphereParticleEmitter {
|
|
|
38
38
|
*/
|
|
39
39
|
startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {
|
|
40
40
|
const direction = particle.position.subtract(worldMatrix.getTranslation()).normalize();
|
|
41
|
-
const randX =
|
|
42
|
-
const randY =
|
|
43
|
-
const randZ =
|
|
41
|
+
const randX = RandomRange(0, this.directionRandomizer);
|
|
42
|
+
const randY = RandomRange(0, this.directionRandomizer);
|
|
43
|
+
const randZ = RandomRange(0, this.directionRandomizer);
|
|
44
44
|
direction.x += randX;
|
|
45
45
|
direction.y += randY;
|
|
46
46
|
direction.z += randZ;
|
|
@@ -59,9 +59,9 @@ export class SphereParticleEmitter {
|
|
|
59
59
|
* @param isLocal defines if the position should be set in local space
|
|
60
60
|
*/
|
|
61
61
|
startPositionFunction(worldMatrix, positionToUpdate, particle, isLocal) {
|
|
62
|
-
const randRadius = this.radius -
|
|
63
|
-
const v =
|
|
64
|
-
const phi =
|
|
62
|
+
const randRadius = this.radius - RandomRange(0, this.radius * this.radiusRange);
|
|
63
|
+
const v = RandomRange(0, 1.0);
|
|
64
|
+
const phi = RandomRange(0, 2 * Math.PI);
|
|
65
65
|
const theta = Math.acos(2 * v - 1);
|
|
66
66
|
const randX = randRadius * Math.cos(phi) * Math.sin(theta);
|
|
67
67
|
const randY = randRadius * Math.cos(theta);
|
|
@@ -165,9 +165,9 @@ export class SphereDirectedParticleEmitter extends SphereParticleEmitter {
|
|
|
165
165
|
* @param directionToUpdate is the direction vector to update with the result
|
|
166
166
|
*/
|
|
167
167
|
startDirectionFunction(worldMatrix, directionToUpdate) {
|
|
168
|
-
const randX =
|
|
169
|
-
const randY =
|
|
170
|
-
const randZ =
|
|
168
|
+
const randX = RandomRange(this.direction1.x, this.direction2.x);
|
|
169
|
+
const randY = RandomRange(this.direction1.y, this.direction2.y);
|
|
170
|
+
const randZ = RandomRange(this.direction1.z, this.direction2.z);
|
|
171
171
|
Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, worldMatrix, directionToUpdate);
|
|
172
172
|
}
|
|
173
173
|
/**
|