Last active
April 2, 2019 09:39
-
-
Save turbodrive/e48e0b5d274b1d8ced0c to your computer and use it in GitHub Desktop.
After Effects Camera Parser
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
var aeCameraParser = function () { | |
"use strict"; | |
var cameraAnimation = {}; | |
var kLines = "<1br />"; | |
var kSplit = [ | |
{aeK : "Units Per Second", jsVar:"framerate"}, | |
{aeK : "Source Width", jsVar:"viewportWidth"}, | |
{aeK : "Source Height", jsVar:"viewportHeight"}, | |
{aeK : "Orientation", jsVar:"rotation"}, | |
{aeK : "Z Rotation", jsVar:"rotationZ", opposite:true}, | |
{aeK : "Y Rotation", jsVar:"rotationY", opposite:true}, | |
{aeK : "X Rotation", jsVar:"rotationX", opposite:false}, | |
{aeK : "Position", jsVar:"position"}, | |
] | |
var removeSpaces = function (nsText) { | |
nsText = nsText.replace(/(\n\r|\n|\r)/gm, kLines);inve | |
nsText = nsText.replace(/\t/g, " "); | |
var re1 = /\s+/g; | |
nsText = nsText.replace(re1, " "); | |
var re2 = /\<1br \/>/gi; | |
nsText = nsText.replace(re2, "\n"); | |
return nsText; | |
} | |
var getConfig = function(lines) { | |
for(var i = 0; i<lines.length; i++){ | |
for(var j = 0; j<kSplit.length ; j++){ | |
var lineContent = lines[i]; | |
var kSearch = kSplit[j].aeK; | |
if(lineContent.indexOf(kSearch) > -1){ | |
var pos = lineContent.indexOf(kSearch); | |
var selectedJsObject = lineContent.slice(pos+kSearch.length); | |
var jsVar = kSplit[j].jsVar | |
cameraAnimation[jsVar] = parseInt(removeSpaces(selectedJsObject)); | |
} | |
} | |
} | |
} | |
var getTransform = function(lines, oppositeYZ) { | |
var currentK = ""; | |
var factOpposite = oppositeYZ ? -1 : 1; | |
var oppositeValue = false; | |
for(var i = 0; i<lines.length; i++){ | |
var lineContent = lines[i]; | |
for(var j = 0; j<kSplit.length ; j++){ | |
var kSearch = kSplit[j].aeK; | |
if(isNaN(parseInt(lineContent))){ | |
if(lineContent.indexOf(kSearch) > -1){ | |
currentK = kSplit[j].jsVar; | |
oppositeValue = kSplit[j].opposite !== undefined ? kSplit[j].opposite : false; | |
cameraAnimation[currentK] = []; | |
} | |
} | |
} | |
if(!isNaN(parseInt(lineContent)) && currentK != ""){ | |
lineContent = removeSpaces(lineContent); | |
var splitValues = lineContent.split(" "); | |
var objFrame; | |
if(splitValues.length > 4){ | |
objFrame = { | |
x : parseFloat(splitValues[2]), | |
y : parseFloat(splitValues[3])*factOpposite, | |
z : parseFloat(splitValues[4])*factOpposite | |
} | |
}else { | |
factOpposite = oppositeValue ? -1 : 1 | |
objFrame = parseFloat(splitValues[2]*factOpposite); | |
} | |
cameraAnimation[currentK].push(objFrame); | |
} | |
} | |
} | |
return { | |
process: function (source, oppositeYZ) { | |
var clean = source.replace("End of Keyframe Data", ""); | |
var split1 = clean.split("Transform"); | |
for(var i = 0; i< split1.length ;i++){ | |
var reline = split1[i].replace(/(\r\n|\n|\r)/gm, kLines); | |
var splitLine = reline.split(kLines); | |
if(i == 0) { | |
getConfig(splitLine); | |
} else { | |
getTransform(splitLine, oppositeYZ); | |
} | |
} | |
cameraAnimation.totalFrames = cameraAnimation.position.length; | |
return cameraAnimation; | |
} | |
} | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment