@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.
92 lines • 3.13 kB
JavaScript
import { RegisterClass } from "../../../../Misc/typeStore.js";
import { NodeParticleBlockConnectionPointTypes } from "../../Enums/nodeParticleBlockConnectionPointTypes.js";
import { NodeParticleBlock } from "../../nodeParticleBlock.js";
import { _ConnectAtTheEnd } from "../../../Queue/executionQueue.js";
import { FlowMap } from "../../../flowMap.js";
/**
* Block used to update particle position based on a flow map
*/
export class UpdateFlowMapBlock extends NodeParticleBlock {
/**
* Create a new UpdateFlowMapBlock
* @param name defines the block name
*/
constructor(name) {
super(name);
this.registerInput("particle", NodeParticleBlockConnectionPointTypes.Particle);
this.registerInput("flowMap", NodeParticleBlockConnectionPointTypes.Texture);
this.registerInput("strength", NodeParticleBlockConnectionPointTypes.Float, true, 1);
this.registerOutput("output", NodeParticleBlockConnectionPointTypes.Particle);
}
/**
* Gets the particle component
*/
get particle() {
return this._inputs[0];
}
/**
* Gets the flowMap input component
*/
get flowMap() {
return this._inputs[1];
}
/**
* Gets the strength input component
*/
get strength() {
return this._inputs[2];
}
/**
* Gets the output component
*/
get output() {
return this._outputs[0];
}
/**
* Gets the current class name
* @returns the class name
*/
getClassName() {
return "UpdateFlowMapBlock";
}
/**
* Builds the block
* @param state defines the current build state
*/
_build(state) {
const system = this.particle.getConnectedValue(state);
const scene = state.scene;
const flowMapTexture = this.flowMap.connectedPoint?.ownerBlock;
let flowMap;
// eslint-disable-next-line github/no-then
void flowMapTexture.extractTextureContentAsync().then((textureContent) => {
if (!textureContent) {
return;
}
flowMap = new FlowMap(textureContent.width, textureContent.height, textureContent.data);
});
const processFlowMap = (particle) => {
const matrix = scene.getTransformMatrix();
if (!flowMap) {
// If the flow map is not ready, we skip processing
return;
}
const strength = this.strength.getConnectedValue(state);
flowMap._processParticle(particle, strength * system._tempScaledUpdateSpeed, matrix);
};
const flowMapProcessing = {
process: processFlowMap,
previousItem: null,
nextItem: null,
};
if (system._updateQueueStart) {
_ConnectAtTheEnd(flowMapProcessing, system._updateQueueStart);
}
else {
system._updateQueueStart = flowMapProcessing;
}
this.output._storedValue = system;
}
}
RegisterClass("BABYLON.UpdateFlowMapBlock", UpdateFlowMapBlock);
//# sourceMappingURL=updateFlowMapBlock.js.map