maya的脚本是非常之强大的,参数化建模,智能设计师未来的一个趋势。
实现的功能:
· 通过python脚本随机生成60个多边形,并对生成的每个多边形随机进行移动,旋转和缩放;
· 设定中间的球形为目标,生成的多边形受限于目标;
代码实现:[python] view plain copy
1. import maya.cmds as cmds
2. import random
3.
4. random.seed(1111)
5.
6. cubeList = cmds.ls('mycube*')
7. if len(cubeList)>0:
8. cmds.delete(cubeList)
9.
10. groupName = cmds.group(em=True,n='groupCube')
11. for i in range(0,60):
12. result = cmds.polyCube(w=1,h=1,d=1,n='mycube#')
13. cmds.parent(result,groupName)
14. x = random.uniform(-10,10)
15. y = random.uniform(-10,10)
16. z = random.uniform(-10,10)
17. cmds.move(x,y,z,result)
18.
19. xRot = random.uniform(0,180)
20. yRot = random.uniform(0,180)
21. zRot = random.uniform(0,180)
22. cmds.rotate(xRot,yRot,zRot,result)
23.
24. scaleFactor = random.uniform(0.8,1.2)
25. cmds.scale(scaleFactor,scaleFactor,scaleFactor,result)
设置目标:
[python] view plain copy
1. selectionList = cmds.ls(orderedSelection=True)
2. print selectionList
3.
4. if len(selectionList)>=2:
5. targetName = selectionList[0]
6. selectionList.remove(targetName)
7. for objectName in selectionList:
8. cmds.aimConstraint(targetName,objectName,aim=[2.0,1.0,1.0])
9. else:
10. print 'Select more than two objects!'
效果图:
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标常用软件之Maya频道!