Пример #1
0
    def set_channel_key_frames_in_bulk(k_channel_obj, times, values):
        knob = k_channel_obj.knob()
        node_obj = knob.node()
        converter = get_kiko_to_nuke_converter(node_obj, knob)
        if converter:
            index = k_channel_obj.knobIndex()
            keys = [nuke.AnimationKey(times[i],
                                      converter(node_obj, knob, index,
                                                values[i], t=times[i]))
                    for i in range(times)]
        else:
            keys = [nuke.AnimationKey(times[i], values[i])
                    for i in range(len(times))]

        k_channel_obj.addKey(keys)
Пример #2
0
def create_tracker3(trackers, label=''):
    """ Creates an old tracker3 node.
    It is prefered to use the tracker4 instead."""
    def iter_chunk(lst, size):
        """Yield successive n-sized chunks from lst"""
        for i in xrange(0, len(lst), size):
            yield lst[i:i + size]

    nodes = []
    # Chunk tracks by 4
    for chunks in iter_chunk(trackers, 4):
        # Create node
        node = nuke.nodes.Tracker3()
        nodes.append(node)
        if label:
            node['label'].setValue(label)
            node['enable1'].setFlag(0)
        for idx, track in enumerate(chunks, 1):
            # knobs
            node['enable{0}'.format(idx)].setValue('true')
            knob = node['track{0}'.format(idx)]
            knob.setAnimated()
            anim_x = knob.animation(0)
            anim_y = knob.animation(1)
            # animation
            keys_x = [
                nuke.AnimationKey(key['frame'], key['x'])
                for key in track['keys']
            ]
            keys_y = [
                nuke.AnimationKey(key['frame'], key['y'])
                for key in track['keys']
            ]
            anim_x.addKey(keys_x)
            anim_y.addKey(keys_y)
    return nodes
Пример #3
0
def bake(nodes, start, end):
    for node in nodes:
        for knob in list(node.knobs().values()):
            if isinstance(knob, nuke.Link_Knob):
                knob = knob.getLinkedKnob()
            if knob.hasExpression():
                if knob.singleValue():
                    array_size = 1
                else:
                    array_size = knob.arraySize()
                for index in range(array_size):
                    if knob.hasExpression(index):
                        anim = knob.animation(index)
                        anim_keys = []
                        for frame in range(start, end + 1):
                            anim_keys.append(nuke.AnimationKey(frame, anim.evaluate(frame)))
                        anim.addKey(anim_keys)
                        knob.setExpression("curve", index)
                        if anim.constant():
                            knob.clearAnimated(index)
Пример #4
0
def createNukeCornerPinNode(coordinatesArray):

    global frameHeight

    global frameOffset

    cornerPinNode = nuke.nodes.CornerPin2D(label='imported_Mocha-AE_Track')

    cornerPinNode['enable1'].setValue('true')
    cornerPinNode['enable2'].setValue('true')
    cornerPinNode['enable3'].setValue('true')
    cornerPinNode['enable4'].setValue('true')

    # LOWER LEFT

    track1 = cornerPinNode['to1']
    track1.setAnimated()
    track1keysX = []
    track1keysY = []

    for j in coordinatesArray[0]:
        tFrame = int(j[0]) + frameOffset
        tX = float(j[1])
        tY = frameHeight - float(j[2])

        track1keysX.append((tFrame, tX))
        track1keysY.append((tFrame, tY))

    #print "track1keysX: %s" % len(track1keysX)
    #print "track1keysY: %s" % len(track1keysY)

    # LOWER RIGHT

    track2 = cornerPinNode['to2']
    track2.setAnimated()
    track2keysX = []
    track2keysY = []

    for j in coordinatesArray[1]:
        tFrame = int(j[0]) + frameOffset
        tX = float(j[1])
        tY = frameHeight - float(j[2])

        track2keysX.append((tFrame, tX))
        track2keysY.append((tFrame, tY))

    #print "track2keysX: %s" % len(track1keysX)
    #print "track2keysY: %s" % len(track1keysY)

    # UPPER RIGHT

    track3 = cornerPinNode['to3']
    track3.setAnimated()
    track3keysX = []
    track3keysY = []

    for j in coordinatesArray[3]:
        tFrame = int(j[0]) + frameOffset
        tX = float(j[1])
        tY = frameHeight - float(j[2])

        track3keysX.append((tFrame, tX))
        track3keysY.append((tFrame, tY))

    #print "track3keysX: %s" % len(track3keysX)
    #print "track3keysY: %s" % len(track3keysY)

    # UPPER LEFT

    track4 = cornerPinNode['to4']
    track4.setAnimated()
    track4keysX = []
    track4keysY = []

    for j in coordinatesArray[2]:
        tFrame = int(j[0]) + frameOffset
        tX = float(j[1])
        tY = frameHeight - float(j[2])

        track4keysX.append((tFrame, tX))
        track4keysY.append((tFrame, tY))

    #print "track4keysX: %s" % len(track4keysX)
    #print "track4keysY: %s" % len(track4keysY)

    track1animX = track1.animation(0)
    track1animX.addKey(
        [nuke.AnimationKey(frame, value) for (frame, value) in track1keysX])

    track1animY = track1.animation(1)
    track1animY.addKey(
        [nuke.AnimationKey(frame, value) for (frame, value) in track1keysY])

    track2animX = track2.animation(0)
    track2animX.addKey(
        [nuke.AnimationKey(frame, value) for (frame, value) in track2keysX])

    track2animY = track2.animation(1)
    track2animY.addKey(
        [nuke.AnimationKey(frame, value) for (frame, value) in track2keysY])

    track3animX = track3.animation(0)
    track3animX.addKey(
        [nuke.AnimationKey(frame, value) for (frame, value) in track3keysX])

    track3animY = track3.animation(1)
    track3animY.addKey(
        [nuke.AnimationKey(frame, value) for (frame, value) in track3keysY])

    track4animX = track4.animation(0)
    track4animX.addKey(
        [nuke.AnimationKey(frame, value) for (frame, value) in track4keysX])

    track4animY = track4.animation(1)
    track4animY.addKey(
        [nuke.AnimationKey(frame, value) for (frame, value) in track4keysY])

    nuke.show(cornerPinNode)

    nuke.zoom(1, (cornerPinNode.xpos(), cornerPinNode.ypos()))

    return
def set_knob(knob, values, frames, cleanup=False):
    '''
	Set the knob value(s) using either knob.setValue or directly on the AnimCurve.

	Args:
		knob (obj): A knob object.
		values (list): A list of values.
		frames (list): A list of frame numbers to set knob values.
		cleanup (bool): Remove animation from knobs that are static.

	Return:
		None

	'''
    if not values or not frames:
        return

    # No animation.
    if len(values) == 1:
        knob.setValue(values[0])
        return

    if not len(values) == len(frames):
        print("Values and frames are not the same length")
        return

    anim_lists = {}

    for num1, value in enumerate(values):

        if not isinstance(value, (list, tuple)):
            value = [value]

        if len(value) > 1:
            try:
                knob.setSingleValue(False)
            except:
                pass

        # Generate a list with frame numbers and AnimationKey pairs.
        for num2, single in enumerate(value):

            if not num2 in list(anim_lists.keys()):
                anim_lists[num2] = []

            anim_key = nuke.AnimationKey(frames[num1], single)
            anim_lists[num2].append(anim_key)

    # Set each value as animated.
    for i in list(anim_lists.keys()):
        knob.setAnimated(i, True)

    anim_curves = knob.animations()

    # Set values.
    for i in list(anim_lists.keys()):
        anim_curves[i].addKey(anim_lists[i])

    if cleanup:
        for i in anim_curves:
            if i.constant():
                knob.clearAnimated(i.knobIndex())