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.

116 lines 4.15 kB
import { __decorate } from "../../../tslib.es6.js"; import { RegisterClass } from "../../../Misc/typeStore.js"; import { NodeParticleBlock } from "../nodeParticleBlock.js"; import { NodeParticleBlockConnectionPointTypes } from "../Enums/nodeParticleBlockConnectionPointTypes.js"; import { editableInPropertyPage } from "../../../Decorators/nodeDecorator.js"; import { Vector3 } from "../../../Maths/math.vector.js"; /** * Operations supported by the Vector Math block */ export var ParticleVectorMathBlockOperations; (function (ParticleVectorMathBlockOperations) { /** Dot product */ ParticleVectorMathBlockOperations[ParticleVectorMathBlockOperations["Dot"] = 0] = "Dot"; /** Distance between two vectors */ ParticleVectorMathBlockOperations[ParticleVectorMathBlockOperations["Distance"] = 1] = "Distance"; })(ParticleVectorMathBlockOperations || (ParticleVectorMathBlockOperations = {})); /** * Block used to apply math operations that only apply to vectors */ export class ParticleVectorMathBlock extends NodeParticleBlock { /** * Create a new ParticleVectorMathBlock * @param name defines the block name */ constructor(name) { super(name); /** * Gets or sets the operation applied by the block */ this.operation = ParticleVectorMathBlockOperations.Dot; this.registerInput("left", NodeParticleBlockConnectionPointTypes.Vector3); this.registerInput("right", NodeParticleBlockConnectionPointTypes.Vector3); this.registerOutput("output", NodeParticleBlockConnectionPointTypes.Float); } /** * Gets the current class name * @returns the class name */ getClassName() { return "ParticleVectorMathBlock"; } /** * Gets the left input component */ get left() { return this._inputs[0]; } /** * Gets the right input component */ get right() { return this._inputs[1]; } /** * Gets the geometry output component */ get output() { return this._outputs[0]; } _build(state) { let func; const left = this.left; const right = this.right; if (!left.isConnected || !right.isConnected) { this.output._storedFunction = null; this.output._storedValue = null; return; } switch (this.operation) { case ParticleVectorMathBlockOperations.Dot: { func = (state) => { return Vector3.Dot(left.getConnectedValue(state), right.getConnectedValue(state)); }; break; } case ParticleVectorMathBlockOperations.Distance: { func = (state) => { return Vector3.Distance(left.getConnectedValue(state), right.getConnectedValue(state)); }; break; } } this.output._storedFunction = (state) => { return func(state); }; } /** * Serializes this block in a JSON representation * @returns the serialized block object */ serialize() { const serializationObject = super.serialize(); serializationObject.operation = this.operation; return serializationObject; } /** * Deserializes the block from a JSON object * @param serializationObject the JSON object to deserialize from */ _deserialize(serializationObject) { super._deserialize(serializationObject); this.operation = serializationObject.operation; } } __decorate([ editableInPropertyPage("Operation", 5 /* PropertyTypeForEdition.List */, "ADVANCED", { notifiers: { rebuild: true }, embedded: true, options: [ { label: "Dot", value: ParticleVectorMathBlockOperations.Dot }, { label: "Distance", value: ParticleVectorMathBlockOperations.Distance }, ], }) ], ParticleVectorMathBlock.prototype, "operation", void 0); RegisterClass("BABYLON.ParticleVectorMathBlock", ParticleVectorMathBlock); //# sourceMappingURL=particleVectorMathBlock.js.map