UNPKG

@awayjs/graphics

Version:
119 lines (118 loc) 4.37 kB
import { __extends } from "tslib"; import { Vector3D } from '@awayjs/core'; import { ShaderRegisterElement } from '@awayjs/stage'; import { ParticlePropertiesMode } from '../data/ParticlePropertiesMode'; import { ParticleUVState } from '../states/ParticleUVState'; import { ParticleAnimationSet } from '../ParticleAnimationSet'; import { ParticleNodeBase } from './ParticleNodeBase'; /** * A particle animation node used to control the UV offset and scale of a particle over time. */ var ParticleUVNode = /** @class */ (function (_super) { __extends(ParticleUVNode, _super); /** * Creates a new <code>ParticleTimeNode</code> * * @param mode Defines whether the mode of operation acts on local properties of a particle or global properties of the node. * @param [optional] cycle Defines whether the time track is in loop mode. Defaults to false. * @param [optional] scale Defines whether the time track is in loop mode. Defaults to false. * @param [optional] axis Defines whether the time track is in loop mode. Defaults to false. */ function ParticleUVNode(mode, cycle, scale, axis) { if (cycle === void 0) { cycle = 1; } if (scale === void 0) { scale = 1; } if (axis === void 0) { axis = 'x'; } var _this = //because of the stage3d register limitation, it only support the global mode _super.call(this, 'ParticleUV', ParticlePropertiesMode.GLOBAL, 4, ParticleAnimationSet.POST_PRIORITY + 1) || this; _this._pStateClass = ParticleUVState; _this._cycle = cycle; _this._scale = scale; _this._axis = axis; _this.updateUVData(); return _this; } Object.defineProperty(ParticleUVNode.prototype, "cycle", { /** * */ get: function () { return this._cycle; }, set: function (value) { this._cycle = value; this.updateUVData(); }, enumerable: false, configurable: true }); Object.defineProperty(ParticleUVNode.prototype, "scale", { /** * */ get: function () { return this._scale; }, set: function (value) { this._scale = value; this.updateUVData(); }, enumerable: false, configurable: true }); Object.defineProperty(ParticleUVNode.prototype, "axis", { /** * */ get: function () { return this._axis; }, set: function (value) { this._axis = value; }, enumerable: false, configurable: true }); /** * @inheritDoc */ ParticleUVNode.prototype.getAGALUVCode = function (shader, animationSet, registerCache, animationRegisterData) { var code = ''; var uvConst = registerCache.getFreeVertexConstant(); animationRegisterData.setRegisterIndex(this, ParticleUVState.UV_INDEX, uvConst.index); var axisIndex = this._axis == 'x' ? 0 : (this._axis == 'y' ? 1 : 2); var target = new ShaderRegisterElement(animationRegisterData.uvTarget.regName, animationRegisterData.uvTarget.index, axisIndex); var sin = registerCache.getFreeVertexSingleTemp(); if (this._scale != 1) code += 'mul ' + target + ',' + target + ',' + uvConst + '.y\n'; code += 'mul ' + sin + ',' + animationRegisterData.vertexTime + ',' + uvConst + '.x\n'; code += 'sin ' + sin + ',' + sin + '\n'; code += 'add ' + target + ',' + target + ',' + sin + '\n'; return code; }; /** * @inheritDoc */ ParticleUVNode.prototype.getAnimationState = function (animator) { return animator.getAnimationState(this); }; ParticleUVNode.prototype.updateUVData = function () { this._iUvData = new Vector3D(Math.PI * 2 / this._cycle, this._scale, 0, 0); }; /** * @inheritDoc */ ParticleUVNode.prototype._iProcessAnimationSetting = function (particleAnimationSet) { particleAnimationSet.hasUVNode = true; }; /** * */ ParticleUVNode.U_AXIS = 'x'; /** * */ ParticleUVNode.V_AXIS = 'y'; return ParticleUVNode; }(ParticleNodeBase)); export { ParticleUVNode };