-
Notifications
You must be signed in to change notification settings - Fork 6
/
particleToTube.py
94 lines (66 loc) · 3.98 KB
/
particleToTube.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import maya.cmds as mc
import random
import math
allParticleDictionary = {}
emptyFolder = mc.group(em=True, n="extruPath")
emptyCirFolder = mc.group(em=True, n="circleCreation")
empty_ACirFolder = mc.group(em=True, n="circleGeo")
empty_curveFolder = mc.group(em=True, n="curveExtrusions")
minFrames = mc.playbackOptions( q=True, min=True)
maxFrames = mc.playbackOptions( q=True, max=True)
for currentFrame in range(0, int(maxFrames)):
#print('Frame=' + str(currentFrame))
mc.currentTime(currentFrame, update=True, edit=True)
mc.select('nParticle1')
theParticle = mc.ls(sl=True, type='transform')
for part in theParticle:
for particleCount in range(0,mc.particle(part, q=True,ct=True)):
particleName = mc.particle(part, q=True, order=particleCount, at='id')
particlesPosition = mc.particle(part, q=True, order=particleCount, at='position')
#print (particleName, particlesPosition, particleCount)
particleDictionary = {}
if str(particleName[0]) in allParticleDictionary.keys():
particleDictionary = allParticleDictionary[str(particleName[0])]
particleDictionary[currentFrame] = particlesPosition
allParticleDictionary[str(particleName[0])] = particleDictionary
for curveParticleId in allParticleDictionary.keys():
#print sorted(allParticleDictionary[curveParticleId].keys())
#print curveParticleId
pointList = []
sortedKeyFrameList = sorted(allParticleDictionary[curveParticleId].keys())
if len(sortedKeyFrameList) > 1:
for keyFrame in sortedKeyFrameList:
pointList.append(allParticleDictionary[curveParticleId][keyFrame])
curveName = "partiCurve" + str(curveParticleId)
curveObj = mc.curve(name=curveName, p=pointList)
#For every locator we create, make a bubble and attach that to the locator in worldspace and parent in underneath
getCurvLen = mc.arclen(curveObj)
makeCvrLenInt = math.ceil(getCurvLen*.5)#reduces the amount of spans the curve has, this is useful on very long extrusions
makeCircle = mc.circle(n="newCircle",d=1, s=12)
aCircle = mc.planarSrf(makeCircle[0], n="extruTube", ch=1, d=1, ko=0, rn=0, po=1, nds=3)
getTesInfo = mc.listConnections(aCircle[1], t="nurbsTessellate")
mc.setAttr(getTesInfo[0] + ".polygonCount", 1)
mc.setAttr(getTesInfo[0] + ".polygonType", 1)
mc.setAttr(getTesInfo[0] + ".format", 0)
getCurveCVPos = mc.xform(curveObj + ".cv[0]", ws=True, q=True, translation=True)
mc.xform(makeCircle[0], ws=True, t=(getCurveCVPos[0], getCurveCVPos[1], getCurveCVPos[2]),ro=(90, 0, 0))#use "ro" to orient the circle to the curve if your extrusion is black
tubes = mc.polyExtrudeFacet(aCircle[0] + ".f[0]", inc=curveObj, d=makeCvrLenInt)
subCurveCreate = mc.createNode("subCurve", n="subCurve_" + curveObj)
curveShape = mc.listRelatives(curveObj, s=True)
mc.setAttr(subCurveCreate + ".relative", 1)
mc.connectAttr(curveShape[0] + ".worldSpace", subCurveCreate + ".inputCurve", f=True)
mc.connectAttr(subCurveCreate + ".outputCurve", tubes[0] + ".inputProfile", f=True)
mc.setAttr(subCurveCreate + ".maxValue", 0)
mc.setKeyframe(subCurveCreate, attribute='maxValue', t=[sortedKeyFrameList[0]])
mc.setAttr(subCurveCreate + ".maxValue", 1)
mc.setKeyframe(subCurveCreate, attribute='maxValue', t=[sortedKeyFrameList[-1]])
#set the visibility
mc.setAttr(aCircle[0] + ".visibility", 1)
mc.setKeyframe(aCircle[0], attribute='visibility', t=[sortedKeyFrameList[0]])
#mc.currentTime((sortedKeyFrameList[0]-1), update=True, edit=True)
mc.setAttr(aCircle[0] + ".visibility", 0)
mc.setKeyframe(aCircle[0], attribute='visibility', t=[sortedKeyFrameList[0]-1])
mc.parent(makeCircle, emptyCirFolder)
mc.parent(aCircle, empty_ACirFolder)
mc.parent(curveObj, empty_curveFolder)
mc.parent(empty_curveFolder,emptyCirFolder,empty_ACirFolder, emptyFolder)