Maya Python脚本建模之随机生成多边形并设定目标限制

来源:互联网 发布:vivo软件商店下载 编辑:程序博客网 时间:2024/05/16 13:47

maya的脚本是非常之强大的,参数化建模,智能设计师未来的一个趋势。


实现的功能:

  • 通过python脚本随机生成60个多边形,并对生成的每个多边形随机进行移动,旋转和缩放;
  • 设定中间的球形为目标,生成的多边形受限于目标;

代码实现:
import maya.cmds as cmdsimport randomrandom.seed(1111)cubeList = cmds.ls('mycube*')if len(cubeList)>0:    cmds.delete(cubeList)groupName = cmds.group(em=True,n='groupCube')for i in range(0,60):result = cmds.polyCube(w=1,h=1,d=1,n='mycube#')cmds.parent(result,groupName)x = random.uniform(-10,10)y = random.uniform(-10,10)z = random.uniform(-10,10)cmds.move(x,y,z,result)xRot = random.uniform(0,180)yRot = random.uniform(0,180)zRot = random.uniform(0,180)cmds.rotate(xRot,yRot,zRot,result)scaleFactor = random.uniform(0.8,1.2)cmds.scale(scaleFactor,scaleFactor,scaleFactor,result)

设置目标:
selectionList = cmds.ls(orderedSelection=True)print selectionListif len(selectionList)>=2:targetName = selectionList[0]selectionList.remove(targetName)for objectName in selectionList:cmds.aimConstraint(targetName,objectName,aim=[2.0,1.0,1.0])else:print 'Select more than two objects!'


效果图:


最后附上Maya python开发API

0 0
原创粉丝点击