Last active
August 29, 2015 14:25
-
-
Save taikomatsu/97e382972f5396fd2ddf to your computer and use it in GitHub Desktop.
get angle(degree) difference from z axis to selected edge.
This file contains 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
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