-
-
Save shidarin/10748812 to your computer and use it in GitHub Desktop.
Fork of https://gist.github.com/SurpriseTRex/10633830 showing some further revisions possible. Original description: Nuke script. Down-rezzes and re-draws the selected read node in the Node Graph, using Constant nodes as pixels. Accounts for aspect ratio. More than 20x20 not recommended for performance reasons.
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
__author__ = 'SurpriseTRex' | |
def draw_constant(res=10): | |
"""Re-draws a Read node using Constant nodes as pixels.""" | |
# Checks that the user has selected a Read node. | |
try: | |
node = nuke.selectedNode() | |
except ValueError: | |
nuke.message("No node selected!") | |
return False | |
else: | |
if node.Class() != "Read": | |
# Pushes pop up message to the user | |
nuke.message("No Read node selected to re-draw!") | |
return False | |
# Sets the Image Height/Width. | |
imgHeight = node.height() | |
imgWidth = node.width() | |
# Sets the Node Grid Height/Width, making sure to maintain Aspect Ratio. | |
gridHeight = res | |
gridWidth = res * imgWidth / imgHeight | |
# The loops construct the grid layout of the pixels. | |
for y in xrange(gridHeight): | |
for x in xrange(gridWidth): | |
# Construct the Constant nodes and set their position. | |
c = nuke.nodes.Constant(xpos=x * 70, ypos=-y * 70) | |
# Get our sample position | |
sampleX = 0.5 + (x * (imgWidth / gridWidth)) | |
sampleY = 0.5 + (y * (imgHeight / gridHeight)) | |
# Generate a list of rgba values at sample position | |
colorValues = [ | |
nuke.sample( | |
node, | |
color, | |
sampleX, | |
sampleY | |
) for color in ['r', 'g', 'b', 'a']] | |
# Sets Constant colour to sampled pixels. | |
c['color'].setValue(colorValues) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment