2011-06-25 23:50:50 +00:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
|
|
|
# <pep8 compliant>
|
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
import bpy
|
|
|
|
import time
|
|
|
|
|
|
|
|
from bpy.props import *
|
|
|
|
from bpy import *
|
|
|
|
from mathutils import Vector
|
|
|
|
from math import isfinite
|
|
|
|
|
|
|
|
|
|
|
|
bpy.types.Bone.map = bpy.props.StringProperty()
|
|
|
|
import retarget
|
|
|
|
import mocap_tools
|
|
|
|
|
2011-06-25 23:50:50 +00:00
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
class MocapPanel(bpy.types.Panel):
|
|
|
|
bl_label = "Mocap tools"
|
|
|
|
bl_space_type = "PROPERTIES"
|
|
|
|
bl_region_type = "WINDOW"
|
|
|
|
bl_context = "object"
|
2011-06-25 23:50:50 +00:00
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
def draw(self, context):
|
|
|
|
self.layout.label("Preprocessing")
|
|
|
|
row = self.layout.row(align=True)
|
|
|
|
row.alignment = 'EXPAND'
|
|
|
|
row.operator("mocap.samples", text='Samples to Beziers')
|
|
|
|
row.operator("mocap.denoise", text='Clean noise')
|
|
|
|
row2 = self.layout.row(align=True)
|
|
|
|
row2.operator("mocap.looper", text='Loop animation')
|
|
|
|
row2.operator("mocap.limitdof", text='Constrain Rig')
|
|
|
|
self.layout.label("Retargeting")
|
|
|
|
row3 = self.layout.row(align=True)
|
|
|
|
column1 = row3.column(align=True)
|
|
|
|
column1.label("Performer Rig")
|
|
|
|
column2 = row3.column(align=True)
|
|
|
|
column2.label("Enduser Rig")
|
|
|
|
self.layout.label("Hierarchy mapping")
|
2011-06-25 23:50:50 +00:00
|
|
|
enduser_obj = bpy.context.active_object
|
|
|
|
performer_obj = [obj for obj in bpy.context.selected_objects if obj != enduser_obj]
|
|
|
|
if enduser_obj is None or len(performer_obj) != 1:
|
|
|
|
self.layout.label("Select performer rig and target rig (as active)")
|
|
|
|
else:
|
|
|
|
performer_obj = performer_obj[0]
|
2011-06-26 19:54:29 +00:00
|
|
|
if performer_obj.data and enduser_obj.data:
|
|
|
|
if performer_obj.data.name in bpy.data.armatures and enduser_obj.data.name in bpy.data.armatures:
|
|
|
|
perf = performer_obj.data
|
|
|
|
enduser_arm = enduser_obj.data
|
|
|
|
perf_pose_bones = enduser_obj.pose.bones
|
|
|
|
for bone in perf.bones:
|
|
|
|
row = self.layout.row(align=True)
|
|
|
|
row.label(bone.name)
|
|
|
|
row.prop_search(bone, "map", enduser_arm, "bones")
|
|
|
|
label_mod = "FK"
|
|
|
|
if bone.map:
|
|
|
|
pose_bone = perf_pose_bones[bone.map]
|
|
|
|
if pose_bone.is_in_ik_chain:
|
|
|
|
label_mod = "IK"
|
|
|
|
if "IK" in [constraint.type for constraint in pose_bone.constraints]:
|
|
|
|
label_mod = "IKEnd"
|
|
|
|
row.label(label_mod)
|
|
|
|
self.layout.operator("mocap.retarget", text='RETARGET!')
|
2011-06-25 23:50:50 +00:00
|
|
|
|
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
class OBJECT_OT_RetargetButton(bpy.types.Operator):
|
|
|
|
bl_idname = "mocap.retarget"
|
|
|
|
bl_label = "Retargets active action from Performer to Enduser"
|
2011-06-25 23:50:50 +00:00
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
def execute(self, context):
|
|
|
|
retarget.totalRetarget()
|
|
|
|
return {"FINISHED"}
|
2011-06-25 23:50:50 +00:00
|
|
|
|
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
class OBJECT_OT_ConvertSamplesButton(bpy.types.Operator):
|
|
|
|
bl_idname = "mocap.samples"
|
|
|
|
bl_label = "Converts samples / simplifies keyframes to beziers"
|
2011-06-25 23:50:50 +00:00
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
def execute(self, context):
|
|
|
|
mocap_tools.fcurves_simplify()
|
|
|
|
return {"FINISHED"}
|
2011-06-25 23:50:50 +00:00
|
|
|
|
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
class OBJECT_OT_LooperButton(bpy.types.Operator):
|
|
|
|
bl_idname = "mocap.looper"
|
|
|
|
bl_label = "loops animation / sampled mocap data"
|
2011-06-25 23:50:50 +00:00
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
def execute(self, context):
|
|
|
|
mocap_tools.autoloop_anim()
|
|
|
|
return {"FINISHED"}
|
2011-06-25 23:50:50 +00:00
|
|
|
|
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
class OBJECT_OT_DenoiseButton(bpy.types.Operator):
|
|
|
|
bl_idname = "mocap.denoise"
|
|
|
|
bl_label = "Denoises sampled mocap data "
|
2011-06-25 23:50:50 +00:00
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
def execute(self, context):
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
2011-06-25 23:50:50 +00:00
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
class OBJECT_OT_LimitDOFButton(bpy.types.Operator):
|
|
|
|
bl_idname = "mocap.limitdof"
|
|
|
|
bl_label = "Analyzes animations Max/Min DOF and adds hard/soft constraints"
|
2011-06-25 23:50:50 +00:00
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
def execute(self, context):
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
2011-06-25 23:50:50 +00:00
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
def register():
|
2011-06-25 23:50:50 +00:00
|
|
|
bpy.utils.register_module(__name__)
|
|
|
|
|
|
|
|
|
2011-06-24 17:05:53 +00:00
|
|
|
def unregister():
|
|
|
|
bpy.utils.unregister_module(__name__)
|
2011-06-25 23:50:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
register()
|