Skip to content

Instantly share code, notes, and snippets.

@kenjiSpecial
Last active July 9, 2018 05:05
Show Gist options
  • Select an option

  • Save kenjiSpecial/26aea2b06a083e0722ae56a6ffcca8b1 to your computer and use it in GitHub Desktop.

Select an option

Save kenjiSpecial/26aea2b06a083e0722ae56a6ffcca8b1 to your computer and use it in GitHub Desktop.
after effectのアニメーションをjsonファイルとして書き出す。
var ae = require("after-effects");
var aeToJSON = require('ae-to-json/after-effects');
var jsonfile = require('jsonfile')
var fs = require('fs');
var outFileName = 'background_forest'
ae.execute(aeToJSON)
.then(function(json){
fs.writeFile(`temp.json`, JSON.stringify(json), 'utf8', (err)=>{});
var cameraJson = parseJson(json)
var cameraJson = JSON.stringify(cameraJson);
fs.writeFile(`${outFileName}.json`, cameraJson, 'utf8', (err)=>{
});
})
.catch(function(e){
throw e;
});
function getAnimation( transformObj ){
let keyframes = transformObj.keyframes;
let animationArr = [];
for(let ii = 0; ii < keyframes.length; ii++){
let keyframe = keyframes[ii];
time = Number(keyframe[0].toFixed(3));
value = keyframe[1].map((num)=>{return Number(num.toFixed(1));});
animationArr.push([time,value]);
}
return animationArr;
}
function parseJson(json){
var project = json.project;
var layers, camera;// = project.items[project.items.length - 1].layers;
for(var ii = 0; ii < project.items.length; ii++){
if(project.items[ii]['name'] == outFileName){
layers = project.items[ii].layers;
console.log(layers);
}
}
for(var ii = 0; ii < layers.length; ii++){
console.log(layers[ii].name);
if(layers[ii].name == '3D Tracker Camera'){
camera = layers[ii];
}
}
var cameraProperties = camera['properties'];
let options = cameraProperties['Camera Options'];
console.log(options);
let transform = cameraProperties['Transform'];
let positionArr = getAnimation(transform['Position']);
let orientationArr = getAnimation(transform['Orientation']);
var cameraObj = {
animations: {
position: positionArr,
// orientation: orientationArr
},
zoom: {
'unit': options['Zoom']['unitsText'],
'value': Number(options['Zoom']['value'].toFixed(2))
},
aperture: {
'unit': options['Aperture']['unitsText'],
'value': Number(options['Aperture']['value'].toFixed(2))
},
focusDistance: {
'unit': options['Focus Distance']['unitsText'],
'value': Number(options['Focus Distance']['value'].toFixed(2))
}
}
return cameraObj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment