animating over time into a python script

animating over time into a python script

corvidstudios
Enthusiast Enthusiast
699 Views
1 Reply
Message 1 of 2

animating over time into a python script

corvidstudios
Enthusiast
Enthusiast

Hi there, so here's a script adding noise to a 3d object,

and I'm curious to know if its possible to have the noise animated over time?

(I was thinking of multiplying a sin function by time however cannot figure out the way to do it in python)

 

#add noise to a mesh

 

import maya.cmds as mc

import random

 

def addNoise(amt):

 

    selectedObjs = mc.ls(selection=True)

    obj = selectedObjs[-1]

    numVerts = mc.polyEvaluate(obj, vertex=True)

    randAmt = [0, 0, 0]

 

    for i in range(0, numVerts):

 

        for j in range(0, 3):

            randAmt[j] = random.random() * (amt*2) - amt

 

        vertexStr = "{0}.vtx[{1}]".format(obj, i)

        mc.select(vertexStr, replace=True)

        mc.move(randAmt[0], randAmt[1], randAmt[2], relative=True)

        mc.select(obj, replace=True)

 

addNoise (0.05)

0 Likes
700 Views
1 Reply
Reply (1)
Message 2 of 2

haggi_master
Advocate
Advocate

You could use a randomseed(frame) every time before you call the addNoise().

But the problem is that you use a random function, not a noise function. A random function changes very much (randomly) between every call. A 4D noise function will give you a smooth change over time. Unfortunately there is no built-in noise in Maya as much as I know.

0 Likes