Expressions/Scripts/Presets

Moderators: Disciple, zlovatt

 
Paul Hill
Topic Author
Posts: 7
Joined: Mon Apr 30, 2007 4:44 am
Location: Bristol UK

Convert Keyframe Values to Whole Numbers

Wed Nov 15, 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: 19
Joined: Wed Aug 30, 2017 8:35 pm
Location: Detroit, Mi
Contact:

Re: Convert Keyframe Values to Whole Numbers

Thu Nov 16, 2017 3:39 pm

Before you "Convert Expression to Keyframes" in 2 array transform properties like position, anchor, or scale you can use this


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


Math.floor(value)


I hope this solves your problem.
 
Paul Hill
Topic Author
Posts: 7
Joined: Mon Apr 30, 2007 4:44 am
Location: Bristol UK

Re: Convert Keyframe Values to Whole Numbers

Fri Nov 17, 2017 3:13 am

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

Re: Convert Keyframe Values to Whole Numbers

Mon Nov 20, 2017 10:56 am

No problem, glad I could help.

Who is online

Users browsing this forum: No registered users and 3 guests