Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pymel.core import *
- sl = selected()
- scatterAmnt = 1000
- SurfaceOffsetAnmt = .01
- SurfaceForce = -1
- ParticleSize = .1
- UniformDistribution = True
- currentTime(1, u=1)
- for s in sl:
- name = s
- if UniformDistribution:
- ScatterNode = ls(name+"_mesh2arrays") # will chech to see if node exsists already
- if ScatterNode:# if node does not exsist
- delete(ScatterNode)
- ScatterNode = createNode("mesh2arrays") # create node
- rename(ScatterNode, name+"_mesh2arrays")
- ScatterNode = ls(name+"_mesh2arrays") #this is dumb, but finds node again after renaming
- s.worldMesh[0] >> ScatterNode[0].inputMesh # connections
- setAttr(name+"_mesh2arrays"+".type",3)
- setAttr(name+"_mesh2arrays"+".count",scatterAmnt)
- setAttr(name+"_mesh2arrays"+".relaxIterations",20)
- ScatterArray = getAttr(ScatterNode[0].positionArray)
- ScatterNormalArray = getAttr(ScatterNode[0].normalArray)
- ScatterArrayOffset = []
- i=0
- for pos in ScatterArray:# offset particle from surface
- newPos = pos + ScatterNormalArray[i]*SurfaceOffsetAnmt
- ScatterArrayOffset.append(newPos)
- i+=1
- ParticleCheck = ls(name+"_surfaceParticles")
- if ParticleCheck:
- delete(ParticleCheck)
- ParticleScatter = particle(p = ScatterArrayOffset, jr=1, n= name+"_surfaceParticles")
- setAttr(ParticleScatter[0] +".particleRenderType", 4)
- addAttr(ParticleScatter[1], ln="radius", at="float", min= 0, max = 10, dv = ParticleSize)
- setAttr(ParticleScatter[0] +".goalSmoothness", 10)
- setAttr(ParticleScatter[0] +".visibleInReflections", 1)
- setAttr(ParticleScatter[0] +".visibleInRefractions", 1)
- setAttr(ParticleScatter[0] +".lifespanMode", 3)
- NewAttrList = "RandomScale","RandomIndex","collisionU","collisionV","goalU","goalV","traceDepthPP","randomRotationX","rotationPP"
- for attr in NewAttrList:
- addAttr(ParticleScatter, ln=attr,dt="doubleArray")
- goal(ParticleScatter,g= s, w=1)
- addAttr(ParticleScatter, ln="userVector1PP" ,dt="vectorArray")
- collision(s,ParticleScatter[0], r=0, f=1, o =.01)
- connectDynamic(ParticleScatter[0], c=s)
- # expression
- p = str(ParticleScatter[1])
- ex = "{0}.goalPP = 0;".format(ParticleScatter[1])
- ex += "\n"+p+".randomRotationX = rand(360);"
- ex += "\n"+p+".userVector1PP = <<0,1,0>>;"
- ex += "\n"+p+".RandomIndex = rand(0,3);"
- ex += "\n"+p+".RandomScale = rand(.9,1.1);"
- dynExpression(ParticleScatter[1], c=1, s = ex)
- exAD = "vector $normal = <<0,rand(0,360),0>>;"+"\n"
- exAD += "float $rotZ = rad_to_deg((atan2(($normal.y),($normal.x))));"+"\n"
- exAD +="float $rotY = rad_to_deg((asin(-($normal.z))));"+"\n"
- exAD += ""+p+".rotationPP = <<"+p+".randomRotationX,$rotY,$rotZ>>;"
- 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"+"}"
- exBD +="if(frame > 5 && "+p+".goalU == 0){"+p+".lifespanPP = 0;}"
- dynExpression(ParticleScatter[1], rbd=1, s = exBD)
- for i in range(0,scatterAmnt-1): # shoot the particle back at surface
- particle(ParticleScatter[1], at="velocity", id=i, vv = ScatterNormalArray[i]*SurfaceForce, e=1)
Advertisement
Add Comment
Please, Sign In to add comment