Created
June 26, 2018 12:27
-
-
Save hexagit/983dca427100ed790acfacd224cb57d7 to your computer and use it in GitHub Desktop.
Mayaで位置をUVに変換とUVを位置に変換
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
# -*- coding: utf-8 -*- | |
#=========================================== | |
# UV座標に対応するワールド座標とワールド座標に対応するUV座標 | |
#=========================================== | |
import maya.api.OpenMaya as om | |
# メッシュもろもろ取得 | |
mesh_selList = om.MGlobal.getActiveSelectionList() | |
mesh_dag = mesh_selList.getDagPath(0) | |
mesh_MFn = om.MFnMesh(mesh_dag) | |
# 判定ワールド座標 | |
pickPos = om.MPoint(0,0,0) | |
# ワールド空間座標に対応する最近接のUV位置を取得する | |
result = mesh_MFn.getUVAtPoint(pickPos,om.MSpace.kWorld) | |
print u"座標 {} の最近接UV座標 : {}".format(pickPos, result[0], result[1]) | |
print u"座標 {} の最近接UV番号 : {}".format(pickPos, result[2]) | |
# UV座標に対応するワールド空間座標を取得する | |
# こっちは指定したUV座標にフェースが存在していないとエラーがでてしまう | |
faceNum = 9 | |
UV = [0.5,0.5] | |
result = mesh_MFn.getPointAtUV(faceNum, UV[0], UV[1], om.MSpace.kWorld) | |
print u"UV {} の最近接ワールド座標 : {}".format(UV, result[0], result[1], result[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment