Many 3D modeling and animation packages provide a way to add a bit of random noise to the vertices of an object, but Maya does not. This may seem like an oversight, but it also provides us with a great example project.
In this example, we'll write a script to step through all of the vertices of a polygonal object and move each of them slightly. Here's an example of what a simple polygonal sphere looks like both before and after applying the script that we'll be developing:
Create a new script, name it addNoise.py
, and add the following code:
import maya.cmds as cmds import random def addNoise(amt): selectedObjs = cmds.ls(selection=True) obj = selectedObjs[-1] shapeNode = cmds.listRelatives(obj, shapes=True) if (cmds.nodeType(shapeNode) != 'mesh'): cmds.error('Select a mesh') return numVerts = cmds.polyEvaluate(obj, vertex=True) randAmt = [0, 0, 0] for i in range(0, numVerts): for j in range...