Skip to content

Commit 14fba9f

Browse files
committed
Merge branch 'develop'
* develop: File: Fix undefined is not an object error in joinPath Demo: Update transform2Effect demo to copy keys aeq.Property: Update forEachKey aeq.Property: Add getKeys method aeq.pasteKey now convert 3 value arrays to 2 value arrays if needed File: update joinPath to accept File and Folder objects
2 parents 7813c98 + 4adfb32 commit 14fba9f

File tree

4 files changed

+168
-45
lines changed

4 files changed

+168
-45
lines changed

demo/transform2Effect.js

Lines changed: 136 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,165 @@
11
( function() {
22
//@include ../dist/aeq.js
33

4+
aeq.snippet.forEachSelectedLayerOrAll( 'Transform2Effect', transform2Effect )
45

5-
var comp = aeq.getActiveComp()
6-
if ( comp === null ) {
7-
return alert( 'No Comp' )
8-
}
9-
10-
var layers = comp.selectedLayers
11-
if ( !layers.length ) {
12-
var applyToAll = confirm( 'No layers selected, apply to all?', true )
13-
if ( applyToAll ) {
14-
layers = aeq.getLayers( comp )
15-
} else {
16-
return
17-
}
18-
}
19-
20-
aeq.undoGroup( 'Transform2Effect', main, [ layers ] )
21-
22-
function main( layers ) {
23-
aeq.forEach( layers, transform2Effect )
24-
}
25-
6+
/**
7+
* Adds a 'Transform' effect to a layer and moves the values and keyframes
8+
* from the layers transform group to the matching properties on the
9+
* 'Transform' effect.
10+
* @param {Layer} layer The layer to move transform values to the transform effect.
11+
*/
2612
function transform2Effect( layer ) {
2713
var effects = layer.property( 'ADBE Effect Parade' )
2814
if ( effects === null || !effects.canAddProperty( 'ADBE Geometry2' ) ) {
2915
return
3016
}
3117

3218
var effect = effects.addProperty( 'ADBE Geometry2' )
33-
var transformGroup = layer.property( 'ADBE Transform Group' )
34-
35-
moveToEffect( layer, effect, transformGroup )
19+
moveToEffect( layer, effect )
3620
}
3721

38-
function moveToEffect( layer, effect, transformGroup ) {
22+
/**
23+
* Moves the values and keyframes from the layers transform group to the matching
24+
* properties a 'Transform' effect.
25+
* @param {Layer} layer The layer to get transform property values from.
26+
* @param {PropertyGroup} effect The transform effect to copy properties to.
27+
*/
28+
function moveToEffect( layer, effect ) {
29+
var transformGroup = layer.property( 'ADBE Transform Group' )
30+
31+
// Get the middle of the comp, used by as the default value of the
32+
// Position and Anchor Point properties.
3933
var comp = layer.containingComp
4034
var middleOfComp = [ comp.width / 2, comp.height / 2, 0 ]
35+
36+
// The properties matchname in the transform group and their matching
37+
// matchname in the transform effect.
38+
// Second value in the array is the default value of the property
4139
var effects = {
4240
'ADBE Anchor Point': [ 'ADBE Geometry2-0001', middleOfComp ],
4341
'ADBE Position': [ 'ADBE Geometry2-0002', middleOfComp ],
4442
'ADBE Rotate Z': [ 'ADBE Geometry2-0007', 0 ],
4543
'ADBE Opacity': [ 'ADBE Geometry2-0008', 100 ]
4644
}
4745

48-
aeq.forEach( effects, setValue )
49-
50-
function setValue( tranformName, info ) {
46+
// Copy the values of the transform group properties to the transform
47+
// effect properties
48+
aeq.forEach( effects, function( tranformName, info ) {
5149
var effectsName = info[ 0 ]
5250
var defaultValue = info[ 1 ]
53-
var value = transformGroup.property( tranformName ).value
54-
if ( aeq.isArray( value ) && value.length === 3 ) {
55-
value = [ value[0], value[1] ]
51+
var prop = transformGroup.property( tranformName )
52+
53+
if ( prop.numKeys ) {
54+
moveKeys( prop, effect.property( effectsName ) )
55+
} else {
56+
setValue( prop, effect.property( effectsName ) )
5657
}
57-
effect.property( effectsName ).setValue( value )
58-
transformGroup.property( tranformName ).setValue( defaultValue )
59-
}
6058

61-
// Scale
62-
var scaleValue = transformGroup.property( 'ADBE Scale' ).value
63-
if ( scaleValue[0] !== scaleValue[1] ) {
59+
prop.setValue( defaultValue )
60+
} )
61+
62+
// Scale is divided into two properties on the transform effect,
63+
// So can't set in the same ways as the other properties
64+
var scaleProp = transformGroup.property( 'ADBE Scale' )
65+
66+
// Check if the scale is not proportional and switch the 'Use uniform scale' switch.
67+
if ( scaleProp.value[ 0 ] !== scaleProp.value[ 1 ] ) {
6468
effect.property( 'ADBE Geometry2-0011' ).setValue( 0 )
6569
}
66-
effect.property( 'ADBE Geometry2-0004' ).setValue( scaleValue[0] )
67-
effect.property( 'ADBE Geometry2-0003' ).setValue( scaleValue[1] )
68-
transformGroup.property( 'ADBE Scale' ).setValue( [ 100, 100, 100 ] )
70+
if ( scaleProp.numKeys ) {
71+
moveScaleKeys( effect, scaleProp )
72+
} else {
73+
setScaleValue( effect, scaleProp )
74+
}
75+
// Set scale to default value
76+
scaleProp.setValue( [ 100, 100, 100 ] )
77+
}
78+
79+
// Normal property functio
80+
81+
/**
82+
* Moves keys from a source property to a target property.
83+
* Copies the keys to the target property then removes them from the source.
84+
* @param {Property} source The property to get keys from
85+
* @param {Property} target The property to move keys to.
86+
*/
87+
function moveKeys( source, target ) {
88+
var aeqProp = new aeq.Property( source )
89+
aeqProp.forEachKey( function( key ) {
90+
key.copyTo( target )
91+
key.remove()
92+
} )
93+
}
94+
95+
/**
96+
* Copies the value of a source property in the transorm group to a target
97+
* property on the 'transform' effect.
98+
* @method setValue
99+
* @param {[type]} source [description]
100+
* @param {[type]} target [description]
101+
*/
102+
function setValue( source, target ) {
103+
var value = source.value
104+
105+
// The 'Transform' effect is only 2D, so any arry with 3 values needs to
106+
// be converted to an array with 2 values.
107+
if ( aeq.isArray( value ) && value.length === 3 ) {
108+
value = [ value[ 0 ], value[ 1 ] ]
109+
}
110+
target.setValue( value )
111+
}
112+
113+
114+
// Scale property functions
115+
116+
/**
117+
* Moves the keyframes on a Scale property in the transform group to the two
118+
* scale properties on the 'Transform' effect.
119+
* Copies the keyframes and removes the originals.
120+
* @param {PropertyGroup} effect The 'Transform' effect
121+
* @param {Property} scaleProp THe Scale property.
122+
*/
123+
function moveScaleKeys( effect, scaleProp ) {
124+
var theProp = new aeq.Property( scaleProp )
125+
theProp.forEachKey( function( key ) {
126+
var keyInfo = key.getKeyinfo()
127+
var value = keyInfo.value
128+
var inEase = keyInfo.temporalEase.inEase
129+
var outEase = keyInfo.temporalEase.outEase
130+
131+
// Paste key for the first scale direction
132+
keyInfo.property = effect.property( 'ADBE Geometry2-0004' )
133+
keyInfo.value = value[ 0 ]
134+
135+
// Only use first value in temporal ease
136+
keyInfo.temporalEase.inEase = [ inEase[ 0 ] ]
137+
keyInfo.temporalEase.outEase = [ outEase[ 0 ] ]
138+
aeq.pasteKey( keyInfo )
139+
140+
// Paste key for the second scale direction
141+
keyInfo.property = effect.property( 'ADBE Geometry2-0003' )
142+
keyInfo.value = value[ 1 ]
143+
144+
// Only use second value in temporal ease
145+
keyInfo.temporalEase.inEase = [ inEase[ 1 ] ]
146+
keyInfo.temporalEase.outEase = [ outEase[ 1 ] ]
147+
aeq.pasteKey( keyInfo )
148+
149+
// Remove the key.
150+
key.remove()
151+
} )
152+
}
153+
154+
/**
155+
* Copies the value of a scale property in the transform group to the two
156+
* properties on the 'Transform' effect.
157+
* @param {PropertyGroup} effect The 'Transform' effect
158+
* @param {Property} scaleProp THe Scale property.
159+
*/
160+
function setScaleValue( effect, scaleProp ) {
161+
var scaleValue = scaleProp.value
162+
effect.property( 'ADBE Geometry2-0004' ).setValue( scaleValue[ 0 ] )
163+
effect.property( 'ADBE Geometry2-0003' ).setValue( scaleValue[ 1 ] )
69164
}
70-
})()
165+
} )()

lib/modules/file.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,19 @@ aeq.file = aeq.extend({}, {
111111
* Joins path components into an OS-formatted file path string
112112
* @method
113113
* @memberof aeq.file
114+
* @param {...(String|File|Folder)} paths The path elements to join.
114115
* @return {string} File path string joined with OS's path separator
115116
*/
116117
joinPath: function() {
117118
var paths = Array.prototype.slice.call(arguments, 0);
118119
return aeq.file.normalizePath(aeq.filter(paths, function(p, index) {
120+
// Path is a File or Folder object.
121+
if ( p && typeof p.fsName === 'string') {
122+
p = p.fsName
123+
paths[index] = p
124+
}
119125
if (typeof p !== 'string') {
120-
throw new TypeError('Arguments to path.join must be strings');
126+
throw new TypeError('Arguments to path.join must be strings, Files or Folders');
121127
}
122128

123129
return p;

lib/objects/key.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ aeq.forEach([
404404
aeq.pasteKey = function( keyInfo ) {
405405
var keyIndex = keyInfo.property.addKey(keyInfo.time);
406406
var key = new aeq.Key(keyInfo.property, keyIndex);
407+
408+
if (keyInfo.property.value.length === 2 && aeq.isArray(keyInfo.value) && keyInfo.value.length === 3) {
409+
keyInfo.value = [keyInfo.value[0], keyInfo.value[1]];
410+
keyInfo.spatialTangent.inTangent = [keyInfo.spatialTangent.inTangent[0], keyInfo.spatialTangent.inTangent[1]];
411+
keyInfo.spatialTangent.outTangent = [keyInfo.spatialTangent.outTangent[0], keyInfo.spatialTangent.outTangent[1]];
412+
}
407413

408414
key.value(keyInfo.value);
409415

lib/objects/property.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,11 @@ aeq.Property.prototype = {
250250
* @param {Function} callback Function to execute on each key
251251
*/
252252
forEachKey: function(callback) {
253-
var length = this.property.numKeys, i = 1;
253+
var keys = this.getKeys()
254+
var length = keys.length, i = 0;
254255

255-
for ( ; i <= length; i++ ) {
256-
callback(this.key(i), i, this.property);
256+
for ( ; i < length; i++ ) {
257+
callback(keys[i], keys[i].index, this.property);
257258
}
258259
},
259260

@@ -266,6 +267,21 @@ aeq.Property.prototype = {
266267
*/
267268
key: function(keyIndex) {
268269
return new aeq.Key(this.property, keyIndex);
270+
},
271+
272+
/**
273+
* Gets all keys of the property
274+
* @method
275+
* @return {aeq.Key[]} ArrayEx of all keyframes on the property
276+
*/
277+
getKeys: function() {
278+
var keys = []
279+
var length = this.property.numKeys, i = 1;
280+
281+
for ( ; i <= length; i++ ) {
282+
keys.push(this.key(i));
283+
}
284+
return aeq.arrayEx( keys )
269285
}
270286
};
271287

0 commit comments

Comments
 (0)