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.

107 lines 4.13 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"; import { RandomRange } from "../../../../Maths/math.scalar.functions.js"; /** * Block used to provide a flow of particles emitted from a box shape. */ export class BoxShapeBlock extends NodeParticleBlock { /** * Create a new BoxShapeBlock * @param name defines the block name */ constructor(name) { super(name); this.registerInput("particle", NodeParticleBlockConnectionPointTypes.Particle); this.registerInput("direction1", NodeParticleBlockConnectionPointTypes.Vector3, true, new Vector3(0, 1.0, 0)); this.registerInput("direction2", NodeParticleBlockConnectionPointTypes.Vector3, true, new Vector3(0, 1.0, 0)); this.registerInput("minEmitBox", NodeParticleBlockConnectionPointTypes.Vector3, true, new Vector3(-0.5, -0.5, -0.5)); this.registerInput("maxEmitBox", NodeParticleBlockConnectionPointTypes.Vector3, true, new Vector3(0.5, 0.5, 0.5)); this.registerOutput("output", NodeParticleBlockConnectionPointTypes.Particle); } /** * Gets the current class name * @returns the class name */ getClassName() { return "BoxShapeBlock"; } /** * Gets the particle input component */ get particle() { return this._inputs[0]; } /** * Gets the direction1 input component */ get direction1() { return this._inputs[1]; } /** * Gets the direction2 input component */ get direction2() { return this._inputs[2]; } /** * Gets the minEmitBox input component */ get minEmitBox() { return this._inputs[3]; } /** * Gets the maxEmitBox input component */ get maxEmitBox() { return this._inputs[4]; } /** * 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 direction1 = this.direction1.getConnectedValue(state); const direction2 = this.direction2.getConnectedValue(state); const randX = RandomRange(direction1.x, direction2.x); const randY = RandomRange(direction1.y, direction2.y); const randZ = RandomRange(direction1.z, direction2.z); if (state.isEmitterTransformNode) { Vector3.TransformNormalFromFloatsToRef(randX, randY, randZ, state.emitterWorldMatrix, particle.direction); } else { particle.direction.copyFromFloats(randX, randY, randZ); } }; system._positionCreation.process = (particle) => { state.particleContext = particle; state.systemContext = system; const minEmitBox = this.minEmitBox.getConnectedValue(state); const maxEmitBox = this.maxEmitBox.getConnectedValue(state); const randX = RandomRange(minEmitBox.x, maxEmitBox.x); const randY = RandomRange(minEmitBox.y, maxEmitBox.y); const randZ = RandomRange(minEmitBox.z, maxEmitBox.z); if (state.isEmitterTransformNode) { Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, state.emitterWorldMatrix, particle.position); } else { particle.position.copyFromFloats(randX, randY, randZ); particle.position.addInPlace(state.emitterPosition); } }; this.output._storedValue = system; } } RegisterClass("BABYLON.BoxShapeBlock", BoxShapeBlock); //# sourceMappingURL=boxShapeBlock.js.map