Ejemplo n.º 1
0
def addPoint():
    #print pointKnobs()
    #print numberOfPointKnobs()

    num = numberOfPointKnobs()
    node = nuke.thisNode()

    knob = nuke.Color_Knob('color{}'.format(num))
    cKnobs = colorKnobs()
    #avgColorR = sum([k.getValue(0) for k in cKnobs()]) / len(cKnobs())
    #avgColorG = sum([k.getValue(1) for k in cKnobs()]) / len(cKnobs())
    #avgColorB = sum([k.getValue(2) for k in cKnobs()]) / len(cKnobs())

    avgColor = [sum([k.getValue(i) for k in cKnobs]) / len(cKnobs) for i in range(3)] if cKnobs else [0, 0, 0]
    knob.setValue(avgColor)
    node.addKnob(knob)

    knob = nuke.XY_Knob('p{}'.format(num))
    knob.clearFlag(nuke.STARTLINE)  #creates the knob at the same line

    pKnobs = pointKnobs()
    avgPos = [sum([k.getValue(i) for k in pKnobs]) / len(pKnobs) for i in range(2)] if pKnobs else [0, 0]   #calculates average value of all colors. if knob does not exists sets 0 value
    knob.setValue(avgPos)   #sets values to the knob
    knob.clearFlag(nuke.STARTLINE)  #creates the knob at the same line
    node.addKnob(knob)  #adds the knob

    knob = nuke.PyScript_Knob('deletePoint{}'.format(num))  #creates knob 'deletePoints' with the number of the point
    knob.clearFlag(nuke.STARTLINE)  #creates the knob at the same line
    knob.setLabel('delete')
    knob.setCommand('nPointGrad.deletePoints()')
    node.addKnob(knob)  #adds the knob

    makeExpression()
Ejemplo n.º 2
0
def drop_sample(name, knob_type, channel=None, node=None):
    """create a set of paired knobs, a floating point value and a
    droppable 2d position to drive it.  The returning value will either
    be a scalar or an rgb value.

    knob_type will either be an XYZ_Knob for color values, or an
    Array_Knob for scalars.  Use the add_* functions below to add knobs
    to a particular node."""

    # the naming on these knobs is tightly controlled, because we'll be
    # driving knobChanged scripts from here, using the naming convention.
    controlled_knob = knob_type('_'.join((name, 'value')))
    controlled_knob.setLabel(name)
    # the actual dropper knob, which users will use to select points in
    # 2D space.
    control_knob = nuke.XY_Knob('_'.join((name, 'dropper')))
    control_knob.setLabel(' :: ')
    # put the control knob on its own line
    controlled_knob.setFlag(nuke.STARTLINE)
    control_knob.clearFlag(nuke.STARTLINE)

    # add this script to the knobChanged for the node
    current_script = node['knobChanged'].getText()
    new_script = '{}\n'
    if 'import knobs' not in current_script:
        new_script += 'from vfx_utils.plutonium.core import knobs\n'
    else:
        new_script += 'knobs.update_drop_sample(\'{0}\', \'{1}\', \'{2}\')\n'

    # format the script with the correct knob names
    new_script = new_script.format(control_knob.name(), controlled_knob.name(),
                                   channel)
    node.addKnob(controlled_knob)
    node.addKnob(control_knob)
    node['knobChanged'].setValue('\n'.join((current_script, new_script)))
Ejemplo n.º 3
0
    def __init__(self, node):
        self.n = node

        if not self.n.Class() in ('Tracker4', 'Tracker3','CornerPin2D'):
            nuke.message('The selected node is neither a Tracker or a Cornerpin.')
            return

        self._trackNames = self.getTrackNames(self.n)
        if not self._trackNames:
            nuke.message('No Tracks found in %s' %self.n.name())
            return

        nukescripts.PythonPanel.__init__(self, 'Export Tracks from %s' %self.n.name())

        self.fRange = nuke.String_Knob('fRange', 'Framerange: ', '%s-%s' %(nuke.root().firstFrame(), nuke.root().lastFrame()))

        self.trackEnum = []
        self.trackXY = []
        for i in range(len(self._trackNames)):
            if i > 3:
                break

            self.trackEnum.append(nuke.Enumeration_Knob('track%d' %i, 'Track %d' %(i + 1), self._trackNames))
            self.trackEnum[i].setValue(i)

            self.trackXY.append(nuke.XY_Knob('trackpos%d', ''))
            self.trackXY[i].setExpression('root.%s.tracks.%d.track_x' %(self.n.name(), i + 1), 0)
            self.trackXY[i].setExpression('root.%s.tracks.%d.track_y' %(self.n.name(), i + 1), 1)

        self.addKnob(self.fRange)
        for j, k in enumerate(self.trackEnum):
            self.addKnob(k)
            self.addKnob(self.trackXY[j])
Ejemplo n.º 4
0
def getExprThis():

    p = nuke.Panel('rotate Center')
    p.addSingleLineInput("Node_Name:", nodeName)
    p.addSingleLineInput("Knob_Name:", knobName)
    result = p.show()
    nameType = p.value("Node_Name:")
    KnobName2 = p.value("Knob_Name:")
    nameType2 = nameType
    KnobName3 = KnobName2

    firstExpr = str('%s.%s' % (nameType2, KnobName3))
    getExprX = '(((%s) - width/4) * 2) + ((%s - (((%s) - width/4) * 2)) * intensity)' % (
        firstExpr, firstExpr, firstExpr)
    getExprY = '(((%s) - height/4) * 2) + ((%s - (((%s) - height/4) * 2)) * intensity)' % (
        firstExpr, firstExpr, firstExpr)

    newNoop = nuke.createNode('NoOp')
    newNoopTab = nuke.Tab_Knob('rotateCenter')
    newNoopXyKnob = nuke.XY_Knob('Expr')
    newNoopFloat = nuke.Double_Knob('intensity')
    newNoop.addKnob(newNoopTab)
    newNoop.addKnob(newNoopXyKnob)
    newNoop.addKnob(newNoopFloat)
    newNoopFloat.setValue(0)
    newNoopFloat.setRange(-1, 1)
    newNoopXyKnob.setExpression(getExprX, 0)
    newNoopXyKnob.setExpression(getExprY, 1)
Ejemplo n.º 5
0
def createLines(dicValues, id, pCount):
    ## Variables
    n = nuke.thisNode()
    addPath = '<img src=":qrc/images/Add.png">'
    removePath = '<img src=":qrc/images/Remove.png">'

    for i in range(int(pCount)):
        ## Create knobs
        col = nuke.AColor_Knob('p%03d_color' % (i + 1), '%03d' % (i + 1))
        col.setValue(dicValues[i]['color'])
        pos = nuke.XY_Knob('p%03d' % (i + 1), 'position')
        pos.clearFlag(0x1000)
        pos.setValue(dicValues[i]['position'])
        addLine = nuke.PyScript_Knob('p%03d_add' % (i + 1), addPath)
        addLine.setValue('TX_Ramp.addLine()')
        remLine = nuke.PyScript_Knob('p%03d_remove' % (i + 1), removePath)
        remLine.setValue('TX_Ramp.removeLine()')

        ## Create knobs
        n.addKnob(col)
        n.addKnob(pos)
        n.addKnob(addLine)
        n.addKnob(remLine)

    ## Create end knobs
    col = nuke.AColor_Knob('end_color', '  end')
    col.setValue(dicValues[-1]['color'])
    pos = nuke.XY_Knob('end', 'position')
    pos.clearFlag(0x1000)
    pos.setValue(dicValues[-1]['position'])
    pos.setFlag(0x00000080)
    pos.setFlag(0x00008000)
    addLine = nuke.PyScript_Knob('end_add', addPath)
    addLine.setFlag(0x00000080)
    remLine = nuke.PyScript_Knob('end_remove', removePath)
    remLine.setFlag(0x00000080)

    ## Create end knobs
    n.addKnob(col)
    n.addKnob(pos)
    n.addKnob(addLine)
    n.addKnob(remLine)
Ejemplo n.º 6
0
def cropTracked():
    import nuke
    n = nuke.selectedNode()
    x = n['translate'].value(0)
    y = n['translate'].value(1)
    xp = n['xpos'].value()
    yp = n['ypos'].value()
    name = n['name'].value()
    name = "parent."+name
    crop = nuke.nodes.Crop()
    knob = nuke.XY_Knob("extend","extend")
    extend=crop.addKnob(knob)
    offset = nuke.XY_Knob("offset","offset")
    extend=crop.addKnob(offset)
    crop['extend'].setValue(100)
    crop['xpos'].setValue(xp+100)
    crop['ypos'].setValue(yp)
    crop['box'].setExpression(name + '.translate.x-extend.x+root.format.r/2+offset.x',0)
    crop['box'].setExpression(name + '.translate.y-extend.y+root.format.t/2+offset.y',1)
    crop['box'].setExpression(name + '.translate.x+extend.x+root.format.r/2+offset.x',2)
    crop['box'].setExpression(name + '.translate.y+extend.y+root.format.t/2+offset.y',3)
Ejemplo n.º 7
0
def PointProjection():
    # create group and inputs normal and pointPosition
    nName = "pointProjection"
    hpProj = """{pointProjection \n \
    help you to find where is an animated (or not)\n \
    2d point in your 3d space and orient object \n \
    according to the surface normal and direction of \n \
    the motion. \n \n \
    input N : Normal pass \n \
    input P : Point Position \n \
    P is needed to find the 3d position \n \
    N to find the orientation \n \
    the motion is determinate by the animated point \n \n \
    current limitation : \n \
    - P must be in world space \n \
    - N must be in range -1:1 \n \
    (same has nuke ScanlineRender) \n \
    - "the direction of motion" is experimental \n \
    if you use it, you certainly must tweak the rotate Y \n \
    \n papi}"""
    p3dProj = nuke.createNode("Group",
                              "name " + nName + " help " + hpProj,
                              inpanel=True)
    tColor = long(961231103)
    p3dProj.knob('tile_color').setValue(tColor)
    del tColor
    p3dProj.begin()  # in DAG
    nuke.createNode("Input", "name N", inpanel=False)
    nuke.createNode("NoOp", "name noOpN", inpanel=False)
    nuke.createNode("Input", "name P", inpanel=False)
    nuke.createNode("NoOp", "name noOpP", inpanel=False)
    p3dProj.end()  # out DAG

    # interface
    p3dProj.addKnob(nuke.Tab_Knob("main"))
    posXY2d = nuke.XY_Knob("point")
    posXY2d.setTooltip("link or anim your point2d \n for the projection")
    p3dProj.addKnob(posXY2d)
    p3dProj.addKnob(nuke.Text_Knob(""))
    p3dProj.addKnob(nuke.PyScript_Knob("go", "go !", "papiTools.Point2Axis()"))
    p3dProj.addKnob(nuke.Text_Knob("pointProjection v0.3"))
    del p3dProj, posXY2d, nName
Ejemplo n.º 8
0
def dg_PerspLines_AddLine():

    gn = nuke.thisGroup()
    dg_PerspLines_selectOnly(gn.node('add'))
    nuke.nodeCopy('%clipboard%')
    dg_PerspLines_selectOnly(gn.node('base'))
    n = nuke.nodePaste('%clipboard%')

    tn = nuke.thisNode()

    k = nuke.XY_Knob(n.name())
    k.setValue([n.width() / 2, n.height() / 2])
    tn.addKnob(k)
    n['p'].setExpression('parent.' + n.name())

    k = nuke.PyScript_Knob('delete_' + n.name(), 'delete')
    tn.addKnob(k)
    k.clearFlag(nuke.STARTLINE)
    k.setCommand('\n'.join([
        'nuke.delete(nuke.thisGroup().node("' + n.name() + '"))',
        'nuke.thisNode().removeKnob(nuke.thisNode()["' + n.name() + '"])',
        'nuke.thisNode().removeKnob(nuke.thisKnob())'
    ]))
Ejemplo n.º 9
0
def jopsBookmarkSave(index, mode='dag'):
    tabNameString   = "DAG_Bookmarks"
    try:
        nuke.root()[tabNameString]
    except (SyntaxError, NameError):
        nuke.root().addKnob(nuke.Tab_Knob(tabNameString))
        for ind in range(1,10):
            zoomNameString  = "jops_bookmark_"+str(ind)+"_zoom"
            posNameString   = "jops_bookmark_"+str(ind)+"_pos"
            xyKnob   = nuke.XY_Knob(posNameString, str(ind))
            zoomKnob = nuke.Double_Knob(zoomNameString, "")
            zoomKnob.setFlag(nuke.NO_ANIMATION)
            zoomKnob.setFlag(nuke.DISABLED)
            xyKnob.setFlag(nuke.NO_ANIMATION)
            xyKnob.setFlag(nuke.DISABLED)
            zoomKnob.clearFlag(nuke.STARTLINE)
            nuke.root().addKnob(xyKnob)
            nuke.root().addKnob(zoomKnob)
        nuke.root().addKnob(nuke.Text_Knob("j_ops_bookmarks_note", "", "<i>DAG bookmarks are part of the J_Ops toolset available on Nukepedia</i>"))
    
    xpos = 0.0
    ypos = 0.0
    zoom = 0.0
    selectedList = []

    if mode == 'node':
        if nuke.selectedNodes():
            xposList = []
            yposList = []
            for anode in nuke.selectedNodes():
                xposList.append(anode["xpos"].getValue())
                yposList.append(anode["ypos"].getValue())
            xpos = sum(xposList, 0.0) / len(xposList)
            ypos = sum(yposList, 0.0) / len(yposList)
        else:
            return
    else:
        if nuke.selectedNodes():
            for anode in nuke.selectedNodes():
                selectedList.append(anode)
                anode["selected"].setValue(0.0)

        tempNode = nuke.createNode("Dot", inpanel=False)
        xpos = tempNode["xpos"].getValue()
        ypos = tempNode["ypos"].getValue()
        nuke.delete(tempNode)
    
    zoom = nuke.zoom()
    
    zoomNameString  = "jops_bookmark_"+str(index)+"_zoom"
    posNameString   = "jops_bookmark_"+str(index)+"_pos"
        
    nuke.root()[zoomNameString].clearFlag(nuke.DISABLED)
    nuke.root()[zoomNameString].setValue(zoom)
    nuke.root()[posNameString].clearFlag(nuke.DISABLED)
    nuke.root()[posNameString].setValue(xpos,0)
    nuke.root()[posNameString].setValue(ypos,1)
    
    if selectedList:
        for anode in selectedList:
            anode["selected"].setValue(1.0)
Ejemplo n.º 10
0
def cornerPin():
    n = nuke.thisNode()
    mc = methodClass()

    #CREATE KNOBS
    tabKnob = nuke.Tab_Knob('Options')
    methodKnob = nuke.Enumeration_Knob(
        'method', 'method',
        ['AdjustCornerPin', 'Copy4PtTrack', 'Link4PtTrack'])
    methodKnob.setTooltip(tooltips(0))
    stabilizeKnob = nuke.Boolean_Knob('stabilize')
    refFrameKnob = nuke.Int_Knob('refFrame', 'reference frame')
    refFrameKnob.setValue(nuke.Root().firstFrame())
    refFrameKnob.setEnabled(False)
    refFrameKnob.setTooltip(tooltips(1))
    enableRefFrameKnob = nuke.Boolean_Knob('enableRefFrame', '')
    enableRefFrameKnob.setFlag(nuke.ENDLINE)
    updateKnob = nuke.PyScript_Knob('update', 'Update', '%s' % mc.initial())

    fromHiddenKnob1 = nuke.XY_Knob('fromH1')
    fromHiddenKnob1.setValue(n['from1'].value())
    fromHiddenKnob1.setFlag(nuke.INVISIBLE)
    fromHiddenKnob2 = nuke.XY_Knob('fromH2')
    fromHiddenKnob2.setValue(n['from2'].value())
    fromHiddenKnob2.setFlag(nuke.INVISIBLE)
    fromHiddenKnob3 = nuke.XY_Knob('fromH3')
    fromHiddenKnob3.setValue(n['from3'].value())
    fromHiddenKnob3.setFlag(nuke.INVISIBLE)
    fromHiddenKnob4 = nuke.XY_Knob('fromH4')
    fromHiddenKnob4.setValue(n['from4'].value())
    fromHiddenKnob4.setFlag(nuke.INVISIBLE)

    toHiddenKnob1 = nuke.XY_Knob('toH1')
    toHiddenKnob1.setValue(n['to1'].value())
    toHiddenKnob1.setFlag(nuke.INVISIBLE)
    toHiddenKnob2 = nuke.XY_Knob('toH2')
    toHiddenKnob2.setValue(n['to2'].value())
    toHiddenKnob2.setFlag(nuke.INVISIBLE)
    toHiddenKnob3 = nuke.XY_Knob('toH3')
    toHiddenKnob3.setValue(n['to3'].value())
    toHiddenKnob3.setFlag(nuke.INVISIBLE)
    toHiddenKnob4 = nuke.XY_Knob('toH4')
    toHiddenKnob4.setValue(n['to4'].value())
    toHiddenKnob4.setFlag(nuke.INVISIBLE)

    snapKnob = nuke.XY_Knob('imageSize')
    snapKnob.setFlag(nuke.INVISIBLE)
    storeKnob = nuke.XY_Knob('store')
    storeKnob.setFlag(nuke.INVISIBLE)
    for i in (snapKnob, storeKnob):
        i.setValue(n.width(), 0)
        i.setValue(n.height(), 1)

    #ADD KNOBS
    n.addKnob(tabKnob)
    n.addKnob(methodKnob)
    n.addKnob(stabilizeKnob)
    n.addKnob(refFrameKnob)
    n.addKnob(enableRefFrameKnob)
    n.addKnob(updateKnob)

    n.addKnob(fromHiddenKnob1)
    n.addKnob(fromHiddenKnob2)
    n.addKnob(fromHiddenKnob3)
    n.addKnob(fromHiddenKnob4)
    n.addKnob(toHiddenKnob1)
    n.addKnob(toHiddenKnob2)
    n.addKnob(toHiddenKnob3)
    n.addKnob(toHiddenKnob4)

    n.addKnob(snapKnob)
    n.addKnob(storeKnob)
Ejemplo n.º 11
0
# CREATE GROUP NODE
# --------------------------------------------------------------
cornerPin2D_grp = nuke.nodes.Group()
cornerPin2D_grp.setName('CornerPin2D')
cornerPin2D_grp.begin()

# create the input, output, and cornerPin nodes for the group
grp_input = nuke.createNode('Input')
cornerPin = nuke.createNode('CornerPin2D')
grp_output = nuke.createNode('Output')

# --------------------------------------------------------------
# GLOBAL VARIABLES
# --------------------------------------------------------------
# create cornerPin 'to' knobs
grp_to1 = nuke.XY_Knob('to1', 'to1')
grp_to2 = nuke.XY_Knob('to2', 'to2')
grp_to3 = nuke.XY_Knob('to3', 'to3')
grp_to4 = nuke.XY_Knob('to4', 'to4')

# add the knobs to a list
cornerPin_to_knobs = []
cornerPin_to_knobs.append(grp_to1)
cornerPin_to_knobs.append(grp_to2)
cornerPin_to_knobs.append(grp_to3)
cornerPin_to_knobs.append(grp_to4)

# create cornerPin 'to enable' knobs
grp_to1_enable = nuke.Boolean_Knob('grp_enable1', 'enable1')
grp_to2_enable = nuke.Boolean_Knob('grp_enable2', 'enable2')
grp_to3_enable = nuke.Boolean_Knob('grp_enable3', 'enable3')