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.

120 lines 4.55 kB
import { __decorate } from "../../../tslib.es6.js"; import { RegisterClass } from "../../../Misc/typeStore.js"; import { editableInPropertyPage } from "../../../Decorators/nodeDecorator.js"; import { NodeParticleBlock } from "../nodeParticleBlock.js"; import { NodeParticleBlockConnectionPointTypes } from "../Enums/nodeParticleBlockConnectionPointTypes.js"; /** * Operations supported by the FloatToInt block */ export var ParticleFloatToIntBlockOperations; (function (ParticleFloatToIntBlockOperations) { /** Round */ ParticleFloatToIntBlockOperations[ParticleFloatToIntBlockOperations["Round"] = 0] = "Round"; /** Ceil */ ParticleFloatToIntBlockOperations[ParticleFloatToIntBlockOperations["Ceil"] = 1] = "Ceil"; /** Floor */ ParticleFloatToIntBlockOperations[ParticleFloatToIntBlockOperations["Floor"] = 2] = "Floor"; /** Truncate */ ParticleFloatToIntBlockOperations[ParticleFloatToIntBlockOperations["Truncate"] = 3] = "Truncate"; })(ParticleFloatToIntBlockOperations || (ParticleFloatToIntBlockOperations = {})); /** * Block used to transform a float to an int */ export class ParticleFloatToIntBlock extends NodeParticleBlock { /** * Creates a new ParticleFloatToIntBlock * @param name defines the block name */ constructor(name) { super(name); /** * Gets or sets the operation applied by the block */ this.operation = ParticleFloatToIntBlockOperations.Round; this.registerInput("input", NodeParticleBlockConnectionPointTypes.AutoDetect); this.registerOutput("output", NodeParticleBlockConnectionPointTypes.Int); this._outputs[0]._typeConnectionSource = this._inputs[0]; this._inputs[0].addExcludedConnectionPointFromAllowedTypes(NodeParticleBlockConnectionPointTypes.Float | NodeParticleBlockConnectionPointTypes.Int); } /** * Gets the current class name * @returns the class name */ getClassName() { return "ParticleFloatToIntBlock"; } /** * Gets the input component */ get input() { return this._inputs[0]; } /** * Gets the output component */ get output() { return this._outputs[0]; } _build(state) { super._build(state); let func = null; const input = this.input; switch (this.operation) { case ParticleFloatToIntBlockOperations.Round: { func = (state) => { return Math.round(input.getConnectedValue(state)); }; break; } case ParticleFloatToIntBlockOperations.Ceil: { func = (state) => { return Math.ceil(input.getConnectedValue(state)); }; break; } case ParticleFloatToIntBlockOperations.Floor: { func = (state) => { return Math.floor(input.getConnectedValue(state)); }; break; } case ParticleFloatToIntBlockOperations.Truncate: { func = (state) => { return Math.trunc(input.getConnectedValue(state)); }; break; } } if (!func) { this.output._storedFunction = null; this.output._storedValue = null; return; } this.output._storedFunction = (state) => { return func(state); }; } serialize() { const serializationObject = super.serialize(); serializationObject.operation = this.operation; return serializationObject; } _deserialize(serializationObject) { super._deserialize(serializationObject); this.operation = serializationObject.operation; } } __decorate([ editableInPropertyPage("Operation", 5 /* PropertyTypeForEdition.List */, "ADVANCED", { notifiers: { rebuild: true }, embedded: true, options: [ { label: "Round", value: ParticleFloatToIntBlockOperations.Round }, { label: "Ceil", value: ParticleFloatToIntBlockOperations.Ceil }, { label: "Floor", value: ParticleFloatToIntBlockOperations.Floor }, { label: "Truncate", value: ParticleFloatToIntBlockOperations.Truncate }, ], }) ], ParticleFloatToIntBlock.prototype, "operation", void 0); RegisterClass("BABYLON.ParticleFloatToIntBlock", ParticleFloatToIntBlock); //# sourceMappingURL=particleFloatToIntBlock.js.map