Skip to content

Instantly share code, notes, and snippets.

@FryPotato893
Last active August 21, 2020 02:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FryPotato893/a3612fb0dfe7c32e2c2c33fb19b17460 to your computer and use it in GitHub Desktop.
Save FryPotato893/a3612fb0dfe7c32e2c2c33fb19b17460 to your computer and use it in GitHub Desktop.
【Maya Python API2.0】 選択したDAGノードのUV値からワールド位置情報を取得。
#-*- 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