rafaelperez
9/17/2019 - 7:45 PM

Deeptopos

Group {
 name DeepToPosition
 tile_color 0x2866ff
 label "<font color=cyan>Deep Output</font>"
 addUserKnob {20 tab_general l General}
 addUserKnob {22 set_link l "link to selected camera" t "Deep data is related to camera. So when convert deep data to anything, it required the camera data.\n\nhow to use :\nSelect the camera, which can be link to any axis nodes. This tool will get the focal, haperture and world matrix from selected camera to generate world space position data.\n\nYou can find the world space position pass store under <b>'deepPosition'</b> channel after this node. The pass support volumatric deep data. If want to bring the position data to 2D in downstream. Please only use <b>DeepPositionToImage</b> which comes along with this toolset.\n\nAdditional note:\nThis node will also create another channel called <b>'deepColor'</b> . This channel stored the original of deep data from raw input, for any dev purposes in downstream. User not necessary to use this channel but better to keep it if this toolset occur in downstream." T "def getLevel() :\n\t### level define ###\n\tif len(nuke.thisNode().fullName().split('.')) == 1 :\n\t\t  ggLevel = nuke.root()\n\telse :\n\t\t  nodePath = nuke.thisNode().fullName().split('.')\n\t\t  nodePath.pop()\n\t\t  ggLevel = nuke.toNode('.'.join(nodePath))\n\treturn ggLevel\n\nroot = getLevel()\nthisGRP = nuke.thisGroup()\n\nmainKnobs = \['world_matrix','cam_focal','cam_haperture']\ndefaultKnobs = \{\n\t\t\t'world matrix' : 'world_matrix',\n\t\t\t'focal length' : 'focal',\n\t\t\t'horiz aperture' : 'haperture'\n\t\t\t\}\nselNodeKnobs = \[]\nmissingKnob = \[]\n\ntry :\n\twith root :\n\t\tselNode = nuke.selectedNode()\n\n\tfor knob in selNode.knobs() :\n\t\tselNodeKnobs.append( knob )\n\n\tselNodeKnobs.sort()\n\n\tfor key,value in defaultKnobs.items() :\n\t\tif value not in selNodeKnobs :\n\t\t\tmissingKnob.append( key )\n\n\tif not len(missingKnob) :\n\t\twith root :\n\t\t\tCAMnode = selNode.name()\n\t\t\tthisGRP\[mainKnobs\[0]].setExpression('\{0\}.world_matrix'.format(CAMnode))\n\t\t\tthisGRP\[mainKnobs\[1]].setExpression('\{0\}.focal'.format(CAMnode))\n\t\t\tthisGRP\[mainKnobs\[2]].setExpression('\{0\}.haperture'.format(CAMnode))\n\telse :\n\t\tp = nuke.Panel('Select knobs :')\n\t\tp.addBooleanCheckBox( '<b>Unable to find the default knobs. Please use the pulldown menu below to define the knob manually.</b>' , False)\n\t\tfor rk in missingKnob :\n\t\t\tp.addEnumerationPulldown( rk, ' '.join( selNodeKnobs ) )\n\n\t\tif p.show() :\n\t\t\ttry :\n\t\t\t\tfor key,value in defaultKnobs.items() :\n\t\t\t\t\tif p.value( key ) != None :\n\t\t\t\t\t\tdefaultKnobs\[key] = p.value( key )\n\t\t\texcept :\n\t\t\t\tpass\n\n\t\t\twith root :\n\t\t\t\tCAMnode = selNode.name()\n\t\t\t\tthisGRP\[mainKnobs\[0]].setExpression('\{0\}.\{1\}'.format(CAMnode, defaultKnobs\['world matrix']))\n\t\t\t\tthisGRP\[mainKnobs\[1]].setExpression('\{0\}.\{1\}'.format(CAMnode, defaultKnobs\['focal length']))\n\t\t\t\tthisGRP\[mainKnobs\[2]].setExpression('\{0\}.\{1\}'.format(CAMnode, defaultKnobs\['horiz aperture']))\nexcept :\n\tnuke.message('no node selected.')" +STARTLINE}
 addUserKnob {22 remove_link l "remove linked expression" t "Remove the linked camera expression but won't reset any data. So the position data still works if input doesn't contain any camera movement." -STARTLINE T "thisGRP = nuke.thisGroup()\nmainKnobs = \['world_matrix','cam_focal','cam_haperture']\n\nfor knob in thisGRP.knobs() :\n    if mainKnobs.count(knob) != 0 :\n        thisGRP\[knob].clearAnimated()"}
 addUserKnob {20 cam_data_grp l "CAMERA DATA" n 1}
 cam_data_grp 0
 addUserKnob {7 cam_focal l "focal length" R 5 100}
 cam_focal 50
 addUserKnob {7 cam_haperture l "horiz aperture" R 0.1 50}
 cam_haperture 24.576
 addUserKnob {41 world_matrix l "world matrix" T cam_data.matrix}
 addUserKnob {20 endGroup_1 l endGroup n -1}
 addUserKnob {20 t_VERSION l Version}
 addUserKnob {26 l_VERSION l <b>Version</b> T 2.8}
 addUserKnob {26 l_DATE l "<b>Date Modified</b>" T 2019-08-22}
 addUserKnob {26 l_CHANGELOG l <b>Changelog</b> T "2.8\n- fix DeepVPCamProjection's\n  project z range animated issue.\n\n2.7\n- removed un-use expression\n  in DeepToPosition\n\n2.6\n- fix premult issue on DeepVolumeMatte \n  on Deep Output under Nuke10\n  * Thanks Luddnel Magne test it out.\n- corrected DeepVolumeMatte's shape\n  on the menu.\n  ( Nuke10 supported all shapes )"}
 addUserKnob {26 l_DEV l "<b>Developed by</b>" T "<a href='https://facebook.com/MJTLab'><font color='orange'>Mark Joey Tang</font></a>"}
}
 Input {
  inputs 0
  name deep
  xpos 0
  ypos -454
 }
 Dot {
  name Dot3
  xpos 34
  ypos -374
 }
set N8cdc06b0 [stack 0]
 DeepToImage {
  name DeepToImage3
  xpos -148
  ypos -377
 }
add_layer {deepPosition deepPosition.red deepPosition.green deepPosition.blue deepPosition.alpha}
 AddChannels {
  channels deepPosition
  name AddChannels3
  xpos -148
  ypos -285
 }
push $N8cdc06b0
 DeepRecolor {
  inputs 2
  channels {{{parent.AddChannels3.channels}}}
  name DeepRecolor2
  xpos 0
  ypos -285
 }
 DeepExpression {
  temp_name0 xpos
  temp_expr0 "( ( x/\[value input.width] ) - 0.5 ) * \[value hratio] * deep.front )"
  temp_name1 ypos
  temp_expr1 "( ( y/\[value input.height] ) - 0.5 ) * ( ( \[value hratio]*deep.front ) / ( \[value input.width]/\[value input.height] ) )"
  temp_name2 zpos
  temp_expr2 -deep.front
  chans0 none
  chans1 {deepPosition.red deepPosition.green deepPosition.blue -deepPosition.alpha}
  deepPosition.red "(xpos * \[value cam_data.world_matrix.0] + ypos * \[value cam_data.world_matrix.1] + zpos * \[value cam_data.world_matrix.2]) + \[value cam_data.world_matrix.3]"
  deepPosition.green "(xpos * \[value cam_data.world_matrix.4] + ypos * \[value cam_data.world_matrix.5] + zpos * \[value cam_data.world_matrix.6]) + \[value cam_data.world_matrix.7]"
  deepPosition.blue "(xpos * \[value cam_data.world_matrix.8] + ypos * \[value cam_data.world_matrix.9] + zpos * \[value cam_data.world_matrix.10]) + \[value cam_data.world_matrix.11]"
  name DeepExpression1
  label DeepPosition
  xpos 0
  ypos -197
  addUserKnob {20 User}
  addUserKnob {7 hratio}
  hratio {{"\[value cam_data.haperture] / \[value cam_data.focal]"}}
 }
 Output {
  name Output1
  xpos 0
  ypos -88
 }
 Camera {
  inputs 0
  display off
  selectable false
  rot_order XYZ
  useMatrix true
  focal {{parent.cam_focal}}
  haperture {{parent.cam_haperture}}
  name cam_data
  selected true
  xpos -119
  ypos -214
 }
end_group