UNPKG

@awayjs/graphics

Version:
116 lines (115 loc) 5.12 kB
import { __extends } from "tslib"; import { AnimationElements } from './data/AnimationElements'; import { ParticlePropertiesMode } from './data/ParticlePropertiesMode'; import { AnimatorBase } from './AnimatorBase'; /** * Provides an interface for assigning paricle-based animation data sets to sprite-based entity objects * and controlling the various available states of animation through an interative playhead that can be * automatically updated or manually triggered. * * Requires that the containing geometry of the parent sprite is particle geometry * * @see away.base.ParticleAnimator */ var ParticleAnimator = /** @class */ (function (_super) { __extends(ParticleAnimator, _super); /** * Creates a new <code>ParticleAnimator</code> object. * * @param particleAnimationSet The animation data set containing the particle animations used by the animator. */ function ParticleAnimator(particleAnimationSet) { var _this = _super.call(this, particleAnimationSet) || this; _this._animationParticleStates = new Array(); _this._animatorParticleStates = new Array(); _this._timeParticleStates = new Array(); _this._totalLenOfOneVertex = 0; _this._animatorSubGeometries = new Object(); _this._particleAnimationSet = particleAnimationSet; var state; var node; for (var i = 0; i < _this._particleAnimationSet.particleNodes.length; i++) { node = _this._particleAnimationSet.particleNodes[i]; state = _this.getAnimationState(node); if (node.mode == ParticlePropertiesMode.LOCAL_DYNAMIC) { _this._animatorParticleStates.push(state); node._iDataOffset = _this._totalLenOfOneVertex; _this._totalLenOfOneVertex += node.dataLength; } else { _this._animationParticleStates.push(state); } if (state.needUpdateTime) _this._timeParticleStates.push(state); } return _this; } /** * @inheritDoc */ ParticleAnimator.prototype.clone = function () { return new ParticleAnimator(this._particleAnimationSet); }; /** * @inheritDoc */ ParticleAnimator.prototype.setRenderState = function (shader, renderable) { var animationRegisterData = this._particleAnimationSet._iAnimationRegisterData; var particleCollection = renderable.renderable.particleCollection; var elements = renderable.renderable.elements; //process animation sub geometries var animationElements = this._particleAnimationSet.getAnimationElements(particleCollection, elements); var i; for (i = 0; i < this._animationParticleStates.length; i++) this._animationParticleStates[i].setRenderState(shader, renderable, animationElements, animationRegisterData); //process animator subgeometries var animatorElements = this.getAnimatorElements(particleCollection, elements); for (i = 0; i < this._animatorParticleStates.length; i++) this._animatorParticleStates[i].setRenderState(shader, renderable, animatorElements, animationRegisterData); }; /** * @inheritDoc */ ParticleAnimator.prototype.testGPUCompatibility = function (shader) { }; /** * @inheritDoc */ ParticleAnimator.prototype.start = function () { _super.prototype.start.call(this); for (var i = 0; i < this._timeParticleStates.length; i++) this._timeParticleStates[i].offset(this._pAbsoluteTime); }; /** * @inheritDoc */ ParticleAnimator.prototype._pUpdateDeltaTime = function (dt) { this._pAbsoluteTime += dt; for (var i = 0; i < this._timeParticleStates.length; i++) this._timeParticleStates[i].update(this._pAbsoluteTime); }; /** * @inheritDoc */ ParticleAnimator.prototype.resetTime = function (offset) { if (offset === void 0) { offset = 0; } for (var i = 0; i < this._timeParticleStates.length; i++) this._timeParticleStates[i].offset(this._pAbsoluteTime + offset); this.update(this.time); }; ParticleAnimator.prototype.dispose = function () { for (var key in this._animatorSubGeometries) this._animatorSubGeometries[key].dispose(); }; ParticleAnimator.prototype.getAnimatorElements = function (particleCollection, elements) { if (!this._animatorParticleStates.length) return; var animatorElements = this._animatorSubGeometries[elements.id] = new AnimationElements(); //create the vertexData vector that will be used for local state data animatorElements.createVertexData(elements.numVertices, this._totalLenOfOneVertex); //pass the particles data to the animator elements animatorElements.animationParticles = this._particleAnimationSet.getAnimationElements(particleCollection, elements).animationParticles; }; return ParticleAnimator; }(AnimatorBase)); export { ParticleAnimator };