[Bf-extensions-cvs] [2857bf9e] master: mocap tools: moved to contrib T63750
meta-androcto
noreply at git.blender.org
Thu Jul 4 12:24:29 CEST 2019
Commit: 2857bf9e902610bb00cc7f827b7ac7b5178dfb6e
Author: meta-androcto
Date: Thu Jul 4 20:23:54 2019 +1000
Branches: master
https://developer.blender.org/rBAC2857bf9e902610bb00cc7f827b7ac7b5178dfb6e
mocap tools: moved to contrib T63750
===================================================================
A mocap/__init__.py
A mocap/mocap_constraints.py
A mocap/mocap_tools.py
A mocap/retarget.py
===================================================================
diff --git a/mocap/__init__.py b/mocap/__init__.py
new file mode 100644
index 00000000..f040e0b1
--- /dev/null
+++ b/mocap/__init__.py
@@ -0,0 +1,933 @@
+# ##### 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>
+
+bl_info = {
+ "name": "Motion Capture Tools",
+ "author": "Benjy Cook",
+ "blender": (2, 73, 0),
+ "version": (1, 1, 1),
+ "location": "Active Armature > Object Properties > Mocap tools",
+ "description": "Various tools for working with motion capture animation",
+ "warning": "",
+ "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
+ "Scripts/Animation/Motion_Capture_Tools",
+ "support": 'OFFICIAL',
+ "category": "Animation",
+}
+
+if "bpy" in locals():
+ import importlib
+ if "mocap_constraints" in locals():
+ importlib.reload(mocap_constraints)
+ if "retarget" in locals():
+ importlib.reload(retarget)
+ if "mocap_tools" in locals():
+ importlib.reload(mocap_tools)
+else:
+ import bpy
+ from bpy.props import (
+ BoolProperty,
+ CollectionProperty,
+ EnumProperty,
+ FloatProperty,
+ FloatVectorProperty,
+ IntProperty,
+ PointerProperty,
+ StringProperty,
+ )
+ from . import (
+ mocap_constraints,
+ retarget,
+ mocap_tools,
+ )
+
+
+# MocapConstraint class
+# Defines MocapConstraint datatype, used to add and configute mocap constraints
+# Attached to Armature data
+
+def hasIKConstraint(pose_bone):
+ #utility function / predicate, returns True if given bone has IK constraint
+ ik = [constraint for constraint in pose_bone.constraints if constraint.type == "IK"]
+ if ik:
+ return ik[0]
+ else:
+ return False
+
+
+class MocapConstraint(bpy.types.PropertyGroup):
+ name: StringProperty(name="Name",
+ default="Mocap Fix",
+ description="Name of Mocap Fix",
+ update=mocap_constraints.setConstraint)
+ constrained_bone: StringProperty(name="Bone",
+ default="",
+ description="Constrained Bone",
+ update=mocap_constraints.updateConstraintBoneType)
+ constrained_boneB: StringProperty(name="Bone (2)",
+ default="",
+ description="Other Constrained Bone (optional, depends on type)",
+ update=mocap_constraints.setConstraint)
+ s_frame: IntProperty(name="Start",
+ default=0,
+ description="Start frame of Fix",
+ update=mocap_constraints.setConstraint)
+ e_frame: IntProperty(name="End",
+ default=100,
+ description="End frame of Fix",
+ update=mocap_constraints.setConstraint)
+ smooth_in: IntProperty(name="In",
+ default=10,
+ description="Number of frames to smooth in",
+ update=mocap_constraints.setConstraint,
+ min=0)
+ smooth_out: IntProperty(name="Out",
+ default=10,
+ description="Number of frames to smooth out",
+ update=mocap_constraints.setConstraint,
+ min=0)
+ targetMesh: StringProperty(name="Mesh",
+ default="",
+ description="Target of Fix - Mesh (optional, depends on type)",
+ update=mocap_constraints.setConstraint)
+ active: BoolProperty(name="Active",
+ default=True,
+ description="Fix is active",
+ update=mocap_constraints.setConstraint)
+ show_expanded: BoolProperty(name="Show Expanded",
+ default=True,
+ description="Fix is fully shown")
+ targetPoint: FloatVectorProperty(name="Point", size=3,
+ subtype="XYZ", default=(0.0, 0.0, 0.0),
+ description="Target of Fix - Point",
+ update=mocap_constraints.setConstraint)
+ targetDist: FloatProperty(name="Offset",
+ default=0.0,
+ description="Distance and Floor Fixes - Desired offset",
+ update=mocap_constraints.setConstraint)
+ targetSpace: EnumProperty(
+ items=[("WORLD", "World Space", "Evaluate target in global space"),
+ ("LOCAL", "Object space", "Evaluate target in object space"),
+ ("constrained_boneB", "Other Bone Space", "Evaluate target in specified other bone space")],
+ name="Space",
+ description="In which space should Point type target be evaluated",
+ update=mocap_constraints.setConstraint)
+ type: EnumProperty(name="Type of constraint",
+ items=[("point", "Maintain Position", "Bone is at a specific point"),
+ ("freeze", "Maintain Position at frame", "Bone does not move from location specified in target frame"),
+ ("floor", "Stay above", "Bone does not cross specified mesh object eg floor"),
+ ("distance", "Maintain distance", "Target bones maintained specified distance")],
+ description="Type of Fix",
+ update=mocap_constraints.updateConstraintBoneType)
+ real_constraint: StringProperty()
+ real_constraint_bone: StringProperty()
+
+
+# Animation Stitch Settings, used for animation stitching of 2 retargeted animations.
+class AnimationStitchSettings(bpy.types.PropertyGroup):
+ first_action: StringProperty(name="Action 1",
+ description="First action in stitch")
+ second_action: StringProperty(name="Action 2",
+ description="Second action in stitch")
+ blend_frame: IntProperty(name="Stitch frame",
+ description="Frame to locate stitch on")
+ blend_amount: IntProperty(name="Blend amount",
+ description="Size of blending transition, on both sides of the stitch",
+ default=10)
+ second_offset: IntProperty(name="Second offset",
+ description="Frame offset for 2nd animation, where it should start",
+ default=10)
+ stick_bone: StringProperty(name="Stick Bone",
+ description="Bone to freeze during transition",
+ default="")
+
+
+# MocapNLA Tracks. Stores which tracks/actions are associated with each retargeted animation.
+class MocapNLATracks(bpy.types.PropertyGroup):
+ name: StringProperty()
+ base_track: StringProperty()
+ auto_fix_track: StringProperty()
+ manual_fix_track: StringProperty()
+ stride_action: StringProperty()
+
+
+#Update function for Advanced Retarget boolean variable.
+def advancedRetargetToggle(self, context):
+ enduser_obj = context.active_object
+ performer_obj = [obj for obj in context.selected_objects if obj != enduser_obj]
+ if enduser_obj is None or len(performer_obj) != 1:
+ print("Need active and selected armatures")
+ return
+ else:
+ performer_obj = performer_obj[0]
+ if self.advancedRetarget:
+ retarget.preAdvancedRetargeting(performer_obj, enduser_obj)
+ else:
+ retarget.cleanTempConstraints(enduser_obj)
+
+
+def toggleIKBone(self, context):
+ #Update function for IK functionality. Is called when IK prop checkboxes are toggled.
+ if self.IKRetarget:
+ if not self.is_in_ik_chain:
+ print(self.name + " IK toggled ON!")
+ ik = self.constraints.new('IK')
+ #ik the whole chain up to the root, excluding
+ chainLen = 0
+ for parent_bone in self.parent_recursive:
+ chainLen += 1
+ if hasIKConstraint(parent_bone):
+ break
+ #~ deformer_children = [child for child in parent_bone.children if child.bone.use_deform]
+ #~ if len(deformer_children) > 1:
+ #~ break
+ ik.chain_count = chainLen
+ for bone in self.parent_recursive:
+ if bone.is_in_ik_chain:
+ bone.IKRetarget = True
+ else:
+ print(self.name + " IK toggled OFF!")
+ cnstrn_bones = []
+ newChainLength = []
+ if hasIKConstraint(self):
+ cnstrn_bones = [self]
+ elif self.is_in_ik_chain:
+ cnstrn_bones = [child for child in self.children_recursive if hasIKConstraint(child)]
+ for cnstrn_bone in cnstrn_bones:
+ newChainLength.append(cnstrn_bone.parent_recursive.index(self) + 1)
+ if cnstrn_bones:
+ # remove constraint, and update IK retarget for all parents of cnstrn_bone up to chain_len
+ for i, cnstrn_bone in enumerate(cnstrn_bones):
+ print(cnstrn_bone.name)
+ if newChainLength:
+ ik = hasIKConstraint(cnstrn_bone)
+ ik.chain_count = newChainLength[i]
+ else:
+ ik = hasIKConstraint(cnstrn_bone)
+ cnstrn_bone.constraints.remove(ik)
+ cnstrn_bone.IKRetarget = False
+ for bone in cnstrn_bone.parent_recursive:
+ if not bone.is_in_ik_chain:
+ bone.IKRetarget = False
+
+
+#MocapMap class for storing mapping on enduser performer,
+# where a bone may be linked to more than one on the performer
+class MocapMapping(bpy.types.PropertyGroup):
+ name: StringProperty()
+
+# Disabling for now [#28933] - campbell
+'''
+def updateIKRetarget():
+ # ensures that Blender constraints and IK properties are in sync
+ # currently runs when module is loaded, should run when scene is loaded
+ # or user adds a constraint to armature. Will be corrected in the future,
+ # once python callbacks are implemented
+ for obj in bpy.data.objects:
+ if obj.pose:
+ bones = obj.pose.bone
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list