Created
January 23, 2013 16:02
-
-
Save julik/4608655 to your computer and use it in GitHub Desktop.
This baby will compute the center pivot of a CornerPin node in Nuke
This file contains hidden or 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
import nuke | |
def run(): | |
cornerpin = nuke.selectedNode() | |
xform = nuke.nodes.TransformMasked() | |
xform["center"].setAnimated() | |
f = nuke.frame() | |
center = xform["center"] | |
xanim = center.animations()[0] | |
yanim = center.animations()[1] | |
# Python ranges are NOT inclusive therefore +1 | |
for current_frame in range(nuke.root().firstFrame(), nuke.root().lastFrame() + 1): | |
xvalues = [] | |
yvalues = [] | |
for corner_index in range(1, 4+1): | |
xcurve, ycurve = cornerpin["to%d" % corner_index].animations() | |
xvalues.append(xcurve.evaluate(current_frame)) | |
yvalues.append(ycurve.evaluate(current_frame)) | |
mean_x = sum(xvalues) / 4.0 | |
mean_y = sum(yvalues) / 4.0 | |
xanim.setKey(current_frame, mean_x) | |
yanim.setKey(current_frame, mean_y) | |
nuke.frame(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment