Skip to content

Instantly share code, notes, and snippets.

@taikomatsu
Last active January 10, 2017 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taikomatsu/ffac6dbbf544717c436c11e1f268b516 to your computer and use it in GitHub Desktop.
Save taikomatsu/ffac6dbbf544717c436c11e1f268b516 to your computer and use it in GitHub Desktop.
Create clone cameras for data exchanging with other DCC apps.
# Houdiniにカメラを持っていく用に、値をbakeしてシンプルなデータにするための処理を自動化。
# 一応複数対応してる感じで書いてるけど、あんまり想定してないしテストもしていないw
# filmoffsetに関して、アニメーションの再接続をしているもののこれもそのままは持っていけないので一応やってるだけ。
# bakeするレンジはtime sliderに準拠する。
from pymel.core import *
cams = []
for o in selected():
new_cam = duplicate(o, rr=True)[0]
try:
parent(new_cam, w=True)
new_cam.rename('{}_baked'.format(o.name()))
attrs = listAttr([new_cam, new_cam.getShape()], l=True)
for a in attrs:
new_cam.attr(a).set(l=False)
parentConstraint(o, new_cam)
new_cam.s.set(1, 1, 1)
for a in ['focalLength', 'horizontalFilmOffset', 'verticalFilmOffset']:
inputs = o.attr(a).inputs(p=True)
if len(inputs):
inputs[0].connect(new_cam.attr(a))
cams.append(new_cam)
except Exception, e:
print e
delete(new_cam)
st = playbackOptions(q=True, min=True)
ed = playbackOptions(q=True, max=True)
mel.eval('HideUnselectedObjects')
bakeResults(cams, sm=True, t=(st, ed), sb=1,
dic=True, pok=True, sac=False, ral=False, rba=False, bol=False, mr=False,
at=('tx', 'ty', 'tz', 'rx', 'ry', 'rz'))
mel.eval('ShowLastHidden')
delete(listRelatives(cams, ad=True, pa=True, type='parentConstraint'))
for o in cams:
print('[INFO] New Camera Created: {}'.format(o.name()))
print('# Done')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment