TransformEffect.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import effectTypes from '../utils/helpers/effectTypes';
  2. import Matrix from '../3rd_party/transformation-matrix';
  3. import { degToRads } from '../utils/common';
  4. function TransformEffect() {
  5. }
  6. TransformEffect.prototype.init = function (effectsManager) {
  7. this.effectsManager = effectsManager;
  8. this.type = effectTypes.TRANSFORM_EFFECT;
  9. this.matrix = new Matrix();
  10. this.opacity = -1;
  11. this._mdf = false;
  12. this._opMdf = false;
  13. };
  14. TransformEffect.prototype.renderFrame = function (forceFrame) {
  15. this._opMdf = false;
  16. this._mdf = false;
  17. if (forceFrame || this.effectsManager._mdf) {
  18. var effectElements = this.effectsManager.effectElements;
  19. var anchor = effectElements[0].p.v;
  20. var position = effectElements[1].p.v;
  21. var isUniformScale = effectElements[2].p.v === 1;
  22. var scaleHeight = effectElements[3].p.v;
  23. var scaleWidth = isUniformScale ? scaleHeight : effectElements[4].p.v;
  24. var skew = effectElements[5].p.v;
  25. var skewAxis = effectElements[6].p.v;
  26. var rotation = effectElements[7].p.v;
  27. this.matrix.reset();
  28. this.matrix.translate(-anchor[0], -anchor[1], anchor[2]);
  29. this.matrix.scale(scaleWidth * 0.01, scaleHeight * 0.01, 1);
  30. this.matrix.rotate(-rotation * degToRads);
  31. this.matrix.skewFromAxis(-skew * degToRads, (skewAxis + 90) * degToRads);
  32. this.matrix.translate(position[0], position[1], 0);
  33. this._mdf = true;
  34. if (this.opacity !== effectElements[8].p.v) {
  35. this.opacity = effectElements[8].p.v;
  36. this._opMdf = true;
  37. }
  38. }
  39. };
  40. export default TransformEffect;