UNPKG

@awayjs/graphics

Version:
118 lines (117 loc) 5.11 kB
import { __extends } from "tslib"; import { Matrix3D, Vector3D } from '@awayjs/core'; import { ContextGLVertexBufferFormat } from '@awayjs/stage'; import { ParticlePropertiesMode } from '../data/ParticlePropertiesMode'; import { ParticleStateBase } from './ParticleStateBase'; /** * ... */ var ParticleOrbitState = /** @class */ (function (_super) { __extends(ParticleOrbitState, _super); function ParticleOrbitState(animator, particleOrbitNode) { var _this = _super.call(this, animator, particleOrbitNode) || this; _this._particleOrbitNode = particleOrbitNode; _this._usesEulers = _this._particleOrbitNode._iUsesEulers; _this._usesCycle = _this._particleOrbitNode._iUsesCycle; _this._usesPhase = _this._particleOrbitNode._iUsesPhase; _this._eulers = _this._particleOrbitNode._iEulers; _this._radius = _this._particleOrbitNode._iRadius; _this._cycleDuration = _this._particleOrbitNode._iCycleDuration; _this._cyclePhase = _this._particleOrbitNode._iCyclePhase; _this.updateOrbitData(); return _this; } Object.defineProperty(ParticleOrbitState.prototype, "radius", { /** * Defines the radius of the orbit when in global mode. Defaults to 100. */ get: function () { return this._radius; }, set: function (value) { this._radius = value; this.updateOrbitData(); }, enumerable: false, configurable: true }); Object.defineProperty(ParticleOrbitState.prototype, "cycleDuration", { /** * Defines the duration of the orbit 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.updateOrbitData(); }, enumerable: false, configurable: true }); Object.defineProperty(ParticleOrbitState.prototype, "cyclePhase", { /** * Defines the phase of the orbit 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.updateOrbitData(); }, enumerable: false, configurable: true }); Object.defineProperty(ParticleOrbitState.prototype, "eulers", { /** * Defines the euler rotation in degrees, applied to the orientation of the orbit when in global mode. */ get: function () { return this._eulers; }, set: function (value) { this._eulers = value; this.updateOrbitData(); }, enumerable: false, configurable: true }); ParticleOrbitState.prototype.setRenderState = function (shader, renderable, animationElements, animationRegisterData) { var index = animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleOrbitState.ORBIT_INDEX); if (this._particleOrbitNode.mode == ParticlePropertiesMode.LOCAL_STATIC) { if (this._usesPhase) animationElements.activateVertexBuffer(index, this._particleOrbitNode._iDataOffset, shader.stage, ContextGLVertexBufferFormat.FLOAT_4); else animationElements.activateVertexBuffer(index, this._particleOrbitNode._iDataOffset, shader.stage, ContextGLVertexBufferFormat.FLOAT_3); } else shader.setVertexConst(index, this._orbitData.x, this._orbitData.y, this._orbitData.z, this._orbitData.w); if (this._usesEulers) shader.setVertexConstFromMatrix(animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleOrbitState.EULERS_INDEX), this._eulersMatrix); }; ParticleOrbitState.prototype.updateOrbitData = function () { if (this._usesEulers) { this._eulersMatrix = new Matrix3D(); this._eulersMatrix.appendRotation(this._eulers.x, Vector3D.X_AXIS); this._eulersMatrix.appendRotation(this._eulers.y, Vector3D.Y_AXIS); this._eulersMatrix.appendRotation(this._eulers.z, Vector3D.Z_AXIS); } if (this._particleOrbitNode.mode == ParticlePropertiesMode.GLOBAL) { this._orbitData = new Vector3D(this._radius, 0, this._radius * Math.PI * 2, this._cyclePhase * Math.PI / 180); if (this._usesCycle) { if (this._cycleDuration <= 0) throw (new Error('the cycle duration must be greater than zero')); this._orbitData.y = Math.PI * 2 / this._cycleDuration; } else this._orbitData.y = Math.PI * 2; } }; /** @private */ ParticleOrbitState.ORBIT_INDEX = 0; /** @private */ ParticleOrbitState.EULERS_INDEX = 1; return ParticleOrbitState; }(ParticleStateBase)); export { ParticleOrbitState };