UNPKG

@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.

84 lines 2.95 kB
import { RegisterClass } from "../../../../Misc/typeStore.js"; import { NodeParticleBlockConnectionPointTypes } from "../../Enums/nodeParticleBlockConnectionPointTypes.js"; import { Vector3 } from "../../../../Maths/math.vector.js"; import { NodeParticleBlock } from "../../nodeParticleBlock.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); this.registerInput("particle", NodeParticleBlockConnectionPointTypes.Particle); this.registerInput("position", NodeParticleBlockConnectionPointTypes.Vector3, true, new Vector3(0, 0, 0)); this.registerInput("direction", NodeParticleBlockConnectionPointTypes.Vector3, true, new Vector3(0, 1.0, 0)); 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 position input component */ get position() { return this._inputs[1]; } /** * Gets the direction input component */ get direction() { return this._inputs[2]; } /** * 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 direction = this.direction.getConnectedValue(state); if (state.isEmitterTransformNode) { Vector3.TransformNormalToRef(direction, state.emitterWorldMatrix, particle.direction); } else { particle.direction.copyFrom(direction); } }; system._positionCreation.process = (particle) => { state.particleContext = particle; state.systemContext = system; const position = this.position.getConnectedValue(state); if (state.isEmitterTransformNode) { Vector3.TransformCoordinatesToRef(position, state.emitterWorldMatrix, particle.position); } else { particle.position.copyFrom(position); particle.position.addInPlace(state.emitterPosition); } }; this.output._storedValue = system; } } RegisterClass("BABYLON.CustomShapeBlock", CustomShapeBlock); //# sourceMappingURL=customShapeBlock.js.map