cwisbg

ParticlesFollowSurface

Apr 18th, 2019
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. from pymel.core import *
  2. sl = selected()
  3. scatterAmnt = 1000
  4. SurfaceOffsetAnmt = .01
  5. SurfaceForce = -1
  6. ParticleSize = .1
  7. UniformDistribution = True
  8. currentTime(1, u=1)
  9. for s in sl:
  10. name = s
  11. if UniformDistribution:
  12. ScatterNode = ls(name+"_mesh2arrays") # will chech to see if node exsists already
  13. if ScatterNode:# if node does not exsist
  14. delete(ScatterNode)
  15. ScatterNode = createNode("mesh2arrays") # create node
  16. rename(ScatterNode, name+"_mesh2arrays")
  17. ScatterNode = ls(name+"_mesh2arrays") #this is dumb, but finds node again after renaming
  18. s.worldMesh[0] >> ScatterNode[0].inputMesh # connections
  19. setAttr(name+"_mesh2arrays"+".type",3)
  20. setAttr(name+"_mesh2arrays"+".count",scatterAmnt)
  21. setAttr(name+"_mesh2arrays"+".relaxIterations",20)
  22. ScatterArray = getAttr(ScatterNode[0].positionArray)
  23. ScatterNormalArray = getAttr(ScatterNode[0].normalArray)
  24. ScatterArrayOffset = []
  25. i=0
  26. for pos in ScatterArray:# offset particle from surface
  27. newPos = pos + ScatterNormalArray[i]*SurfaceOffsetAnmt
  28. ScatterArrayOffset.append(newPos)
  29. i+=1
  30.  
  31.  
  32. ParticleCheck = ls(name+"_surfaceParticles")
  33. if ParticleCheck:
  34. delete(ParticleCheck)
  35. ParticleScatter = particle(p = ScatterArrayOffset, jr=1, n= name+"_surfaceParticles")
  36. setAttr(ParticleScatter[0] +".particleRenderType", 4)
  37. addAttr(ParticleScatter[1], ln="radius", at="float", min= 0, max = 10, dv = ParticleSize)
  38. setAttr(ParticleScatter[0] +".goalSmoothness", 10)
  39. setAttr(ParticleScatter[0] +".visibleInReflections", 1)
  40. setAttr(ParticleScatter[0] +".visibleInRefractions", 1)
  41. setAttr(ParticleScatter[0] +".lifespanMode", 3)
  42. NewAttrList = "RandomScale","RandomIndex","collisionU","collisionV","goalU","goalV","traceDepthPP","randomRotationX","rotationPP"
  43. for attr in NewAttrList:
  44. addAttr(ParticleScatter, ln=attr,dt="doubleArray")
  45. goal(ParticleScatter,g= s, w=1)
  46. addAttr(ParticleScatter, ln="userVector1PP" ,dt="vectorArray")
  47. collision(s,ParticleScatter[0], r=0, f=1, o =.01)
  48. connectDynamic(ParticleScatter[0], c=s)
  49. # expression
  50. p = str(ParticleScatter[1])
  51. ex = "{0}.goalPP = 0;".format(ParticleScatter[1])
  52. ex += "\n"+p+".randomRotationX = rand(360);"
  53. ex += "\n"+p+".userVector1PP = <<0,1,0>>;"
  54. ex += "\n"+p+".RandomIndex = rand(0,3);"
  55. ex += "\n"+p+".RandomScale = rand(.9,1.1);"
  56. dynExpression(ParticleScatter[1], c=1, s = ex)
  57. exAD = "vector $normal = <<0,rand(0,360),0>>;"+"\n"
  58. exAD += "float $rotZ = rad_to_deg((atan2(($normal.y),($normal.x))));"+"\n"
  59. exAD +="float $rotY = rad_to_deg((asin(-($normal.z))));"+"\n"
  60. exAD += ""+p+".rotationPP = <<"+p+".randomRotationX,$rotY,$rotZ>>;"
  61. exBD = "if("+p+".collisionU > -1)"+"\n"+"{"+"\n"+""+p+".goalPP=1;"+"\n"+""+p+".goalU = "+p+".collisionU;"+"\n"+""+p+".goalV = "+p+".collisionV;"+"\n"+""+p+".traceDepthPP=0;"+"\n"+"}"
  62. exBD +="if(frame > 5 && "+p+".goalU == 0){"+p+".lifespanPP = 0;}"
  63. dynExpression(ParticleScatter[1], rbd=1, s = exBD)
  64. for i in range(0,scatterAmnt-1): # shoot the particle back at surface
  65. particle(ParticleScatter[1], at="velocity", id=i, vv = ScatterNormalArray[i]*SurfaceForce, e=1)
Advertisement
Add Comment
Please, Sign In to add comment