yaotungyu

attach abc to cloth

Dec 7th, 2021
947
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # ----- get namespace here -----
  2. ns = cmds.ls("Alice_Ear_Muffins*:*:Geo_Grp")[0].split(":")[0]
  3.  
  4. # ----- import latest ncloth Rig -----
  5.  
  6. path = 'Y:/{}/assets/type/Character/{}/products/nClothRig/'.format(os.environ['TT_PROJCODE'],ns.rsplit('_',1)[0])
  7. tempFileList = os.listdir(path)
  8. tempFileList.sort()
  9. latestVer = tempFileList[-1]
  10. cfxWorks = path+'/'+latestVer
  11. from abc_sim_workflow import abc_tech_cache_util
  12. abc_tech_cache_util.insert_tech_cache_v2(
  13.     cfxWorks,  
  14.     group_depth = ['nCloth_Rig'],
  15.     insert_ns = [ns,'DYN'],
  16.     ns_div=':',
  17.     mode='reference'
  18.     )
  19.  
  20. rig_ns = ns+':DYN'
  21. abc_ns = ns+':ABC'
  22. # ----- using connect mesh method to connect ncloth sim mesh and animation output mesh -----
  23.  
  24. for mesh in cmds.ls(abc_ns+':*proxyMesh'):
  25.     # query the mesh and shape names
  26.     anim_output_mesh=mesh
  27.     anim_output_shape=cmds.listRelatives(mesh)[0]
  28.    
  29.     ncloth_input_mesh=rig_ns+':'+mesh.split(':')[-1]
  30.     ncloth_input_shape=cmds.listRelatives(ncloth_input_mesh)[0]
  31.    
  32.     cmds.connectAttr(anim_output_shape+'.outMesh',ncloth_input_shape+'.inMesh', force=True)
  33.  
  34. # ----- using connect mesh method to connect attract to mesh and animation output mesh -----    
  35.    
  36. for mesh in cmds.ls(abc_ns+':*proxyMesh'):
  37.     # query the mesh and shape names
  38.     anim_output_mesh=mesh
  39.     anim_output_shape=cmds.listRelatives(mesh)[0]
  40.    
  41.     a2m_mesh=rig_ns+':'+mesh.split(':')[-1].split('__sim__')[0]+'__a2m__mesh'
  42.     a2m_shape=cmds.listRelatives(a2m_mesh)[0]
  43.    
  44.     cmds.connectAttr(anim_output_shape+'.outMesh',a2m_mesh+'.inMesh', force=True)
  45.  
  46. # ----- match anim offset -----
  47.  
  48. cmds.matchTransform(rig_ns+':nclothRig_ctrl',abc_ns+':C_Main_Ground_Ctrl')
  49.  
  50.  
  51. from abc_sim_workflow.sim_obj_set_creator import preb_export_sets_ui_funcs
  52. reload(preb_export_sets_ui_funcs)
  53. sets_by_tags,obj_dict = preb_export_sets_ui_funcs.SetQuery.get_set_dicts(ass_list = [ns.rsplit('_',1)[0]],parse_data = True,use_cmdsls=False)
  54. asset_name = ns.rsplit('_',1)[0]
  55. cmds.group(n=abc_ns+':collision_mesh_grp',em=1)
  56. cmds.parent(abc_ns+':collision_mesh_grp',abc_ns+':Cloth')
  57. cmds.select(cl=1)
  58. for cld_set in sets_by_tags[asset_name]['Cloth']['cld']:
  59.     obj_list = [obj_.replace('__ns__',abc_ns) for obj_ in obj_dict[asset_name]['Cloth'][cld_set]]
  60.     collider_mesh_name = abc_ns+':'+cld_set+'_colliderMesh'
  61.    
  62.     #combine or duplicate collider meshes
  63.     if len(obj_list)>1:
  64.         cmds.select(obj_list)
  65.         cmds.CombinePolygons()
  66.         cmds.rename(collider_mesh_name)
  67.     else:
  68.         cmds.duplicate([obj.replace('__ns__',rig_ref_ns) for obj in collider_set_objs][0],n=collider_mesh_name)
  69.     cmds.parent(collider_mesh_name,abc_ns+':collision_mesh_grp')
  70.  
  71. for mesh in cmds.ls(abc_ns+':*_colliderMesh'):
  72.     # query the mesh and shape names
  73.     anim_output_mesh=mesh
  74.     anim_output_shape=cmds.listRelatives(mesh)[0]
  75.    
  76.     ncloth_input_mesh=rig_ns+':'+mesh.split(':')[-1]
  77.     ncloth_input_shape=cmds.listRelatives(ncloth_input_mesh)[0]
  78.    
  79.     cmds.connectAttr(anim_output_shape+'.outMesh',ncloth_input_shape+'.inMesh', force=True)
  80.  
  81.  
  82. # ----- wrap all the collider mesh into the master collision mesh -----
  83. for colliderMesh in cmds.ls(ns+'_ClothRig:*_colliderMesh'):
  84.     command_utils.create_wrap_deformer(colliderMesh,ns+':Master_Collider_Geo',n='',exclusiveBind = 1)
  85. from abc_sim_workflow import abc_tech_ui_funcs
  86. abc_tech_ui_funcs.SimObjSetQuery.get_sets_in_scene()
  87.  
RAW Paste Data