MayaからUnityへ座標変換
一回FBXにして書き出すとかダルみがすごいのでMaya上でなんとかする
対象ノードを選択して以下を実行
code:convert_unity_coordinate.py
unit_convert_dict = {
"mm": 1000,
"cm": 100,
"m": 1,
"km": 0.001
}
res = []
for target in cmds.ls(sl=True):
# translate
trans = list(cmds.getAttr(target + ".t")0) correct_value = unit_convert_dict.get(cmds.currentUnit(q=True, l=True), 1)
# rotate
matrix = cmds.xform(target, query=True, matrix=True)
mt = om.MTransformationMatrix(om.MMatrix(matrix))
mt.reorderRotation(om.MTransformationMatrix.kZXY) # RotationOrderをUnityに合わせる
rot = mt.rotation()
scale = [str(x) for x in list(cmds.getAttr(target + ".s")0)] translate: {1}
rotate: {2}
scale: {3}
""".format(target, ", ".join(trans), ", ".join(rotate), ", ".join(scale)))
print(os.linesep.join(res))
結果こんなのが出力される
pCylinder1
translate: -0.0471209315147, 0.0, 0.0
rotate: -11.271274565, -15.2160797349, 2.92950845867
scale: 1.0, 1.0, 1.0
pCube1
translate: 0.021504088154, 0.0582450816818, -0.0221797231073
rotate: 25.0958814885, 37.421600975, 37.2086659446
scale: 1.0, 1.0, 1.0
そこそこ需要あるのではと思いつつ情報が案外なくてびびる