第八周——作业
程序员文章站
2022-07-12 13:35:54
...
作业一:
###########################################
############## 作业一 ###################
###########################################
OpenMaya.MFileIO.newFile(True)
#创建小球
for x in range(0, 10, 3):
for y in range(0, 10, 3):
for z in range(0, 10, 3):
pShere = mc.polySphere(r=2)
mc.move(x, y, z, pShere, absolute=True)
# 设置选择物体的起始点坐标,结束点坐标
loc = [(80, 90),(300, 360)]
#按照屏幕的位置进行物体选择
for tx in range(loc[0][0], loc[1][0], 4):
for ty in range(loc[0][1], loc[1][1], 4):
MGlobal.selectFromScreen(tx, ty)
作业二:
objects = mc.ls(typ='phong') + mc.ls(typ='lambert') + mc.ls(typ='shaderGlow')+ mc.ls(typ='shaderGlow')
for obj in objects:
mc.select(obj, add=True)
OpenMaya.MFileIO.exportSelected('C:/Users/wang161x/Desktop/test2.mb','mayaAscii')
作业三:
思路:
先通过MItDependcyNodes找到对应的mesh节点,然后使用MItDenpendGraph再对节点进行遍历,遍历的时候进行筛选
def travel_node(node):
it=OpenMaya.MItDependencyGraph(node,OpenMaya.MFn.kInvalid,OpenMaya.MItDependencyGraph.kUpstream,OpenMaya.MItDependencyGraph.kBreadthFirst,OpenMaya.MItDependencyGraph.kPlugLevel)
it.enablePruningOnFilter()
it.setCurrentFilter(OpenMaya.MFn.kShadingEngine)
#对遍历的结果进行过滤
while not it.isDone():
print(OpenMaya.MFnDependencyNode(it.currentItem()).name())
it.next()
iterator = OpenMaya.MItDependencyNodes(OpenMaya.MFn.kMesh)
# 参数地址 http://help.autodesk.com/view/MAYAUL/2016/CHS/?guid=__cpp_ref_class_m_fn_html
while not iterator.isDone():
print(OpenMaya.MFnDependencyNode(iterator.item()).name())
node = iterator.item()
travel_node(node)
iterator.next()