
Untitled
By: a guest on
Aug 19th, 2012 | syntax:
Python | size: 1.14 KB | hits: 7 | expires: Never
from maya.OpenMaya import *
import maya.cmds as mc
# Extract volume's dag path, so we can get it's matrix
sel = MSelectionList()
sel.add("box1")
dag = MDagPath()
sel.getDagPath(0, dag)
TM = MTransformationMatrix(dag.inclusiveMatrix())
# Get the volume's center point
cntr = TM.getTranslation(MSpace.kWorld)
# Spherical falloff
for i in mc.getAttr("nParticle1.id"):
p = mc.particle("nParticle1", q=1, id=i, at="position")
# Get the point position relative to the volume center
Psrc = MVector(p[0], p[1], p[2]) - cntr
# Transform that into 'volume' space
Pvolume = Psrc*dag.inclusiveMatrixInverse()
# Get the projection of that vector on the volume's surface
Pproj = Pvolume.normal()
# Transform back to get the orientation and scale of the volume
Pproj *= dag.inclusiveMatrix()
# falloff
falloff = Psrc.length()/Pproj.length()
# clamp & invert
falloff = min(1, max(0,falloff))
# test
rgb = [1-falloff]*3
radius = (1-falloff)
mc.particle("nParticle1", e=1, id=i, at="rgbPP", vv=rgb)
mc.particle("nParticle1", e=1, id=i, at="radiusPP", fv=radius)
mc.refresh()