@awayjs/graphics
Version:
AwayJS graphics classes
69 lines (68 loc) • 2.98 kB
JavaScript
import { __extends } from "tslib";
import { Matrix3D, Orientation3D, MathConsts } from '@awayjs/core';
import { ParticleStateBase } from './ParticleStateBase';
/**
* ...
*/
var ParticleBillboardState = /** @class */ (function (_super) {
__extends(ParticleBillboardState, _super);
/**
*
*/
function ParticleBillboardState(animator, particleNode) {
var _this = _super.call(this, animator, particleNode) || this;
_this._matrix = new Matrix3D;
_this._billboardAxis = particleNode._iBillboardAxis;
return _this;
}
ParticleBillboardState.prototype.setRenderState = function (shader, renderable, animationElements, animationRegisterData) {
var comps;
if (this._billboardAxis) {
var pos = renderable.node.getMatrix3D().position;
var look = shader.view.projection.transform.matrix3D.position.subtract(pos);
var right = look.crossProduct(this._billboardAxis);
right.normalize();
look = this.billboardAxis.crossProduct(right);
look.normalize();
//create a quick inverse projection matrix
this._matrix.copyFrom(renderable.node.getMatrix3D());
comps = this._matrix.decompose(Orientation3D.AXIS_ANGLE);
this._matrix.copyColumnFrom(0, right);
this._matrix.copyColumnFrom(1, this.billboardAxis);
this._matrix.copyColumnFrom(2, look);
this._matrix.copyColumnFrom(3, pos);
this._matrix.appendRotation(-comps[1].w * MathConsts.RADIANS_TO_DEGREES, comps[1]);
}
else {
//create a quick inverse projection matrix
this._matrix.copyFrom(renderable.node.getMatrix3D());
this._matrix.append(shader.view.projection.transform.inverseMatrix3D);
//decompose using axis angle rotations
comps = this._matrix.decompose(Orientation3D.AXIS_ANGLE);
//recreate the matrix with just the rotation data
this._matrix.identity();
this._matrix.appendRotation(-comps[1].w * MathConsts.RADIANS_TO_DEGREES, comps[1]);
}
//set a new matrix transform constant
shader.setVertexConstFromMatrix(animationRegisterData.getRegisterIndex(this._pAnimationNode, ParticleBillboardState.MATRIX_INDEX), this._matrix);
};
Object.defineProperty(ParticleBillboardState.prototype, "billboardAxis", {
/**
* Defines the billboard axis.
*/
get: function () {
return this.billboardAxis;
},
set: function (value) {
this.billboardAxis = value ? value.clone() : null;
if (this.billboardAxis)
this.billboardAxis.normalize();
},
enumerable: false,
configurable: true
});
/** @private */
ParticleBillboardState.MATRIX_INDEX = 0;
return ParticleBillboardState;
}(ParticleStateBase));
export { ParticleBillboardState };