forked from airbnb/lottie-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
233 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import effectTypes from '../utils/helpers/effectTypes'; | ||
import Matrix from '../3rd_party/transformation-matrix'; | ||
import { degToRads } from '../utils/common'; | ||
|
||
function TransformEffect() { | ||
} | ||
|
||
TransformEffect.prototype.init = function (effectsManager) { | ||
this.effectsManager = effectsManager; | ||
this.type = effectTypes.TRANSFORM_EFFECT; | ||
this.matrix = new Matrix(); | ||
this.opacity = -1; | ||
this._mdf = false; | ||
this._opMdf = false; | ||
}; | ||
|
||
TransformEffect.prototype.renderFrame = function (forceFrame) { | ||
this._opMdf = false; | ||
this._mdf = false; | ||
if (forceFrame || this.effectsManager._mdf) { | ||
var effectElements = this.effectsManager.effectElements; | ||
var anchor = effectElements[0].p.v; | ||
var position = effectElements[1].p.v; | ||
var scaleHeight = effectElements[3].p.v; | ||
var scaleWidth = effectElements[4].p.v; | ||
var skew = effectElements[5].p.v; | ||
var skewAxis = effectElements[6].p.v; | ||
var rotation = effectElements[7].p.v; | ||
this.matrix.reset(); | ||
this.matrix.translate(-anchor[0], -anchor[1], anchor[2]); | ||
this.matrix.scale(scaleWidth * 0.01, scaleHeight * 0.01, 1); | ||
this.matrix.rotate(-rotation * degToRads); | ||
this.matrix.skewFromAxis(-skew * degToRads, (skewAxis + 90) * degToRads); | ||
this.matrix.translate(position[0], position[1], 0); | ||
this._mdf = true; | ||
if (this.opacity !== effectElements[8].p.v) { | ||
this.opacity = effectElements[8].p.v; | ||
this._opMdf = true; | ||
} | ||
} | ||
}; | ||
|
||
export default TransformEffect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,50 @@ | ||
function CVEffects() { | ||
var registeredEffects = {}; | ||
|
||
function CVEffects(elem) { | ||
var i; | ||
var len = elem.data.ef ? elem.data.ef.length : 0; | ||
this.filters = []; | ||
var filterManager; | ||
for (i = 0; i < len; i += 1) { | ||
filterManager = null; | ||
var type = elem.data.ef[i].ty; | ||
if (registeredEffects[type]) { | ||
var Effect = registeredEffects[type].effect; | ||
filterManager = new Effect(elem.effectsManager.effectElements[i], elem); | ||
} | ||
if (filterManager) { | ||
this.filters.push(filterManager); | ||
} | ||
} | ||
if (this.filters.length) { | ||
elem.addRenderableComponent(this); | ||
} | ||
} | ||
|
||
CVEffects.prototype.renderFrame = function (_isFirstFrame) { | ||
var i; | ||
var len = this.filters.length; | ||
for (i = 0; i < len; i += 1) { | ||
this.filters[i].renderFrame(_isFirstFrame); | ||
} | ||
}; | ||
|
||
CVEffects.prototype.getEffects = function (type) { | ||
var i; | ||
var len = this.filters.length; | ||
var effects = []; | ||
for (i = 0; i < len; i += 1) { | ||
if (this.filters[i].type === type) { | ||
effects.push(this.filters[i]); | ||
} | ||
} | ||
return effects; | ||
}; | ||
|
||
export function registerEffect(id, effect) { | ||
registeredEffects[id] = { | ||
effect, | ||
}; | ||
} | ||
CVEffects.prototype.renderFrame = function () {}; | ||
|
||
export default CVEffects; |
9 changes: 9 additions & 0 deletions
9
player/js/elements/canvasElements/effects/CVTransformEffect.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import TransformEffect from '../../../effects/TransformEffect'; | ||
import { extendPrototype } from '../../../utils/functionExtensions'; | ||
|
||
function CVTransformEffect(effectsManager) { | ||
this.init(effectsManager); | ||
} | ||
extendPrototype([TransformEffect], CVTransformEffect); | ||
|
||
export default CVTransformEffect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
player/js/elements/svgElements/effects/SVGTransformEffect.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import TransformEffect from '../../../effects/TransformEffect'; | ||
import { extendPrototype } from '../../../utils/functionExtensions'; | ||
|
||
function SVGTransformEffect(_, filterManager) { | ||
this.init(filterManager); | ||
} | ||
|
||
extendPrototype([TransformEffect], SVGTransformEffect); | ||
|
||
export default SVGTransformEffect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.