Reader small image

You're reading from  Maya Programming with Python Cookbook

Product typeBook
Published inJul 2016
Reading LevelIntermediate
PublisherPackt
ISBN-139781785283987
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Adrian Herbez
Adrian Herbez
author image
Adrian Herbez

Adrian Herbez is an accomplished software engineer and educator with a background in virtual worlds and gaming. He has worked as a web developer at Linden Lab (the creators of Second Life) and a senior software engineer at Sony Computer Entertainment, America, where he developed games and interactive content for PlayStation Home. He also served as the lead gameplay engineer for KIXEYE's War Commander. Adrian has also taught at the Academy of Art University in San Francisco in a number of different departments over the years, covering Maya, web development, and game programming. He is currently the cofounder and president of Jamwix, a game and media start-up. So far, Jamwix has released CineMagic: Hollywood Madness, a mobile game for iOS and Android as well as the first feature-length movie for virtual reality (The Banshee Chapter: Oculus Rift Edition). Adrian holds a master's degree in Fine Arts from the University of California, Irvine, from the Arts, Computation, and Engineering department, and has served as a juror for IndieCade, the international festival of independent gaming, for a number of years.
Read more about Adrian Herbez

Right arrow

Creating new modifiers (noise)


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:

How to do it...

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...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Maya Programming with Python Cookbook
Published in: Jul 2016Publisher: PacktISBN-13: 9781785283987

Author (1)

author image
Adrian Herbez

Adrian Herbez is an accomplished software engineer and educator with a background in virtual worlds and gaming. He has worked as a web developer at Linden Lab (the creators of Second Life) and a senior software engineer at Sony Computer Entertainment, America, where he developed games and interactive content for PlayStation Home. He also served as the lead gameplay engineer for KIXEYE's War Commander. Adrian has also taught at the Academy of Art University in San Francisco in a number of different departments over the years, covering Maya, web development, and game programming. He is currently the cofounder and president of Jamwix, a game and media start-up. So far, Jamwix has released CineMagic: Hollywood Madness, a mobile game for iOS and Android as well as the first feature-length movie for virtual reality (The Banshee Chapter: Oculus Rift Edition). Adrian holds a master's degree in Fine Arts from the University of California, Irvine, from the Arts, Computation, and Engineering department, and has served as a juror for IndieCade, the international festival of independent gaming, for a number of years.
Read more about Adrian Herbez