-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtransform2Effect.js
More file actions
165 lines (141 loc) Β· 5.3 KB
/
transform2Effect.js
File metadata and controls
165 lines (141 loc) Β· 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
( function() {
//@include ../dist/aeq.js
aeq.snippet.forEachSelectedLayerOrAll( 'Transform2Effect', transform2Effect )
/**
* Adds a 'Transform' effect to a layer and moves the values and keyframes
* from the layers transform group to the matching properties on the
* 'Transform' effect.
* @param {Layer} layer The layer to move transform values to the transform effect.
*/
function transform2Effect( layer ) {
var effects = layer.property( 'ADBE Effect Parade' )
if ( effects === null || !effects.canAddProperty( 'ADBE Geometry2' ) ) {
return
}
var effect = effects.addProperty( 'ADBE Geometry2' )
moveToEffect( layer, effect )
}
/**
* Moves the values and keyframes from the layers transform group to the matching
* properties a 'Transform' effect.
* @param {Layer} layer The layer to get transform property values from.
* @param {PropertyGroup} effect The transform effect to copy properties to.
*/
function moveToEffect( layer, effect ) {
var transformGroup = layer.property( 'ADBE Transform Group' )
// Get the middle of the comp, used by as the default value of the
// Position and Anchor Point properties.
var comp = layer.containingComp
var middleOfComp = [ comp.width / 2, comp.height / 2, 0 ]
// The properties matchname in the transform group and their matching
// matchname in the transform effect.
// Second value in the array is the default value of the property
var effects = {
'ADBE Anchor Point': [ 'ADBE Geometry2-0001', middleOfComp ],
'ADBE Position': [ 'ADBE Geometry2-0002', middleOfComp ],
'ADBE Rotate Z': [ 'ADBE Geometry2-0007', 0 ],
'ADBE Opacity': [ 'ADBE Geometry2-0008', 100 ]
}
// Copy the values of the transform group properties to the transform
// effect properties
aeq.forEach( effects, function( tranformName, info ) {
var effectsName = info[ 0 ]
var defaultValue = info[ 1 ]
var prop = transformGroup.property( tranformName )
if ( prop.numKeys ) {
moveKeys( prop, effect.property( effectsName ) )
} else {
setValue( prop, effect.property( effectsName ) )
}
prop.setValue( defaultValue )
} )
// Scale is divided into two properties on the transform effect,
// So can't set in the same ways as the other properties
var scaleProp = transformGroup.property( 'ADBE Scale' )
// Check if the scale is not proportional and switch the 'Use uniform scale' switch.
if ( scaleProp.value[ 0 ] !== scaleProp.value[ 1 ] ) {
effect.property( 'ADBE Geometry2-0011' ).setValue( 0 )
}
if ( scaleProp.numKeys ) {
moveScaleKeys( effect, scaleProp )
} else {
setScaleValue( effect, scaleProp )
}
// Set scale to default value
scaleProp.setValue( [ 100, 100, 100 ] )
}
// Normal property functio
/**
* Moves keys from a source property to a target property.
* Copies the keys to the target property then removes them from the source.
* @param {Property} source The property to get keys from
* @param {Property} target The property to move keys to.
*/
function moveKeys( source, target ) {
var aeqProp = new aeq.Property( source )
aeqProp.forEachKey( function( key ) {
key.copyTo( target )
key.remove()
} )
}
/**
* Copies the value of a source property in the transorm group to a target
* property on the 'transform' effect.
* @method setValue
* @param {[type]} source [description]
* @param {[type]} target [description]
*/
function setValue( source, target ) {
var value = source.value
// The 'Transform' effect is only 2D, so any arry with 3 values needs to
// be converted to an array with 2 values.
if ( aeq.isArray( value ) && value.length === 3 ) {
value = [ value[ 0 ], value[ 1 ] ]
}
target.setValue( value )
}
// Scale property functions
/**
* Moves the keyframes on a Scale property in the transform group to the two
* scale properties on the 'Transform' effect.
* Copies the keyframes and removes the originals.
* @param {PropertyGroup} effect The 'Transform' effect
* @param {Property} scaleProp THe Scale property.
*/
function moveScaleKeys( effect, scaleProp ) {
var theProp = new aeq.Property( scaleProp )
theProp.forEachKey( function( key ) {
var keyInfo = key.getKeyInfo()
var value = keyInfo.value
var inEase = keyInfo.temporalEase.inEase
var outEase = keyInfo.temporalEase.outEase
// Paste key for the first scale direction
keyInfo.property = effect.property( 'ADBE Geometry2-0004' )
keyInfo.value = value[ 0 ]
// Only use first value in temporal ease
keyInfo.temporalEase.inEase = [ inEase[ 0 ] ]
keyInfo.temporalEase.outEase = [ outEase[ 0 ] ]
aeq.pasteKey( keyInfo )
// Paste key for the second scale direction
keyInfo.property = effect.property( 'ADBE Geometry2-0003' )
keyInfo.value = value[ 1 ]
// Only use second value in temporal ease
keyInfo.temporalEase.inEase = [ inEase[ 1 ] ]
keyInfo.temporalEase.outEase = [ outEase[ 1 ] ]
aeq.pasteKey( keyInfo )
// Remove the key.
key.remove()
} )
}
/**
* Copies the value of a scale property in the transform group to the two
* properties on the 'Transform' effect.
* @param {PropertyGroup} effect The 'Transform' effect
* @param {Property} scaleProp THe Scale property.
*/
function setScaleValue( effect, scaleProp ) {
var scaleValue = scaleProp.value
effect.property( 'ADBE Geometry2-0004' ).setValue( scaleValue[ 0 ] )
effect.property( 'ADBE Geometry2-0003' ).setValue( scaleValue[ 1 ] )
}
} )()