Reduce the size of animations produced via motion capture (e.g. Mixamo) by removing duplicate keyframes
Background
Using tools like Mixamo is great for getting realistic, potentially complex animations for NPCs. However, they use motion capture to create the animations, which creates a TON of keyframes and poses, even when there’s essentially no difference from one frame to the next. This causes bloat in the memory used by your game and causes a rapid rise in the number of instances managed by your game.
So what I did was I wrote a PowerShell script to read the exported animation (.rbxmx file), and then starting at the beginning of the time sequence, move forward and compare the part positions in each sequential keyframe and determine if it had moved enough to warrant a new keyframe. If not, that entry is removed. It goes through the entire animnation part by part, comparing CFrames with a precision of 0.01. Any movement less than that amount is considered discardable.
Why PowerShell and not a Studio plugin? Easy - the instances of keyframes and Poses within Studio do not expose all of the actual position properties that are available in the exported RBXMX file. So it’s not physically possible within Studio. Exporting the animation as an RBXMX is simple enough, and re-importing the modified file is also simple. The hardest part for most people using this tool will be using PowerShell
Results
I have achieved anywhere from 15% to 50% reduction in the size of animations this has been run against, with no appreciable loss in quality of the animation itself. Greater reductions are achieved when there is relatively little motion for most of the character such as an idle animation. Lower reduction percentages happen when there is a lot of motion of all of the parts of the character, such as shaking.
Note that reducing the overall number of animated part keyframes in your animation can also have the effect of actually letting you edit it in the Roblox animation editor. When you have too many keyframes in an animation, the editor simply draws a line all the way across for the part, rending it just about un-editable. As you’ll see from the examples below, reducing keyframes can help you overcome this.
Examples:
Idle animation - previous version with 1594 instances
Idle animation - new version with 991 instances (38% reduction)
Old animation with 6,283 instances
New Animation with 3,653 instances (42% reduction)
Usage
To use this tool:
- Within Roblox Studio, open your character in Explorer and select an animation from inside the AnimSaves model
- Right-click and select “Save to File”, enter a file name, and make sure “Save as type” has
Roblox XML Model Files (*.rbxmx)
selected, and click Save . Be sure to rename your old animation after exporting for safe-keeping. - Run the PowerShell script in your favorite PowerShell editor and it will prompt you to select the file to process. Select what you just exported.
- The PowerShell script will run and output some info to the console output. When done, you will have a new file named
(yourfilename)_New.rbxmx
. - Go back into Studio and right-click the AnimSaves model, then select
Insert from File
and then select the file just created and clickOpen
. Your new animation should now be playable via Animation Editor.