Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CornerPin node with offset controls for each corner. Useful for tweaking cornerpin after all keyframes are baked (e.g. , from a tracker), in case you need to cheat the perspective or something else.
set cut_paste_input [stack 0]
push $cut_paste_input
Group {
name CornerPinOffset
tile_color 0x9073adff
addUserKnob {20 PinControl}
addUserKnob {26 CornerPinControls l "" +STARTLINE T "<font size=5><b>Corner Pin Data</b></font>"}
addUserKnob {20 CornerPinData l "" +STARTLINE n 1}
addUserKnob {41 to1 T cpMaster.to1}
addUserKnob {41 enable1 -STARTLINE T cpMaster.enable1}
addUserKnob {41 to2 T cpMaster.to2}
addUserKnob {41 enable2 -STARTLINE T cpMaster.enable2}
addUserKnob {41 to3 T cpMaster.to3}
addUserKnob {41 enable3 -STARTLINE T cpMaster.enable3}
addUserKnob {41 to4 T cpMaster.to4}
addUserKnob {41 enable4 -STARTLINE T cpMaster.enable4}
addUserKnob {41 copy_from_to_1 l "Copy 'from'" T cpMaster.copy_from_to}
addUserKnob {20 endGroup_1 l endGroup n -1}
addUserKnob {20 from_group n 1}
addUserKnob {41 from1 T cpMaster.from1}
addUserKnob {41 from2 T cpMaster.from2}
addUserKnob {41 from3 T cpMaster.from3}
addUserKnob {41 from4 T cpMaster.from4}
addUserKnob {41 set_to_input l "Set to input" T cpMaster.set_to_input}
addUserKnob {41 copy_from_to l "Copy 'to'" -STARTLINE T cpMaster.copy_from_to}
addUserKnob {41 invert T cpOutput.invert}
addUserKnob {41 filter T cpOutput.filter}
addUserKnob {41 black_outside l "black outside" T cpOutput.black_outside}
addUserKnob {20 endGroup_2 l endGroup n -1}
addUserKnob {41 motionblur T cpOutput.motionblur}
addUserKnob {41 shutter T cpOutput.shutter}
addUserKnob {41 shutteroffset l "shutter offset" T cpOutput.shutteroffset}
addUserKnob {41 shuttercustomoffset l "" -STARTLINE T cpOutput.shuttercustomoffset}
addUserKnob {26 ""}
addUserKnob {26 OffsetControls l "" +STARTLINE T "<font size=5><b>Offset Controls</b></font>"}
addUserKnob {41 offsetto1 l "offset to1" T offset1.translate}
addUserKnob {22 control1 t "Show the transform jack by opening the control panel of the grouped transform node" -STARTLINE T "nuke.show(nuke.thisGroup().node('offset1'), True)"}
addUserKnob {22 hide1 t "Closes the panel if you don't feel like doing it yourself" -STARTLINE T nuke.thisGroup().node('offset1').hideControlPanel()}
addUserKnob {41 offsetto2 l "offset to2" T offset2.translate}
addUserKnob {22 control2 t "Show the transform jack by opening the control panel of the grouped transform node" -STARTLINE T "nuke.show(nuke.thisGroup().node('offset2'), True)"}
addUserKnob {22 hide2 t "Closes the panel if you don't feel like doing it yourself" -STARTLINE T nuke.thisGroup().node('offset2').hideControlPanel()}
addUserKnob {41 offsetto3 l "offset to3" T offset3.translate}
addUserKnob {22 control3 t "Show the transform jack by opening the control panel of the grouped transform node" -STARTLINE T "nuke.show(nuke.thisGroup().node('offset3'), True)"}
addUserKnob {22 hide3 t "Closes the panel if you don't feel like doing it yourself" -STARTLINE T nuke.thisGroup().node('offset3').hideControlPanel()}
addUserKnob {41 offsetto4 l "offset to4" T offset4.translate}
addUserKnob {22 control4 t "Show the transform jack by opening the control panel of the grouped transform node" -STARTLINE T "nuke.show(nuke.thisGroup().node('offset4'), True)"}
addUserKnob {22 hide4 t "Closes the panel if you don't feel like doing it yourself" -STARTLINE T nuke.thisGroup().node('offset4').hideControlPanel()}
addUserKnob {22 showRefLines l "Show Ref Lines" t "Show Lines between pins, for lining up occluded corners." T "nuke.show(nuke.thisGroup().node('Roto1'), True)" +STARTLINE}
addUserKnob {26 div l "" +STARTLINE}
addUserKnob {22 LoadMochaAE l "Load Mocha AE Track" T "import nuke, re\n# is a comment about what following code does\n#??? is an informational side note\n#!!! is something that needs to be fixed or extended\n\n# Creates a Nuke Panel for the user to paste tracking data into.\np = nuke.Panel('Get MochaAE Track')\np.addMultilineTextInput('Track Data', '''Paste corner pin data from Mocha AE here. \\nMust be the type that supports RG Warp and mochaImport''')\np.addBooleanCheckBox('Motionblur On', True)\np.addSingleLineInput('Frame Offset', 'Frame Offset (Default: 0)')\n\nif not p.show():\n\traise\nmochatrack = p.value('''Track Data''')\ntext = mochatrack.splitlines(True)\ntry:\n\tif p.value('Frame Offset') == 'Frame Offset (Default: 0)':\n\t\tframe_offset = 0 + int(nuke.root().knob(\"first_frame\").value())\n\telse:\n\t\tframe_offset = int(p.value('Frame Offset')) + int(nuke.root().knob(\"first_frame\").value())\nexcept:\n\tnuke.message(\"Error! Start Frame must be an integer.\")\n\traise\nmotionblur_on = p.value('Motionblur On')\n# Get width and height from mocha tracking data\ncomp_width = int(re.search(r'Source Width\\t\\b\\d+\\b', mochatrack).group().split('\\t')\[1])\ncomp_height = int(re.search(r'Source Height\\t\\b\\d+\\b', mochatrack).group().split('\\t')\[1])\n\n\n# Iterates through every match for frame xpos ypos. The regex searches for <tab><int><tab><float/int><tab><float/int>\n# The search also matches 'Pin-####'. When a match for pin is found, it gets the corner number, and then skips getting frame and xpos/ypos\n# Data is added to a 4-dimensional list called track_data\n# The track_data list has 4 lists, one for each corner. Each of these lists has a list for each frame with frame,xpos,ypos data. \n# Therefore, track_data\[0] is the list of all frames for corner 1, track_data\[1] is corner 2, etc.\n# track_data\[0]\[23] would return \[frame,xpos,ypos] for frame 23 of corner 1\n\n# Initialize vars for loop\t\ntrack_data = \[\[],\[],\[],\[]]\nlast_frame = 0\nfor match in re.finditer(r'\\b\\d+\\b\\t\[-+]?\\b\[0-9]*\\.?\[0-9]+\\b\\t\[-+]?\\b\[0-9]*\\.?\[0-9]+\\b|Pin-\\d*', mochatrack):\n\tif re.match(r'Pin*', match.group()):\n\t\tcorner = int( match.group().split('-')\[1] )-1\n\t\tcontinue\n\tframe \t= int(match.group().split('\\t')\[0])\n\txpos\t= float(match.group().split('\\t')\[1])\n\typos\t= float(match.group().split('\\t')\[2])\n\ttrack_data\[corner].append(\[frame, xpos, ypos])\n\tlast_frame = frame\n\n# Converts the track_data corner order from AE to Nuke, since our data is stored in AE's corner format\n# Nuke is 1=LL, 2=LR, 3=UR, 4=UL. AE is LL=2, LR=3, UR=1, UL=0\ntrack_data\[0], track_data\[1], track_data\[2], track_data\[3] = track_data\[2], track_data\[3], track_data\[1], track_data\[0]\n\n\n##########################\n# Create CornerPin Node\n##########################\ncp = nuke.thisGroup().node('cpMaster')\n#cp = nuke.createNode('CornerPin2D')\nif motionblur_on == True:\n\tcp.knob('shutteroffset').setValue('centred')\n\tcp.knob('motionblur').setValue(20)\nto_knobs = \[ cp.knob('to1'), cp.knob('to2'), cp.knob('to3'), cp.knob('to4') ]\ncorner = 0\n# For each 'to' knob in the CornerPin node, set it to be animated, and for every frame in the track, set a key for xpos and ypos\n# frame\[0] is the frame number, frame\[1] is the xpos, frame\[2] is the ypos\n# ypos must be inverted (height - ypos), to be right in nuke\nfor knob in to_knobs:\n\tknob.setAnimated()\n\tfor frame in track_data\[corner]:\n\t\tknob.setValueAt( frame\[1], frame\[0]+frame_offset, 0 )\n\t\tknob.setValueAt( (comp_height - frame\[2]), frame\[0]+frame_offset, 1 )\n\tcorner += 1" +STARTLINE}
addUserKnob {20 OffsetCornerPinData n 1}
addUserKnob {41 to1_1 l to1 T cpOutput.to1}
addUserKnob {41 to2_1 l to2 T cpOutput.to2}
addUserKnob {41 to3_1 l to3 T cpOutput.to3}
addUserKnob {41 to4_1 l to4 T cpOutput.to4}
addUserKnob {20 endGroup n -1}
}
Input {
inputs 0
name Input
xpos 730
ypos -263
}
CornerPin2D {
to1 {{cpMaster.to1+offset1.translate} {cpMaster.to1+offset1.translate}}
to2 {{cpMaster.to2+offset2.translate} {cpMaster.to2+offset2.translate}}
to3 {{cpMaster.to3+offset3.translate} {cpMaster.to3+offset3.translate}}
to4 {{cpMaster.to4+offset4.translate} {cpMaster.to4+offset4.translate}}
invert false
shutteroffset centred
from1 {{parent.cpMaster.from1} {parent.cpMaster.from1}}
from2 {{parent.cpMaster.from2} {parent.cpMaster.from2}}
from3 {{parent.cpMaster.from3} {parent.cpMaster.from3}}
from4 {{parent.cpMaster.from4} {parent.cpMaster.from4}}
name cpOutput
xpos 730
ypos -153
}
Output {
name Output1
xpos 730
ypos -9
}
Roto {
inputs 0
curves {{{v x3f99999a}
{f 0}
{n
{layer Root
{f 512}
{t x44700000 x44070000}
{a}
{curvegroup Bezier1 512 bezier
{{cc
{f 8192}
{p
{}
{{=cpOutput.to4 x43870000}
{=cpOutput.to4 x441b8000}}
{}
{}
{{=cpOutput.to3 x44358000}
{=cpOutput.to3 x44410000}}
{}
{}
{{=cpOutput.to2 x446e8000}
{=cpOutput.to2 x43c50000}}
{}
{}
{{=cpOutput.to1 x43d70000}
{=cpOutput.to1 x43480000}}
{}}}
{cc
{f 8192}
{p
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}}}}
{t x4414c000 x43f88000}
{a spx 0 spy 0 sb 1 tt x40800000}}}}}}
toolbox {selectAll {
{ selectAll str 1 ssx 1 ssy 1 sf 1 }
{ createBezier str 1 ssx 1 ssy 1 sf 1 sb 1 tt 4 }
{ createBezierCusped str 1 ssx 1 ssy 1 sf 1 sb 1 }
{ createBSpline str 1 ssx 1 ssy 1 sf 1 sb 1 tt 5 }
{ createEllipse str 1 ssx 1 ssy 1 sf 1 sb 1 tt 6 }
{ createRectangle str 1 ssx 1 ssy 1 sf 1 sb 1 tt 7 }
{ createRectangleCusped str 1 ssx 1 ssy 1 sf 1 sb 1 }
{ createOpenSpline str 1 ssx 1 ssy 1 sf 1 sb 1 }
{ brush str 1 ssx 1 ssy 1 sf 1 sb 1 }
{ eraser src 2 str 1 ssx 1 ssy 1 sf 1 sb 1 }
{ clone src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
{ reveal src 3 str 1 ssx 1 ssy 1 sf 1 sb 1 }
{ dodge src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
{ burn src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
{ blur src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
{ sharpen src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
{ smear src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
} }
toolbar_autokey false
toolbar_brush_hardness 0.200000003
toolbar_source_transform_scale {1 1}
toolbar_source_transform_center {320 240}
colorOverlay 0
lifetime_type "all frames"
motionblur_shutter_offset_type centred
source_black_outside true
name Roto1
xpos 840
ypos -154
}
CornerPin2D {
inputs 0
to1 {0 0}
to2 {2048 0}
to3 {2048 1152}
to4 {0 1152}
invert false
motionblur 20
shutteroffset centred
from1 {0 0}
from2 {2048 0}
from3 {2048 1536}
from4 {0 1536}
name cpMaster
xpos 509
ypos -157
}
Transform {
inputs 0
center {{cpMaster.to4 x1 0 x64 0 x172 0 x189 0 x1001 0 x1475 0} {cpMaster.to4 x1 0 x64 0 x172 0 x189 0 x1001 0 x1475 0}}
name offset4
xpos 447
ypos -226
}
Transform {
inputs 0
center {{cpMaster.to3 x1 0 x4 0 0 x64 0 x172 0 x189 0 x1001 0 x1475 0} {cpMaster.to3 x1 0 x4 0 0 x64 0 x172 0 x189 0 x1001 0 x1475 0}}
name offset3
xpos 565
ypos -226
}
Transform {
inputs 0
center {{cpMaster.to2 x1 0 x64 0 x65 0 x172 0 x189 0 x295 0 x313 0 x1001 0 x1475 0} {cpMaster.to2 x1 0 x64 0 x65 0 x172 0 x189 0 x295 0 x313 0 x1001 0 x1475 0}}
name offset2
xpos 571
ypos -106
}
Transform {
inputs 0
center {{cpMaster.to1 x1 0 x64 0 x172 0 x189 0 x1001 0 x1475 0} {cpMaster.to1 x1 0 x64 0 x172 0 x189 0 x1001 0 x1475 0}}
name offset1
xpos 445
ypos -106
}
end_group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.