-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMeshToParticlesUtils.py
More file actions
69 lines (51 loc) · 2.2 KB
/
Copy pathMeshToParticlesUtils.py
File metadata and controls
69 lines (51 loc) · 2.2 KB
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
import maya.cmds as mc
def meshToParticles(meshes=None):
if meshes is None:
meshes = mc.ls(sl=True, dag=True, shapes=True, type="mesh")
if not meshes:
mc.warning("No mesh selected.")
return
for mesh in meshes:
setupParticles(mesh + '.outMesh')
def setupParticles(mesh_attr, create_attr=True, name="particle"):
"""Creates particles from a given mesh attribute"""
# Create meshToParticles
mtp = mc.createNode('meshToParticles', ss=True)
mc.setAttr(mtp + '.ca', create_attr)
mc.connectAttr(mesh_attr, mtp + '.inMesh')
# Create particle shape
particle = mc.createNode('particle', n=name + 'Shape', ss=True)
mc.setAttr(particle + '.isDynamic', 0)
mc.setAttr(particle + '.startFrame', 10000000)
mc.setAttr(particle + '.particleRenderType', 4)
# Connect
mc.connectAttr(mtp + ".output", particle + '.currentTime')
return mtp, particle
def bifrostToParticles(bif_attr):
"""Creates particles from a Bifrost graph attribute"""
print("creating particles from", bif_attr)
bif = mc.createNode('bifrostGeoToMaya', ss=True)
mc.setAttr(bif + '.ct', "", type="string")
mc.setAttr(bif + '.pr', "* !point_position", type="string")
mc.connectAttr(bif_attr, bif + '.bifrostGeo')
setupParticles(bif + '.mayaMesh[0]', name=bif_attr.split('.')[1])
def bifrostToParticlesDialog():
"""Dialog to selecting a Bifrost graph port to create particles from"""
containers = mc.ls(sl=True, dag=True, shapes=True, type='bifrostGraphShape')
if not containers:
containers = mc.ls(sl=True, type='bifrostBoard')
if not containers:
mc.warning("No bifrost container selected.")
return
container = containers[0]
ports = mc.vnnCompound(container, "/", lp=True, op=True)
# Create dialog
dialog = mc.window(title="Bifrost To Particles", widthHeight=(200, 100), retain=False)
mc.columnLayout(adjustableColumn=True)
def createAndClose(p):
bifrostToParticles(p)
mc.deleteUI(dialog)
# Create button for each port
for port in ports:
mc.button(label=port, command=lambda x=None, p=f"{container}.{port}": createAndClose(p))
mc.showWindow(dialog)