@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
98 lines • 3.98 kB
JavaScript
import { TmpVectors, Vector3 } from "../../../../Maths/math.vector.js";
import { RegisterClass } from "../../../../Misc/typeStore.js";
import { EmptyGeneratorFunc } from "../../../EmitterTypes/customParticleEmitter.js";
import { NodeParticleBlock } from "../../nodeParticleBlock.js";
import { NodeParticleBlockConnectionPointTypes } from "../../Enums/nodeParticleBlockConnectionPointTypes.js";
import { _CreateLocalPositionData } from "./emitters.functions.js";
/**
* Block used to provide a flow of particles emitted from a custom position.
*/
export class CustomShapeBlock extends NodeParticleBlock {
/**
* Create a new CustomShapeBlock
* @param name defines the block name
*/
constructor(name) {
super(name);
/** The particle position generator function */
this.particlePositionGenerator = EmptyGeneratorFunc;
/** The particle destination generator function */
this.particleDestinationGenerator = EmptyGeneratorFunc;
/** The particle direction generator function */
this.particleDirectionGenerator = EmptyGeneratorFunc;
this.registerInput("particle", NodeParticleBlockConnectionPointTypes.Particle);
this.registerOutput("output", NodeParticleBlockConnectionPointTypes.Particle);
}
/**
* Gets the current class name
* @returns the class name
*/
getClassName() {
return "CustomShapeBlock";
}
/**
* Gets the particle component
*/
get particle() {
return this._inputs[0];
}
/**
* Gets the output component
*/
get output() {
return this._outputs[0];
}
/**
* Builds the block
* @param state defines the build state
*/
_build(state) {
const system = this.particle.getConnectedValue(state);
system._directionCreation.process = (particle) => {
state.particleContext = particle;
state.systemContext = system;
const tmpVector = TmpVectors.Vector3[0];
if (this.particleDirectionGenerator && this.particleDirectionGenerator !== EmptyGeneratorFunc) {
this.particleDirectionGenerator(-1, particle, tmpVector);
}
else if (this.particleDestinationGenerator && this.particleDestinationGenerator !== EmptyGeneratorFunc) {
this.particleDestinationGenerator(-1, particle, tmpVector);
// Get direction
const diffVector = TmpVectors.Vector3[1];
tmpVector.subtractToRef(particle.position, diffVector);
diffVector.scaleToRef(1 / particle.lifeTime, tmpVector);
}
else {
tmpVector.set(0, 0, 0);
}
if (system.isLocal) {
particle.direction.copyFrom(tmpVector);
}
else {
Vector3.TransformNormalToRef(tmpVector, state.emitterWorldMatrix, particle.direction);
}
particle._properties.initialDirection = particle.direction.clone();
};
system._positionCreation.process = (particle) => {
state.particleContext = particle;
state.systemContext = system;
const tmpVector = TmpVectors.Vector3[0];
if (this.particlePositionGenerator && this.particlePositionGenerator !== EmptyGeneratorFunc) {
this.particlePositionGenerator(-1, particle, tmpVector);
}
else {
tmpVector.set(0, 0, 0);
}
if (system.isLocal) {
particle.position.copyFrom(tmpVector);
}
else {
Vector3.TransformCoordinatesToRef(tmpVector, state.emitterWorldMatrix, particle.position);
}
_CreateLocalPositionData(particle);
};
this.output._storedValue = system;
}
}
RegisterClass("BABYLON.CustomShapeBlock", CustomShapeBlock);
//# sourceMappingURL=customShapeBlock.js.map