Page 1 of 1

Convert Keyframe Values to Whole Numbers

Posted: November 15th, 2017, 9:09 am
by Paul Hill

I'm not great at working out expressions, so there might be a really simple solution to this.

A little context. I need to output keyframe data from After Effects to a piece of bespoke web software. Basically, I create a simple animation on a layer. I then copy all of the transform values and paste them into a spreadsheet. The bespoke web software is able to read this spreadsheet and apply the animation to its own visual elements.

The web software requires that every single frame has a keyframe value in the spreadsheet. I do this by simply using 'Add Expression' on every transform property (Position, Rotation, etc) and then use 'Convert Expression to Keyframes' in the Animation Assistant. However, there is a problem. The web software is unable to deal with anything less than a whole number. This means that when it renders its visual element it can jitter back and forth as it rounds all the values up or down.

So I'm looking for an expression or script that will round the transform values up or down for each keyframe (It's probably best if it always round in one direction e.g down). This will still likely cause a jitter, but at least I will be able to see it in After Effects and correct it before I output the data for the web software.

Any ideas?

Ultimately, I'd like to create a script that automatically converts all transform values to whole number keyframes on every frame. This would mean I no longer need to add expressions and convert to keyframes.


Re: Convert Keyframe Values to Whole Numbers

Posted: November 16th, 2017, 3:39 pm
by CodingAe
Before you "Convert Expression to Keyframes" in 2 array transform properties like position, anchor, or scale you can use this

Code: Select all

var x = Math.floor(value[0]); // Math.floor will round down the decimals to a whole number
var y = Math.floor(value[1]);
[x, y]
For transform properties with no arrays like rotation and opacity

Code: Select all

I hope this solves your problem.

Re: Convert Keyframe Values to Whole Numbers

Posted: November 17th, 2017, 3:13 am
by Paul Hill
Yes. That worked perfectly. Thank you very much.  :)

Re: Convert Keyframe Values to Whole Numbers

Posted: November 20th, 2017, 10:56 am
by CodingAe
No problem, glad I could help.