ddc8a96213751ac036cb3c2f35493c2a67d74f66c073a22710ea445f0ced7c4c.json 15 KB

1
  1. {"ast":null,"code":"import { DeepCopier } from \"../../Misc/deepCopier.js\";\nimport { Vector3 } from \"../../Maths/math.vector.js\";\nimport { RandomRange } from \"../../Maths/math.scalar.functions.js\";\n/**\n * Particle emitter emitting particles from the inside of a hemisphere.\n * It emits the particles alongside the hemisphere radius. The emission direction might be randomized.\n */\nexport class HemisphericParticleEmitter {\n /**\n * Creates a new instance HemisphericParticleEmitter\n * @param radius the radius of the emission hemisphere (1 by default)\n * @param radiusRange the range of the emission hemisphere [0-1] 0 Surface only, 1 Entire Radius (1 by default)\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\n */\n constructor(\n /**\n * [1] The radius of the emission hemisphere.\n */\n radius = 1,\n /**\n * [1] The range of emission [0-1] 0 Surface only, 1 Entire Radius.\n */\n radiusRange = 1,\n /**\n * [0] How much to randomize the particle direction [0-1].\n */\n directionRandomizer = 0) {\n this.radius = radius;\n this.radiusRange = radiusRange;\n this.directionRandomizer = directionRandomizer;\n }\n /**\n * Called by the particle System when the direction is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param directionToUpdate is the direction vector to update with the result\n * @param particle is the particle we are computed the direction for\n * @param isLocal defines if the direction should be set in local space\n */\n startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {\n const direction = particle.position.subtract(worldMatrix.getTranslation()).normalize();\n const randX = RandomRange(0, this.directionRandomizer);\n const randY = RandomRange(0, this.directionRandomizer);\n const randZ = RandomRange(0, this.directionRandomizer);\n direction.x += randX;\n direction.y += randY;\n direction.z += randZ;\n direction.normalize();\n if (isLocal) {\n directionToUpdate.copyFrom(direction);\n return;\n }\n Vector3.TransformNormalFromFloatsToRef(direction.x, direction.y, direction.z, worldMatrix, directionToUpdate);\n }\n /**\n * Called by the particle System when the position is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param positionToUpdate is the position vector to update with the result\n * @param particle is the particle we are computed the position for\n * @param isLocal defines if the position should be set in local space\n */\n startPositionFunction(worldMatrix, positionToUpdate, particle, isLocal) {\n const randRadius = this.radius - RandomRange(0, this.radius * this.radiusRange);\n const v = RandomRange(0, 1.0);\n const phi = RandomRange(0, 2 * Math.PI);\n const theta = Math.acos(2 * v - 1);\n const randX = randRadius * Math.cos(phi) * Math.sin(theta);\n const randY = randRadius * Math.cos(theta);\n const randZ = randRadius * Math.sin(phi) * Math.sin(theta);\n if (isLocal) {\n positionToUpdate.copyFromFloats(randX, Math.abs(randY), randZ);\n return;\n }\n Vector3.TransformCoordinatesFromFloatsToRef(randX, Math.abs(randY), randZ, worldMatrix, positionToUpdate);\n }\n /**\n * Clones the current emitter and returns a copy of it\n * @returns the new emitter\n */\n clone() {\n const newOne = new HemisphericParticleEmitter(this.radius, this.directionRandomizer);\n DeepCopier.DeepCopy(this, newOne);\n return newOne;\n }\n /**\n * Called by the GPUParticleSystem to setup the update shader\n * @param uboOrEffect defines the update shader\n */\n applyToShader(uboOrEffect) {\n uboOrEffect.setFloat(\"radius\", this.radius);\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\n }\n /**\n * Creates the structure of the ubo for this particle emitter\n * @param ubo ubo to create the structure for\n */\n buildUniformLayout(ubo) {\n ubo.addUniform(\"radius\", 1);\n ubo.addUniform(\"radiusRange\", 1);\n ubo.addUniform(\"directionRandomizer\", 1);\n }\n /**\n * Returns a string to use to update the GPU particles update shader\n * @returns a string containing the defines string\n */\n getEffectDefines() {\n return \"#define HEMISPHERICEMITTER\";\n }\n /**\n * Returns the string \"HemisphericParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"HemisphericParticleEmitter\";\n }\n /**\n * Serializes the particle system to a JSON object.\n * @returns the JSON object\n */\n serialize() {\n const serializationObject = {};\n serializationObject.type = this.getClassName();\n serializationObject.radius = this.radius;\n serializationObject.radiusRange = this.radiusRange;\n serializationObject.directionRandomizer = this.directionRandomizer;\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n this.radius = serializationObject.radius;\n this.radiusRange = serializationObject.radiusRange;\n this.directionRandomizer = serializationObject.directionRandomizer;\n }\n}","map":{"version":3,"names":["DeepCopier","Vector3","RandomRange","HemisphericParticleEmitter","constructor","radius","radiusRange","directionRandomizer","startDirectionFunction","worldMatrix","directionToUpdate","particle","isLocal","direction","position","subtract","getTranslation","normalize","randX","randY","randZ","x","y","z","copyFrom","TransformNormalFromFloatsToRef","startPositionFunction","positionToUpdate","randRadius","v","phi","Math","PI","theta","acos","cos","sin","copyFromFloats","abs","TransformCoordinatesFromFloatsToRef","clone","newOne","DeepCopy","applyToShader","uboOrEffect","setFloat","buildUniformLayout","ubo","addUniform","getEffectDefines","getClassName","serialize","serializationObject","type","parse"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Particles/EmitterTypes/hemisphericParticleEmitter.js"],"sourcesContent":["import { DeepCopier } from \"../../Misc/deepCopier.js\";\nimport { Vector3 } from \"../../Maths/math.vector.js\";\nimport { RandomRange } from \"../../Maths/math.scalar.functions.js\";\n/**\n * Particle emitter emitting particles from the inside of a hemisphere.\n * It emits the particles alongside the hemisphere radius. The emission direction might be randomized.\n */\nexport class HemisphericParticleEmitter {\n /**\n * Creates a new instance HemisphericParticleEmitter\n * @param radius the radius of the emission hemisphere (1 by default)\n * @param radiusRange the range of the emission hemisphere [0-1] 0 Surface only, 1 Entire Radius (1 by default)\n * @param directionRandomizer defines how much to randomize the particle direction [0-1]\n */\n constructor(\n /**\n * [1] The radius of the emission hemisphere.\n */\n radius = 1, \n /**\n * [1] The range of emission [0-1] 0 Surface only, 1 Entire Radius.\n */\n radiusRange = 1, \n /**\n * [0] How much to randomize the particle direction [0-1].\n */\n directionRandomizer = 0) {\n this.radius = radius;\n this.radiusRange = radiusRange;\n this.directionRandomizer = directionRandomizer;\n }\n /**\n * Called by the particle System when the direction is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param directionToUpdate is the direction vector to update with the result\n * @param particle is the particle we are computed the direction for\n * @param isLocal defines if the direction should be set in local space\n */\n startDirectionFunction(worldMatrix, directionToUpdate, particle, isLocal) {\n const direction = particle.position.subtract(worldMatrix.getTranslation()).normalize();\n const randX = RandomRange(0, this.directionRandomizer);\n const randY = RandomRange(0, this.directionRandomizer);\n const randZ = RandomRange(0, this.directionRandomizer);\n direction.x += randX;\n direction.y += randY;\n direction.z += randZ;\n direction.normalize();\n if (isLocal) {\n directionToUpdate.copyFrom(direction);\n return;\n }\n Vector3.TransformNormalFromFloatsToRef(direction.x, direction.y, direction.z, worldMatrix, directionToUpdate);\n }\n /**\n * Called by the particle System when the position is computed for the created particle.\n * @param worldMatrix is the world matrix of the particle system\n * @param positionToUpdate is the position vector to update with the result\n * @param particle is the particle we are computed the position for\n * @param isLocal defines if the position should be set in local space\n */\n startPositionFunction(worldMatrix, positionToUpdate, particle, isLocal) {\n const randRadius = this.radius - RandomRange(0, this.radius * this.radiusRange);\n const v = RandomRange(0, 1.0);\n const phi = RandomRange(0, 2 * Math.PI);\n const theta = Math.acos(2 * v - 1);\n const randX = randRadius * Math.cos(phi) * Math.sin(theta);\n const randY = randRadius * Math.cos(theta);\n const randZ = randRadius * Math.sin(phi) * Math.sin(theta);\n if (isLocal) {\n positionToUpdate.copyFromFloats(randX, Math.abs(randY), randZ);\n return;\n }\n Vector3.TransformCoordinatesFromFloatsToRef(randX, Math.abs(randY), randZ, worldMatrix, positionToUpdate);\n }\n /**\n * Clones the current emitter and returns a copy of it\n * @returns the new emitter\n */\n clone() {\n const newOne = new HemisphericParticleEmitter(this.radius, this.directionRandomizer);\n DeepCopier.DeepCopy(this, newOne);\n return newOne;\n }\n /**\n * Called by the GPUParticleSystem to setup the update shader\n * @param uboOrEffect defines the update shader\n */\n applyToShader(uboOrEffect) {\n uboOrEffect.setFloat(\"radius\", this.radius);\n uboOrEffect.setFloat(\"radiusRange\", this.radiusRange);\n uboOrEffect.setFloat(\"directionRandomizer\", this.directionRandomizer);\n }\n /**\n * Creates the structure of the ubo for this particle emitter\n * @param ubo ubo to create the structure for\n */\n buildUniformLayout(ubo) {\n ubo.addUniform(\"radius\", 1);\n ubo.addUniform(\"radiusRange\", 1);\n ubo.addUniform(\"directionRandomizer\", 1);\n }\n /**\n * Returns a string to use to update the GPU particles update shader\n * @returns a string containing the defines string\n */\n getEffectDefines() {\n return \"#define HEMISPHERICEMITTER\";\n }\n /**\n * Returns the string \"HemisphericParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"HemisphericParticleEmitter\";\n }\n /**\n * Serializes the particle system to a JSON object.\n * @returns the JSON object\n */\n serialize() {\n const serializationObject = {};\n serializationObject.type = this.getClassName();\n serializationObject.radius = this.radius;\n serializationObject.radiusRange = this.radiusRange;\n serializationObject.directionRandomizer = this.directionRandomizer;\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n this.radius = serializationObject.radius;\n this.radiusRange = serializationObject.radiusRange;\n this.directionRandomizer = serializationObject.directionRandomizer;\n }\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,0BAA0B;AACrD,SAASC,OAAO,QAAQ,4BAA4B;AACpD,SAASC,WAAW,QAAQ,sCAAsC;AAClE;AACA;AACA;AACA;AACA,OAAO,MAAMC,0BAA0B,CAAC;EACpC;AACJ;AACA;AACA;AACA;AACA;EACIC,WAAWA;EACX;AACJ;AACA;EACIC,MAAM,GAAG,CAAC;EACV;AACJ;AACA;EACIC,WAAW,GAAG,CAAC;EACf;AACJ;AACA;EACIC,mBAAmB,GAAG,CAAC,EAAE;IACrB,IAAI,CAACF,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,WAAW,GAAGA,WAAW;IAC9B,IAAI,CAACC,mBAAmB,GAAGA,mBAAmB;EAClD;EACA;AACJ;AACA;AACA;AACA;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