Skip to content

Instantly share code, notes, and snippets.

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/97e382972f5396fd2ddf to your computer and use it in GitHub Desktop.
Save taikomatsu/97e382972f5396fd2ddf to your computer and use it in GitHub Desktop.
get angle(degree) difference from z axis to selected edge.
from pymel.core import *
# 確実にエッジを取得したいのでfilterExpandを使用。
e = filterExpand(sm=32)[0]
# 更にfilterExpandを使用するとls -flをした時と同様に要素が1つずつ確実に返ってくる。
# edgeの両端のvertexの場合、頂点番号がつながっているとそのまま1まとまりで返されたりする。
# なので念のため再度filterExpandに渡してデータにエラーがないようにしている。
# filterExpandでは文字列を返してくるため最後にPyNodeを使ってpymelオブジェクトに変換。
v = [PyNode(v) for v in filterExpand(polyListComponentConversion(e, fromEdge=True, toVertex=True), sm=31)]
space = 'world'
# normal()はnormalizeされたデータのコピーを返す。
diff = (v[0].getPosition(space=space) - v[1].getPosition(space=space)).normal()
# 軸は任意で変更可能。
# dotは向きだけを取得したいので長さは確実に1にしておくこと。
axis = dt.Vector(0, 0, 1)
d = diff.dot(axis)
deg = dt.degrees(dt.acos(d))
print('[Result] %f degree' % deg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment