@awayjs/graphics
Version:
AwayJS graphics classes
154 lines (153 loc) • 9.58 kB
JavaScript
import { __extends } from "tslib";
import { Vector3D } from '@awayjs/core';
import { ContextGLVertexBufferFormat } from '@awayjs/stage';
import { ParticlePropertiesMode } from '../data/ParticlePropertiesMode';
import { ParticleStateBase } from './ParticleStateBase';
/**
* ...
* @author ...
*/
var ParticleColorState = /** @class */ (function (_super) {
__extends(ParticleColorState, _super);
function ParticleColorState(animator, particleColorNode) {
var _this = _super.call(this, animator, particleColorNode) || this;
_this._particleColorNode = particleColorNode;
_this._usesMultiplier = _this._particleColorNode._iUsesMultiplier;
_this._usesOffset = _this._particleColorNode._iUsesOffset;
_this._usesCycle = _this._particleColorNode._iUsesCycle;
_this._usesPhase = _this._particleColorNode._iUsesPhase;
_this._startColor = _this._particleColorNode._iStartColor;
_this._endColor = _this._particleColorNode._iEndColor;
_this._cycleDuration = _this._particleColorNode._iCycleDuration;
_this._cyclePhase = _this._particleColorNode._iCyclePhase;
_this.updateColorData();
return _this;
}
Object.defineProperty(ParticleColorState.prototype, "startColor", {
/**
* Defines the start color transform of the state, when in global mode.
*/
get: function () {
return this._startColor;
},
set: function (value) {
this._startColor = value;
this.updateColorData();
},
enumerable: false,
configurable: true
});
Object.defineProperty(ParticleColorState.prototype, "endColor", {
/**
* Defines the end color transform of the state, when in global mode.
*/
get: function () {
return this._endColor;
},
set: function (value) {
this._endColor = value;
this.updateColorData();
},
enumerable: false,
configurable: true
});
Object.defineProperty(ParticleColorState.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.updateColorData();
},
enumerable: false,
configurable: true
});
Object.defineProperty(ParticleColorState.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.updateColorData();
},
enumerable: false,
configurable: true
});
ParticleColorState.prototype.setRenderState = function (shader, renderable, animationElements, animationRegisterData) {
if (shader.usesFragmentAnimation) {
var dataOffset = this._particleColorNode._iDataOffset;
if (this._usesCycle)
shader.setVertexConst(animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleColorState.CYCLE_INDEX), this._cycleData.x, this._cycleData.y, this._cycleData.z, this._cycleData.w);
if (this._usesMultiplier) {
if (this._particleColorNode.mode == ParticlePropertiesMode.LOCAL_STATIC) {
animationElements.activateVertexBuffer(animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleColorState.START_MULTIPLIER_INDEX), dataOffset, shader.stage, ContextGLVertexBufferFormat.FLOAT_4);
dataOffset += 4;
animationElements.activateVertexBuffer(animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleColorState.DELTA_MULTIPLIER_INDEX), dataOffset, shader.stage, ContextGLVertexBufferFormat.FLOAT_4);
dataOffset += 4;
}
else {
shader.setVertexConst(animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleColorState.START_MULTIPLIER_INDEX), this._startMultiplierData.x, this._startMultiplierData.y, this._startMultiplierData.z, this._startMultiplierData.w);
shader.setVertexConst(animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleColorState.DELTA_MULTIPLIER_INDEX), this._deltaMultiplierData.x, this._deltaMultiplierData.y, this._deltaMultiplierData.z, this._deltaMultiplierData.w);
}
}
if (this._usesOffset) {
if (this._particleColorNode.mode == ParticlePropertiesMode.LOCAL_STATIC) {
animationElements.activateVertexBuffer(animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleColorState.START_OFFSET_INDEX), dataOffset, shader.stage, ContextGLVertexBufferFormat.FLOAT_4);
dataOffset += 4;
animationElements.activateVertexBuffer(animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleColorState.DELTA_OFFSET_INDEX), dataOffset, shader.stage, ContextGLVertexBufferFormat.FLOAT_4);
}
else {
shader.setVertexConst(animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleColorState.START_OFFSET_INDEX), this._startOffsetData.x, this._startOffsetData.y, this._startOffsetData.z, this._startOffsetData.w);
shader.setVertexConst(animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleColorState.DELTA_OFFSET_INDEX), this._deltaOffsetData.x, this._deltaOffsetData.y, this._deltaOffsetData.z, this._deltaOffsetData.w);
}
}
}
};
ParticleColorState.prototype.updateColorData = function () {
if (this._usesCycle) {
if (this._cycleDuration <= 0)
throw (new Error('the cycle duration must be greater than zero'));
this._cycleData = new Vector3D(Math.PI * 2 / this._cycleDuration, this._cyclePhase * Math.PI / 180, 0, 0);
}
if (this._particleColorNode.mode == ParticlePropertiesMode.GLOBAL) {
if (this._usesCycle) {
if (this._usesMultiplier) {
this._startMultiplierData = new Vector3D((this._startColor.redMultiplier + this._endColor.redMultiplier) / 2, (this._startColor.greenMultiplier + this._endColor.greenMultiplier) / 2, (this._startColor.blueMultiplier + this._endColor.blueMultiplier) / 2, (this._startColor.alphaMultiplier + this._endColor.alphaMultiplier) / 2);
this._deltaMultiplierData = new Vector3D((this._endColor.redMultiplier - this._startColor.redMultiplier) / 2, (this._endColor.greenMultiplier - this._startColor.greenMultiplier) / 2, (this._endColor.blueMultiplier - this._startColor.blueMultiplier) / 2, (this._endColor.alphaMultiplier - this._startColor.alphaMultiplier) / 2);
}
if (this._usesOffset) {
this._startOffsetData = new Vector3D((this._startColor.redOffset + this._endColor.redOffset) / (255 * 2), (this._startColor.greenOffset + this._endColor.greenOffset) / (255 * 2), (this._startColor.blueOffset + this._endColor.blueOffset) / (255 * 2), (this._startColor.alphaOffset + this._endColor.alphaOffset) / (255 * 2));
this._deltaOffsetData = new Vector3D((this._endColor.redOffset - this._startColor.redOffset) / (255 * 2), (this._endColor.greenOffset - this._startColor.greenOffset) / (255 * 2), (this._endColor.blueOffset - this._startColor.blueOffset) / (255 * 2), (this._endColor.alphaOffset - this._startColor.alphaOffset) / (255 * 2));
}
}
else {
if (this._usesMultiplier) {
this._startMultiplierData = new Vector3D(this._startColor.redMultiplier, this._startColor.greenMultiplier, this._startColor.blueMultiplier, this._startColor.alphaMultiplier);
this._deltaMultiplierData = new Vector3D((this._endColor.redMultiplier - this._startColor.redMultiplier), (this._endColor.greenMultiplier - this._startColor.greenMultiplier), (this._endColor.blueMultiplier - this._startColor.blueMultiplier), (this._endColor.alphaMultiplier - this._startColor.alphaMultiplier));
}
if (this._usesOffset) {
this._startOffsetData = new Vector3D(this._startColor.redOffset / 255, this._startColor.greenOffset / 255, this._startColor.blueOffset / 255, this._startColor.alphaOffset / 255);
this._deltaOffsetData = new Vector3D((this._endColor.redOffset - this._startColor.redOffset) / 255, (this._endColor.greenOffset - this._startColor.greenOffset) / 255, (this._endColor.blueOffset - this._startColor.blueOffset) / 255, (this._endColor.alphaOffset - this._startColor.alphaOffset) / 255);
}
}
}
};
/** @private */
ParticleColorState.START_MULTIPLIER_INDEX = 0;
/** @private */
ParticleColorState.DELTA_MULTIPLIER_INDEX = 1;
/** @private */
ParticleColorState.START_OFFSET_INDEX = 2;
/** @private */
ParticleColorState.DELTA_OFFSET_INDEX = 3;
/** @private */
ParticleColorState.CYCLE_INDEX = 4;
return ParticleColorState;
}(ParticleStateBase));
export { ParticleColorState };