UNPKG

@awayjs/graphics

Version:
82 lines (81 loc) 4.17 kB
import { __extends } from "tslib"; import { ColorTransform } from '@awayjs/core'; import { ParticlePropertiesMode } from '../data/ParticlePropertiesMode'; import { ParticleInitialColorState } from '../states/ParticleInitialColorState'; import { ParticleAnimationSet } from '../ParticleAnimationSet'; import { ParticleNodeBase } from './ParticleNodeBase'; /** * */ var ParticleInitialColorNode = /** @class */ (function (_super) { __extends(ParticleInitialColorNode, _super); function ParticleInitialColorNode(mode, usesMultiplier, usesOffset, initialColor) { if (usesMultiplier === void 0) { usesMultiplier = true; } if (usesOffset === void 0) { usesOffset = false; } if (initialColor === void 0) { initialColor = null; } var _this = _super.call(this, 'ParticleInitialColor', mode, (usesMultiplier && usesOffset) ? 8 : 4, ParticleAnimationSet.COLOR_PRIORITY) || this; _this._pStateClass = ParticleInitialColorState; _this._iUsesMultiplier = usesMultiplier; _this._iUsesOffset = usesOffset; _this._iInitialColor = initialColor || new ColorTransform(); return _this; } /** * @inheritDoc */ ParticleInitialColorNode.prototype.getAGALVertexCode = function (shader, animationSet, registerCache, animationRegisterData) { var code = ''; if (shader.usesFragmentAnimation) { if (this._iUsesMultiplier) { var multiplierValue = (this._pMode == ParticlePropertiesMode.GLOBAL) ? registerCache.getFreeVertexConstant() : registerCache.getFreeVertexAttribute(); animationRegisterData.setRegisterIndex(this, ParticleInitialColorState.MULTIPLIER_INDEX, multiplierValue.index); code += 'mul ' + animationRegisterData.colorMulTarget + ',' + multiplierValue + ',' + animationRegisterData.colorMulTarget + '\n'; } if (this._iUsesOffset) { var offsetValue = (this._pMode == ParticlePropertiesMode.LOCAL_STATIC) ? registerCache.getFreeVertexAttribute() : registerCache.getFreeVertexConstant(); animationRegisterData.setRegisterIndex(this, ParticleInitialColorState.OFFSET_INDEX, offsetValue.index); code += 'add ' + animationRegisterData.colorAddTarget + ',' + offsetValue + ',' + animationRegisterData.colorAddTarget + '\n'; } } return code; }; /** * @inheritDoc */ ParticleInitialColorNode.prototype._iProcessAnimationSetting = function (particleAnimationSet) { if (this._iUsesMultiplier) particleAnimationSet.hasColorMulNode = true; if (this._iUsesOffset) particleAnimationSet.hasColorAddNode = true; }; /** * @inheritDoc */ ParticleInitialColorNode.prototype._iGeneratePropertyOfOneParticle = function (param) { var initialColor = param[ParticleInitialColorNode.COLOR_INITIAL_COLORTRANSFORM]; if (!initialColor) throw (new Error('there is no ' + ParticleInitialColorNode.COLOR_INITIAL_COLORTRANSFORM + ' in param!')); var i = 0; //multiplier if (this._iUsesMultiplier) { this._pOneData[i++] = initialColor.redMultiplier; this._pOneData[i++] = initialColor.greenMultiplier; this._pOneData[i++] = initialColor.blueMultiplier; this._pOneData[i++] = initialColor.alphaMultiplier; } //offset if (this._iUsesOffset) { this._pOneData[i++] = initialColor.redOffset / 255; this._pOneData[i++] = initialColor.greenOffset / 255; this._pOneData[i++] = initialColor.blueOffset / 255; this._pOneData[i++] = initialColor.alphaOffset / 255; } }; /** * Reference for color node properties on a single particle (when in local property mode). * Expects a <code>ColorTransform</code> object representing the color transform applied to the particle. */ ParticleInitialColorNode.COLOR_INITIAL_COLORTRANSFORM = 'ColorInitialColorTransform'; return ParticleInitialColorNode; }(ParticleNodeBase)); export { ParticleInitialColorNode };