import re
from maya import cmds
from pymel.core.datatypes import Vector, Matrix, Point
obj = 'pCube1'
# Get the world transformation matrix of the object
obj_matrix = Matrix(cmds.xform(obj, query=True, worldSpace=True, matrix=True))
# Iterate through all faces
for face in cmds.ls(obj + '.f[*]', flatten=True):
# Get face normal in object space
face_normals_text = cmds.polyInfo(face, faceNormals=True)[0]
# Convert to a list of floats
face_normals = [float(digit) for digit in re.findall(r'-?\d*\.\d*', face_normals_text)]
# Create a Vector object and multiply with matrix to get world space
v = Vector(face_normals) * obj_matrix
# Check if vector faces downwards
if max(abs(v[0]), abs(v[1]), abs(v[2])) == -v[1]:
print face, v
如果您只需要一个没有向量数学和Pymel或API的快速解决方案,可以使用
cmds.polySelectConstraint
来查找与法线对齐的面。您只需选择所有面,然后使用约束仅获取指向正确方向的面。这将选择网格中沿给定轴指向的所有面:
^{pr2}$axis
是你想要的x,y,z轴,tolerance
是你能容忍的斜率。为了得到向下的脸你会这样做或者
这种方法的优势主要是在玛雅的C++中运行,它将比基于Python的方法在网格中的所有面上循环更快。在
使用pymel,代码可以更紧凑一些。选择向下的面:
相关问题 更多 >
编程相关推荐