Happy New Year guys, as promised, here is what I did with your code. Thanks again for sharing it!
First, get your bones setup as ziva bones.
In our character some muscles would fail the ziva model test, but would pass if I average verts. So I built that in to the makeZivaMuscle procedure.
def makeZivaMuscle():
# need muscle selected
if len(mc.ls(sl=1)) > 1:
print 'Select only one mesh to make into muscle'
return False
simGeo = mc.ls(sl=1)[0]
# try creating muscle, if fails average vtx and try again
mc.select(simGeo, r=1)
try:
zNodes = mc.ziva(t=1)
except:
# print '\t!', simGeo, 'ziva muscle failed. Averaging vtx and trying again'
mc.polyAverageVertex(simGeo)
try:
zNodes = mc.ziva(t=1)
print '\t! created zMuscle on ', simGeo
except:
return False
zGeo = zNodes[0]
zTissue = zNodes[1]
zTet = zNodes[2]
zMaterial = zNodes[3]
return zNodes
Next is the procedure that would do the attachments. I wanted muscles to be attached to different bones so it takes in which end point to attach to a given bone. I wouldn't have known about muscle end points if it wasn't for Khalil66. Thanks for the inspiration.
def zAttach(boneMeshName, muscleGeo, iGrow, endPoint):
cmds.select(cl=1)
cmds.select(muscleGeo)
# create fiber to get end points
z = cmds.ziva(f=1)[0]
a = cmds.getAttr(z + '.endPoints')
cmds.delete(z)
pointcv = []
# collect end points
for g in range(len(a)):
if a[g] == 0 or a[g] == 1:
pointcv.append(g)
cmds.select(cl=1)
if endPoint == 'top':
print 'endpoint', muscleGeo, '.vtx[', str(pointcv[1]), ']'
cmds.select(muscleGeo + '.vtx[' + str(pointcv[1]) + ']')
for s in range(iGrow):
cmds.GrowPolygonSelectionRegion()
cmds.select(boneMeshName, add=1)
cmds.ziva(a=1)
if endPoint == 'bottom':
print 'endpoint', muscleGeo, '.vtx[', str(pointcv[0]), ']'
cmds.select(muscleGeo + '.vtx[' + str(pointcv[0]) + ']')
for s in range(iGrow):
cmds.GrowPolygonSelectionRegion()
cmds.select(boneMeshName, add=1)
cmds.ziva(a=1)
return True
That's it for the definitions. And now here's how it's used. First we need a dictionary that assigns muscles to bones specifying which side of the muscle (top or bottom) attaches to which bone. And then basically just a loop to go through it all.
zSetupDict = {
'fermur001_L_IN': [
{'bottom': ["backLeg001_L_02_SIM", "backLeg001_L_03_SIM", "backLeg001_L_05_SIM", "backLeg001_L_06_SIM",
"backLeg001_L_09_SIM", "backLeg001_L_012_SIM", "backLeg001_L_013_SIM", "backLeg001_L_01_SIM",
"backLeg001_L_02_SIM", ]},
{'top': ["backLeg001_L_05_SIM", "backLeg001_L_06_SIM", "backLeg001_L_08_SIM", "backLeg001_L_07_SIM",
"backLeg001_L_05_SIM"]}, ],
'pelvis001_C_IN': [
{'top': ["backLeg001_L_02_SIM", "backLeg001_L_01_SIM", "backLeg001_L_03_SIM", "backLeg001_L_013_SIM",
"backLeg001_R_016_SIM", "backLeg001_R_017_SIM", "backLeg001_R_08_SIM",
"backLeg001_R_01_SIM", ]},
{'bottom': ["backLeg001_L_08_SIM", "backLeg001_L_09_SIM", "backLeg001_L_09_SIM", "backLeg001_R_04_SIM",
"backLeg001_R_05_SIM", "backLeg001_R_06_SIM", "backLeg001_R_07_SIM", "backLeg001_L_07_SIM",
"backLeg001_L_012_SIM", "backLeg001_L_05_SIM"]}, ],
}
for bone in zSetupDict.keys():
print bone
for items in zSetupDict[bone]:
for endPoint, muscles in items.iteritems():
print endPoint, muscles
if muscles == None:
continue
for msc in muscles:
mc.select(msc, r=1)
makeZivaMuscle()
try:
zAttach(bone, msc, 2, endPoint)
except:
mc.setAttr(msc+'.v', 0)
pass
Feedback welcome.
Enjoy!!