Last active
August 21, 2020 02:21
-
-
Save FryPotato893/a3612fb0dfe7c32e2c2c33fb19b17460 to your computer and use it in GitHub Desktop.
【Maya Python API2.0】 選択したDAGノードの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 -*- | |
import maya.cmds as cmds | |
import maya.api.OpenMaya as om | |
def getPointAtUV(U,V): | |
u""" | |
概要: | |
選択したDAGノードのUV値からワールド位置情報を取得。 | |
例 : getPointAtUV(0.5,0.5) | |
引数: | |
U (float) : U値。 | |
V (float) : V値。 | |
戻り値: | |
vector[] : ワールド位置情報。 | |
UV値上にフェースが無い場合はNone。 | |
""" | |
selList = om.MGlobal.getActiveSelectionList() | |
dagPath = selList.getDagPath(0) | |
#メッシュノードか判定 | |
if dagPath.hasFn( om.MFn.kMesh ): | |
mesh = om.MFnMesh(dagPath) | |
uvset = mesh.getUVSetNames() | |
for i in range(mesh.numPolygons): | |
try: | |
point = mesh.getPointAtUV(i,U,V,space=om.MSpace.kWorld,uvSet=uvset[0],tolerance=0.0) | |
return list(point)[:3] | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment