Advertisement
Totheroo

Nuke - Pixels2Position

Feb 17th, 2022
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.97 KB | None | 0 0
  1. Group {
  2. name Pixels2Position
  3. inputs 2
  4. tile_color 0x990000ff
  5. addUserKnob {20 User l Parameters}
  6. addUserKnob {26 NodeName l "" +STARTLINE T "<font color = white font size = 4> Pixels2Position<font color = grey font size = 2> By Eli Saliba"}
  7. addUserKnob {26 ""}
  8. addUserKnob {3 pointCounter l INVISIBLE +INVISIBLE}
  9. addUserKnob {22 addPoint l "<font color=green>Add Point" T "#Add point\nnode = nuke.thisNode()\n\nFrame = nuke.frame()\ninput = node.input(1)\nwhile node.input and input.Class() == 'Dot':\n input = input.input(0)\nif input and input.Class() == 'Camera2' or 'Camera':\n sFocal= input\['focal'].value(0)\n sHaperture= input\['haperture'].value(0)\n sVaperture= input\['vaperture'].value(0)\n sWinTranslateX= input\['win_translate'].value(0)\n sWinTranslateY= input\['win_translate'].value(1)\n sWinScaleX= input\['win_scale'].value(0)\n sWinScaleY= input\['win_scale'].value(1)\n sWinRoll= input\['winroll'].value(0)\nnode.begin()\ntargetCamera = nuke.toNode('CameraMain')\ntargetCamera\['focal'].setAnimated()\ntargetCamera\['haperture'].setAnimated()\ntargetCamera\['vaperture'].setAnimated()\ntargetCamera\['win_translate'].setAnimated()\ntargetCamera\['win_translate'].setAnimated()\ntargetCamera\['win_scale'].setAnimated()\ntargetCamera\['win_scale'].setAnimated()\ntargetCamera\['winroll'].setAnimated()\ntargetCamera\['focal'].setValueAt(sFocal, Frame)\ntargetCamera\['haperture'].setValueAt(sHaperture, Frame)\ntargetCamera\['vaperture'].setValueAt(sVaperture, Frame)\ntargetCamera\['win_translate'].setValueAt(sWinTranslateX, Frame, 0)\ntargetCamera\['win_translate'].setValueAt(sWinTranslateY, Frame, 1)\ntargetCamera\['win_scale'].setValueAt(sWinScaleX, Frame, 0)\ntargetCamera\['win_scale'].setValueAt(sWinScaleY, Frame, 1)\ntargetCamera\['winroll'].setValueAt(sWinRoll, Frame)\n\nnode.end()\n\npointCounter = node\['pointCounter']\naccuracy = node\['accuracy']\nindex = node\['pointCounter'].value()\n\n\n\nif index < 2:\n index += 1\n pointCounter.setValue(index)\n \n def Position2D():\n viewer = nuke.activeViewer()\n activeInput = nuke.ViewerWindow.activeInput(viewer)\n viewerNode = viewer.node()\n sampledImage=viewerNode.input(activeInput)\n bboxinfo = viewer.node()\['colour_sample_bbox'].value()\n aspect = float(sampledImage.width())/float(sampledImage.height())\n position = 0\n position = \[(bboxinfo\[0]*0.5+0.5)*sampledImage.width(),(((bboxinfo\[1]*0.5)+(0.5/aspect))*aspect)*sampledImage.height()]\n return position\n \n samples = nuke.Text_Knob('Sample\{0\}'.format(int(pointCounter.value())) , 'Position <font color=\"grey\">\{1\} \{2\} <font color=\"light grey\">Frame<font color=\"grey\"> \{0\}'.format( int(nuke.frame()), int(Position2D()\[0]), int(Position2D()\[1])) )\n #samples.setFlag(0x00040000) #Hide\n samples.clearFlag(0x1000) #newline\n\n #add 2d samples knobs\n position = nuke.UV_Knob('Position\{0\}'.format(int(pointCounter.value())))\n position.setValue(Position2D())\n position.setFlag(0x00040000) #Hide\n position.setFlag(0x1000) #newline\n \n frame = nuke.Int_Knob('Frame\{0\}'.format(int(pointCounter.value())))\n frame.setValue(nuke.frame())\n frame.setFlag(0x00040000) #Hide\n frame.clearFlag(0x1000) #newline\n \n for each in (position, samples, frame):\n node.addKnob(each)\n \nelse:\n nuke.message( \"maximum points amount\" )\n\nif index == 2:\n node.begin()\n nuke.toNode('XYZMesh')\['disable'].setValue(0)\n node.end()\n" +STARTLINE}
  10. addUserKnob {22 reset l "<font color =red> Reset" -STARTLINE T "#reset\n\nnode = nuke.thisNode()\npointCounter = node\['pointCounter']\n\nindex = 0\npointCounter.setValue(index)\nnode\['sceneScale'].setValue(999)\n\nfor each in node.allKnobs():\n if each.name().startswith('Position') or each.name().startswith('Frame') or each.name().startswith('Sample') or each.name().startswith('Remove') or each.name().startswith('textAccuracy'):\n node.removeKnob(each)\n elif each.name().startswith('Feedback'):\n node.removeKnob(each)\n\n\nnode.begin()\ntargetCamera = nuke.toNode('CameraMain')\ntargetCamera\['focal'].clearAnimated()\ntargetCamera\['haperture'].clearAnimated()\ntargetCamera\['vaperture'].clearAnimated()\ntargetCamera\['win_translate'].clearAnimated()\ntargetCamera\['win_translate'].clearAnimated()\ntargetCamera\['win_scale'].clearAnimated()\ntargetCamera\['win_scale'].clearAnimated()\ntargetCamera\['winroll'].clearAnimated()\nnuke.toNode('XYZMesh')\['disable'].setValue(1)\nnode.begin()\n\nnode\['XYoutput'].clearAnimated()\nnode\['XYoutput'].setValue(0)\nnode\['XYoutput'].setVisible(False)"}
  11. addUserKnob {22 Help -STARTLINE T "#help\n\nimport webbrowser\nwebbrowser.open('http://www.nukepedia.com/gizmos/3d/pixels2position')"}
  12. addUserKnob {26 ""}
  13. addUserKnob {41 XYZoutput l "XYZ output" T IntersectionPoint.translate}
  14. addUserKnob {12 XYoutput l "XY output" +HIDDEN}
  15. addUserKnob {22 exportAxis l "Export Axis" T "node = nuke.thisNode()\nwith nuke.root():\n\tknob = node\['XYZoutput'].value()\n\tposX = node\['xpos'].value()\n\tposY = node\['ypos'].value()\n\n\tAxis = nuke.nodes.Axis()\n\tAxis\['xpos'].setValue(posX + 100)\n\tAxis\['ypos'].setValue(posY + 100)\n\tAxis\['translate'].setValue(knob)" +STARTLINE}
  16. addUserKnob {22 showXY l "Export XY" -STARTLINE T "#show XY\n\nimport nuke\nfrom nukescripts import snap3d as sn\nimport math\n\n\ndef cameraProjectionMatrix(cameraNode, frame, imageformat):\n ## modified code from nukescripts/Snap3D\n # Matrix to transform points into camera-relative coords.\n wm = nuke.math.Matrix4()\n for i in xrange(16):\n wm\[i] = cameraNode\['matrix'].getValueAt(frame,i)\n wm.transpose()\n camTransform = wm.inverse()\n # Matrix to take the camera projection knobs into account\n roll = float(cameraNode\['winroll'].getValueAt(frame,0))\n scale_x = float(cameraNode\['win_scale'].getValueAt(frame,0))\n scale_y = float(cameraNode\['win_scale'].getValueAt(frame,1))\n m = nuke.math.Matrix4()\n m.makeIdentity()\n m.rotateZ(math.radians(roll))\n m.scale(1.0 / scale_x, 1.0 / scale_y, 1.0)\n #matrix to fix win_translate\n focal_length = float(cameraNode\['focal'].getValueAt(frame))\n h_aperture = float(cameraNode\['haperture'].getValueAt(frame))\n win_translateX = float(cameraNode\['win_translate'].getValueAt(frame,0))\n win_translateY = float(cameraNode\['win_translate'].getValueAt(frame,1))\n translate_x = (( h_aperture / focal_length ) * -0.5) * win_translateX\n translate_y = (( h_aperture / focal_length ) * -0.5) * win_translateY\n wt = nuke.math.Matrix4()\n wt.makeIdentity()\n for i in xrange(16):\n if i == 2:\n wt\[i] = translate_x\n elif i == 6:\n wt\[i] = translate_y\n wt.transpose()\n wti = wt.inverse()\n # Projection matrix based on the focal length, aperture and clipping planes of the camera\n focal_length = float(cameraNode\['focal'].getValueAt(frame))\n h_aperture = float(cameraNode\['haperture'].getValueAt(frame))\n near = float(cameraNode\['near'].getValueAt(frame))\n far = float(cameraNode\['far'].getValueAt(frame))\n projection_mode = int(cameraNode\['projection_mode'].getValueAt(frame))\n p = nuke.math.Matrix4()\n p.projection(focal_length / h_aperture, near, far, projection_mode == 0)\n # Matrix to translate the projected points into normalised pixel coords\n imageAspect = float(imageformat.height()) / float(imageformat.width())\n t = nuke.math.Matrix4()\n t.makeIdentity()\n t.translate( 1.0, 1.0 - (1.0 - imageAspect / float(imageformat.pixelAspect())), 0.0 )\n # Matrix to scale normalised pixel coords into actual pixel coords.\n x_scale = float(imageformat.width()) / 2.0\n y_scale = x_scale * imageformat.pixelAspect()\n s = nuke.math.Matrix4()\n s.makeIdentity()\n s.scale(x_scale, y_scale, 1.0)\n return s * t * p * m * wti * camTransform\n\n\ndef projectPoints(frame, camera=None, point=None, imageformat=None):\n # Modify projectpoint function in nukescripts.snap3d to add frame argument\n if not imageformat:\n imageformat = nuke.root()\['format'].value()\n camMatrix = cameraProjectionMatrix(camera, frame, imageformat)\n if camMatrix == None:\n raise RuntimeError, \"snap3d.cameraProjectionMatrix() returned None for camera.\"\n\n if not ( isinstance(point, list) or isinstance(point, tuple) ):\n raise ValueError, \"Argument point must be a list or tuple.\"\n\n for point in point:\n # Would be nice to not do this for every item but since lists/tuples can\n # containg anything...\n if isinstance(point, nuke.math.Vector3):\n pt = point\n elif isinstance(point, list) or isinstance(point, tuple):\n pt = nuke.math.Vector3(point\[0], point\[1], point\[2])\n else:\n raise ValueError, \"All items in point must be nuke.math.Vector3 or list/tuple of 3 floats.\"\n\n tPos = camMatrix * nuke.math.Vector4(pt.x, pt.y, pt.z, 1.0)\n #print tPos\n try:\n yield nuke.math.Vector2(tPos.x / tPos.w, tPos.y / tPos.w)\n except ZeroDivisionError:\n print \"Zero Division Error on frame \{0\} with point data \{1\}\".format(frame, point)\n yield nuke.math.Vector2()\n\ndef getCamera(node):\n myInput = node.input(0)\n while 'Camera' not in myInput.Class():\n myInput = getCamera(myInput)\n return myInput\n\ndef Project(node):\n cam_input = node.input(1)\n if 'Camera' in cam_input.Class():\n cam = cam_input\n else:\n cam = getCamera(cam_input)\n # Get framerange to operate on from camera animation curves\n first = None\n last = None\n try:\n if cam\['translate'].isAnimated():\n for curve in cam\['translate'].animations():\n if first == None:\n first = int(curve.keys()\[0].x)\n else:\n first = min(first, int(curve.keys()\[0].x))\n for curve in cam\['translate'].animations():\n if last == None:\n last = int(curve.keys()\[-1].x)\n else:\n last = max(last, int(curve.keys()\[-1].x))\n elif cam\['rotate'].isAnimated():\n for curve in cam\['rotate'].animations():\n if first == None:\n first = int(curve.keys()\[0].x)\n else:\n first = min(first, int(curve.keys()\[0].x))\n for curve in cam\['rotate'].animations():\n if last == None:\n last = int(curve.keys()\[-1].x)\n else:\n last = max(last, int(curve.keys()\[-1].x))\n else:\n return\n except:\n nuke.message(\"!!!\")\n first = nuke.root().firstFrame()\n last = nuke.root().lastFrame()\n framerange = nuke.FrameRange('\{0\}-\{1\}'.format(first, last))\n\n input = node\[\"XYZoutput\"]\n output = node\[\"XYoutput\"]\n output.clearAnimated()\n output.setAnimated()\n point_animcurve = \[\[], \[]]\n for frame in framerange:\n\n #print \"values are \", ipknob.getValueAt(frame)\n # Sample input point knob on every frame if it's animated or expression-linked\n if input.isAnimated() or input.hasExpression():\n point = projectPoints(frame, cam, \[input.getValueAt(frame)], node.format()).next()\n else:\n point = projectPoints(frame, cam, \[input.value()], node.format()).next()\n for index in xrange(2):\n point_animcurve\[index].append(nuke.AnimationKey(frame, point\[index]))\n\n for index, curve in enumerate(output.animations()):\n curve.addKey(point_animcurve\[index])\n\n\nnode = nuke.thisNode()\nknob = node\['XYoutput']\n\n#set visibility\nif knob.visible() == 1:\n knob.setVisible(False)\nelse:\n knob.setVisible(True)\n if __name__==\"__main__\":\n Project(node)"}
  17. addUserKnob {20 advancedSettings l "Advanced Settings" n 1}
  18. advancedSettings 0
  19. addUserKnob {7 sceneScale l "Scene Scale" R 1 999}
  20. sceneScale 999
  21. addUserKnob {41 disable_1 l Locator T Switch1.disable}
  22. addUserKnob {41 uniform_scale l Size -STARTLINE T TransformGeo1.uniform_scale}
  23. addUserKnob {20 endGroup n -1}
  24. addUserKnob {26 feedback l Feedback}
  25. addUserKnob {41 accuracy l Accuracy T fourPoints.accuracy}
  26. }
  27. Input {
  28. inputs 0
  29. name Camera
  30. xpos 262
  31. ypos 192
  32. number 1
  33. }
  34. set N171644f0 [stack 0]
  35. Axis2 {
  36. inputs 0
  37. translate {{parent.fourPoints.IntersectionPoint.x} {parent.fourPoints.IntersectionPoint.y} {parent.fourPoints.IntersectionPoint.z}}
  38. name IntersectionPoint
  39. xpos 941
  40. ypos 124
  41. }
  42. set N171699d0 [stack 0]
  43. Group {
  44. inputs 0
  45. name XYZMesh
  46. xpos 769
  47. ypos 89
  48. disable true
  49. }
  50. Constant {
  51. inputs 0
  52. channels {-rgba.red -rgba.green rgba.blue none}
  53. color 1
  54. name Constant2
  55. xpos 635
  56. ypos 50
  57. postage_stamp false
  58. }
  59. Cylinder {
  60. inputs 0
  61. rows 1
  62. columns 8
  63. radius 0.03
  64. height 1
  65. translate {0 0.5 0}
  66. uniform_scale 0.9
  67. pivot {0 -0.5 0}
  68. name Cylinder1
  69. xpos 878
  70. ypos -335
  71. }
  72. set N1718e9a0 [stack 0]
  73. push $N1718e9a0
  74. RadialDistort {
  75. distortion 55
  76. power_bias 1.98
  77. scale {0.3 0.03 0.3}
  78. name RadialDistort1
  79. xpos 972
  80. ypos -266
  81. }
  82. TransformGeo {
  83. translate {3.540680638e-09 -0.04420004 0}
  84. rotate {0 0 180}
  85. pivot {0 0.68 0}
  86. name TransformGeo4
  87. xpos 972
  88. ypos -242
  89. }
  90. MergeGeo {
  91. inputs 2
  92. name MergeGeo2
  93. xpos 878
  94. ypos -242
  95. }
  96. set N171bd5b0 [stack 0]
  97. TransformGeo {
  98. rotate {90 0 0}
  99. name TransformGeo2
  100. xpos 758
  101. ypos -167
  102. }
  103. ApplyMaterial {
  104. inputs 2
  105. name ApplyMaterial3
  106. xpos 758
  107. ypos 50
  108. }
  109. Constant {
  110. inputs 0
  111. channels {-rgba.red rgba.green -rgba.blue none}
  112. color 1
  113. name Constant3
  114. xpos 635
  115. ypos 21
  116. postage_stamp false
  117. }
  118. push $N171bd5b0
  119. ApplyMaterial {
  120. inputs 2
  121. name ApplyMaterial2
  122. xpos 878
  123. ypos 47
  124. }
  125. Constant {
  126. inputs 0
  127. channels {rgba.red -rgba.green -rgba.blue none}
  128. color 1
  129. name Constant1
  130. xpos 1109
  131. ypos 42
  132. postage_stamp false
  133. }
  134. push $N171bd5b0
  135. TransformGeo {
  136. rotate {0 0 -90}
  137. name TransformGeo3
  138. xpos 1004
  139. ypos -165
  140. }
  141. ApplyMaterial {
  142. inputs 2
  143. name ApplyMaterial1
  144. xpos 1004
  145. ypos 42
  146. }
  147. MergeGeo {
  148. inputs 3
  149. name MergeGeo1
  150. xpos 878
  151. ypos 143
  152. }
  153. Output {
  154. name Output1
  155. xpos 878
  156. ypos 279
  157. }
  158. end_group
  159. TransformGeo {
  160. inputs 2
  161. uniform_scale 1
  162. name TransformGeo1
  163. xpos 769
  164. ypos 145
  165. }
  166. Switch {
  167. which 1
  168. name Switch1
  169. xpos 769
  170. ypos 192
  171. disable true
  172. }
  173. Input {
  174. inputs 0
  175. name Input
  176. xpos 580
  177. ypos 145
  178. addUserKnob {20 User}
  179. addUserKnob {14 format R 0 100}
  180. format {{"\[value Input.format.w]"} {"\[value Input.format.h]"}}
  181. addUserKnob {7 aspect}
  182. aspect {{format.h/format.w}}
  183. addUserKnob {7 pixelAspect l "Pixel Aspect"}
  184. pixelAspect {{"\[value Input.format.pixel_aspect]"}}
  185. }
  186. ScanlineRender {
  187. inputs 3
  188. conservative_shader_sampling false
  189. antialiasing medium
  190. motion_vectors_type distance
  191. name ScanlineRender1
  192. xpos 580
  193. ypos 192
  194. }
  195. Output {
  196. name Output1
  197. xpos 580
  198. ypos 248
  199. }
  200. push $N171699d0
  201. Dot {
  202. name Dot10
  203. xpos 965
  204. ypos 287
  205. }
  206. push $N171644f0
  207. Camera2 {
  208. useMatrix true
  209. matrix {
  210. {1 0 {((CameraMain.haperture/CameraMain.focal)*-0.5)*CameraMain.win_translate.0} 0}
  211. {0 1 {((CameraMain.haperture/CameraMain.focal)*-0.5)*CameraMain.win_translate.1} 0}
  212. {0 0 1 0}
  213. {0 0 0 1}
  214. }
  215. focal 47.4744898
  216. haperture 23.56826019
  217. vaperture 19.0597551
  218. win_translate {0.07755101995 0.03877550997}
  219. win_scale {1.19387755 0.96122449}
  220. winroll -4.062499944
  221. name CameraMain
  222. label "Apply win_translate in matrix"
  223. xpos 272
  224. ypos 249
  225. addUserKnob {20 plus}
  226. addUserKnob {7 FOV}
  227. FOV {{"degrees(2 * atan (( 0.5 * this.haperture) / (this.focal)))"}}
  228. }
  229. Axis2 {
  230. xform_order RST
  231. rotate {0 0 {-CameraMain.winroll}}
  232. scaling {{CameraMain.win_scale.u} {CameraMain.win_scale.v} 1}
  233. name Axis3
  234. label "Apply \"win_scale\" and \"winroll\""
  235. xpos 272
  236. ypos 344
  237. }
  238. set N1728b870 [stack 0]
  239. Axis2 {
  240. translate {{"tan(radians(CameraMain.FOV*0.5)) * sceneScale * (Position2.u - Input.format.w/2)/(Input.format.w/2)"} {"tan(radians(CameraMain.FOV*0.5)) * sceneScale * (Position2.v - Input.format.h/2)/(Input.format.h/2) * Input.aspect"} {-sceneScale}}
  241. name Axis2
  242. label Position2
  243. xpos 399
  244. ypos 344
  245. }
  246. NoOp {
  247. inputs 0
  248. name fourPoints
  249. xpos 928
  250. ypos 54
  251. hide_input true
  252. addUserKnob {20 User}
  253. addUserKnob {13 a}
  254. a {{parent.CameraMain.world_matrix.3(Frame1)} {parent.CameraMain.world_matrix.7(Frame1)} {parent.CameraMain.world_matrix.11(Frame1)}}
  255. addUserKnob {13 b}
  256. b {{parent.Axis1.world_matrix.3(Frame1)} {parent.Axis1.world_matrix.7(Frame1)} {parent.Axis1.world_matrix.11(Frame1)}}
  257. addUserKnob {13 c}
  258. c {{parent.CameraMain.world_matrix.3(Frame2)} {parent.CameraMain.world_matrix.7(Frame2)} {parent.CameraMain.world_matrix.11(Frame2)}}
  259. addUserKnob {13 d}
  260. d {{parent.Axis2.world_matrix.3(Frame2)} {parent.Axis2.world_matrix.7(Frame2)} {parent.Axis2.world_matrix.11(Frame2)}}
  261. addUserKnob {26 ""}
  262. addUserKnob {13 IntersectionPoint}
  263. IntersectionPoint {{"\[python -execlocal node\\ =\\ nuke.thisNode()\\na,b,c,d\\ =\\ node\\\['a'\\].value(),node\\\['b'\\].value(),node\\\['c'\\].value(),node\\\['d'\\].value()\\n\\ntry:\\n\\ \\ \\ \\ #constants\\ required\\ for\\ solving\\ t\\ and\\ s\\n\\ \\ \\ \\ A=b\\\[0\\]-a\\\[0\\]\\n\\ \\ \\ \\ B=c\\\[0\\]-d\\\[0\\]\\n\\ \\ \\ \\ C=c\\\[0\\]-a\\\[0\\]\\n\\ \\ \\ \\ D=b\\\[1\\]-a\\\[1\\]\\n\\ \\ \\ \\ E=c\\\[1\\]-d\\\[1\\]\\n\\ \\ \\ \\ F=c\\\[1\\]-a\\\[1\\]\\n\\ \\ \\ \\ \\n\\ \\ \\ \\ #find\\ t\\ and\\ s\\ using\\ formula\\n\\ \\ \\ \\ t=(C*E-F*B)/(E*A-B*D)\\n\\ \\ \\ \\ s=(D*C-A*F)/(D*B-A*E)\\n\\ \\ \\ \\ \\n\\ \\ \\ \\ #accuracy\\n\\ \\ \\ \\ accuracy\\ =\\ \\ abs\\ (\\ (t*(b\\\[2\\]-a\\\[2\\])+s*(c\\\[2\\]-d\\\[2\\]))\\ -\\ (c\\\[2\\]-a\\\[2\\]))\\ \\n\\ \\ \\ \\ \\n\\ \\ \\ \\ #find\\ intersection\\ point\\n\\ \\ \\ \\ pointx\\ =\\ a\\\[0\\]\\ +\\ t*(b\\\[0\\]-a\\\[0\\])\\n\\ \\ \\ \\ pointy\\ =\\ a\\\[1\\]\\ +\\ t*(b\\\[1\\]-a\\\[1\\])\\n\\ \\ \\ \\ pointz\\ =\\ a\\\[2\\]\\ +\\ t*(b\\\[2\\]-a\\\[2\\])\\n\\ \\ \\ \\ \\n\\ \\ \\ \\ ret\\ =\\ pointx\\nexcept\\ ZeroDivisionError:\\n\\ \\ \\ \\ ret\\ =\\ 0]"} {"\[python -execlocal node\\ =\\ nuke.thisNode()\\na,b,c,d\\ =\\ node\\\['a'\\].value(),node\\\['b'\\].value(),node\\\['c'\\].value(),node\\\['d'\\].value()\\n\\ntry:\\n\\ \\ \\ \\ #constants\\ required\\ for\\ solving\\ t\\ and\\ s\\n\\ \\ \\ \\ A=b\\\[0\\]-a\\\[0\\]\\n\\ \\ \\ \\ B=c\\\[0\\]-d\\\[0\\]\\n\\ \\ \\ \\ C=c\\\[0\\]-a\\\[0\\]\\n\\ \\ \\ \\ D=b\\\[1\\]-a\\\[1\\]\\n\\ \\ \\ \\ E=c\\\[1\\]-d\\\[1\\]\\n\\ \\ \\ \\ F=c\\\[1\\]-a\\\[1\\]\\n\\ \\ \\ \\ \\n\\ \\ \\ \\ #find\\ t\\ and\\ s\\ using\\ formula\\n\\ \\ \\ \\ t=(C*E-F*B)/(E*A-B*D)\\n\\ \\ \\ \\ s=(D*C-A*F)/(D*B-A*E)\\n\\ \\ \\ \\ \\n\\ \\ \\ \\ #accuracy\\n\\ \\ \\ \\ accuracy\\ =\\ \\ abs\\ (\\ (t*(b\\\[2\\]-a\\\[2\\])+s*(c\\\[2\\]-d\\\[2\\]))\\ -\\ (c\\\[2\\]-a\\\[2\\]))\\ \\n\\ \\ \\ \\ \\n\\ \\ \\ \\ #find\\ intersection\\ point\\n\\ \\ \\ \\ pointx\\ =\\ a\\\[0\\]\\ +\\ t*(b\\\[0\\]-a\\\[0\\])\\n\\ \\ \\ \\ pointy\\ =\\ a\\\[1\\]\\ +\\ t*(b\\\[1\\]-a\\\[1\\])\\n\\ \\ \\ \\ pointz\\ =\\ a\\\[2\\]\\ +\\ t*(b\\\[2\\]-a\\\[2\\])\\n\\ \\ \\ \\ \\n\\ \\ \\ \\ ret\\ =\\ pointy\\nexcept\\ ZeroDivisionError:\\n\\ \\ \\ \\ ret\\ =\\ 0]"} {"\[python -execlocal node\\ =\\ nuke.thisNode()\\na,b,c,d\\ =\\ node\\\['a'\\].value(),node\\\['b'\\].value(),node\\\['c'\\].value(),node\\\['d'\\].value()\\n\\ntry:\\n\\ \\ \\ \\ #constants\\ required\\ for\\ solving\\ t\\ and\\ s\\n\\ \\ \\ \\ A=b\\\[0\\]-a\\\[0\\]\\n\\ \\ \\ \\ B=c\\\[0\\]-d\\\[0\\]\\n\\ \\ \\ \\ C=c\\\[0\\]-a\\\[0\\]\\n\\ \\ \\ \\ D=b\\\[1\\]-a\\\[1\\]\\n\\ \\ \\ \\ E=c\\\[1\\]-d\\\[1\\]\\n\\ \\ \\ \\ F=c\\\[1\\]-a\\\[1\\]\\n\\ \\ \\ \\ \\n\\ \\ \\ \\ #find\\ t\\ and\\ s\\ using\\ formula\\n\\ \\ \\ \\ t=(C*E-F*B)/(E*A-B*D)\\n\\ \\ \\ \\ s=(D*C-A*F)/(D*B-A*E)\\n\\ \\ \\ \\ \\n\\ \\ \\ \\ #accuracy\\n\\ \\ \\ \\ accuracy\\ =\\ \\ abs\\ (\\ (t*(b\\\[2\\]-a\\\[2\\])+s*(c\\\[2\\]-d\\\[2\\]))\\ -\\ (c\\\[2\\]-a\\\[2\\]))\\ \\n\\ \\ \\ \\ \\n\\ \\ \\ \\ #find\\ intersection\\ point\\n\\ \\ \\ \\ pointx\\ =\\ a\\\[0\\]\\ +\\ t*(b\\\[0\\]-a\\\[0\\])\\n\\ \\ \\ \\ pointy\\ =\\ a\\\[1\\]\\ +\\ t*(b\\\[1\\]-a\\\[1\\])\\n\\ \\ \\ \\ pointz\\ =\\ a\\\[2\\]\\ +\\ t*(b\\\[2\\]-a\\\[2\\])\\n\\ \\ \\ \\ \\n\\ \\ \\ \\ ret\\ =\\ pointz\\nexcept\\ ZeroDivisionError:\\n\\ \\ \\ \\ ret\\ =\\ 0]"}}
  264. addUserKnob {7 accuracy}
  265. accuracy {{"\[python -execlocal node\\ =\\ nuke.thisNode()\\na,b,c,d\\ =\\ node\\\['a'\\].value(),node\\\['b'\\].value(),node\\\['c'\\].value(),node\\\['d'\\].value()\\n\\ntry:\\n\\ \\ \\ \\ #constants\\ required\\ for\\ solving\\ t\\ and\\ s\\n\\ \\ \\ \\ A=b\\\[0\\]-a\\\[0\\]\\n\\ \\ \\ \\ B=c\\\[0\\]-d\\\[0\\]\\n\\ \\ \\ \\ C=c\\\[0\\]-a\\\[0\\]\\n\\ \\ \\ \\ D=b\\\[1\\]-a\\\[1\\]\\n\\ \\ \\ \\ E=c\\\[1\\]-d\\\[1\\]\\n\\ \\ \\ \\ F=c\\\[1\\]-a\\\[1\\]\\n\\ \\ \\ \\ \\n\\ \\ \\ \\ #find\\ t\\ and\\ s\\ using\\ formula\\n\\ \\ \\ \\ t=(C*E-F*B)/(E*A-B*D)\\n\\ \\ \\ \\ s=(D*C-A*F)/(D*B-A*E)\\n\\ \\ \\ \\ \\n\\ \\ \\ \\ #accuracy\\n\\ \\ \\ \\ accuracy\\ =\\ \\ abs\\ (\\ (t*(b\\\[2\\]-a\\\[2\\])+s*(c\\\[2\\]-d\\\[2\\]))\\ -\\ (c\\\[2\\]-a\\\[2\\]))\\ \\n\\ \\ \\ \\ \\n\\ \\ \\ \\ #find\\ intersection\\ point\\n\\ \\ \\ \\ pointx\\ =\\ a\\\[0\\]\\ +\\ t*(b\\\[0\\]-a\\\[0\\])\\n\\ \\ \\ \\ pointy\\ =\\ a\\\[1\\]\\ +\\ t*(b\\\[1\\]-a\\\[1\\])\\n\\ \\ \\ \\ pointz\\ =\\ a\\\[2\\]\\ +\\ t*(b\\\[2\\]-a\\\[2\\])\\n\\ \\ \\ \\ \\n\\ \\ \\ \\ ret\\ =\\ accuracy\\nexcept\\ ZeroDivisionError:\\n\\ \\ \\ \\ ret\\ =\\ 0\\n\\ \\ \\ \\ ]"}}
  266. }
  267. push $N1728b870
  268. Axis2 {
  269. translate {{"tan(radians(CameraMain.FOV*0.5)) * sceneScale * (Position1.u - Input.format.w/2)/(Input.format.w/2)"} {"tan(radians(CameraMain.FOV*0.5)) * sceneScale * (Position1.v - Input.format.h/2)/(Input.format.h/2) * Input.aspect"} {-sceneScale}}
  270. name Axis1
  271. label Position1
  272. xpos 146
  273. ypos 344
  274. }
  275. end_group
  276.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement