@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.
195 lines • 7.98 kB
JavaScript
import { __decorate } from "../../../tslib.es6.js";
import { RegisterClass } from "../../../Misc/typeStore.js";
import { NodeParticleBlockConnectionPointTypes } from "../Enums/nodeParticleBlockConnectionPointTypes.js";
import { NodeParticleBlock } from "../nodeParticleBlock.js";
import { editableInPropertyPage } from "../../../Decorators/nodeDecorator.js";
import { BaseParticleSystem } from "../../baseParticleSystem.js";
import { _TriggerSubEmitter } from "./Triggers/triggerTools.js";
/**
* Block used to get a system of particles
*/
export class SystemBlock extends NodeParticleBlock {
/**
* Create a new SystemBlock
* @param name defines the block name
*/
constructor(name) {
super(name);
/**
* Gets or sets the blend mode for the particle system
*/
this.blendMode = BaseParticleSystem.BLENDMODE_ONEONE;
/**
* Gets or sets the epsilon value used for comparison
*/
this.capacity = 1000;
/**
* Gets or sets the emit rate
*/
this.emitRate = 10;
/**
* Gets or sets the target stop duration for the particle system
*/
this.targetStopDuration = 0;
/**
* Gets or sets the target stop duration for the particle system
*/
this.startDelay = 0;
/**
* Gets or sets a boolean indicating if the system should not start automatically
*/
this.doNoStart = false;
/** @internal */
this._internalId = SystemBlock._IdCounter++;
this._isSystem = true;
this.registerInput("particle", NodeParticleBlockConnectionPointTypes.Particle);
this.registerInput("texture", NodeParticleBlockConnectionPointTypes.Texture);
this.registerInput("onStart", NodeParticleBlockConnectionPointTypes.System, true);
this.registerInput("onEnd", NodeParticleBlockConnectionPointTypes.System, true);
this.registerOutput("system", NodeParticleBlockConnectionPointTypes.System);
}
/**
* Gets the current class name
* @returns the class name
*/
getClassName() {
return "SystemBlock";
}
/**
* Gets the particle input component
*/
get particle() {
return this._inputs[0];
}
/**
* Gets the texture input component
*/
get texture() {
return this._inputs[1];
}
/**
* Gets the onStart input component
*/
get onStart() {
return this._inputs[2];
}
/**
* Gets the onEnd input component
*/
get onEnd() {
return this._inputs[3];
}
/**
* Gets the system output component
*/
get system() {
return this._outputs[0];
}
/**
* Builds the block and return a functional particle system
* @param state defines the building state
* @returns the built particle system
*/
createSystem(state) {
state.capacity = this.capacity;
state.buildId = this._buildId++;
this.build(state);
const particleSystem = this.particle.getConnectedValue(state);
particleSystem.particleTexture = this.texture.getConnectedValue(state);
particleSystem.emitRate = this.emitRate;
particleSystem.blendMode = this.blendMode;
particleSystem.name = this.name;
particleSystem._targetStopDuration = this.targetStopDuration;
particleSystem.startDelay = this.startDelay;
this.system._storedValue = this;
particleSystem.canStart = () => {
return !this.doNoStart;
};
particleSystem.onStartedObservable.add((system) => {
// Triggers
const onStartSystem = this.onStart.getConnectedValue(state);
if (onStartSystem) {
system.onStartedObservable.addOnce(() => {
state.systemContext = particleSystem;
const clone = _TriggerSubEmitter(onStartSystem, state.scene, state.emitterPosition);
this.onDisposeObservable.addOnce(() => {
// Clean up the cloned system when the original system is disposed
clone.dispose();
});
});
}
const onEndSystem = this.onEnd.getConnectedValue(state);
if (onEndSystem) {
system.onStoppedObservable.addOnce(() => {
state.systemContext = particleSystem;
const clone = _TriggerSubEmitter(onEndSystem, state.scene, state.emitterPosition);
this.onDisposeObservable.addOnce(() => {
// Clean up the cloned system when the original system is disposed
clone.dispose();
});
});
}
});
this.onDisposeObservable.addOnce(() => {
particleSystem.dispose();
});
// Return
return particleSystem;
}
serialize() {
const serializationObject = super.serialize();
serializationObject.capacity = this.capacity;
serializationObject.emitRate = this.emitRate;
serializationObject.blendMode = this.blendMode;
serializationObject.doNoStart = this.doNoStart;
serializationObject.targetStopDuration = this.targetStopDuration;
serializationObject.startDelay = this.startDelay;
return serializationObject;
}
_deserialize(serializationObject) {
super._deserialize(serializationObject);
this.capacity = serializationObject.capacity;
this.emitRate = serializationObject.emitRate;
this.doNoStart = !!serializationObject.doNoStart;
if (serializationObject.blendMode !== undefined) {
this.blendMode = serializationObject.blendMode;
}
if (serializationObject.targetStopDuration !== undefined) {
this.targetStopDuration = serializationObject.targetStopDuration;
}
if (serializationObject.startDelay !== undefined) {
this.startDelay = serializationObject.startDelay;
}
}
}
SystemBlock._IdCounter = 0;
__decorate([
editableInPropertyPage("Blend mode", 5 /* PropertyTypeForEdition.List */, "ADVANCED", {
notifiers: { rebuild: true },
embedded: true,
options: [
{ label: "OneOne", value: BaseParticleSystem.BLENDMODE_ONEONE },
{ label: "Standard", value: BaseParticleSystem.BLENDMODE_STANDARD },
{ label: "Add", value: BaseParticleSystem.BLENDMODE_ADD },
{ label: "Multiply", value: BaseParticleSystem.BLENDMODE_MULTIPLY },
{ label: "MultiplyAdd", value: BaseParticleSystem.BLENDMODE_MULTIPLYADD },
],
})
], SystemBlock.prototype, "blendMode", void 0);
__decorate([
editableInPropertyPage("Capacity", 2 /* PropertyTypeForEdition.Int */, "ADVANCED", { embedded: true, notifiers: { rebuild: true }, min: 0, max: 10000 })
], SystemBlock.prototype, "capacity", void 0);
__decorate([
editableInPropertyPage("Emit rate", 2 /* PropertyTypeForEdition.Int */, "ADVANCED", { embedded: true, notifiers: { rebuild: true }, min: 0 })
], SystemBlock.prototype, "emitRate", void 0);
__decorate([
editableInPropertyPage("Target duration", 1 /* PropertyTypeForEdition.Float */, "ADVANCED", { embedded: true, notifiers: { rebuild: true }, min: 0 })
], SystemBlock.prototype, "targetStopDuration", void 0);
__decorate([
editableInPropertyPage("Delay start(ms)", 1 /* PropertyTypeForEdition.Float */, "ADVANCED", { embedded: true, notifiers: { rebuild: true }, min: 0 })
], SystemBlock.prototype, "startDelay", void 0);
__decorate([
editableInPropertyPage("Do no start", 0 /* PropertyTypeForEdition.Boolean */, "ADVANCED", { embedded: true, notifiers: { rebuild: true } })
], SystemBlock.prototype, "doNoStart", void 0);
RegisterClass("BABYLON.SystemBlock", SystemBlock);
//# sourceMappingURL=systemBlock.js.map