1 |
- {"ast":null,"code":"import { DeepCopier } from \"../../Misc/deepCopier.js\";\nimport { Vector3, TmpVectors } from \"../../Maths/math.vector.js\";\n/**\n * Particle emitter emitting particles from a custom list of positions.\n */\nexport class CustomParticleEmitter {\n /**\n * Creates a new instance CustomParticleEmitter\n */\n constructor() {\n /**\n * Gets or sets the position generator that will create the initial position of each particle.\n * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\n */\n this.particlePositionGenerator = () => {};\n /**\n * Gets or sets the destination generator that will create the final destination of each particle.\n * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\n */\n this.particleDestinationGenerator = () => {};\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 tmpVector = TmpVectors.Vector3[0];\n if (this.particleDestinationGenerator) {\n this.particleDestinationGenerator(-1, particle, tmpVector);\n // Get direction\n const diffVector = TmpVectors.Vector3[1];\n tmpVector.subtractToRef(particle.position, diffVector);\n diffVector.scaleToRef(1 / particle.lifeTime, tmpVector);\n } else {\n tmpVector.set(0, 0, 0);\n }\n if (isLocal) {\n directionToUpdate.copyFrom(tmpVector);\n return;\n }\n Vector3.TransformNormalToRef(tmpVector, 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 tmpVector = TmpVectors.Vector3[0];\n if (this.particlePositionGenerator) {\n this.particlePositionGenerator(-1, particle, tmpVector);\n } else {\n tmpVector.set(0, 0, 0);\n }\n if (isLocal) {\n positionToUpdate.copyFrom(tmpVector);\n return;\n }\n Vector3.TransformCoordinatesToRef(tmpVector, 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 CustomParticleEmitter();\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 // eslint-disable-next-line @typescript-eslint/no-unused-vars\n applyToShader(uboOrEffect) {}\n /**\n * Creates the structure of the ubo for this particle emitter\n * @param ubo ubo to create the structure for\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n buildUniformLayout(ubo) {}\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 CUSTOMEMITTER\";\n }\n /**\n * Returns the string \"PointParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"CustomParticleEmitter\";\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.particlePositionGenerator = this.particlePositionGenerator;\n serializationObject.particleDestinationGenerator = this.particleDestinationGenerator;\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n if (serializationObject.particlePositionGenerator) {\n this.particlePositionGenerator = serializationObject.particlePositionGenerator;\n }\n if (serializationObject.particleDestinationGenerator) {\n this.particleDestinationGenerator = serializationObject.particleDestinationGenerator;\n }\n }\n}","map":{"version":3,"names":["DeepCopier","Vector3","TmpVectors","CustomParticleEmitter","constructor","particlePositionGenerator","particleDestinationGenerator","startDirectionFunction","worldMatrix","directionToUpdate","particle","isLocal","tmpVector","diffVector","subtractToRef","position","scaleToRef","lifeTime","set","copyFrom","TransformNormalToRef","startPositionFunction","positionToUpdate","TransformCoordinatesToRef","clone","newOne","DeepCopy","applyToShader","uboOrEffect","buildUniformLayout","ubo","getEffectDefines","getClassName","serialize","serializationObject","type","parse"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Particles/EmitterTypes/customParticleEmitter.js"],"sourcesContent":["import { DeepCopier } from \"../../Misc/deepCopier.js\";\nimport { Vector3, TmpVectors } from \"../../Maths/math.vector.js\";\n/**\n * Particle emitter emitting particles from a custom list of positions.\n */\nexport class CustomParticleEmitter {\n /**\n * Creates a new instance CustomParticleEmitter\n */\n constructor() {\n /**\n * Gets or sets the position generator that will create the initial position of each particle.\n * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\n */\n this.particlePositionGenerator = () => { };\n /**\n * Gets or sets the destination generator that will create the final destination of each particle.\n * * Index will be provided when used with GPU particle. Particle will be provided when used with CPU particles\n */\n this.particleDestinationGenerator = () => { };\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 tmpVector = TmpVectors.Vector3[0];\n if (this.particleDestinationGenerator) {\n this.particleDestinationGenerator(-1, particle, tmpVector);\n // Get direction\n const diffVector = TmpVectors.Vector3[1];\n tmpVector.subtractToRef(particle.position, diffVector);\n diffVector.scaleToRef(1 / particle.lifeTime, tmpVector);\n }\n else {\n tmpVector.set(0, 0, 0);\n }\n if (isLocal) {\n directionToUpdate.copyFrom(tmpVector);\n return;\n }\n Vector3.TransformNormalToRef(tmpVector, 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 tmpVector = TmpVectors.Vector3[0];\n if (this.particlePositionGenerator) {\n this.particlePositionGenerator(-1, particle, tmpVector);\n }\n else {\n tmpVector.set(0, 0, 0);\n }\n if (isLocal) {\n positionToUpdate.copyFrom(tmpVector);\n return;\n }\n Vector3.TransformCoordinatesToRef(tmpVector, 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 CustomParticleEmitter();\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 // eslint-disable-next-line @typescript-eslint/no-unused-vars\n applyToShader(uboOrEffect) { }\n /**\n * Creates the structure of the ubo for this particle emitter\n * @param ubo ubo to create the structure for\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n buildUniformLayout(ubo) { }\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 CUSTOMEMITTER\";\n }\n /**\n * Returns the string \"PointParticleEmitter\"\n * @returns a string containing the class name\n */\n getClassName() {\n return \"CustomParticleEmitter\";\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.particlePositionGenerator = this.particlePositionGenerator;\n serializationObject.particleDestinationGenerator = this.particleDestinationGenerator;\n return serializationObject;\n }\n /**\n * Parse properties from a JSON object\n * @param serializationObject defines the JSON object\n */\n parse(serializationObject) {\n if (serializationObject.particlePositionGenerator) {\n this.particlePositionGenerator = serializationObject.particlePositionGenerator;\n }\n if (serializationObject.particleDestinationGenerator) {\n this.particleDestinationGenerator = serializationObject.particleDestinationGenerator;\n }\n }\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,0BAA0B;AACrD,SAASC,OAAO,EAAEC,UAAU,QAAQ,4BAA4B;AAChE;AACA;AACA;AACA,OAAO,MAAMC,qBAAqB,CAAC;EAC/B;AACJ;AACA;EACIC,WAAWA,CAAA,EAAG;IACV;AACR;AACA;AACA;IACQ,IAAI,CAACC,yBAAyB,GAA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