Created
July 17, 2021 01:48
-
-
Save justintaylor-dev/bef8dfb828325f4c9d172d0b386b9d7c to your computer and use it in GitHub Desktop.
reduce-keyframes #code_aeft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Loop through all keyframes of selected properties and delete duplicates that don't impact animation | |
if(!app.project.activeItem instanceof CompItem){ | |
alert('Please Select a Comp'); | |
} | |
else if(!app.project.activeItem.selectedProperties[0]){ | |
alert('Please Select at least one Property with Keyframes'); | |
}else{ | |
var comp = app.project.activeItem; | |
var keyedProps = app.project.activeItem.selectedProperties; | |
var removeList = []; | |
function eq(p, a, b) { | |
var propA = p.keyValue(a); | |
var propB = p.keyValue(a); | |
if(typeof propA === 'string' || typeof propA === 'number' || typeof propA === 'boolean'){ | |
return p.keyValue(a) === p.keyValue(b); | |
}else{ | |
return JSON.stringify(p.keyValue(a)) === JSON.stringify(p.keyValue(b)); | |
} | |
} | |
for (var i = 0; i < keyedProps.length; i++) { | |
var prop = keyedProps[i]; | |
var numKeys = prop.numKeys; | |
prop.keyValue(numKeys) | |
for (var j = numKeys; j > 0; j--) { | |
var numKeys = prop.numKeys; | |
var isLastKeyframe = j === prop.numKeys; | |
var isFirstKeyframe = j === 1; | |
var curKeyValue = prop.keyValue(j); | |
if(numKeys === 1){ | |
prop.removeKey(j); | |
}else if(isLastKeyframe){ | |
var previousKeyValue = prop.keyValue(j - 1); | |
if(eq(prop, j, j - 1)){ | |
prop.removeKey(j); | |
} | |
}else if(isFirstKeyframe){ | |
var nextKeyValue = prop.keyValue(j + 1); | |
if(eq(prop, j, j + 1)){ | |
prop.removeKey(j); | |
} | |
}else{ | |
var previousKeyValue = prop.keyValue(j - 1); | |
var nextKeyValue = prop.keyValue(j + 1); | |
if(eq(prop, j, j - 1)&&eq(prop, j, j + 1)){ | |
prop.removeKey(j); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment