Advertisement
OCEAlpha

mocaptool_ui

Jan 21st, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.85 KB | None | 0 0
  1. bl_info = {
  2.     'name': 'Mocap Animation Tools',
  3.     'category': 'Import-Export',
  4. }
  5.  
  6. import bpy
  7.        
  8. class importPanel(bpy.types.Panel):
  9.     bl_space_type = 'VIEW_3D'
  10.     bl_region_type = 'TOOLS'
  11.     bl_category = 'Animation'
  12.     bl_label = 'Mocap Import and Map'
  13.  
  14.     @classmethod
  15.     def poll(self, context):
  16.         try:
  17.             return True
  18.         except (AttributeError, KeyError, TypeError):
  19.             return False
  20.                
  21.     def draw(self, context): ### VARIABLES ###
  22.         col = self.layout.column(align=True)
  23.         scene = context.scene
  24.        
  25.         def CullBones(name): ### FUNTIONS ###
  26.             if 'IK' in name or 'Pole' in name: return 'I'
  27.             elif 'Hand' in name or 'Finger' in name: return 'H'
  28.             elif '.L' in name or 'Left' in name: return 'L'
  29.             elif '.R' in name or 'Right' in name: return 'R'
  30.             else: return 'C'
  31.  
  32.         col.label(text='Scource of Animation') ### SOURCE ###
  33.         row = col.row(align=True)
  34.         row.operator_context = 'INVOKE_REGION_WIN'
  35.         if scene.mocap.source == '' or bpy.data.objects[scene.mocap.source].type != 'ARMATURE':
  36.             row.prop_search(scene.mocap, 'source', bpy.data, 'objects', text='',icon='NONE')
  37.             row.operator('import_anim.bvh', text='Import BVH', icon='ARMATURE_DATA')            
  38.         else:
  39.             row.prop_search(scene.mocap, 'source', bpy.data, 'objects', text='',icon='OUTLINER_OB_ARMATURE')
  40.             row.operator('import_anim.bvh', text='', icon='ARMATURE_DATA')
  41.             col.operator('wm.normalize_names', text='Normalize Bone Names', icon='NONE')
  42.        
  43.  
  44.         col.label(text='Target For Animation') ### TARGET ###
  45.         row = col.row(align=True)
  46.         if scene.mocap.target == '' or bpy.data.objects[scene.mocap.target].type != 'ARMATURE':
  47.             row.prop_search(scene.mocap, 'target', bpy.data, 'objects', text='',icon='NONE')
  48.         else:
  49.             row.prop_search(scene.mocap, 'target', bpy.data, 'objects', text='',icon='OUTLINER_OB_ARMATURE')
  50.        
  51.        
  52.         col = self.layout.column(align=True) ### VARIABLES ###
  53.         if scene.mocap.target == '': return
  54.         armature = bpy.data.objects[scene.mocap.target]
  55.         if armature is None or armature.type != 'ARMATURE': return
  56.        
  57.         col.label(text='Bone Mapping') ### SOURCE -> TARGET ###
  58.         row = col.row(align=True)
  59.         row.prop(scene.mocap, 'bone_filter', expand=True)
  60.            
  61.         if scene.mocap.bone_filter != 'N': #Show bone mapping box
  62.             box = col.box()
  63.             for bone in armature.pose.bones:
  64.                 if scene.mocap.bone_filter == CullBones(bone.name) or scene.mocap.bone_filter == 'A':
  65.                     split = box.split(percentage=0.40)
  66.                     brow = split.row()                    
  67.                     brow.label(text=bone.name)
  68.                     brow = split.row()
  69.                    
  70.                     if scene.mocap.source != '': #Display prop_search for bones in source armature
  71.                         brow.prop_search(bone, 'bone_source', bpy.data.objects[scene.mocap.source].pose, 'bones', text='',icon='NONE')
  72.                     else: #just display the prop if there is no source armature
  73.                         brow.prop(bone, 'bone_source', text='', icon='NONE')                        
  74.         col.operator('wm.automap_names', text='Auto Map Names', icon='BONE_DATA')
  75.                      
  76.         col = self.layout.column() #BONES old
  77.        
  78. class transferPanel(bpy.types.Panel):
  79.     bl_space_type = 'VIEW_3D'
  80.     bl_region_type = 'TOOLS'
  81.     bl_category = 'Animation'
  82.     bl_label = 'Mocap Transfer Animation'
  83.    
  84.     @classmethod
  85.     def poll(self, context):
  86.         try:
  87.             mocap = context.scene.mocap
  88.             return (mocap.target != '' and mocap.source != '' and
  89.                     bpy.data.objects[mocap.source].type == 'ARMATURE' and
  90.                     bpy.data.objects[mocap.target].type == 'ARMATURE')
  91.         except (AttributeError, KeyError, TypeError):
  92.             return False
  93.    
  94.     def draw(self, context): ### VARIABLES ###
  95.         col = self.layout.column(align=True)
  96.         scene = context.scene
  97.         source_arm = bpy.data.objects[scene.mocap.source].pose
  98.         target_arm = bpy.data.objects[scene.mocap.target].pose
  99.        
  100.         for tbone in target_arm.bones:
  101.             if "IK" in tbone.constraints.keys():
  102.                 if tbone.constraints['IK'].mute:                  
  103.                     col.operator('wm.toggle_ikconstraints', text='Activate IK Constraints', icon='VISIBLE_IPO_OFF')
  104.                 else:
  105.                     col.operator('wm.toggle_ikconstraints', text='Disable IK Constraints', icon='VISIBLE_IPO_ON')
  106.                 break
  107.            
  108.         col.prop(scene.mocap, 'rotation_mode', text = '')
  109.         col = self.layout.column(align=True)
  110.         col.operator('wm.copy_mapped_animation', text='Copy Animation', icon='COPY_ID')
  111.        
  112.                    
  113. #        for fcurve in bpy.data.objects[scene.mocap.target].animation_data.action.fcurves:
  114. #            if fcurve.group is not None:
  115. #                col.label(text='Scource group ' + fcurve.group.name)
  116.                
  117.         col.label(text='----')
  118.        
  119. class MocapPanelSettings(bpy.types.PropertyGroup):
  120.     source = bpy.props.StringProperty()
  121.     target = bpy.props.StringProperty()
  122.    
  123.     bone_filter = bpy.props.EnumProperty(name = 'Bone Filter',
  124.         items = [('N', 'None', 'Don\'t display any bones'),
  125.                 ('L', 'L', 'Only bones with names containing .L or Left'),
  126.                 ('C', 'C', 'Only bones with no tags'),
  127.                 ('R', 'R', 'Only bones with names containing .R or Right'),
  128.                 ('I', 'IK', 'Only bones with names containing IK or Pole'),
  129.                 ('A', 'All', 'Display all bones in the armature')],    
  130.         description = "Which bones to display in this menu")
  131.        
  132.     rotation_mode = bpy.props.EnumProperty(name = "Rotation",
  133.        items = [('QUATERNION', 'Quaternion (WXYZ)', 'QUAT' ),
  134.                 ('XYZ', 'XYZ Euler', 'XYZ' ),
  135.                 ('XZY', 'XZY Euler', 'XZY' ),
  136.                 ('YXZ', 'YXZ Euler', 'YXZ' ),
  137.                 ('YZX', 'YZX Euler', 'YZX' ),
  138.                 ('ZXY', 'ZXY Euler', 'ZXY' ),
  139.                 ('ZYX', 'ZYX Euler', 'ZYX' ) ],    
  140.         description = "The target rotation mode")
  141.  
  142. def register():
  143.     bpy.utils.register_module(__name__)
  144.     bpy.types.Scene.mocap = bpy.props.PointerProperty(type=MocapPanelSettings)
  145.     bpy.types.PoseBone.bone_source = bpy.props.StringProperty(name="Bone Source",
  146.         description="Property to store which bone to copy animation from")
  147.  
  148. def unregister():
  149.     bpy.utils.unregister_module(__name__)
  150.     del bpy.types.Scene.mocap
  151.     del bpy.types.PoseBone.bone_source
  152.    
  153. if __name__ == '__main__':
  154.     register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement