Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bl_info = {
- 'name': 'Mocap Animation Tools',
- 'category': 'Import-Export',
- }
- import bpy
- class importPanel(bpy.types.Panel):
- bl_space_type = 'VIEW_3D'
- bl_region_type = 'TOOLS'
- bl_category = 'Animation'
- bl_label = 'Mocap Import and Map'
- @classmethod
- def poll(self, context):
- try:
- return True
- except (AttributeError, KeyError, TypeError):
- return False
- def draw(self, context): ### VARIABLES ###
- col = self.layout.column(align=True)
- scene = context.scene
- def CullBones(name): ### FUNTIONS ###
- if 'IK' in name or 'Pole' in name: return 'I'
- elif 'Hand' in name or 'Finger' in name: return 'H'
- elif '.L' in name or 'Left' in name: return 'L'
- elif '.R' in name or 'Right' in name: return 'R'
- else: return 'C'
- col.label(text='Scource of Animation') ### SOURCE ###
- row = col.row(align=True)
- row.operator_context = 'INVOKE_REGION_WIN'
- if scene.mocap.source == '' or bpy.data.objects[scene.mocap.source].type != 'ARMATURE':
- row.prop_search(scene.mocap, 'source', bpy.data, 'objects', text='',icon='NONE')
- row.operator('import_anim.bvh', text='Import BVH', icon='ARMATURE_DATA')
- else:
- row.prop_search(scene.mocap, 'source', bpy.data, 'objects', text='',icon='OUTLINER_OB_ARMATURE')
- row.operator('import_anim.bvh', text='', icon='ARMATURE_DATA')
- col.operator('wm.normalize_names', text='Normalize Bone Names', icon='NONE')
- col.label(text='Target For Animation') ### TARGET ###
- row = col.row(align=True)
- if scene.mocap.target == '' or bpy.data.objects[scene.mocap.target].type != 'ARMATURE':
- row.prop_search(scene.mocap, 'target', bpy.data, 'objects', text='',icon='NONE')
- else:
- row.prop_search(scene.mocap, 'target', bpy.data, 'objects', text='',icon='OUTLINER_OB_ARMATURE')
- col = self.layout.column(align=True) ### VARIABLES ###
- if scene.mocap.target == '': return
- armature = bpy.data.objects[scene.mocap.target]
- if armature is None or armature.type != 'ARMATURE': return
- col.label(text='Bone Mapping') ### SOURCE -> TARGET ###
- row = col.row(align=True)
- row.prop(scene.mocap, 'bone_filter', expand=True)
- if scene.mocap.bone_filter != 'N': #Show bone mapping box
- box = col.box()
- for bone in armature.pose.bones:
- if scene.mocap.bone_filter == CullBones(bone.name) or scene.mocap.bone_filter == 'A':
- split = box.split(percentage=0.40)
- brow = split.row()
- brow.label(text=bone.name)
- brow = split.row()
- if scene.mocap.source != '': #Display prop_search for bones in source armature
- brow.prop_search(bone, 'bone_source', bpy.data.objects[scene.mocap.source].pose, 'bones', text='',icon='NONE')
- else: #just display the prop if there is no source armature
- brow.prop(bone, 'bone_source', text='', icon='NONE')
- col.operator('wm.automap_names', text='Auto Map Names', icon='BONE_DATA')
- col = self.layout.column() #BONES old
- class transferPanel(bpy.types.Panel):
- bl_space_type = 'VIEW_3D'
- bl_region_type = 'TOOLS'
- bl_category = 'Animation'
- bl_label = 'Mocap Transfer Animation'
- @classmethod
- def poll(self, context):
- try:
- mocap = context.scene.mocap
- return (mocap.target != '' and mocap.source != '' and
- bpy.data.objects[mocap.source].type == 'ARMATURE' and
- bpy.data.objects[mocap.target].type == 'ARMATURE')
- except (AttributeError, KeyError, TypeError):
- return False
- def draw(self, context): ### VARIABLES ###
- col = self.layout.column(align=True)
- scene = context.scene
- source_arm = bpy.data.objects[scene.mocap.source].pose
- target_arm = bpy.data.objects[scene.mocap.target].pose
- for tbone in target_arm.bones:
- if "IK" in tbone.constraints.keys():
- if tbone.constraints['IK'].mute:
- col.operator('wm.toggle_ikconstraints', text='Activate IK Constraints', icon='VISIBLE_IPO_OFF')
- else:
- col.operator('wm.toggle_ikconstraints', text='Disable IK Constraints', icon='VISIBLE_IPO_ON')
- break
- col.prop(scene.mocap, 'rotation_mode', text = '')
- col = self.layout.column(align=True)
- col.operator('wm.copy_mapped_animation', text='Copy Animation', icon='COPY_ID')
- # for fcurve in bpy.data.objects[scene.mocap.target].animation_data.action.fcurves:
- # if fcurve.group is not None:
- # col.label(text='Scource group ' + fcurve.group.name)
- col.label(text='----')
- class MocapPanelSettings(bpy.types.PropertyGroup):
- source = bpy.props.StringProperty()
- target = bpy.props.StringProperty()
- bone_filter = bpy.props.EnumProperty(name = 'Bone Filter',
- items = [('N', 'None', 'Don\'t display any bones'),
- ('L', 'L', 'Only bones with names containing .L or Left'),
- ('C', 'C', 'Only bones with no tags'),
- ('R', 'R', 'Only bones with names containing .R or Right'),
- ('I', 'IK', 'Only bones with names containing IK or Pole'),
- ('A', 'All', 'Display all bones in the armature')],
- description = "Which bones to display in this menu")
- rotation_mode = bpy.props.EnumProperty(name = "Rotation",
- items = [('QUATERNION', 'Quaternion (WXYZ)', 'QUAT' ),
- ('XYZ', 'XYZ Euler', 'XYZ' ),
- ('XZY', 'XZY Euler', 'XZY' ),
- ('YXZ', 'YXZ Euler', 'YXZ' ),
- ('YZX', 'YZX Euler', 'YZX' ),
- ('ZXY', 'ZXY Euler', 'ZXY' ),
- ('ZYX', 'ZYX Euler', 'ZYX' ) ],
- description = "The target rotation mode")
- def register():
- bpy.utils.register_module(__name__)
- bpy.types.Scene.mocap = bpy.props.PointerProperty(type=MocapPanelSettings)
- bpy.types.PoseBone.bone_source = bpy.props.StringProperty(name="Bone Source",
- description="Property to store which bone to copy animation from")
- def unregister():
- bpy.utils.unregister_module(__name__)
- del bpy.types.Scene.mocap
- del bpy.types.PoseBone.bone_source
- if __name__ == '__main__':
- register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement