예제 #1
0
def imagePlane():

    g = nuke.createNode('Group')

    # ------creating knobs outside---------#

    projectionframe = nuke.Array_Knob("projectionframe", "projection frame")
    zposition = nuke.Array_Knob("zposition", "zposition")
    pickcamera = nuke.PyScript_Knob("pickcamera", "Pick Camera", "imageplane.PickCamera()")

    g.addKnob(projectionframe)
    g.addKnob(zposition)
    g.addKnob(pickcamera)

    #:::::::::::::::GROUP BEGININ:::::::::::::::
    g.begin()

    n = nuke.createNode('camera_project_1.0.0.nk')
    #hubCamera.HubCamera()
    p = nuke.selectedNode()
    k = p.knob("create_projection")
    k.execute()

    searchcamera = nuke.allNodes()
    camera = []
    for x in searchcamera:
        if x.Class() == "Camera2":
            camera.append(x)
            x["projection_frame"].setExpression("parent.projectionframe")
            x["zposition"].setExpression("parent.zposition")


    g.end()
예제 #2
0
def Smoother():

    sh = nuke.selectedNode()
    sh.addKnob(nuke.Array_Knob("sm_gl", "smooth global"))
    sh['sm_gl'].setValue(1)
    sh.addKnob(nuke.XYZ_Knob("sm_t", "smooth translation"))
    sh['sm_t'].setValue(1)
    sh.addKnob(nuke.XYZ_Knob("sm_r", "smooth rotation"))
    sh['sm_r'].setValue(1)
    sh.addKnob(nuke.XYZ_Knob("shaked_translate"))
    sh.addKnob(nuke.XYZ_Knob("shaked_rotate"))
    sh['shaked_translate'].copyAnimations(sh['translate'].animations())
    sh['shaked_rotate'].copyAnimations(sh['rotate'].animations())

    eTx = "shaked_translate.x.integrate(frame-sm_gl*sm_t.x,frame+sm_gl*sm_t.x)/(2*sm_gl*sm_t.x)"
    sh['translate'].setExpression(eTx, 0)
    eTy = "shaked_translate.y.integrate(frame-sm_gl*sm_t.y,frame+sm_gl*sm_t.y)/(2*sm_gl*sm_t.y)"
    sh['translate'].setExpression(eTy, 1)
    eTz = "shaked_translate.z.integrate(frame-sm_gl*sm_t.z,frame+sm_gl*sm_t.z)/(2*sm_gl*sm_t.z)"
    sh['translate'].setExpression(eTz, 2)
    eRx = "shaked_rotate.x.integrate(frame-sm_gl*sm_r.x,frame+sm_gl*sm_r.x)/(2*sm_gl*sm_r.x)"
    sh['rotate'].setExpression(eRx, 0)
    eRy = "shaked_rotate.y.integrate(frame-sm_gl*sm_r.y,frame+sm_gl*sm_r.y)/(2*sm_gl*sm_r.y)"
    sh['rotate'].setExpression(eRy, 1)
    eRz = "shaked_rotate.z.integrate(frame-sm_gl*sm_r.z,frame+sm_gl*sm_r.z)/(2*sm_gl*sm_r.z)"
    sh['rotate'].setExpression(eRz, 2)
    sh['label'].setValue("smoothed")
    sh['tile_color'].setValue(65280L)
예제 #3
0
    def test_node(self):
        yr.YNode("").create("TimeWarp")

        if hasattr(yr.meta, "knob"):
            import nuke
            b = nuke.toNode("aaa")
            k = nuke.Array_Knob("name", "label")
            b.addKnob(k)
예제 #4
0
    def __init__(self):
        """
        Adding knobs to UI panel.
        """
        nukescripts.PythonPanel.__init__(
            self, "Multi Knob Values", "com.parimalvfx.MultiKnobValuesPanel")

        self.note = nuke.Text_Knob("note", "",
                                   "Enter knob calling Name and Value")
        self.div0 = nuke.Text_Knob("div0", "", " ")
        self.intFloat = nuke.Text_Knob(
            "intFloat", "", "<font color='grey'><b>Integer/Float</b></font>")
        self.knob1 = nuke.String_Knob("knob1", "Knob 1")
        self.value1 = nuke.Array_Knob("value1", " = Value 1")
        self.value1.clearFlag(nuke.STARTLINE)
        self.knob2 = nuke.String_Knob("knob2", "Knob 2")
        self.value2 = nuke.Array_Knob("value2", " = Value 2")
        self.value2.clearFlag(nuke.STARTLINE)
        self.knob3 = nuke.String_Knob("knob3", "Knob 3")
        self.value3 = nuke.Array_Knob("value3", " = Value 3")
        self.value3.clearFlag(nuke.STARTLINE)
        self.div1 = nuke.Text_Knob("div1", "", " ")
        self.strEnu = nuke.Text_Knob(
            "strEnu", "",
            "<font color='grey'><b>String/Enumeration</b></font>")
        self.knob4 = nuke.String_Knob("knob4", "Knob 4")
        self.value4 = nuke.String_Knob("value4", " = Value 4")
        self.value4.clearFlag(nuke.STARTLINE)
        self.knob5 = nuke.String_Knob("knob5", "Knob 5")
        self.value5 = nuke.String_Knob("value5", " = Value 5")
        self.value5.clearFlag(nuke.STARTLINE)
        self.knob6 = nuke.String_Knob("knob6", "Knob 6")
        self.value6 = nuke.String_Knob("value6", " = Value 6")
        self.value6.clearFlag(nuke.STARTLINE)
        self.div2 = nuke.Text_Knob("div2", "", " ")

        for each in (self.note, self.div0, self.intFloat, self.knob1,
                     self.value1, self.knob2, self.value2, self.knob3,
                     self.value3, self.div1, self.strEnu, self.knob4,
                     self.value4, self.knob5, self.value5, self.knob6,
                     self.value6, self.div2):
            self.addKnob(each)
예제 #5
0
        def __init__(self):
            nukescripts.PythonPanel.__init__(self, 'Fader menu')

            self.Value = nuke.Array_Knob("value", 'value', 4)
            self.Value.setValue(0, 0)
            self.Value.setValue(curValue, 1)
            self.Value.setValue(curValue, 2)
            self.Value.setValue(0, 3)

            self.Frame = nuke.Array_Knob("frame", 'frame', 4)
            self.Frame.setValue(inFrame, 0)
            self.Frame.setValue(curFrameA, 1)
            self.Frame.setValue(curFrameA, 2)
            self.Frame.setValue(outFrame, 3)

            self.Check = nuke.Boolean_Knob('Delete Current Animation')
            self.addKnob(self.Check)

            for k in (self.Frame, self.Value):
                self.addKnob(k)
예제 #6
0
    def setup(cls, groupmo):
        """Builds all the interior nodes and knobs of SpillSuppress"""

        # =====================================================================
        # Nodes
        # =====================================================================

        # Input ===============================================================

        input_node = nuke.nodes.Input()
        dot = nuke.nodes.Dot(
            inputs=[input_node],
            xpos=input_node.xpos() + 40 - 6,
            ypos=input_node.ypos() + 100
        )

        # Shuffles ============================================================

        def set_shuffle(shuffle, color):
            """Sets all the color channels of a shuffle to be the same color"""
            shuffle['red'].setValue(color)
            shuffle['green'].setValue(color)
            shuffle['blue'].setValue(color)
            shuffle['alpha'].setValue('white')

        # Shuffle to extract the green channel
        green_shuffle = nuke.nodes.Shuffle(
            inputs=[dot],
            name='Green',
            xpos=input_node.xpos(),
            ypos=dot.ypos() + 100
        )
        set_shuffle(green_shuffle, 'green')

        # Shuffle to extract the red channel
        red_shuffle = nuke.nodes.Shuffle(
            inputs=[dot],
            name='Red',
            xpos=green_shuffle.xpos() - 160,
            ypos=green_shuffle.ypos()
        )
        set_shuffle(red_shuffle, 'red')

        # Shuffle to extract the blue channel
        blue_shuffle = nuke.nodes.Shuffle(
            inputs=[dot],
            name='Blue',
            xpos=green_shuffle.xpos() + 160,
            ypos=green_shuffle.ypos()
        )
        set_shuffle(blue_shuffle, 'blue')

        dot2 = nuke.nodes.Dot(
            inputs=[dot],
            xpos=blue_shuffle.xpos() + 160,
            ypos=blue_shuffle.ypos() + 4,
        )

        # Color Switches ======================================================

        # This will autoswitch from green primary to blue primary, depending
        # on which color has a higher value.
        main_switch = nuke.nodes.Switch(
            inputs=[blue_shuffle, green_shuffle],
            name='BGSwitch',
            xpos=blue_shuffle.xpos(),
            ypos=blue_shuffle.ypos() + 100
        )
        # We set this to an expression which looks at the AutoBalance node.
        # Expression Reads:
        # If AutoBalance's Source Color Green channel minus the Blue channel is
        # greater than 0, value should be 1. Else, value should be 0.
        main_switch['which'].setExpression(
            'AutoBalance.source.g - AutoBalance.source.b > 0 ? 1 : 0'
        )

        # Inverse Switch (will be the opposite of Main Switch)
        inverse_switch = nuke.nodes.Switch(
            inputs=[green_shuffle, blue_shuffle],
            name='BGSwitchInverse',
            xpos=green_shuffle.xpos(),
            ypos=green_shuffle.ypos() + 100
        )
        inverse_switch['which'].setExpression(
            'BGSwitch.which'
        )

        # Channel Mixing ======================================================

        # These nodes will determine how the alternate color channels
        # (the color channels that are NOT the spill channel) are mixed
        # together to help determine how much of the spill channel is spill.
        cross = nuke.nodes.Merge2(
            inputs=[red_shuffle, inverse_switch],
            name='Cross',
            xpos=red_shuffle.xpos(),
            ypos=red_shuffle.ypos() + 200)
        cross.addKnob(nuke.Array_Knob('chanMix', 'channel mix'))
        cross['chanMix'].setValue(0.5)
        cross['chanMix'].setTooltip(
            "Adjust the weighted average of the alternate color channels. 0 "
            "is always the full red channel, 1 is either the blue or green "
            "channel. If the spill color is blue, 1 is the green channel and "
            "vice versa."
        )
        cross['chanMix'].setFlag(flags.SLIDER)
        cross['chanMix'].setFlag(flags.FORCE_RANGE)
        cross['mix'].setExpression('chanMix')

        max = nuke.nodes.Merge2(
            inputs=[red_shuffle, inverse_switch],
            name='Max',
            xpos=cross.xpos() - 160,
            ypos=cross.ypos(),
        )
        max['operation'].setValue('max')

        # Mix Switch will be a user controlled switch. When checked, it will
        # use the Max method instead of Crossing between the two.
        mix_switch = nuke.nodes.Switch(
            inputs=[cross, max],
            name='MaxOrCross',
            xpos=cross.xpos(),
            ypos=cross.ypos() + 100
        )
        mix_switch['which'].setExpression('parent.useMax')

        # Spill Controls ======================================================

        # These control the ebb and flow of the spill mask.
        thresh_gamma = nuke.nodes.Gamma(
            inputs=[mix_switch],
            name='ThresholdGamma',
            xpos=mix_switch.xpos(),
            ypos=mix_switch.ypos() + 26
        )
        thresh_gamma['value'].setExpression('parent.gamma')

        thresh_gain = nuke.nodes.Multiply(
            inputs=[thresh_gamma],
            name='ThresholdGain',
            xpos=thresh_gamma.xpos(),
            ypos=thresh_gamma.ypos() + 38)
        thresh_gain['value'].setExpression('parent.gain')

        # Spill Removal =======================================================

        # After the adjustments to the spill matte with gain and gamma, we
        # can now subtract the spill.
        subtract_spill = nuke.nodes.Merge2(
            inputs=[thresh_gain, main_switch],
            name='SubtractSpill',
            xpos=main_switch.xpos(),
            ypos=thresh_gain.ypos() + 6,
        )
        subtract_spill['operation'].setValue('minus')

        remove_negatives = nuke.nodes.Expression(
            inputs=[subtract_spill],
            name='RemoveNegatives',
            xpos=subtract_spill.xpos(),
            ypos=subtract_spill.ypos() + 26
        )
        remove_negatives['expr0'].setValue('r>0?r:0')
        remove_negatives['expr1'].setValue('g>0?g:0')
        remove_negatives['expr2'].setValue('b>0?b:0')

        # Balancing ===========================================================

        # These nodes, by way of adding or removing spill channel, determine
        # the resultant color balance of the shot.
        auto_balance = nuke.nodes.Expression(
            inputs=[remove_negatives],
            name='AutoBalance',
            xpos=remove_negatives.xpos() - 80,
            ypos=remove_negatives.ypos() + 100
        )

        # We'll be using these variables in the channel calculations
        #
        # Essentially, we're determining the multiplier value needed to get
        # from the despilled source color to the destination color.
        # Most of these calculations are determining what the despilled
        # color will look like.
        auto_balance['temp_name0'].setValue('bspill')
        auto_balance['temp_expr0'].setValue(
            'source.b - pow(source.r * (1 - Cross.mix) '
            '+ source.g * Cross.mix, 1 / (ThresholdGamma.value '
            '+ 0.000001) ) * ThresholdGain.value'
        )
        auto_balance['temp_name1'].setValue('gspill')
        auto_balance['temp_expr1'].setValue(
            'source.g - pow(source.r * (1 - Cross.mix) '
            '+ source.b * Cross.mix, 1 / (ThresholdGamma.value '
            '+ 0.000001) ) * ThresholdGain.value'
        )
        # This expression simply compares the two colors to determine which
        # spill calculation to use, then we'll that below.
        auto_balance['temp_name2'].setValue('spill')
        auto_balance['temp_expr2'].setValue(
            'source.g - source.b > 0 ? gspill : bspill'
        )

        auto_balance['expr0'].setValue(
            'r * (dest.r - source.r) / spill'
        )
        auto_balance['expr1'].setValue(
            'g * (dest.g - source.g) / spill'
        )
        auto_balance['expr2'].setValue(
            'b * (dest.b - source.b) / spill'
        )

        # Now we need to add the knobs it's referencing to the AutoBalance
        # node.
        auto_balance.addKnob(nuke.Tab_Knob('spillcontrols', 'Spill Controls'))
        auto_balance.addKnob(nuke.Color_Knob('source', 'Source Color'))
        auto_balance.addKnob(nuke.Color_Knob('dest', 'Destination Color'))
        auto_balance['source'].setValue([0.1, 0.2, 0.3])
        auto_balance['dest'].setValue([0.3, 0.3, 0.3])

        # Auto Balancing Tooltips
        auto_balance['source'].setTooltip(
            "Color of spill to remove. This color will be used to determine if "
            "the screen color is blue or green, based on which color channel"
            "has a higher value."
        )
        auto_balance['dest'].setTooltip(
            "Color to change the spill color to. This should be a sampled "
            "average of the background behind your character. This color is "
            "normally not the neutral grey most spill suppression corrects to. "
            "Spill suppression should not only suppress the spill color, but "
            "transform the spill and reflected spill to reflect the "
            "environment. This will lead to better edges and color. "
            "Extremely bright or dark values will break. Adjust values until "
            "result is no longer 'grainy.'"
        )

        # Manual Balancing
        manual_balance = nuke.nodes.Multiply(
            inputs=[remove_negatives],
            name='ManualBalance',
            channels='rgb',
            xpos=remove_negatives.xpos() + 80,
            ypos=auto_balance.ypos(),
        )
        # We need to set the values to trigger the channels to split.
        manual_balance['value'].setValue([0.1, 0.1, 0.1, 1])
        # But now we can set their expressions
        manual_balance['value'].setExpression('AutoBalance.dest.r', 0)
        manual_balance['value'].setExpression('AutoBalance.dest.g', 1)
        manual_balance['value'].setExpression('AutoBalance.dest.b', 2)

        auto_switch = nuke.nodes.Switch(
            inputs=[auto_balance, manual_balance],
            name='AutoManualSwitch',
            xpos=remove_negatives.xpos(),
            ypos=remove_negatives.ypos() + 200
        )
        auto_switch['which'].setExpression('parent.useManual')

        blur = nuke.nodes.Blur(
            inputs=[auto_switch],
            name='BlurSpill',
            xpos=auto_switch.xpos(),
            ypos=auto_switch.ypos() + 26
        )

        dot3 = nuke.nodes.Dot(
            inputs=[dot2],
            xpos=dot2.xpos(),
            ypos=blur.ypos() + 42,
        )

        remove_spill = nuke.nodes.Merge2(
            inputs=[dot3, blur],
            name='RemoveSpill',
            xpos=blur.xpos(),
            ypos=blur.ypos() + 38,
        )
        remove_spill['operation'].setValue('plus')

        # Output ==============================================================

        copy_channels = nuke.nodes.Copy(
            inputs=[dot3, remove_spill],
            name='ProtectAll',
            xpos=remove_spill.xpos(),
            ypos=remove_spill.ypos() + 100
        )
        copy_channels['from0'].setValue('rgba.red')
        copy_channels['from1'].setValue('rgba.green')
        copy_channels['from2'].setValue('rgba.blue')
        copy_channels['to0'].setValue('rgba.red')
        copy_channels['to1'].setValue('rgba.green')
        copy_channels['to2'].setValue('rgba.blue')

        nuke.nodes.Output(
            inputs=[copy_channels],
            xpos=copy_channels.xpos(),
            ypos=copy_channels.ypos() + 100
        )

        # =====================================================================
        # Knobs
        # =====================================================================

        set_link('source', groupmo, auto_balance)

        groupmo.addKnob(nuke.Text_Knob('source_divider', ''))

        set_link('chanMix', groupmo, cross)
        use_max = nuke.Boolean_Knob('useMax', 'use maximum for mix')
        use_max.clearFlag(nuke.STARTLINE)
        use_max.setTooltip(
            "Instead of averaging the alternate color channels, use a max "
            "operation to combine them."
        )
        groupmo.addKnob(use_max)

        gain = nuke.Array_Knob('gain', 'gain')
        gamma = nuke.Array_Knob('gamma', 'gamma')
        gamma.clearFlag(nuke.STARTLINE)
        gain.setValue(0.95)
        gamma.setValue(0.95)
        gain.setFlag(flags.SLIDER)
        gain.setFlag(flags.LOG_SLIDER)
        gamma.setFlag(flags.SLIDER)
        gamma.setFlag(flags.LOG_SLIDER)
        gain.setTooltip(
            "Multiples the spill threshold to increase or decrease what gets "
            "considered spill. Has a larger effect on brighter areas."
        )
        gamma.setTooltip(
            "Does a gamma operation on the spill threshold, which has a "
            "larger effect on midtones."
        )
        groupmo.addKnob(gain)
        groupmo.addKnob(gamma)

        set_link('size', groupmo, blur, label='blur spill')

        groupmo.addKnob(nuke.Text_Knob('destination_divider', ''))

        set_link('dest', groupmo, auto_balance)
        use_manual = nuke.Boolean_Knob('useManual', 'use for manual balancing')
        use_manual.clearFlag(nuke.STARTLINE)
        use_manual.setTooltip(
            "If selected, the Destination Color will instead become a manual "
            "gain control for the final result."
        )
        groupmo.addKnob(use_manual)

        # =====================================================================
        # Callbacks
        # =====================================================================

        groupmo['knobChanged'].setValue(
            'keying.SpillSuppress.disable_channel_mix_callback()'
        )
예제 #7
0
def setNode():
	'''builds controls
	return: n (obj)
	'''

	n = nuke.nodes.NoOp()
	n.setName('ku_FlickerWaves')
	n['label'].setValue('[format "%.2f" [value wave]]')
	n['note_font'].setValue('Bold')
	n['note_font_size'].setValue(24)
	n['tile_color'].setValue(4290707711)
	n['hide_input'].setValue(True)
	nuke.zoom(2, [n.xpos(),n.ypos()])
	print "Created %s" % n.name()

	# First Tab
	k_tab = nuke.Tab_Knob('tb_main', 'ku_FlickerWaves')

	k_output = nuke.Array_Knob('wave', 'output wave',1)
	k_output.setEnabled(False)
	k_edit = nuke.Boolean_Knob('edit','enable')
	k_edit.clearFlag(nuke.STARTLINE)
	k_global_amp = nuke.Double_Knob('g_amp', 'global amp')
	k_global_freq = nuke.Double_Knob('g_freq', 'global freq')
	k_fade = nuke.Double_Knob('fade','fade')

	k_div1 = nuke.Text_Knob('','')

	k_tx1 = nuke.Text_Knob('','Array Order',"[Base Wave, Mid Wave, High Wave]")
	k_seed = nuke.Array_Knob('seed','seed',3)
	k_amp_ratio = nuke.Array_Knob('amp_ratio','amp ratio',3)
	k_freq_ratio = nuke.Array_Knob('freq_ratio','freq ratio',3)
	k_shift = nuke.Double_Knob('shift','base shift')
	k_timeoffset = nuke.Array_Knob('timeoffset','timeoffset',3)

	k_div2 = nuke.Text_Knob('','')
	k_link = nuke.PyScript_Knob('bt_link','link to selected<br><b>Multiply</b> node','')
	k_curve = nuke.PyScript_Knob('bt_curve','Show in<br><b>Curve Editor</b>',"nuke.tcl('curve_editor')")
	k_curve.clearFlag(nuke.STARTLINE)

	# Second Tab
	k_secondary = nuke.Tab_Knob('tb_secondary','Output Waves')

	k_b_out = nuke.Double_Knob('base_freq', 'base freq')
	k_m_out = nuke.Double_Knob('mid_freq', 'mid freq')
	k_h_out = nuke.Double_Knob('high_freq', 'high freq')

	# Set default values
	k_fade.setValue(1)
	k_global_amp.setValue(1)
	k_global_amp.setRange(1,2)
	k_global_freq.setValue(1)
	k_global_freq.setRange(1,2)
	k_seed.setValue([666,888,686])
	k_amp_ratio.setValue([1,0.25,0.125])
	k_freq_ratio.setValue([0.25,0.5,1])
	k_shift.setRange(-1,1)

	ls_knob = [k_tab, k_output, k_edit ,k_global_amp, k_global_freq, k_fade, k_div1,k_tx1,k_seed,k_amp_ratio,k_freq_ratio,k_shift,k_timeoffset,k_div2,k_link,k_curve,k_secondary,k_b_out,k_m_out,k_h_out]
	for k in ls_knob:
		n.addKnob(k)

	return n
예제 #8
0
def CP_to_Matrix():

    node = nuke.thisNode()
    parentNode = node.input(0)
    imageWidth = float(node.width())
    imageHeight = float(node.height())
    xps = node['xpos'].value()
    yps = node['ypos'].value()

    #CREATING EMPTY MATRICES
    cornerPinMatrixTo = nuke.math.Matrix4()
    cornerPinMatrixFrom = nuke.math.Matrix4()

    #CREATING KNOBS
    baked = nuke.nodes.CornerPin2D(name=node.name() + '_Matrix',
                                   xpos=xps + 100,
                                   ypos=yps)
    baked['from2'].setValue(imageWidth, 0)
    baked['from3'].setValue(imageWidth, 0)
    baked['from3'].setValue(imageHeight, 1)
    baked['from4'].setValue(imageHeight, 1)
    baked['to2'].setValue(imageWidth, 0)
    baked['to3'].setValue(imageWidth, 0)
    baked['to3'].setValue(imageHeight, 1)
    baked['to4'].setValue(imageHeight, 1)
    baked.setInput(0, parentNode)
    tab = nuke.Tab_Knob('plus', 'plus')
    switcher = nuke.Enumeration_Knob('switcher', 'Matrix Type', [
        'All', 'Scale Only', 'Rotation Only', 'Translate Only',
        'ScaleAndRotate Only'
    ])
    finalMatrixArr = nuke.Array_Knob('finalMatrixKnob', 'All', 16)
    mtxScaleArr = nuke.Array_Knob('mtxScaleKnob', 'Scale Only', 16)
    mtxRotationArr = nuke.Array_Knob('mtxRotationKnob', 'Rotation Only', 16)
    mtxTranslationArr = nuke.Array_Knob('mtxTranslationKnob', 'Translate Only',
                                        16)
    mtxScaleRotationArr = nuke.Array_Knob('mtxScaleRotationKnob',
                                          'ScaleAndRotate Only', 16)
    #ADDING KNOBS
    check = node.knob('plus')
    if check is not None:
        baked.addKnob(switcher)
        for each in (finalMatrixArr, mtxScaleArr, mtxRotationArr,
                     mtxTranslationArr, mtxScaleRotationArr):
            baked.addKnob(each)
            each.setVisible(False)
    else:
        baked.addKnob(tab)
        baked.addKnob(switcher)
        for each in (finalMatrixArr, mtxScaleArr, mtxRotationArr,
                     mtxTranslationArr, mtxScaleRotationArr):
            baked.addKnob(each)
            each.setVisible(False)

    #FRAME RANGE
    range = nuke.getFramesAndViews(
        'Get Frame Range',
        '%s-%s' % (nuke.root().firstFrame(), nuke.root().lastFrame()))
    frange = nuke.FrameRange(range[0])

    for n in frange:
        #GETTING KNOBS VALUES
        vectorsTo = [
            nuke.math.Vector2(node[f].getValueAt(n)[0],
                              node[f].getValueAt(n)[1])
            for f in sorted(node.knobs().keys()) if f.startswith('to')
        ]
        vectorsFrom = [
            nuke.math.Vector2(node[f].getValueAt(n)[0],
                              node[f].getValueAt(n)[1])
            for f in sorted(node.knobs().keys()) if f.startswith('from')
        ]

        #CONVERTING CORNER PIN TO MATRICES
        cornerPinMatrixTo.mapUnitSquareToQuad(vectorsTo[0].x, vectorsTo[0].y,
                                              vectorsTo[1].x, vectorsTo[1].y,
                                              vectorsTo[2].x, vectorsTo[2].y,
                                              vectorsTo[3].x, vectorsTo[3].y)
        cornerPinMatrixFrom.mapUnitSquareToQuad(
            vectorsFrom[0].x, vectorsFrom[0].y, vectorsFrom[1].x,
            vectorsFrom[1].y, vectorsFrom[2].x, vectorsFrom[2].y,
            vectorsFrom[3].x, vectorsFrom[3].y)

        #FINAL MATRIX VALUE
        finalMatrix = cornerPinMatrixTo * cornerPinMatrixFrom.inverse()
        finalMatrix.transpose()

        #DERIVATIVES
        mtxRotation = nuke.math.Matrix4(finalMatrix)
        mtxRotation.rotationOnly()
        mtxScale = nuke.math.Matrix4(finalMatrix)
        mtxScale.scaleOnly()
        mtxTranslation = nuke.math.Matrix4(finalMatrix)
        mtxTranslation.translationOnly()
        mtxScaleRotation = nuke.math.Matrix4(finalMatrix)
        mtxScaleRotation.scaleAndRotationOnly()
        #SET ANIMATED
        baked['finalMatrixKnob'].setAnimated()
        baked['mtxScaleKnob'].setAnimated()
        baked['mtxRotationKnob'].setAnimated()
        baked['mtxTranslationKnob'].setAnimated()
        baked['mtxScaleRotationKnob'].setAnimated()

        #ASSIGNING MATRICES TO KNOBS
        knobsCount = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

        [(baked['finalMatrixKnob'].setValueAt(finalMatrix[i], n, i))
         for i in knobsCount]
        [(baked['mtxScaleKnob'].setValueAt(mtxScale[i], n, i))
         for i in knobsCount]
        [(baked['mtxRotationKnob'].setValueAt(mtxRotation[i], n, i))
         for i in knobsCount]
        [(baked['mtxTranslationKnob'].setValueAt(mtxTranslation[i], n, i))
         for i in knobsCount]
        [(baked['mtxScaleRotationKnob'].setValueAt(mtxScaleRotation[i], n, i))
         for i in knobsCount]

    baked['transform_matrix'].setExpression('finalMatrixKnob')
    print finalMatrix
예제 #9
0
            def __init__(self, node):
                nukescripts.PythonPanel.__init__(self, "Multi Knob Values")
                self.setMinimumSize(370, 250)
                self.note = nuke.Text_Knob(
                    "note", "", "Enter knob calling Name and Value")
                self.blank1 = nuke.Text_Knob("blank1", "", " ")
                self.knob1 = nuke.String_Knob("konb1", "Knob 1")
                self.value1 = nuke.Array_Knob("value1", " = Value 1")
                self.value1.clearFlag(nuke.STARTLINE)
                self.knob2 = nuke.String_Knob("knob2", "Knob 2")
                self.value2 = nuke.Array_Knob("value2", " = Value 2")
                self.value2.clearFlag(nuke.STARTLINE)
                self.knob3 = nuke.String_Knob("knob3", "Knob 3")
                self.value3 = nuke.Array_Knob("value3", " = Value 3")
                self.value3.clearFlag(nuke.STARTLINE)
                self.knob4 = nuke.String_Knob("knob4", "Knob 4")
                self.value4 = nuke.Array_Knob("value4", " = Value 4")
                self.value4.clearFlag(nuke.STARTLINE)
                self.knob5 = nuke.String_Knob("knob5", "Knob 5")
                self.value5 = nuke.Array_Knob("value5", " = Value 5")
                self.value5.clearFlag(nuke.STARTLINE)
                self.blank2 = nuke.Text_Knob("blank2", "", " ")
                self.help = nuke.PyScript_Knob(
                    "help", "Help",
                    """class HelpPanel( nukescripts.PythonPanel ):
	def __init__( pan, node ):
		nukescripts.PythonPanel.__init__(pan, "Multi Knob Values Help")
		pan.setMinimumSize(830, 455)
		pan.h1 = nuke.Text_Knob("h1", "", "<font color = 'grey' size = '5'><b>Multi Knob Values</b></font><font color = 'grey' size = '3'> v1.0</font>")
		pan.h2 = nuke.Text_Knob("h2", "", "<font color = 'white'><b>Change multiple knob values of selected nodes.</font>")
		pan.gp1 = nuke.Text_Knob("gp1", "", " ")
		pan.h3 = nuke.Text_Knob("h3", "", "<font color = 'grey' size = '5'><b>Step</b>By<b>Step</b>")
		pan.h4 = nuke.Text_Knob("h4", "", "<font color = 'lightgreen'><p><b>#Step 1:</b> Select nodes to change knob values.</p><p><b>#Step 2:</b> Run 'Multi Knob Values'</p><p><b>#Step 3:</b> Enter knob calling name of your desired knob in any of the Knob inputs.</p><p><b>#Step 4:</b> Enter desired value for that knob in Value input.<p></p>")
		pan.h5 = nuke.Text_Knob("h5", "", "<font color = 'grey' size = '5'><b>Caution</font>")
		pan.h6 = nuke.Text_Knob("h6", "", "<font color = 'red'><b><p>#Make sure the value of knob which you are wanting to change, that knob is available in all selected nodes.</p><p>#Currently only numerical and boolean values are supported for Value input.</p><p>#If you try to set knob values other than numericals and boolean, no value will get applied to that knob.</p><p>#If you write only knob calling name and don't assign any value to it then 0 value will get applied to that knob.</p><p></p>")
		pan.support = nuke.Text_Knob("support", "<b>Support</b>")
		pan.documentation = nuke.PyScript_Knob("documentation", "Documentation", '''for search in nuke.pluginPath():
	path = os.path.dirname(search) + "/documentation/MultiKnobValuesv10.html"
	if os.path.exists(path):
		webbrowser.open("file:///" + path)
		break
	else:
		if nuke.ask("Pr_Suite documentation not found in expected installation directory. Click 'Yes' to access online Pr_Suite documentation."):
			webbrowser.open("http://www.parimalvfx.com/rnd/pr_suite/documentation/")
		break''')
		pan.documentation.clearFlag( nuke.STARTLINE )
		pan.report_bug = nuke.PyScript_Knob("report_bug", "Report Bug", "webbrowser.open('http://www.parimalvfx.com/rnd/pr_suite/report-bug/')")
		pan.report_bug.clearFlag( nuke.STARTLINE )
		pan.check_updates = nuke.PyScript_Knob("check_updates", "Check for Updates", "webbrowser.open('http://www.parimalvfx.com/rnd/pr_suite/python-scripts/')")
		pan.gp2 = nuke.Text_Knob("gp2", "       ", "")
		pan.gp3 = nuke.Text_Knob("gp3", "", " ")
		
		for insert in ( pan.h1, pan.h2, pan.gp1, pan.h3, pan.h4, pan.h5, pan.h6, pan.support, pan.documentation, pan.report_bug, pan.check_updates, pan.gp2, pan.gp3 ):
			pan.addKnob( insert )

show = HelpPanel( "node" )
show.showModal()""")

                for add in (self.note, self.blank1, self.knob1, self.value1,
                            self.knob2, self.value2, self.knob3, self.value3,
                            self.knob4, self.value4, self.knob5, self.value5,
                            self.blank2, self.help):
                    self.addKnob(add)