Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov <angavrilov@gmail.com>2019-10-15 19:21:25 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2019-10-16 13:41:48 +0300
commit358bc43ef460e97239bccc379086f98ef6d95472 (patch)
tree6456ee46d145dd7f8a7269eabeff61dfd686e81f /rigify/rigs/basic/pivot.py
parent465f3e3f581f7dc25b299a15c5be6cdc58bbe053 (diff)
Rigify: implement optional custom pivot controls.
- Add an optional custom pivot between torso and the rest of the spine. - Add a custom pivot rig that can be used as a parent of the spine. - Add an optional custom pivot under limb IK controls.
Diffstat (limited to 'rigify/rigs/basic/pivot.py')
-rw-r--r--rigify/rigs/basic/pivot.py143
1 files changed, 143 insertions, 0 deletions
diff --git a/rigify/rigs/basic/pivot.py b/rigify/rigs/basic/pivot.py
new file mode 100644
index 00000000..d4c5898d
--- /dev/null
+++ b/rigify/rigs/basic/pivot.py
@@ -0,0 +1,143 @@
+#====================== 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>
+
+import bpy
+
+from ...base_rig import BaseRig
+
+from ...utils.naming import make_derived_name
+from ...utils.widgets_basic import create_cube_widget, create_pivot_widget
+
+
+class Rig(BaseRig):
+ """ A rig providing a rotation pivot control that can be moved. """
+ def find_org_bones(self, pose_bone):
+ return pose_bone.name
+
+
+ def initialize(self):
+ self.make_control = self.params.make_extra_control
+ self.make_deform = self.params.make_extra_deform
+
+
+ def generate_bones(self):
+ org = self.bones.org
+
+ self.bones.ctrl.pivot = self.copy_bone(org, make_derived_name(org, 'ctrl'), parent=not self.make_control)
+
+ if self.make_control:
+ self.bones.ctrl.master = self.copy_bone(org, make_derived_name(org, 'ctrl', '_master'), parent=True)
+
+ if self.make_deform:
+ self.bones.deform = self.copy_bone(org, make_derived_name(org, 'def'), bbone=True)
+
+
+ def parent_bones(self):
+ if self.make_control:
+ self.set_bone_parent(self.bones.ctrl.pivot, self.bones.ctrl.master, use_connect=False)
+
+ self.set_bone_parent(self.bones.org, self.bones.ctrl.pivot, use_connect=False)
+
+ if self.make_deform:
+ self.set_bone_parent(self.bones.deform, self.bones.org, use_connect=False)
+
+
+ def configure_bones(self):
+ self.copy_bone_properties(self.bones.org, self.bones.ctrl.pivot)
+
+ if self.make_control:
+ self.copy_bone_properties(self.bones.org, self.bones.ctrl.master)
+
+
+ def rig_bones(self):
+ self.make_constraint(
+ self.bones.org, 'COPY_LOCATION', self.bones.ctrl.pivot,
+ space='LOCAL', invert_xyz=(True,)*3
+ )
+
+
+ def generate_widgets(self):
+ create_pivot_widget(self.obj, self.bones.ctrl.pivot, square=True, axis_size=2.0)
+
+ if self.make_control:
+ create_cube_widget(self.obj, self.bones.ctrl.master, radius=0.5)
+
+
+ @classmethod
+ def add_parameters(self, params):
+ params.make_extra_control = bpy.props.BoolProperty(
+ name = "Extra Control",
+ default = False,
+ description = "Create an extended control"
+ )
+
+ params.make_extra_deform = bpy.props.BoolProperty(
+ name = "Extra Deform",
+ default = False,
+ description = "Create an extra deform bone"
+ )
+
+
+ @classmethod
+ def parameters_ui(self, layout, params):
+ r = layout.row()
+ r.prop(params, "make_extra_control", text="Extra Master Control")
+ r = layout.row()
+ r.prop(params, "make_extra_deform", text="Deform Bone")
+
+
+def create_sample(obj):
+ """ Create a sample metarig for this rig type.
+ """
+ # generated by rigify.utils.write_metarig
+ bpy.ops.object.mode_set(mode='EDIT')
+ arm = obj.data
+
+ bones = {}
+
+ bone = arm.edit_bones.new('Bone')
+ bone.head[:] = 0.0000, 0.0000, 0.0000
+ bone.tail[:] = 0.0000, 0.0000, 0.2000
+ bone.roll = 0.0000
+ bone.use_connect = False
+ bones['Bone'] = bone.name
+
+ bpy.ops.object.mode_set(mode='OBJECT')
+ pbone = obj.pose.bones[bones['Bone']]
+ pbone.rigify_type = 'basic.pivot'
+ pbone.lock_location = (False, False, False)
+ pbone.lock_rotation = (False, False, False)
+ pbone.lock_rotation_w = False
+ pbone.lock_scale = (False, False, False)
+ pbone.rotation_mode = 'QUATERNION'
+
+ bpy.ops.object.mode_set(mode='EDIT')
+ for bone in arm.edit_bones:
+ bone.select = False
+ bone.select_head = False
+ bone.select_tail = False
+ for b in bones:
+ bone = arm.edit_bones[bones[b]]
+ bone.select = True
+ bone.select_head = True
+ bone.select_tail = True
+ arm.edit_bones.active = bone
+
+ return bones