Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
5.9 kB
3
Indexable
Never
######## Create NCLOTH Rig ########

# import proxyMesh
import sys
pth='G:/Tech_Animation/scripts'
if pth not in sys.path:
    sys.path.append(pth)
    
import fileTools as ft
from shotFinalEZ_pub.re_asset_commander import command_utils
reload(command_utils)

path = ft.ez.path('products').replace('\\','/') + '/cfx_build/hybrid/'
tempFileList = os.listdir(path)
tempFileList.sort()
latestVer = tempFileList[-1]

cfxWorks=path+'/'+ latestVer+'/data/skeleton.ma'

cmds.file(cfxWorks,i=True)

# reference rig

path = ft.ez.path('products').replace('\\','/') + '/rig'
tempFileList = os.listdir(path)
tempFileList.sort()
latestVer = tempFileList[-1]

cfxWorks=path+'/'+ latestVer

cmds.file(cfxWorks,r=True,ns='REF_nCloth')

# create a master control
cmds.circle(name='nclothRig_ctrl')

# create group hierachy
cmds.group(em=True, name='proxy_mesh_for_sim')
cmds.group(em=True, name='nCloth_dyn_Grp')
cmds.group(em=True, name='attract_to_mesh')
cmds.group(em=True, name='nCloth_OUTPUT_Grp')
cmds.group(em=True, name='misc')

# --- sub group elements under nCloth dyn grp ---
cmds.group(em=True, name='nRigid_grp')
cmds.group(em=True, name='collision_mesh_grp')
cmds.group(em=True, name='constrain_grp')

# --- sub group element under misc ---
cmds.group(em=True, name='goal_rigid_grp')
cmds.group(em=True, name='goal_dynConst_grp')
cmds.group('goal_*_grp', name='goal_grp')

cmds.group(em=True, name='wrap_Bases')

# --- sub group element under nCloth_OUPTU_Grp

cmds.group(em=True,name='Output_LowMesh')
cmds.group(em=True,name='Output_HighMesh')

# group setting

# --- set control size ---
cmds.setAttr('nclothRig_ctrl.rotateX',90)
cmds.setAttr('nclothRig_ctrl.sx',1.5)
cmds.setAttr('nclothRig_ctrl.sy',1.5)
cmds.setAttr('nclothRig_ctrl.sz',1.5)
cmds.makeIdentity('nclothRig_ctrl',apply=True, t=1, r=1, s=1, n=2 )

# --- set visibility ---
cmds.setAttr('attract_to_mesh.visibility',0)
cmds.setAttr('goal_rigid_grp.visibility',0)
cmds.setAttr('goal_dynConst_grp.visibility',0)
cmds.setAttr('wrap_Bases.visibility',0)
    
# --- re arrange group ---
cmds.parent('goal_grp','misc')
cmds.parent('wrap_Bases','misc')

cmds.parent('nRigid_grp','nCloth_dyn_Grp')
cmds.parent('collision_mesh_grp','nCloth_dyn_Grp')
cmds.parent('constrain_grp','nCloth_dyn_Grp')

cmds.parentConstraint('nclothRig_ctrl','collision_mesh_grp')

cmds.parent('Output_LowMesh','nCloth_OUTPUT_Grp')
cmds.parent('Output_HighMesh','nCloth_OUTPUT_Grp')


# --- create a2m mesh ---
for proxyMesh in cmds.ls('*_proxyMesh'):
    cmds.duplicate(proxyMesh)
    a2m_mesh = cmds.rename(proxyMesh+'1',(proxyMesh+'1').replace('sim','a2m'))
    a2m_mesh = cmds.rename(a2m_mesh,a2m_mesh.replace('proxyMesh1','mesh'))
    
# --- create Output_LowMesh mesh ---
for proxyMesh in cmds.ls('*_proxyMesh'):
    cmds.duplicate(proxyMesh)
    Output_LowMesh = cmds.rename(proxyMesh+'1',(proxyMesh+'1').replace('sim','Output'))
    Output_LowMesh = cmds.rename(Output_LowMesh,Output_LowMesh.replace('proxyMesh1','LowRes'))
    
# --- create Output_HighMesh mesh ---
for proxyMesh in cmds.ls('*_proxyMesh'):
    cmds.duplicate('REF_nCloth:'+proxyMesh.split('__sim__')[0]+'_Geo')
    Output_HighMesh = cmds.rename(proxyMesh.split('__sim__')[0]+'_Geo',proxyMesh.split('__sim__')[0]+'__Output__HighRes')

# create ncloth on proxyMesh
nucleus_name = 'nCloth_nucleus'
for proxyMesh in cmds.ls('*_proxyMesh'):
    cmds.select(proxyMesh)
    mel.eval('createNCloth 0;')
    
    command_utils.assign_nucleus('nCloth1', nucleus_name)
    cmds.currentTime(cmds.getAttr(nucleus_name+'.startFrame'))
    cmds.rename('nCloth1',proxyMesh.split('__sim__')[0]+'_nCloth')


# create a2m constraint
for proxyMesh in cmds.ls('*_proxyMesh'):
    a2m_mesh=proxyMesh.split('__sim__')[0]+'__a2m__mesh'
    
    cmds.select(proxyMesh)
    cmds.select(a2m_mesh,add=True)

    matchingMesh=mel.eval('createNConstraint match 0')
    
    for node in matchingMesh:
        transform_node = cmds.listRelatives(node, parent=True)
        transformName = cmds.rename(transform_node, proxyMesh.split('__sim__')[0]+'__a2m__'+transform_node[0])
        
# --- create wrap from LowRes on proxyMesh

for proxyMesh in cmds.ls('*_proxyMesh'):
    LowRes = proxyMesh.split('__')[0]+'__Output__LowRes'
    command_utils.create_wrap_deformer(LowRes,proxyMesh,exclusiveBind = 1)
    
# --- create wrap from HighRes on proxyMesh

for lowRes in cmds.ls('*__LowRes'):
    HighRes = lowRes.rsplit('__',1)[0]+'__HighRes'
    command_utils.create_wrap_deformer(HighRes,lowRes,exclusiveBind = 1)

# --- put proxy mesh under proxyMesh ---
for proxyMesh in cmds.ls('*_proxyMesh'):
    cmds.parent(proxyMesh, 'proxy_mesh_for_sim')
    
# --- put Output Low mesh under Output_lowMesh grp ---
for output_low in cmds.ls('*__Output__LowRes'):
    cmds.parent(output_low, 'Output_LowMesh')
    
# --- put Output High mesh under Output_highMesh grp ---
for output_high in cmds.ls('*__Output__HighRes'):
    cmds.parent(output_high, 'Output_HighMesh')
    
# --- put nCloth under nCloth dyn grp group ---
for ncloth in cmds.ls('*nCloth'):
    cmds.parent(ncloth, 'nCloth_dyn_Grp')
cmds.parent('nCloth_nucleus','nCloth_dyn_Grp')

# --- put a2m_rigid under goal_dynConst group ---
for a2m_rigid in cmds.ls('*__a2m__nRigid1'):
    cmds.parent(a2m_rigid, 'goal_rigid_grp')

# --- put a2m_mesh under attract to mesh group ---
for a2m in cmds.ls('*__a2m__mesh'):
    cmds.parent(a2m, 'attract_to_mesh')
    
# --- put a2m dynamic consteraint under goal dynConst group ---
for dynConst in cmds.ls('*__a2m__dynamicConstraint1'):
    cmds.parent(dynConst, 'goal_dynConst_grp')
    
# --- put all extra wrapBase under wrape_Bases grp
for base in cmds.ls('*Base'):
    cmds.parent(base, 'wrap_Bases')