Convert Keyframe Values to Whole Numbers

Moderators: Disciple, zlovatt

Post Reply
Paul Hill
Posts: 7
Joined: April 30th, 2007, 4:44 am
Location: Bristol UK

November 15th, 2017, 9:09 am

Hi

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.

Thanks
User avatar
CodingAe
Posts: 20
Joined: August 30th, 2017, 8:35 pm
Location: Detroit, Mi
Contact:

November 16th, 2017, 3:39 pm

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

Math.floor(value)
I hope this solves your problem.
Paul Hill
Posts: 7
Joined: April 30th, 2007, 4:44 am
Location: Bristol UK

November 17th, 2017, 3:13 am

Yes. That worked perfectly. Thank you very much.  :)
User avatar
CodingAe
Posts: 20
Joined: August 30th, 2017, 8:35 pm
Location: Detroit, Mi
Contact:

November 20th, 2017, 10:56 am

No problem, glad I could help.
Post Reply