Created
January 31, 2012 23:26
-
-
Save K240-zz/1713764 to your computer and use it in GitHub Desktop.
Export Maya camera to Nuke .chan file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import maya.cmds as cmds | |
| import math | |
| def dump_camera_channels( cameraName, time ): | |
| current = time | |
| shapeName = cmds.listRelatives(cameraName,shapes=True)[0] | |
| tx = cmds.getAttr(cameraName+".tx", t=current) | |
| ty = cmds.getAttr(cameraName+".ty", t=current) | |
| tz = cmds.getAttr(cameraName+".tz", t=current) | |
| rx = cmds.getAttr(cameraName+".rx", t=current) | |
| ry = cmds.getAttr(cameraName+".ry", t=current) | |
| rz = cmds.getAttr(cameraName+".rz", t=current) | |
| hfa = cmds.getAttr(shapeName + '.horizontalFilmAperture',t=current) | |
| vfa = cmds.getAttr(shapeName + '.verticalFilmAperture',t=current) | |
| fl = cmds.getAttr(shapeName + '.focalLength',t=current) | |
| vfov = 2 * (math.atan2(vfa/2.0*25.4,fl) * 180 / math.pi); | |
| return str(current) + " " + str(tx) + " " + str(ty) + " " + str(tz) + " " + str(rx) + " " + str(ry) + " " + str(rz) + " " + str(vfov) | |
| def export_camera( filename, cameraName, **kwargs ): | |
| st = 1 | |
| ed = 1 | |
| step = 1 | |
| if 'st' in kwargs: | |
| st = kwargs['st'] | |
| if 'ed' in kwargs: | |
| ed = kwargs['ed'] | |
| if 'step' in kwargs: | |
| step = kwargs['step'] | |
| try: | |
| f = open( filename, 'w') | |
| for time in xrange(st, ed, step): | |
| l = dump_camera_channels( cameraName, time ) | |
| f.write(l + "\n") | |
| f.close() | |
| except IOError: | |
| pass | |
| if __name__ == '__main__': | |
| export_camera( "/Users/hideki/test.chan", "camera1", st = 1, ed = 30 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment