@awayjs/graphics
Version:
AwayJS graphics classes
72 lines (71 loc) • 3.52 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';
/**
* ...
*/
var ParticleRotationalVelocityState = /** @class */ (function (_super) {
__extends(ParticleRotationalVelocityState, _super);
function ParticleRotationalVelocityState(animator, particleRotationNode) {
var _this = _super.call(this, animator, particleRotationNode) || this;
_this._particleRotationalVelocityNode = particleRotationNode;
_this._rotationalVelocity = _this._particleRotationalVelocityNode._iRotationalVelocity;
_this.updateRotationalVelocityData();
return _this;
}
Object.defineProperty(ParticleRotationalVelocityState.prototype, "rotationalVelocity", {
/**
* Defines the default rotationalVelocity of the state, used when in global mode.
*/
get: function () {
return this._rotationalVelocity;
},
set: function (value) {
this._rotationalVelocity = value;
this.updateRotationalVelocityData();
},
enumerable: false,
configurable: true
});
/**
*
*/
ParticleRotationalVelocityState.prototype.getRotationalVelocities = function () {
return this._pDynamicProperties;
};
ParticleRotationalVelocityState.prototype.setRotationalVelocities = function (value) {
this._pDynamicProperties = value;
this._pDynamicPropertiesDirty = new Object();
};
/**
* @inheritDoc
*/
ParticleRotationalVelocityState.prototype.setRenderState = function (shader, renderable, animationElements, animationRegisterData) {
if (this._particleRotationalVelocityNode.mode == ParticlePropertiesMode.LOCAL_DYNAMIC && !this._pDynamicPropertiesDirty[animationElements._iUniqueId])
this._pUpdateDynamicProperties(animationElements);
var index = animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleRotationalVelocityState.ROTATIONALVELOCITY_INDEX);
if (this._particleRotationalVelocityNode.mode == ParticlePropertiesMode.GLOBAL)
shader.setVertexConst(index, this._rotationalVelocityData.x, this._rotationalVelocityData.y, this._rotationalVelocityData.z, this._rotationalVelocityData.w);
else
animationElements.activateVertexBuffer(index, this._particleRotationalVelocityNode._iDataOffset, shader.stage, ContextGLVertexBufferFormat.FLOAT_4);
};
ParticleRotationalVelocityState.prototype.updateRotationalVelocityData = function () {
if (this._particleRotationalVelocityNode.mode == ParticlePropertiesMode.GLOBAL) {
if (this._rotationalVelocity.w <= 0)
throw (new Error('the cycle duration must greater than zero'));
var rotation = this._rotationalVelocity.clone();
if (rotation.length <= 0)
rotation.z = 1; //set the default direction
else
rotation.normalize();
// w is used as angle/2 in agal
this._rotationalVelocityData = new Vector3D(rotation.x, rotation.y, rotation.z, Math.PI / rotation.w);
}
};
/** @private */
ParticleRotationalVelocityState.ROTATIONALVELOCITY_INDEX = 0;
return ParticleRotationalVelocityState;
}(ParticleStateBase));
export { ParticleRotationalVelocityState };