UNPKG

@awayjs/graphics

Version:
110 lines (109 loc) 4.74 kB
import { __extends } from "tslib"; import { Vector3D } from '@awayjs/core'; import { ContextGLVertexBufferFormat } from '@awayjs/stage'; import { ParticlePropertiesMode } from '../data/ParticlePropertiesMode'; import { ParticleStateBase } from './ParticleStateBase'; /** * ... */ var ParticleScaleState = /** @class */ (function (_super) { __extends(ParticleScaleState, _super); function ParticleScaleState(animator, particleScaleNode) { var _this = _super.call(this, animator, particleScaleNode) || this; _this._particleScaleNode = particleScaleNode; _this._usesCycle = _this._particleScaleNode._iUsesCycle; _this._usesPhase = _this._particleScaleNode._iUsesPhase; _this._minScale = _this._particleScaleNode._iMinScale; _this._maxScale = _this._particleScaleNode._iMaxScale; _this._cycleDuration = _this._particleScaleNode._iCycleDuration; _this._cyclePhase = _this._particleScaleNode._iCyclePhase; _this.updateScaleData(); return _this; } Object.defineProperty(ParticleScaleState.prototype, "minScale", { /** * Defines the end scale of the state, when in global mode. Defaults to 1. */ get: function () { return this._minScale; }, set: function (value) { this._minScale = value; this.updateScaleData(); }, enumerable: false, configurable: true }); Object.defineProperty(ParticleScaleState.prototype, "maxScale", { /** * Defines the end scale of the state, when in global mode. Defaults to 1. */ get: function () { return this._maxScale; }, set: function (value) { this._maxScale = value; this.updateScaleData(); }, enumerable: false, configurable: true }); Object.defineProperty(ParticleScaleState.prototype, "cycleDuration", { /** * Defines the duration of the animation in seconds, used as a period independent of particle duration when in global mode. Defaults to 1. */ get: function () { return this._cycleDuration; }, set: function (value) { this._cycleDuration = value; this.updateScaleData(); }, enumerable: false, configurable: true }); Object.defineProperty(ParticleScaleState.prototype, "cyclePhase", { /** * Defines the phase of the cycle in degrees, used as the starting offset of the cycle when in global mode. Defaults to 0. */ get: function () { return this._cyclePhase; }, set: function (value) { this._cyclePhase = value; this.updateScaleData(); }, enumerable: false, configurable: true }); ParticleScaleState.prototype.setRenderState = function (shader, renderable, animationElements, animationRegisterData) { var index = animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleScaleState.SCALE_INDEX); if (this._particleScaleNode.mode == ParticlePropertiesMode.LOCAL_STATIC) { if (this._usesCycle) { if (this._usesPhase) animationElements.activateVertexBuffer(index, this._particleScaleNode._iDataOffset, shader.stage, ContextGLVertexBufferFormat.FLOAT_4); else animationElements.activateVertexBuffer(index, this._particleScaleNode._iDataOffset, shader.stage, ContextGLVertexBufferFormat.FLOAT_3); } else animationElements.activateVertexBuffer(index, this._particleScaleNode._iDataOffset, shader.stage, ContextGLVertexBufferFormat.FLOAT_2); } else shader.setVertexConst(index, this._scaleData.x, this._scaleData.y, this._scaleData.z, this._scaleData.w); }; ParticleScaleState.prototype.updateScaleData = function () { if (this._particleScaleNode.mode == ParticlePropertiesMode.GLOBAL) { if (this._usesCycle) { if (this._cycleDuration <= 0) throw (new Error('the cycle duration must be greater than zero')); this._scaleData = new Vector3D((this._minScale + this._maxScale) / 2, Math.abs(this._minScale - this._maxScale) / 2, Math.PI * 2 / this._cycleDuration, this._cyclePhase * Math.PI / 180); } else this._scaleData = new Vector3D(this._minScale, this._maxScale - this._minScale, 0, 0); } }; /** @private */ ParticleScaleState.SCALE_INDEX = 0; return ParticleScaleState; }(ParticleStateBase)); export { ParticleScaleState };