1 |
- {"ast":null,"code":"import { Vector3 } from \"../../Maths/math.vector.js\";\nimport { RandomRange } from \"../../Maths/math.scalar.functions.js\";\nimport { DeepCopier } from \"../../Misc/deepCopier.js\";\n/**\n * Particle emitter emitting particles from the inside of a box.\n * It emits the particles randomly between 2 given directions.\n */\nexport class BoxParticleEmitter {\n /**\n * Creates a new instance BoxParticleEmitter\n */\n constructor() {\n /**\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\n */\n this.direction1 = new Vector3(0, 1.0, 0);\n /**\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\n */\n this.direction2 = new Vector3(0, 1.0, 0);\n /**\n * Minimum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.\n */\n this.minEmitBox = new Vector3(-0.5, -0.5, -0.5);\n /**\n * Maximum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.\n */\n this.maxEmitBox = new Vector3(0.5, 0.5, 0.5);\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 randX = RandomRange(this.direction1.x, this.direction2.x);\n const randY = RandomRange(this.direction1.y, this.direction2.y);\n const randZ = RandomRange(this.direction1.z, this.direction2.z);\n if (isLocal) {\n directionToUpdate.x = randX;\n directionToUpdate.y = randY;\n directionToUpdate.z = randZ;\n return;\n }\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, 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 randX = RandomRange(this.minEmitBox.x, this.maxEmitBox.x);\n const randY = RandomRange(this.minEmitBox.y, this.maxEmitBox.y);\n const randZ = RandomRange(this.minEmitBox.z, this.maxEmitBox.z);\n if (isLocal) {\n positionToUpdate.x = randX;\n positionToUpdate.y = randY;\n positionToUpdate.z = randZ;\n return;\n }\n Vector3.TransformCoordinatesFromFloatsToRef(randX, 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 BoxParticleEmitter();\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.setVector3(\"direction1\", this.direction1);\n uboOrEffect.setVector3(\"direction2\", this.direction2);\n uboOrEffect.setVector3(\"minEmitBox\", this.minEmitBox);\n uboOrEffect.setVector3(\"maxEmitBox\", this.maxEmitBox);\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(\"direction1\", 3);\n ubo.addUniform(\"direction2\", 3);\n ubo.addUniform(\"minEmitBox\", 3);\n ubo.addUniform(\"maxEmitBox\", 3);\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 BOXEMITTER\";\n }\n /**\n * Returns the string \"BoxParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"BoxParticleEmitter\";\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.direction1 = this.direction1.asArray();\n serializationObject.direction2 = this.direction2.asArray();\n serializationObject.minEmitBox = this.minEmitBox.asArray();\n serializationObject.maxEmitBox = this.maxEmitBox.asArray();\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\n Vector3.FromArrayToRef(serializationObject.minEmitBox, 0, this.minEmitBox);\n Vector3.FromArrayToRef(serializationObject.maxEmitBox, 0, this.maxEmitBox);\n }\n}","map":{"version":3,"names":["Vector3","RandomRange","DeepCopier","BoxParticleEmitter","constructor","direction1","direction2","minEmitBox","maxEmitBox","startDirectionFunction","worldMatrix","directionToUpdate","particle","isLocal","randX","x","randY","y","randZ","z","TransformNormalFromFloatsToRef","startPositionFunction","positionToUpdate","TransformCoordinatesFromFloatsToRef","clone","newOne","DeepCopy","applyToShader","uboOrEffect","setVector3","buildUniformLayout","ubo","addUniform","getEffectDefines","getClassName","serialize","serializationObject","type","asArray","parse","FromArrayToRef"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Particles/EmitterTypes/boxParticleEmitter.js"],"sourcesContent":["import { Vector3 } from \"../../Maths/math.vector.js\";\nimport { RandomRange } from \"../../Maths/math.scalar.functions.js\";\nimport { DeepCopier } from \"../../Misc/deepCopier.js\";\n/**\n * Particle emitter emitting particles from the inside of a box.\n * It emits the particles randomly between 2 given directions.\n */\nexport class BoxParticleEmitter {\n /**\n * Creates a new instance BoxParticleEmitter\n */\n constructor() {\n /**\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\n */\n this.direction1 = new Vector3(0, 1.0, 0);\n /**\n * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.\n */\n this.direction2 = new Vector3(0, 1.0, 0);\n /**\n * Minimum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.\n */\n this.minEmitBox = new Vector3(-0.5, -0.5, -0.5);\n /**\n * Maximum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.\n */\n this.maxEmitBox = new Vector3(0.5, 0.5, 0.5);\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 randX = RandomRange(this.direction1.x, this.direction2.x);\n const randY = RandomRange(this.direction1.y, this.direction2.y);\n const randZ = RandomRange(this.direction1.z, this.direction2.z);\n if (isLocal) {\n directionToUpdate.x = randX;\n directionToUpdate.y = randY;\n directionToUpdate.z = randZ;\n return;\n }\n Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, 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 randX = RandomRange(this.minEmitBox.x, this.maxEmitBox.x);\n const randY = RandomRange(this.minEmitBox.y, this.maxEmitBox.y);\n const randZ = RandomRange(this.minEmitBox.z, this.maxEmitBox.z);\n if (isLocal) {\n positionToUpdate.x = randX;\n positionToUpdate.y = randY;\n positionToUpdate.z = randZ;\n return;\n }\n Vector3.TransformCoordinatesFromFloatsToRef(randX, 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 BoxParticleEmitter();\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.setVector3(\"direction1\", this.direction1);\n uboOrEffect.setVector3(\"direction2\", this.direction2);\n uboOrEffect.setVector3(\"minEmitBox\", this.minEmitBox);\n uboOrEffect.setVector3(\"maxEmitBox\", this.maxEmitBox);\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(\"direction1\", 3);\n ubo.addUniform(\"direction2\", 3);\n ubo.addUniform(\"minEmitBox\", 3);\n ubo.addUniform(\"maxEmitBox\", 3);\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 BOXEMITTER\";\n }\n /**\n * Returns the string \"BoxParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"BoxParticleEmitter\";\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.direction1 = this.direction1.asArray();\n serializationObject.direction2 = this.direction2.asArray();\n serializationObject.minEmitBox = this.minEmitBox.asArray();\n serializationObject.maxEmitBox = this.maxEmitBox.asArray();\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n Vector3.FromArrayToRef(serializationObject.direction1, 0, this.direction1);\n Vector3.FromArrayToRef(serializationObject.direction2, 0, this.direction2);\n Vector3.FromArrayToRef(serializationObject.minEmitBox, 0, this.minEmitBox);\n Vector3.FromArrayToRef(serializationObject.maxEmitBox, 0, this.maxEmitBox);\n }\n}\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,4BAA4B;AACpD,SAASC,WAAW,QAAQ,sCAAsC;AAClE,SAASC,UAAU,QAAQ,0BAA0B;AACrD;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,CAAC;EAC5B;AACJ;AACA;EACIC,WAAWA,CAAA,EAAG;IACV;AACR;AACA;IACQ,IAAI,CAACC,UAAU,GAAG,IAAIL,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACxC;AACR;AACA;IACQ,IAAI,CAACM,UAAU,GAAG,IAAIN,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACxC;AACR;AACA;IACQ,I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