Created
September 22, 2021 08:14
-
-
Save U29/f56971c2056294e0c93289c3a9d3d03a to your computer and use it in GitHub Desktop.
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
def shapeCenter(node, shapeName, frame): | |
shape = node['curves'].toElement(shapeName) | |
x = 0 | |
y = 0 | |
for eachPoint in shape: | |
x = x + eachPoint.center.getPosition(nuke.frame(frame))[0] | |
y = y + eachPoint.center.getPosition(nuke.frame(frame))[1] | |
# avarage of point value | |
x = x / len(shape) | |
y = y / len(shape) | |
return [x, y] | |
# Roto Node Name Here | |
node = nuke.toNode('Roto Node Name') | |
# Target Roto Shape Name | |
shapeName = 'layer/shape' | |
# Target Tracker Name Here | |
tNode = nuke.toNode('Tracker3') | |
k = tNode['tracks'] | |
numColumns = 31 | |
colTrackX = 2 | |
colTrackY = 3 | |
trackIdx = 0 # for the first track | |
first = nuke.Root()['first_frame'].getValue() | |
last = nuke.Root()['last_frame'].getValue() + 1 | |
for frame in range(int(first), int(last)): | |
nuke.activeViewer().frameControl(frame) | |
center = shapeCenter(node, shapeName, frame) | |
tNode['translate'].setAnimated() | |
k.setValueAt(center[0], frame, numColumns*trackIdx + colTrackX) | |
k.setValueAt(center[1], frame, numColumns*trackIdx + colTrackY) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment