Last active
June 30, 2023 10:10
-
-
Save K240-zz/4403498 to your computer and use it in GitHub Desktop.
maya camera export to houdini chan.
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 pymel.core as pm | |
import math | |
def exportCameraChan(obj, st, ed, filename): | |
bt = pm.currentTime( query=True ) | |
fd = open(filename, 'wt') | |
for i in range(ed-st): | |
pm.currentTime(i+st) | |
t = obj.getTranslation() | |
r = obj.getRotation() | |
ap = math.tan(obj.getHorizontalFieldOfView()/2*(math.pi/180)) * obj.getFocalLength()* 2 | |
# folowing name of channel for Houdini. | |
# tx ty tz rx ry rz aperture focal | |
fd.write( "%f %f %f %f %f %f %f %f\n" % (t[0], t[1], t[2], r[0], r[1], r[2], ap, obj.getFocalLength()) ) | |
fd.close() | |
pm.currentTime(bt) | |
filename = pm.fileDialog( dfn='camera.chan', dm='*.chan', mode=1 ) | |
if filename: | |
st = pm.playbackOptions(query=True, minTime=True) | |
ed = pm.playbackOptions(query=True, maxTime=True) | |
# need selected camera | |
exportCameraChan(pm.selected()[0], int(st), int(ed), filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment