Last active
August 29, 2015 14:07
-
-
Save turbodrive/0e6aaf1ff1eacfa4f110 to your computer and use it in GitHub Desktop.
AE to CSS Workflow - Part 2 - Transposition CSS to After Effects and JSON exporting
This file contains hidden or 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
<Effect matchname="Custom TargetFCam" name="$$$/AE/Preset/TargetsFCamManager=Targets FCam Manager"> | |
<Group name="$$$/AE/Preset/Targets=Targets"> | |
<Layer name="$$$/AE/Preset/Target1=Target 1" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target2=Target 2" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target3=Target 3" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target4=Target 4" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target5=Target 5" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target6=Target 6" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target7=Target 7" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target8=Target 8" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target9=Target 9" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target10=Target 10" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target11=Target 11" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target12=Target 12" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target13=Target 13" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target14=Target 14" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target15=Target 15" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target16=Target 16" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target17=Target 17" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target18=Target 18" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target19=Target 19" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target20=Target 20" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target21=Target 21" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target22=Target 22" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target23=Target 23" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target24=Target 24" default_self="false"/> | |
<Layer name="$$$/AE/Preset/Target25=Target 25" default_self="false"/> | |
</Group> | |
<Slider name="$$$/AE/Preset/GlobalCamProgression=GlobalCamProgression" default="1" valid_min="1" valid_max="25" slider_min="1" slider_max="25" precision="2"/> | |
</Effect> |
This file contains hidden or 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
function getJsonObjectFromLayer(layer) { | |
var name = layer.name; | |
var pX = layer.property("Position").value[0]; | |
var pY = layer.property("Position").value[1]; | |
var pZ = -layer.property("Position").value[2]; | |
var rX = -layer.property("xRotation").value; | |
var rY = -layer.property("yRotation").value; | |
var rZ = layer.property("zRotation").value; | |
var jsonObject = '{"name":"' + name + '","x":' + pX + ',"y":' + pY + ',"z":' + pZ + ',"rotationX":' + rX + ',"rotationY":' + rY + ',"rotationZ":' + rZ + '}'; | |
return jsonObject; | |
} | |
function getAndWriteData(comp, layer) { | |
var file = new File("positions.json"); | |
// create file | |
var numEffects = layer.Effects.numProperties; | |
// number of effects for the selected layer | |
if (file.open("w")) { | |
// open the file | |
file.writeln('{"targets":['); | |
// start write the JSON array "targets" | |
var effectLayer, matchName, i, idLayer, jsonObject; | |
var listTransformEffectsToExport = []; | |
var list3dLayerToExport = []; | |
var j = 1 | |
var nbrTargetExported = 0; | |
// let's look for a specific Custom Control | |
for (i = 1; i <= numEffects; i++) { | |
effectLayer = layer.Effects.property(i); | |
matchName = effectLayer.matchName; | |
if (matchName == "Custom TargetFCam") { | |
// get ids of the targets and store them in an array | |
idLayer = effectLayer("Target " + j) | |
while (effectLayer("Target " + j).value != 0) { | |
idLayer = effectLayer("Target " + j).value; | |
listTransformEffectsToExport.push(idLayer); | |
j++ | |
} | |
} | |
if (matchName == "3dLayer_Exporter") { | |
// get ids of the other 3dlayer and store them in an array | |
for (j = 1; j <= 50; j++) { | |
idLayer = effectLayer("Layer " + j).value | |
if (idLayer > 0) { | |
list3dLayerToExport.push(idLayer); | |
} | |
} | |
} | |
} | |
for (i = 0; i < listTransformEffectsToExport.length; i++) { | |
jsonObject = getJsonObjectFromLayer(comp.layer(listTransformEffectsToExport[i])) | |
if (i < listTransformEffectsToExport.length - 1) { | |
jsonObject += ','; | |
} | |
// write JSON objects for each stored id Target | |
file.writeln(jsonObject); | |
// increase count of exported objects | |
nbrTargetExported++; | |
} | |
file.writeln(']'); | |
// close JSON Array | |
if (list3dLayerToExport.length > 0) { | |
file.writeln(',"sprites3d":['); | |
// start write the JSON array "sprites3d" | |
for (i = 0; i < list3dLayerToExport.length; i++) { | |
var layer = comp.layer(list3dLayerToExport[i]); | |
jsonObject = getJsonObjectFromLayer(comp.layer(list3dLayerToExport[i])); | |
if (i < list3dLayerToExport.length - 1) { | |
jsonObject += ','; | |
} | |
// write JSON objects for each stored id Layer | |
file.writeln(jsonObject); | |
// increase count of exported objects | |
nbrTargetExported++; | |
} | |
file.writeln(']'); | |
// close JSON array | |
} | |
file.writeln('}'); | |
// close JSON object | |
file.close(); | |
// close file | |
} | |
var stringTarget = nbrTargetExported > 1 ? "objects" : "object"; | |
alert(nbrTargetExported + " " + stringTarget + " exported successfully."); | |
// provide info about number of objects exported | |
} | |
var comp = app.project.activeItem; | |
var layer = comp.selectedLayers[0]; | |
// get current selected comp and layer | |
getAndWriteData(comp, layer); |
This file contains hidden or 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
[getValForProp("position", gcprogress,0),getValForProp("position", gcprogress, 1 ),getValForProp("position", gcprogress, 2)]; |
This file contains hidden or 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
getValForProp("rotationX", gcprogress); |
This file contains hidden or 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
getValForProp("rotationY", gcprogress); |
This file contains hidden or 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
getValForProp("rotationZ", gcprogress); |
This file contains hidden or 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
var comp = thisComp; | |
var gcprogress = comp.layer("Pages And Camera Control").effect("Targets FCam Manager")("GlobalCamProgression"); | |
//change here the reference of the adjustement layer and custom control, or use the expression pick whip. | |
function getValueForIDProgression(idProgression, nameProp) { | |
var trgt = "Target "+parseInt(idProgression); | |
var layer= comp.layer("Pages And Camera Control").effect("Targets FCam Manager")(trgt); | |
// get the layer associated to the idProgression (id == 1 > 'Target 1', id == 2 > 'Target 2', id == 3 > Target 3...) | |
if(layer == undefined) return | |
return layer[nameProp]; | |
// return the value of the property for the name of the property given in parameter | |
} | |
function getValForProp(propName, globalCamProgression, index){ | |
if(globalCamProgression == parseInt(globalCamProgression)){ | |
var value = getValueForIDProgression(globalCamProgression, propName); | |
if(index != undefined){ | |
// in the case of the position, it’s an array, so I provide an array index. | |
return -value[index]; | |
} else { | |
return -value; | |
} | |
// globalCamProgression is an integer, I return the opposite value of the target property. | |
}else{ | |
var t0 = Math.ceil(globalCamProgression-1); | |
var t1 = Math.ceil(globalCamProgression); | |
var vt0 = getValueForIDProgression(t0, propName); | |
var vt1 = getValueForIDProgression(t1, propName); | |
var v0 = vt0; | |
var v1 = vt1; | |
if(index != undefined){ | |
// in the case of the position, it’s an array, so I provide an array index. | |
vt0 = vt0[index]; | |
vt1 = vt1[index]; | |
} | |
return -(vt0 + ((vt1-vt0)*(globalCamProgression-(parseInt(globalCamProgression))))); | |
// return the opposite of the linear interpolation calculated. | |
}; |
This file contains hidden or 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
{"targets":[ | |
{"name":"Page 1","x":-8,"y":169,"z":-1450,"rotationX":0,"rotationY":-3,"rotationZ":0}, | |
{"name":"Page 2","x":702,"y":416,"z":260,"rotationX":-11,"rotationY":9,"rotationZ":15}, | |
{"name":"Page 3","x":700,"y":-450,"z":1251,"rotationX":-21,"rotationY":-103,"rotationZ":94}, | |
{"name":"Page 4","x":3642,"y":-1596,"z":-522,"rotationX":0,"rotationY":-132,"rotationZ":140} | |
] | |
,"sprites3d":[ | |
{"name":"Cube 1","x":611.156680247838,"y":368,"z":-288.410033613247,"rotationX":-67,"rotationY":0,"rotationZ":0}, | |
{"name":"Cube 2","x":678.156680247838,"y":749,"z":235.589966386753,"rotationX":-67,"rotationY":-51,"rotationZ":50}, | |
{"name":"Cube 3","x":-115,"y":846,"z":957,"rotationX":-115,"rotationY":-16,"rotationZ":44}, | |
{"name":"Cube 4","x":752,"y":-342,"z":1640,"rotationX":-28,"rotationY":-86,"rotationZ":109}, | |
{"name":"Cube 5","x":3260,"y":2870,"z":-69,"rotationX":-30,"rotationY":-120,"rotationZ":131}, | |
{"name":"Cube 6","x":2240,"y":990,"z":1561,"rotationX":-270,"rotationY":-9,"rotationZ":75}, | |
{"name":"Cube 7","x":5610,"y":5410,"z":-4939,"rotationX":-126,"rotationY":-175,"rotationZ":71} | |
] | |
} |
This file contains hidden or 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
comp("interactiveContainer").layer(this.name).transform.xRotation; |
This file contains hidden or 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
comp("interactiveContainer").layer(this.name).transform.position; |
This file contains hidden or 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
comp("interactiveContainer").layer(this.name).transform.yRotation |
This file contains hidden or 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
comp("interactiveContainer").layer(this.name).transform.zRotation; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment