Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 19th, 2012  |  syntax: Python  |  size: 1.14 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from maya.OpenMaya import *
  2. import maya.cmds as mc
  3.  
  4. # Extract volume's dag path, so we can get it's matrix
  5. sel = MSelectionList()
  6. sel.add("box1")
  7. dag = MDagPath()
  8. sel.getDagPath(0, dag)
  9. TM = MTransformationMatrix(dag.inclusiveMatrix())
  10. # Get the volume's center point
  11. cntr = TM.getTranslation(MSpace.kWorld)
  12.  
  13. # Spherical falloff
  14. for i in mc.getAttr("nParticle1.id"):
  15.     p = mc.particle("nParticle1", q=1, id=i, at="position")
  16.     # Get the point position relative to the volume center
  17.     Psrc = MVector(p[0], p[1], p[2]) - cntr
  18.     # Transform that into 'volume' space
  19.     Pvolume = Psrc*dag.inclusiveMatrixInverse()
  20.     # Get the projection of that vector on the volume's surface
  21.     Pproj = Pvolume.normal()
  22.     # Transform back to get the orientation and scale of the volume
  23.     Pproj *= dag.inclusiveMatrix()
  24.     # falloff
  25.     falloff = Psrc.length()/Pproj.length()
  26.     # clamp & invert
  27.     falloff = min(1, max(0,falloff))
  28.     # test
  29.     rgb = [1-falloff]*3
  30.     radius = (1-falloff)
  31.     mc.particle("nParticle1", e=1, id=i, at="rgbPP", vv=rgb)
  32.     mc.particle("nParticle1", e=1, id=i, at="radiusPP", fv=radius)
  33. mc.refresh()