@awayjs/graphics
Version:
AwayJS graphics classes
89 lines (88 loc) • 4.24 kB
JavaScript
import { __extends } from "tslib";
import { ContextGLVertexBufferFormat } from '@awayjs/stage';
import { ParticlePropertiesMode } from '../data/ParticlePropertiesMode';
import { ParticleStateBase } from './ParticleStateBase';
/**
* ...
*/
var ParticleSpriteSheetState = /** @class */ (function (_super) {
__extends(ParticleSpriteSheetState, _super);
function ParticleSpriteSheetState(animator, particleSpriteSheetNode) {
var _this = _super.call(this, animator, particleSpriteSheetNode) || this;
_this._particleSpriteSheetNode = particleSpriteSheetNode;
_this._usesCycle = _this._particleSpriteSheetNode._iUsesCycle;
_this._usesPhase = _this._particleSpriteSheetNode._iUsesCycle;
_this._totalFrames = _this._particleSpriteSheetNode._iTotalFrames;
_this._numColumns = _this._particleSpriteSheetNode._iNumColumns;
_this._numRows = _this._particleSpriteSheetNode._iNumRows;
_this._cycleDuration = _this._particleSpriteSheetNode._iCycleDuration;
_this._cyclePhase = _this._particleSpriteSheetNode._iCyclePhase;
_this.updateSpriteSheetData();
return _this;
}
Object.defineProperty(ParticleSpriteSheetState.prototype, "cyclePhase", {
/**
* Defines the cycle phase, when in global mode. Defaults to zero.
*/
get: function () {
return this._cyclePhase;
},
set: function (value) {
this._cyclePhase = value;
this.updateSpriteSheetData();
},
enumerable: false,
configurable: true
});
Object.defineProperty(ParticleSpriteSheetState.prototype, "cycleDuration", {
/**
* Defines the cycle duration in seconds, when in global mode. Defaults to 1.
*/
get: function () {
return this._cycleDuration;
},
set: function (value) {
this._cycleDuration = value;
this.updateSpriteSheetData();
},
enumerable: false,
configurable: true
});
ParticleSpriteSheetState.prototype.setRenderState = function (shader, renderable, animationElements, animationRegisterData) {
if (!shader.usesUVTransform) {
shader.setVertexConst(animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleSpriteSheetState.UV_INDEX_0), this._spriteSheetData[0], this._spriteSheetData[1], this._spriteSheetData[2], this._spriteSheetData[3]);
if (this._usesCycle) {
var index = animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleSpriteSheetState.UV_INDEX_1);
if (this._particleSpriteSheetNode.mode == ParticlePropertiesMode.LOCAL_STATIC) {
if (this._usesPhase)
animationElements.activateVertexBuffer(index, this._particleSpriteSheetNode._iDataOffset, shader.stage, ContextGLVertexBufferFormat.FLOAT_3);
else
animationElements.activateVertexBuffer(index, this._particleSpriteSheetNode._iDataOffset, shader.stage, ContextGLVertexBufferFormat.FLOAT_2);
}
else
shader.setVertexConst(index, this._spriteSheetData[4], this._spriteSheetData[5]);
}
}
};
ParticleSpriteSheetState.prototype.updateSpriteSheetData = function () {
this._spriteSheetData = new Array(8);
var uTotal = this._totalFrames / this._numColumns;
this._spriteSheetData[0] = uTotal;
this._spriteSheetData[1] = 1 / this._numColumns;
this._spriteSheetData[2] = 1 / this._numRows;
if (this._usesCycle) {
if (this._cycleDuration <= 0)
throw (new Error('the cycle duration must be greater than zero'));
this._spriteSheetData[4] = uTotal / this._cycleDuration;
this._spriteSheetData[5] = this._cycleDuration;
if (this._usesPhase)
this._spriteSheetData[6] = this._cyclePhase;
}
};
/** @private */
ParticleSpriteSheetState.UV_INDEX_0 = 0;
/** @private */
ParticleSpriteSheetState.UV_INDEX_1 = 1;
return ParticleSpriteSheetState;
}(ParticleStateBase));
export { ParticleSpriteSheetState };