1.lesson25_Maya API 中的多边形处理 - MFnMesh/MItMesh
2.lesson26_Maya API 中的指针 - MScriptUtil
def get_vtx_uv_point(obj, vtx_index):
"""
"""
shape_mobj = pm.PyNode(obj).getShape().__apimobject__()
mfn = om.MFnMesh(shape_mobj)
s_util = om.MScriptUtil()
uv_ptr = s_util.asFloat2Ptr()
m_point = om.MPoint()
mfn.getPoint(vtx_index, m_point)
mfn.getUVAtPoint(m_point, uv_ptr)
u_value = s_util.getFloat2ArrayItem(uv_ptr, 0, 0)
v_value = s_util.getFloat2ArrayItem(uv_ptr, 0, 1)
return (u_value, v_value)
get_vtx_uv_point('pSphere2', 2)
3.lesson27_Maya API 中的事件捕获 - MMessage
写法1:
import maya.OpenMaya as om
import maya.cmds as cmds
from functools import partial
def rename_ref_func(*args, **kwages):
new_name_space = kwages.get('new_name_space')
file_path = args[1].resolvedFullName()
cmds.file(file_path, e=1, namespace=new_name_space)
ref_callback_id = om.MSceneMessage.addReferenceCallback(om.MSceneMessage.kAfterCreateReference,
partial(rename_ref_func,new_name_space='Test'))
# remove
om.MMessage.removeCallback(ref_callback_id)
写法2:
import maya.OpenMaya as om
import maya.cmds as cmds
from functools import partial
def rename_ref_func(new_name_space, *args):
file_path = args[1].resolvedFullName()
cmds.file(file_path, e=1, namespace=new_name_space)
ref_callback_id = om.MSceneMessage.addReferenceCallback(om.MSceneMessage.kAfterCreateReference,
partial(rename_ref_func, 'Test'))
# remove
om.MMessage.removeCallback(ref_callback_id)