예제 #1
0
def animation_reverse():
    a = nuke.animations()
    for i in a:
        anim = nuke.animation(i, "expression")
        if anim is not None and anim == "curve(first_frame+last_frame-frame)":
            nuke.animation(i, "expression", ("curve", ))
        else:
            nuke.animation(i, "expression",
                           ("curve(first_frame+last_frame-frame)", ))
예제 #2
0
def animation_loop():
    p = nuke.Panel("Loop")
    p.addSingleLineInput("First frame of loop:", 1)
    p.addSingleLineInput("Last frame of loop:", nuke.animationEnd())
    result = p.show()
    if result:
        anim = nuke.animations()
        for i in anim:
            loopstart = p.value("First frame of loop:")
            loopend = p.value("Last frame of loop:")
            nuke.animation(i, "expression",
                           ("curve(((frame-" + loopstart + ")%(" + loopend +
                            "-" + loopstart + "+1))+" + loopstart + ")", ))
예제 #3
0
def toggle(knob):
  """ "Inverts" some flags on the selected nodes.

  What this really does is set all of them to the same value, by finding the
  majority value and using the inverse of that."""

  value = 0
  n = nuke.selectedNodes()
  for i in n:
    try:
      val = i.knob(knob).value()
      if val:
        value += 1
      else:
        value -= 1
    except:
      pass

  status = value < 0
  for i in n:
    if not nuke.exists(i.name()+"."+knob):
      continue
    knobbie = i.knob(knob)
    knobbie_str = i.name()+"."+knob
    size = nuke.animation(knobbie_str, "size")
    if size is not None and int(size) > 0:
      knobbie.setKeyAt(nuke.frame())
      knobbie.setValue(status)
    else:
      knobbie.setValue(status)
    nuke.modified(True)
예제 #4
0
def createProjector(nodes=[]):
  if not nodes:
    nuke.message('ERROR: No node(s) selected.')
    return

  for node in nodes:
    deselectAllNodes()
    if node.Class() in [ "Camera2", "Camera"]:
      node_name = node.name()
      frame = nuke.getInput("Frame to Project for {0}?".format(node_name))
      try:
        int(frame)
      except ValueError:
        nuke.message("You must enter a frame number!")
        return 0
      node['selected'].setValue(True)
      copyPaste()
      new_camera = nuke.selectedNode()
      new_camera.addKnob(nuke.Int_Knob('ref_frame', 'Reference Frame'))
      new_camera['ref_frame'].setValue(int(frame))
      new_camera['label'].setValue("Projection at frame: [value ref_frame]")
      new_camera['tile_color'].setValue(123863)
      new_camera['gl_color'].setValue(123863)
  
      for knob in new_camera.knobs().values():
        if knob.hasExpression():
          if knob.arraySize() ==1:
            chan_name = "{0}.{1}".format(new_camera.name(), knob.name())
            first = "{0}".format(nuke.root().firstFrame())
            last = "{0}".format(nuke.root().lastFrame())
            knob_name = "{0}".format(knob.name())
            nuke.animation( chan_name, "generate", (first, last, "1", "y", knob_name))
          else:
            i = knob.arraySize() - 1
            while i > -1:
              chan_name = "{0}.{1}.{2}".format(new_camera.name(), knob.name(), i)
              first = "{0}".format(nuke.root().firstFrame())
              last = "{0}".format(nuke.root().lastFrame())
              knob_name = "{0}".format(knob.name())
              nuke.animation( chan_name, "generate", first, last, "1", "y", knob_name))
              i-=1
  
      for knob in new_camera.knobs().values():
         if knob.isAnimated():
           knob.setExpression('curve(ref_frame)')
예제 #5
0
def createProjector():
  selectedNodes = nuke.selectedNodes()
  for cameraNode in nuke.selectedNodes():
    if cameraNode.Class() in [ "Camera2", "Camera"]:
      cameraNodeName = cameraNode.name()
      frame = nuke.getInput("Frame to Project for {0}?".format(cameraNode.name()))
      try:
        int(frame)
      except ValueError:
        nuke.message("You must enter a frame number!")
        return 0
      copy_paste()
      selectedCamera = nuke.selectedNode()
      selectedCamera.addKnob(nuke.Int_Knob('referenceFrame', 'Reference Frame'))
      selectedCamera['referenceFrame'].setValue(int(frame))
      selectedCamera['label'].setValue("Projection at frame: [value referenceFrame]")
      selectedCamera['tile_color'].setValue(123863)
      selectedCamera['gl_color'].setValue(123863)
  
      for knob in selectedCamera.knobs().values():
        if knob.hasExpression():
          if knob.arraySize() ==1:
            nuke.animation( \
              "{0}.{1}".format(selectedCamera.name(), knob.name()), \
              "generate", \
              ("{0}".format(nuke.root().firstFrame()), \
              "{0}".format(nuke.root().lastFrame()), \
              "1", "y", "{0}".format(knob.name()) \
              ))
          else:
            i = knob.arraySize() -1
            while i > -1:
              nuke.animation( \
                "{0}.{1}.{2}".format(selectedCamera.name(), knob.name(), i), \
                "generate", \
                ("{0}".format(nuke.root().firstFrame()), \
                "{0}".format(nuke.root().lastFrame()), \
                "1", "y", "{0}".format(knob.name()) \
                ))
              i = i-1
  
      for knob in selectedCamera.knobs().values():
         if knob.isAnimated():
           knob.setExpression('curve(referenceFrame)')
예제 #6
0
    def Set_value_in_knob(self):

        knob_channel_num = self.knob.arraySize()

        #如果按钮调节数为1,此类型按钮则直接烘焙
        if knob_channel_num == 1:
            self.knob.setExpression(self.Custom_max_min())
            nuke.animation(self.knob.fullyQualifiedName(), "generate",
                           (str(self.firstframe), str(self.lastframe), "1",
                            "y", self.knob.fullyQualifiedName()))

        #如果按钮调节数为多个,则分别检测用户的选择
        else:

            #选中的输入通道label
            curve = '%s.%s' % (self.knob.name(), str(self.from_channel_num))
            #如果选中了ALL,则迭代全部烘焙
            if self.output_channel_num == 'All':

                self.knob.setExpression(
                    self.Custom_max_min(self.from_channel_num),
                    self.from_channel_num)
                nuke.animation(
                    '%s.%s' % (self.knob.fullyQualifiedName(),
                               str(self.from_channel_num)), "generate",
                    (str(self.firstframe), str(
                        self.lastframe), "1", "y", self.knob.name()))

                for i in xrange(knob_channel_num):
                    if i != self.from_channel_num:
                        self.knob.setExpression(curve, i)
                    nuke.animation(
                        '%s.%s' % (self.knob.fullyQualifiedName(), str(i)),
                        "generate", (str(self.firstframe), str(
                            self.lastframe), "1", "y", self.knob.name()))
                self.knob.setSingleValue(True)

            #选中要输出的就单独烘焙某个通道
            else:
                #如果输入和输出相同
                if self.output_channel_num == self.from_channel_num:
                    self.knob.setExpression(
                        self.Custom_max_min(self.from_channel_num),
                        self.from_channel_num)
                else:
                    curve = "(%s-%s)*%s+%s" % (curve, str(
                        self.Value_min()), str(
                            self.Interval_multiple()), str(self.min_value))
                    self.knob.setExpression(curve, self.output_channel_num)
                nuke.animation(
                    '%s.%s' % (self.knob.fullyQualifiedName(),
                               str(self.output_channel_num)), "generate",
                    (str(self.firstframe), str(
                        self.lastframe), "1", "y", self.knob.name()))
예제 #7
0
def animation_negate():
    anim = nuke.animations()
    for i in anim:
        expr = "-(" + nuke.animation(i, "expression") + ")"
        nuke.animation(i, "expression", (expr, ))