Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jedypod
jedypod / DistortTracks
Last active January 19, 2024 16:42
Distort Tracks Gizmo(Description in Comments, because description does not support markdown?)
set cut_paste_input [stack 0]
push $cut_paste_input
Group {
name DistortTracks
help "<b>Distort Tracks Gizmo</b>\n\n<b>About</b>:\nThis gizmo reformats and/or distorts tracking data based on a uv distortion map input. When you are working with CG elements in your comp that are undistorted and padded resolution, sometimes it is useful to reconcile tracking data from a 3d position through a camera into screen space. This data can then be used to do stuff in 2d: track in lens flares, matchmove roto or splinewarps, etc. The problem is that when this tracking data comes back from our padded undistorted 3d scene into distorted, unpadded resolution comp land, it doesn't line up. \n\n<b>Instructions</b>:\n1. Connect the UV input to a uv distortion map and set the channel that holds it, (for example, a LensDistortion node set to output type Displacement, outputting a UV distortion map into the forward.u and forward.v channels)\n2. Set the padded resolution format and the destination format: Padded resolution is the ov
@jedypod
jedypod / Bake Roto
Last active June 5, 2018 20:05
Bake Roto is a python script that will bake an arbitrary control vertex on a Nuke Rotopaint shape or stroke into position data. Baking nearly instantaneous, and takes into account transforms for shapes parented under layers that have animations or expression links. The idea for this was based on Magno Borgo's BakeRotoShapesToTrackers script.
"""
Bake Roto is a python script that will bake an arbitrary control vertex on a Nuke Rotopaint shape or stroke into position data. Baking nearly instantaneous, and takes into account transforms for shapes parented under layers that have animations or expression links. The idea for this was based on <a href="http://www.borgo.tv/">Magno Borgo</a>'s BakeRotoShapesToTrackers script.
http://www.nukepedia.com/python/misc/bakerotoshapestotrackers/
Usage:
Select a Roto or RotoPaint node and run the script. Don't forget to turn on the "toolbar label points" button to see the cv numbers.
Example Installation:
Add code to your menu.py to add the script to a menu.
import bake_roto
@jedypod
jedypod / Link Tools
Last active November 24, 2021 11:49
# Time offset start and end of all rotoshapes
import nuke.rotopaint as rp, _curvelib as cl
# Amount of frames to offset
time_offset = -200
t = nuke.frame()
# Get all Roto or RotoPaint nodes and loop through them
roto_nodes = [n for n in nuke.allNodes() if 'Roto' in n.Class()]
for roto_node in roto_nodes:
Expression {
expr0 "isinf(r) ? ((r(x+1,y)+r(x+1,y+1)+r(x+1,y-1)+r(x,y+1)+r(x,y-1)+r(x-1,y+1)+r(x-1,y)+r(x-1,y-1))/8) : r"
expr1 "isinf(g) ? ((g(x+1,y)+g(x+1,y+1)+g(x+1,y-1)+g(x,y+1)+g(x,y-1)+g(x-1,y+1)+g(x-1,y)+g(x-1,y-1))/8) : g"
expr2 "isinf(b) ? ((b(x+1,y)+b(x+1,y+1)+b(x+1,y-1)+b(x,y+1)+b(x,y-1)+b(x-1,y+1)+b(x-1,y)+b(x-1,y-1))/8) : b"
expr3 a
name infToAverage
selected true
xpos -68
ypos -273
}
@jedypod
jedypod / LeftHand_Shortcuts
Last active August 29, 2015 14:06
Map commonly used Nuke functionality to the left hand: frame advancing and stereo view-switching.
# Add these to the menu.py in your ~/.nuke or NUKE_PATH folder
# Viewer Shortcuts
nuke.menu('Viewer').addCommand("Next Frame", lambda: nuke.activeViewer().frameControl(1), "shift+f")
nuke.menu('Viewer').addCommand("Previous Frame", lambda: nuke.activeViewer().frameControl(-1), "shift+d")
nuke.menu('Viewer').addCommand("Next Keyframe", lambda: nuke.activeViewer().frameControl(2), "ctrl+shift+f")
nuke.menu('Viewer').addCommand("Previous Keyframe", lambda: nuke.activeViewer().frameControl(-2), "ctrl+shift+d")
# Swap stereo views: requires eyes to be named as lname and rname
lname = "L"
@jedypod
jedypod / PlanarProjection.nk
Last active October 12, 2023 06:31
PlanarProjection Planar Projection Generates 2D coordinates for points in 3D space. Works on 4 points at once, is instantaneous to calculate, and generates a 4x4 transform matrix for use in rotos.
set cut_paste_input [stack 0]
push $cut_paste_input
Group {
name PlanarProjection
help "<b>Planar Projection</b>\nGenerates 2D coordinates for points in 3D space. Type in 3D point coordinates, or use vertex selection in 3D viewer and click set to pick average of selected points, or set points to set all four points at once. \n\nYou can connect node output to scene together with your pointcloud or geometry and see where your points are located in 3d space. Double click any of them to move it in 3d space like any traditional nuke transform control. \n\nA matrix transform is also generated to be used with RotoPaint, SplineWarp and GridWarp nodes. If you are using matrix in GridWarp, points have to be in clockwise order, pick them one by one! \n\nCommand set points doesn't respect selection order! \n\nCheck out the demo video on my website! Kudos to Ivan Busquets for help with matrix math. \n\n-- developed by Vit Sedlacek 2012 www.vitsedlacek.com \n\n-- Modified by Jed Smith to make calculation time nearly inst
@jedypod
jedypod / hidden_input_handler.py
Last active November 12, 2020 10:38
Python tool to enhance the default behavior when copying / cutting and pasting nodes with hidden inputs. Instead of the pasted copy becoming disconnected, the node with the hidden input is connected to the node that the original was connected to.
import nuke, nukescripts, os
'''
## Hidden Input Handler
# Add these lines to your menu.py:
import hidden_input_handler
nuke.toolbar('Nodes').addCommand('Other/PostageStamp', 'hidden_input_handler.create()', 'alt+shift+p')
nuke.menu("Nuke").addCommand('Edit/Cut', lambda: hidden_input_handler.cut(), 'ctrl+x')
@jedypod
jedypod / terminal_render.py
Last active August 28, 2018 01:08
Render Nuke jobs in the terminal on OSX and Linux
from __future__ import with_statement
import os
import sys
import re
import glob
import subprocess
import nuke
import nukescripts