Convert Keyframe Values to Whole Numbers

Moderators: Disciple, zlovatt

Paul Hill
Posts: 7
Joined: April 30th, 2007, 4:44 am
Location: Bristol UK
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
CodingAe
Posts: 21
Joined: August 30th, 2017, 8:35 pm
Location: Detroit, Mi
Contact:
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
Yes. That worked perfectly. Thank you very much.
CodingAe
Posts: 21
Joined: August 30th, 2017, 8:35 pm
Location: Detroit, Mi
Contact:
No problem, glad I could help.