-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert-project-to-ae-keyframes.js
executable file
·101 lines (85 loc) · 2.1 KB
/
convert-project-to-ae-keyframes.js
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
import {execSync} from 'child_process'
import fs from 'fs'
import {Euler, Quaternion} from 'three'
// Open the JSON file specified in the first argument of the command
const file = fs.readFileSync(process.argv[2], 'utf8')
// // Get the JSON data from the first argumnet of the command
const data = JSON.parse(file)
const {komas} = data
const keyframes = komas
.map((koma, frame) => {
const shot = koma.shots[0]
if (!shot) return null
return {
frame,
shootTime: shot.shootTime,
...shot.cameraConfigs,
...(shot.tracker ?? {}),
}
})
.filter(Boolean)
const keyProps = [
{aeProp: 'Slider Control #2\tSlider #2', key: 'shootTime'},
{aeProp: 'Slider Control #3\tSlider #2', key: 'iso'},
{
aeProp: 'Slider Control #4\tSlider #2',
key: 'shutterSpeed',
f: v => v.split('/')[0],
},
{
aeProp: 'Slider Control #5\tSlider #2',
key: 'shutterSpeed',
f: v => v.split('/')[1],
},
{
aeProp: 'Slider Control #6\tSlider #2',
key: 'aperture',
},
{
aeProp: 'Slider Control #7\tSlider #2',
key: 'focalLength',
},
{
aeProp: '3D Point Control #8\t3D Point #2',
key: 'position',
header: ['X pixels', 'Y pixels', 'Z pixels'],
f: v => v.join('\t'),
},
{
aeProp: '3D Point Control #9\t3D Point #2',
key: 'rotation',
header: ['X pixels', 'Y pixels', 'Z pixels'],
f: v =>
new Euler()
.setFromQuaternion(new Quaternion(...v))
.toArray()
.slice(0, 3)
.map(v => (v * 180) / Math.PI)
.join('\t'),
},
]
const keyframeString = keyProps
.map(({aeProp, header, key, f}) => {
f ??= v => v
header ??= []
const values = keyframes
.map(k => {
if (k[key] === undefined) return null
return `\t${k.frame}\t${f(k[key])}\t`
})
.filter(Boolean)
.join('\n')
return `Effects\t${aeProp}\n\tFrame\t${header.join('\t')}\t\n${values}\n`
})
.join('\n')
const clipboardData = `Adobe After Effects 8.0 Keyframe Data
Units Per Second 15
Source Width 100
Source Height 100
Source Pixel Aspect Ratio 1
Comp Pixel Aspect Ratio 1
${keyframeString}
End of Keyframe Data`
// console.log(clipboardData)
// Copy to clipboard
execSync(`echo "${clipboardData}" | pbcopy`)