[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37857] branches/soc-2011-pepper/release/ scripts/startup/ui_mocap.py: Added more IK functionality to UI.
Benjy Cook
benjycook at hotmail.com
Mon Jun 27 14:46:53 CEST 2011
Revision: 37857
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37857
Author: benjycook
Date: 2011-06-27 12:46:53 +0000 (Mon, 27 Jun 2011)
Log Message:
-----------
Added more IK functionality to UI. You can now toggle IK for selected bones.
Modified Paths:
--------------
branches/soc-2011-pepper/release/scripts/startup/ui_mocap.py
Modified: branches/soc-2011-pepper/release/scripts/startup/ui_mocap.py
===================================================================
--- branches/soc-2011-pepper/release/scripts/startup/ui_mocap.py 2011-06-27 12:03:28 UTC (rev 37856)
+++ branches/soc-2011-pepper/release/scripts/startup/ui_mocap.py 2011-06-27 12:46:53 UTC (rev 37857)
@@ -26,8 +26,54 @@
from mathutils import Vector
from math import isfinite
+def toggleIKBone(self, context):
+ 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
+ chainLen = len(self.bone.parent_recursive)
+ 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_bone = False
+ if hasIKConstraint(self):
+ cnstrn_bone = self
+ elif self.is_in_ik_chain:
+ cnstrn_bone = [child for child in self.children_recursive if hasIKConstraint(child)][0]
+ if cnstrn_bone:
+ # remove constraint, and update IK retarget for all parents of cnstrn_bone up to chain_len
+ ik = [constraint for constraint in cnstrn_bone.constraints if constraint.type == "IK"][0]
+ 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
+
bpy.types.Bone.map = bpy.props.StringProperty()
+bpy.types.PoseBone.IKRetarget = bpy.props.BoolProperty(name="IK",
+ description = "Toggles IK Retargeting method for given bone",
+ update = toggleIKBone)
+
+def hasIKConstraint(pose_bone):
+ return ("IK" in [constraint.type for constraint in pose_bone.constraints])
+
+def updateIKRetarget():
+ for obj in bpy.data.objects:
+ if obj.pose:
+ bones = obj.pose.bones
+ for pose_bone in bones:
+ if pose_bone.is_in_ik_chain or hasIKConstraint(pose_bone):
+ pose_bone.IKRetarget = True
+ else:
+ pose_bone.IKRetarget = False
+
+updateIKRetarget()
+
import retarget
import mocap_tools
@@ -66,17 +112,19 @@
enduser_arm = enduser_obj.data
perf_pose_bones = enduser_obj.pose.bones
for bone in perf.bones:
- row = self.layout.row(align=True)
+ row = self.layout.row()
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"
+ label_mod = "ik chain"
+ if hasIKConstraint(pose_bone):
+ label_mod = "ik end"
+ row.prop(pose_bone, 'IKRetarget')
row.label(label_mod)
+
self.layout.operator("mocap.retarget", text='RETARGET!')
@@ -132,4 +180,4 @@
if __name__ == "__main__":
- register()
+ register()
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list