Hi
This is a simple python script, which create independent copy of selected
camera. All dependencies, parenting, targets etc. are resolved and recalculated
to "standalone" Nuke Camera, with baked XYZ. Such a camera You can export with
chan file or fbx or whatever.
Best
Adrian Baltowski
*************** world_to_XYZ********************
import math
import nuke
def bakeCamera():
ver=str(nuke.NUKE_VERSION_MAJOR)+str(nuke.NUKE_VERSION_MINOR)
if int(ver) < 61:
nuke.message("This script works only withe Nuke 6.1 and higher")
return
if len(nuke.selectedNodes()) != 1:
nuke.message("Select Camera Node")
return
n=nuke.selectedNode()
if n.Class() != "Camera2":
nuke.message("No Camera selected")
return
firstFrame = int(nuke.numvalue('root.first_frame'))
lastFrame = int(nuke.numvalue('root.last_frame'))
step = 1
_range = str(nuke.FrameRange(firstFrame,lastFrame,step))
r = nuke.getInput('Enter Frame Range:', _range)
bakeFocal = False
bakeHaperture = False
bakeVaperture = False
k = n['world_matrix']
newCam = nuke.createNode("Camera2")
newCam.setInput(0, None)
newCam['rotate'].setAnimated()
newCam['translate'].setAnimated()
oldFocal = n['focal']
if oldFocal.isAnimated() and not (oldFocal.animation(0).constant()):
newCam['focal'].setAnimated()
bakeFocal = True
else:
newCam['focal'].setValue(oldFocal.value())
oldHaperture = n['haperture']
if oldHaperture.isAnimated() and not (oldHaperture.animation(0).constant()):
newCam['haperture'].setAnimated()
bakeHaperture = True
else:
newCam['haperture'].setValue(oldHaperture.value())
oldVaperture = n['vaperture']
if oldVaperture.isAnimated() and not (oldVaperture.animation(0).constant()):
newCam['vaperture'].setAnimated()
bakeVaperture = True
else:
newCam['vaperture'].setValue(oldVaperture.value())
newCam['win_translate'].setValue(n['win_translate'].value())
newCam['win_scale'].setValue(n['win_scale'].value())
for x in nuke.FrameRange(r):
m = nuke.math.Matrix4()
for y in range(k.height()):
for z in range(k.width()):
m[z+(y*k.width())] = k.getValueAt(x, (y+(z*k.width())))
rotM = nuke.math.Matrix4(m)
rotM.rotationOnly()
rot = rotM.rotationsZXY()
newCam['rotate'].setValueAt(math.degrees(rot[0]), x, 0)
newCam['rotate'].setValueAt(math.degrees(rot[1]), x, 1)
newCam['rotate'].setValueAt(math.degrees(rot[2]), x, 2)
newCam['translate'].setValueAt(k.getValueAt(x, 3), x, 0)
newCam['translate'].setValueAt(k.getValueAt(x, 7), x, 1)
newCam['translate'].setValueAt(k.getValueAt(x, 11), x, 2)
if bakeFocal:
newCam['focal'].setValueAt(oldFocal.getValueAt(x), x)
if bakeHaperture:
newCam['haperture'].setValueAt(oldHaperture.getValueAt(x), x)
if bakeVaperture:
newCam['vaperture'].setValueAt(oldVaperture.getValueAt(x), x)
*******************************************************************
W dniu 2013-03-25 17:50:48 użytkownik Gustaf Nilsson <[email protected]>
napisał:
wouldnt it be epic if every 3d node had their world space coords easily
accessible? *cough* *cough* ;)
On Fri, Mar 15, 2013 at 11:54 PM, koremelt <[email protected]>
wrote:
Anyone know of a way to export (or even get the position of) a camera which is
parented to an axis?
I'm using Nuke 7 and trying to get the camera to Maya 2013.
I've tried exporting fbx and Alembic as well as some scripts from Nukepedia but
nothing seems to work.
I can see looking at the world matrix the xyz positions of the camera but can't
get the rotation values.
Any suggestions greatly appreciated
To Nuke or not to Nuke
_______________________________________________
Nuke-users mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
--
■ ■ ■ ■ ■ ■ ■ ■ ■ ■
_______________________________________________
Nuke-users mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users