Guest User

duplicate3D

a guest
May 4th, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.94 KB | None | 0 0
  1. import nuke
  2.  
  3. knobChangedCode = '''
  4. n = nuke.thisNode()
  5. k = nuke.thisKnob()
  6. geo_input = n.node('Geo')
  7. scene = n.node('Clones_Scene')
  8. curr = n.knob('current_num')
  9.  
  10. if k.name() == 'number_of_clones':
  11.    if k.value() > curr.value():
  12.        for i in range(int(curr.value()), int(k.value())):
  13.            to = nuke.nodes.TimeOffset()
  14.            to.knob('time_offset').setExpression('parent.master_time_offset*%s' % str(i+1))
  15.            to.setInput(0, geo_input)
  16.            to.setXpos(geo_input.xpos()+(i+1)*200)
  17.            to.setYpos(geo_input.ypos()+100)
  18.  
  19.            tr = nuke.nodes.TransformGeo()
  20.            tr.setInput(0, to)
  21.            tr.setXpos(to.xpos())
  22.            tr.setYpos(to.ypos()+200)
  23.  
  24.            ax = nuke.nodes.Axis()
  25.            for j,v in enumerate(['x','y','z']):
  26.                ax.knob('translate').setExpression('parent.master_translate.%s' % v, j)
  27.                ax.knob('rotate').setExpression('parent.master_rotate.%s' % v, j)
  28.                ax.knob('scaling').setExpression('parent.master_scaling.%s' % v, j)
  29.                ax.knob('skew').setExpression('parent.master_skew.%s' % v, j)
  30.            ax.knob('uniform_scale').setExpression('parent.master_uniform_scale')
  31.  
  32.            ax.setXpos(tr.xpos()+100)
  33.            ax.setYpos(tr.ypos()-100)
  34.  
  35.            if i == 0:
  36.                node_to_connect = None
  37.            else:
  38.                node_to_connect = [ a for a in nuke.allNodes() if a.Class() == 'Axis' ][1]
  39.  
  40.            ax.setInput(0, node_to_connect)
  41.  
  42.            tr.setInput(1,ax)
  43.            scene.setInput(i+1, tr)
  44.  
  45.            curr.setValue(k.value())
  46.  
  47. '''
  48.  
  49. def main():
  50.     g = nuke.nodes.Group(name = 'Duplicate3D')
  51.  
  52.     newNameFormat = "%s%%d" % g.name()
  53.     i = 1
  54.     while nuke.exists(newNameFormat % i):
  55.         i += 1
  56.     g.setName(newNameFormat % i)
  57.  
  58.     t = nuke.Tab_Knob('Duplicate3D')
  59.  
  60.     # divider1 = nuke.Text_Knob('clones', 'Clones' )
  61.     curr_num = nuke.Int_Knob('current_num')
  62.     curr_num.setFlag(0x00040000)
  63.     num_clones = nuke.Int_Knob('number_of_clones', 'number of clones')
  64.  
  65.     # divider2 = nuke.Text_Knob('time_offset', 'Time Offset')
  66.     master_time_offset = nuke.Int_Knob('master_time_offset', 'time_offset')
  67.  
  68.     divider3 = nuke.Text_Knob( 'transform', 'Transform' )
  69.     master_tr = nuke.XYZ_Knob('master_translate', 'translate')
  70.     master_tr.setValue((1,0,0))
  71.     master_rot = nuke.XYZ_Knob('master_rotate', 'rotate')
  72.     master_scale = nuke.Scale_Knob('master_scaling', 'scale')
  73.     master_size = nuke.Double_Knob('master_uniform_scale', 'uniform scale')
  74.     master_size.setValue(1)
  75.     master_skew = nuke.XYZ_Knob('master_skew', 'skew')
  76.  
  77.     divider4 = nuke.Text_Knob( 'random_mult', 'Randomize Clones' )
  78.     local_tr = nuke.XYZ_Knob('local_translate', 'translate')
  79.     local_rot = nuke.XYZ_Knob('local_rotate', 'rotate')
  80.     local_scale = nuke.Scale_Knob('local_scaling', 'scale')
  81.     local_size = nuke.Double_Knob('local_uniform_scale', 'uniform scale')
  82.     local_size.setValue(1)
  83.     local_skew = nuke.XYZ_Knob('local_skew', 'skew')
  84.  
  85.     g.addKnob( curr_num )
  86.     g.addKnob( num_clones )
  87.  
  88.     g.addKnob( master_time_offset )
  89.  
  90.     g.addKnob( divider3 )
  91.     g.addKnob( master_tr )
  92.     g.addKnob( master_rot )
  93.     g.addKnob( master_scale )
  94.     g.addKnob( master_size )
  95.     g.addKnob( master_skew )
  96.  
  97.     g.addKnob( divider4 )
  98.     g.addKnob( local_tr )
  99.     g.addKnob( local_rot )
  100.     g.addKnob( local_scale )
  101.     g.addKnob( local_size )
  102.     g.addKnob( local_skew )
  103.  
  104.     g.knob('knobChanged').setValue(knobChangedCode)
  105.  
  106.     g.begin()
  107.  
  108.     i = nuke.nodes.Input(name = 'Geo')
  109.     o = nuke.nodes.Output(name = 'Clones_Output')
  110.     s = nuke.nodes.Scene(name = 'Clones_Scene')
  111.     s.setInput(0,i)
  112.     o.setInput(0,s)
  113.  
  114.  
  115.     s.setXpos(i.xpos())
  116.     s.setYpos(i.ypos()+500)
  117.  
  118.     o.setXpos(s.xpos())
  119.     o.setYpos(s.ypos()+100)
  120.  
  121.     g.end()
  122.  
  123.     try:
  124.         sel = nuke.selectedNode()
  125.         g.setInput(0, sel)
  126.     except:
  127.         pass
Advertisement
Add Comment
Please, Sign In to add comment