Changeset View
Changeset View
Standalone View
Standalone View
rigify/rigs/experimental/super_chain.py
| import bpy | import bpy | ||||
| from mathutils import Vector | from mathutils import Vector | ||||
| from math import pi | from math import pi | ||||
| from ...utils import copy_bone, flip_bone, put_bone, org, align_bone_y_axis, align_bone_x_axis, align_bone_z_axis | from ...utils import copy_bone, flip_bone, put_bone, org, align_bone_y_axis, align_bone_x_axis, align_bone_z_axis | ||||
| from ...utils import strip_org, make_deformer_name, connected_children_names | from ...utils import strip_org, make_deformer_name, connected_children_names | ||||
| from ...utils import create_circle_widget, create_sphere_widget, create_widget, create_chain_widget | from ...utils import create_circle_widget, create_sphere_widget, create_widget, create_chain_widget | ||||
| from ...utils import MetarigError, make_mechanism_name, create_cube_widget | from ...utils import MetarigError, make_mechanism_name, create_cube_widget | ||||
| from ...utils import ControlLayersOption | |||||
| from rna_prop_ui import rna_idprop_ui_prop_get | from rna_prop_ui import rna_idprop_ui_prop_get | ||||
| from ..limbs.limb_utils import get_bone_name | from ..limbs.limb_utils import get_bone_name | ||||
| script = """ | script = """ | ||||
| controls = [%s] | controls = [%s] | ||||
| torso = '%s' | torso = '%s' | ||||
| if is_selected( controls ): | if is_selected( controls ): | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | def __init__(self, obj, bone_name, params): | ||||
| # TODO: | # TODO: | ||||
| # Limit neck_pos prop to 1 --> num of bones - 1 (last is head) | # Limit neck_pos prop to 1 --> num of bones - 1 (last is head) | ||||
| # Limit pivot_pos prop to 2 --> num of bones (must leave place for lower torso) | # Limit pivot_pos prop to 2 --> num of bones (must leave place for lower torso) | ||||
| # if params.tail_pos: | # if params.tail_pos: | ||||
| # self.tail_pos = params.tail_pos | # self.tail_pos = params.tail_pos | ||||
| # Assign values to tweak layers props if opted by user | |||||
| if params.tweak_extra_layers: | |||||
| self.tweak_layers = list(params.tweak_layers) | |||||
| else: | |||||
| self.tweak_layers = None | |||||
| # Report error of user created less than the minimum of 4 bones for rig | # Report error of user created less than the minimum of 4 bones for rig | ||||
| # if len(self.org_bones) <= 4: | # if len(self.org_bones) <= 4: | ||||
| # raise MetarigError( | # raise MetarigError( | ||||
| # "RIGIFY ERROR: invalid rig structure" % (strip_org(bone_name)) | # "RIGIFY ERROR: invalid rig structure" % (strip_org(bone_name)) | ||||
| # ) | # ) | ||||
| # def build_bone_structure( self ): | # def build_bone_structure( self ): | ||||
| ▲ Show 20 Lines • Show All 943 Lines • ▼ Show 20 Lines | def locks_and_widgets(self, bones): | ||||
| create_cube_widget( | create_cube_widget( | ||||
| self.obj, | self.obj, | ||||
| bones['chain']['conv'], | bones['chain']['conv'], | ||||
| radius = 0.5, | radius = 0.5, | ||||
| bone_transform_name = None | bone_transform_name = None | ||||
| ) | ) | ||||
| # Assigning layers to tweaks and ctrls | # Assigning layers to tweaks and ctrls | ||||
| for bone in bones['chain']['tweak']: | ControlLayersOption.TWEAK.assign(self.params, pb, bones['chain']['tweak']) | ||||
| if self.tweak_layers: | |||||
| pb[bone].bone.layers = self.tweak_layers | |||||
| # for bone in bones['chain']['ctrl']: | # for bone in bones['chain']['ctrl']: | ||||
| # if self.tweak_layers: | # if self.tweak_layers: | ||||
| # pb[bone].bone.layers = self.tweak_layers | # pb[bone].bone.layers = self.tweak_layers | ||||
| return | return | ||||
| ▲ Show 20 Lines • Show All 210 Lines • ▼ Show 20 Lines | def add_parameters(params): | ||||
| # | # | ||||
| # params.tail_pos = bpy.props.IntProperty( | # params.tail_pos = bpy.props.IntProperty( | ||||
| # name = 'tail_position', | # name = 'tail_position', | ||||
| # default = 0, | # default = 0, | ||||
| # min = 0, | # min = 0, | ||||
| # description = 'Where the tail starts (change from 0 to enable)' | # description = 'Where the tail starts (change from 0 to enable)' | ||||
| # ) | # ) | ||||
| # Setting up extra layers for the FK and tweak | ControlLayersOption.TWEAK.add_parameters(params) | ||||
| params.tweak_extra_layers = bpy.props.BoolProperty( | |||||
| name = "tweak_extra_layers", | |||||
| default = True, | |||||
| description = "" | |||||
| ) | |||||
| params.tweak_layers = bpy.props.BoolVectorProperty( | |||||
| size = 32, | |||||
| description = "Layers for the tweak controls to be on", | |||||
| default = tuple( [ i == 1 for i in range(0, 32) ] ) | |||||
| ) | |||||
| def parameters_ui(layout, params): | def parameters_ui(layout, params): | ||||
| """ Create the ui for the rig parameters.""" | """ Create the ui for the rig parameters.""" | ||||
| # r = layout.row() | # r = layout.row() | ||||
| # r.prop(params, "neck_pos") | # r.prop(params, "neck_pos") | ||||
| # | # | ||||
| Show All 16 Lines | def parameters_ui(layout, params): | ||||
| # row.prop(params, "tweak_axis", index=i, toggle=True, text=axis) | # row.prop(params, "tweak_axis", index=i, toggle=True, text=axis) | ||||
| r = layout.row() | r = layout.row() | ||||
| r.prop(params, "bbones") | r.prop(params, "bbones") | ||||
| r = layout.row() | r = layout.row() | ||||
| r.prop_search(params, 'conv_bone', pb, "bones", text="Convergence Bone") | r.prop_search(params, 'conv_bone', pb, "bones", text="Convergence Bone") | ||||
| r = layout.row() | ControlLayersOption.TWEAK.parameters_ui(layout, params) | ||||
| r.prop(params, "tweak_extra_layers") | |||||
| r.active = params.tweak_extra_layers | |||||
| col = r.column(align=True) | |||||
| row = col.row(align=True) | |||||
| bone_layers = bpy.context.active_pose_bone.bone.layers[:] | |||||
| for i in range(8): | |||||
| icon = "NONE" | |||||
| if bone_layers[i]: | |||||
| icon = "LAYER_ACTIVE" | |||||
| row.prop(params, "tweak_layers", index=i, toggle=True, text="", icon=icon) | |||||
| row = col.row(align=True) | |||||
| for i in range(16,24): | |||||
| icon = "NONE" | |||||
| if bone_layers[i]: | |||||
| icon = "LAYER_ACTIVE" | |||||
| row.prop(params, "tweak_layers", index=i, toggle=True, text="", icon=icon) | |||||
| col = r.column(align=True) | |||||
| row = col.row(align=True) | |||||
| for i in range(8,16): | |||||
| icon = "NONE" | |||||
| if bone_layers[i]: | |||||
| icon = "LAYER_ACTIVE" | |||||
| row.prop(params, "tweak_layers", index=i, toggle=True, text="", icon=icon) | |||||
| row = col.row(align=True) | |||||
| for i in range(24,32): | |||||
| icon = "NONE" | |||||
| if bone_layers[i]: | |||||
| icon = "LAYER_ACTIVE" | |||||
| row.prop(params, "tweak_layers", index=i, toggle=True, text="", icon=icon) | |||||
| def create_sample(obj): | def create_sample(obj): | ||||
| # generated by rigify.utils.write_metarig | # generated by rigify.utils.write_metarig | ||||
| bpy.ops.object.mode_set(mode='EDIT') | bpy.ops.object.mode_set(mode='EDIT') | ||||
| arm = obj.data | arm = obj.data | ||||
| bones = {} | bones = {} | ||||
| ▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines | |||||