Skip to content

Instantly share code, notes, and snippets.

@gregtemp
Last active August 29, 2015 14:02
Show Gist options
  • Save gregtemp/8a8489a6ccad4192d51a to your computer and use it in GitHub Desktop.
Save gregtemp/8a8489a6ccad4192d51a to your computer and use it in GitHub Desktop.
the last thing i was working on - MAYA
# random particle velocity -- (the right way)
import maya.cmds as cmds
import random
from maya.OpenMaya import MVector
random.seed(1234)
# setup
amountOfParticles = 50
r = 10
vr = 4
myList = list()
#list particles and delete
# convenience
particleList = cmds.ls( 'particleObject*' )
#if there are any, then delete them all
if len(particleList) >= 1:
cmds.delete(particleList)
print ('deleted old particleObject')
else:
print ('no old particleObjects')
# make all particles and add em
for i in range( 0, amountOfParticles):
x = random.uniform(- r, r)
y = random.uniform(- r, r)
z = random.uniform(- r, r)
newPosition = (x,y,z)
myList.append(newPosition)
cmds.particle(p=myList,n='particleObject#')
velCExpString = 'float $myRange = %s; float $vx = rand(-$myRange, $myRange); float $vy = rand(-$myRange, $myRange); float $vz = rand(-$myRange, $myRange); particleObject2Shape.velocity = <<$vx, $vy, $vz>>;' %(vr)
#just a little check to see if im doing it right
print (velCExpString)
#the dynExp iterates through each particle... so you dont have to.
cmds.dynExpression( 'particleObject*Shape', s=velCExpString, c=1 )
#make this global
def vectorCompHandler (x, y, z):
print(x)
#use MVector to compare position to get distance
# http://download.autodesk.com/us/maya/2010help/API/class_m_vector.html
# http://www.naughtynathan.co.uk/?p=296
# functions in python
# http://www.tutorialspoint.com/python/python_functions.htm
# some python intro stuff
# http://www.astro.up.pt/~sousasag/Python_For_Astronomers/Python_qr.pdf
# boid stuff
# http://www.vonmammen.org/biocaad/2010/01/demos-2d3d-boids-stigmergy-swarm-grammars/
# https://www.youtube.com/watch?v=bJ58tD2hSWs
#
if (particleObject2Shape.particleId == 0 && (frame%10)==0) { vector $myVector = particleObject2Shape.position; python(vectorCompHandler($myVector.x, $myVector.y, $myVector.z));}
// this doesn't work either because im passing the variables incorrectly (i think?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment