forked from bartvdbraak/blender
automatic layer placement, users can set the layers if they want.
predefined layer types 'main', 'extra', 'ik', 'fk'
This commit is contained in:
parent
32d5429e35
commit
3bf27683be
@ -24,6 +24,7 @@ from Mathutils import Vector
|
||||
# TODO, have these in a more general module
|
||||
from rna_prop_ui import rna_idprop_ui_prop_get
|
||||
SPECIAL_TYPES = "root",
|
||||
LAYER_TYPES = "main", "extra", "ik", "fk"
|
||||
|
||||
|
||||
class RigifyError(Exception):
|
||||
@ -81,6 +82,22 @@ def get_bone_type_options(pbone, type_name):
|
||||
return options
|
||||
|
||||
|
||||
def get_layer_dict(options):
|
||||
'''
|
||||
Extracts layer info from a bone options dict
|
||||
defaulting to the layer index if not set.
|
||||
'''
|
||||
layer_default = [False] * 32
|
||||
result = {}
|
||||
for i, layer_type in enumerate(LAYER_TYPES):
|
||||
# no matter if its not defined
|
||||
layer_index = options.get("layer_" + layer_type, i + 2)
|
||||
layer = layer_default[:]
|
||||
layer[layer_index-1] = True
|
||||
result[layer_type] = layer
|
||||
return result
|
||||
|
||||
|
||||
def validate_rig(context, obj):
|
||||
'''
|
||||
Makes no changes
|
||||
|
@ -19,7 +19,7 @@
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
from rigify import RigifyError
|
||||
from rigify import RigifyError, get_layer_dict
|
||||
from rigify_utils import bone_class_instance, copy_bone_simple, add_pole_target_bone, add_stretch_to, blend_bone_list, get_side_name, get_base_name
|
||||
from rna_prop_ui import rna_idprop_ui_prop_get
|
||||
from Mathutils import Vector
|
||||
@ -170,8 +170,17 @@ def ik(obj, definitions, base_names, options):
|
||||
prop["soft_min"] = 0.0
|
||||
prop["soft_max"] = 1.0
|
||||
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
# last step setup layers
|
||||
layers = get_layer_dict(options)
|
||||
lay = layers["ik"]
|
||||
for attr in ik_chain.attr_names:
|
||||
getattr(ik_chain, attr + "_b").layer = lay
|
||||
for attr in ik.attr_names:
|
||||
getattr(ik, attr + "_b").layer = lay
|
||||
|
||||
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
# don't blend the shoulder
|
||||
return [None] + ik_chain.names()
|
||||
|
||||
@ -184,7 +193,7 @@ def fk(obj, definitions, base_names, options):
|
||||
mt.shoulder, mt.arm, mt.forearm, mt.hand = definitions
|
||||
mt.update()
|
||||
|
||||
ex = bone_class_instance(obj, ["socket", "arm_hinge", "hand_delta"])
|
||||
ex = bone_class_instance(obj, ["socket", "hand_delta"])
|
||||
fk_chain = mt.copy(base_names=base_names)
|
||||
|
||||
# shoulder is used as a hinge
|
||||
@ -263,8 +272,19 @@ def fk(obj, definitions, base_names, options):
|
||||
|
||||
hinge_setup()
|
||||
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
# last step setup layers
|
||||
layers = get_layer_dict(options)
|
||||
lay = layers["fk"]
|
||||
for attr in fk_chain.attr_names:
|
||||
getattr(fk_chain, attr + "_b").layer = lay
|
||||
|
||||
lay = layers["extra"]
|
||||
for attr in ex.attr_names:
|
||||
getattr(ex, attr + "_b").layer = lay
|
||||
|
||||
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
return None, fk_chain.arm, fk_chain.forearm, fk_chain.hand
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
from rigify import get_layer_dict
|
||||
from rigify_utils import bone_class_instance
|
||||
|
||||
METARIG_NAMES = ("cpy",)
|
||||
@ -55,12 +56,17 @@ def main(obj, bone_definition, base_names, options):
|
||||
cp.update()
|
||||
mt.update()
|
||||
|
||||
con = cp.cpy_p.constraints.new('COPY_ROTATION')
|
||||
con.target = obj
|
||||
con.subtarget = mt.cpy
|
||||
|
||||
if not cp.cpy_b.connected:
|
||||
con = cp.cpy_p.constraints.new('COPY_LOCATION')
|
||||
con.target = obj
|
||||
con.subtarget = mt.cpy
|
||||
|
||||
con = cp.cpy_p.constraints.new('COPY_ROTATION')
|
||||
con.target = obj
|
||||
con.subtarget = mt.cpy
|
||||
|
||||
# setup layers last
|
||||
layers = get_layer_dict(options)
|
||||
cp.cpy_b.layer = layers["main"]
|
||||
|
||||
return [mt.cpy]
|
||||
|
@ -19,7 +19,7 @@
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
from rigify import RigifyError
|
||||
from rigify import RigifyError, get_layer_dict
|
||||
from rigify_utils import copy_bone_simple, get_side_name
|
||||
from rna_prop_ui import rna_idprop_ui_prop_get
|
||||
from functools import reduce
|
||||
@ -213,5 +213,15 @@ def main(obj, bone_definition, base_names, options):
|
||||
|
||||
i += 1
|
||||
|
||||
|
||||
# last step setup layers
|
||||
layers = get_layer_dict(options)
|
||||
lay = layers["extra"]
|
||||
for child_bone_name, driver_bone_name in driver_bone_pairs:
|
||||
arm.bones[driver_bone_name].layer = lay
|
||||
|
||||
lay = layers["main"]
|
||||
arm.bones[control_bone_name].layer = lay
|
||||
|
||||
# no blending the result of this
|
||||
return None
|
||||
|
@ -19,7 +19,7 @@
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
from rigify import RigifyError
|
||||
from rigify import RigifyError, get_layer_dict
|
||||
from rigify_utils import bone_class_instance, copy_bone_simple, blend_bone_list, get_side_name, get_base_name
|
||||
from rna_prop_ui import rna_idprop_ui_prop_get
|
||||
|
||||
@ -131,8 +131,6 @@ def ik(obj, bone_definition, base_names, options):
|
||||
# setup the existing bones
|
||||
mt_chain = bone_class_instance(obj, ["thigh", "shin", "foot", "toe"])
|
||||
mt = bone_class_instance(obj, ["hips", "heel"])
|
||||
#ex = bone_class_instance(obj, [""])
|
||||
ex = bone_class_instance(obj, ["thigh_socket", "thigh_hinge", "foot_roll_1", "foot_roll_2", "foot_roll_3"])
|
||||
# children of ik_foot
|
||||
ik = bone_class_instance(obj, ["foot", "foot_roll", "foot_roll_01", "foot_roll_02", "knee_target"])
|
||||
|
||||
@ -215,7 +213,6 @@ def ik(obj, bone_definition, base_names, options):
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
ik.update()
|
||||
ex.update()
|
||||
mt_chain.update()
|
||||
ik_chain.update()
|
||||
|
||||
@ -269,6 +266,15 @@ def ik(obj, bone_definition, base_names, options):
|
||||
con.minimum_x = -180.0 # XXX -deg
|
||||
con.maximum_x = 0.0
|
||||
|
||||
|
||||
# last step setup layers
|
||||
layers = get_layer_dict(options)
|
||||
lay = layers["ik"]
|
||||
for attr in ik_chain.attr_names:
|
||||
getattr(ik_chain, attr + "_b").layer = lay
|
||||
for attr in ik.attr_names:
|
||||
getattr(ik, attr + "_b").layer = lay
|
||||
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
return None, ik_chain.thigh, ik_chain.shin, ik_chain.foot, ik_chain.toe, None
|
||||
@ -348,6 +354,19 @@ def fk(obj, bone_definition, base_names, options):
|
||||
mod.coefficients[0] = 1.0
|
||||
mod.coefficients[1] = -1.0
|
||||
|
||||
|
||||
|
||||
# last step setup layers
|
||||
layers = get_layer_dict(options)
|
||||
lay = layers["fk"]
|
||||
for attr in fk_chain.attr_names:
|
||||
getattr(fk_chain, attr + "_b").layer = lay
|
||||
|
||||
lay = layers["extra"]
|
||||
for attr in ex.attr_names:
|
||||
getattr(ex, attr + "_b").layer = lay
|
||||
|
||||
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
# dont blend the hips or heel
|
||||
|
@ -19,7 +19,7 @@
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
from rigify import RigifyError
|
||||
from rigify import RigifyError, get_layer_dict
|
||||
from rigify_utils import bone_class_instance, copy_bone_simple
|
||||
from rna_prop_ui import rna_idprop_ui_prop_get
|
||||
|
||||
@ -121,7 +121,7 @@ def main(obj, bone_definition, base_names, options):
|
||||
neck_chain_basename = base_names[mt_chain.neck_01_e.name].split(".")[0]
|
||||
neck_chain_segment_length = mt_chain.neck_01_e.length
|
||||
|
||||
ex = bone_class_instance(obj, ["body", "head", "head_hinge", "neck_socket", "head_ctrl"]) # hinge & extras
|
||||
ex = bone_class_instance(obj, ["head", "head_hinge", "neck_socket", "head_ctrl"]) # hinge & extras
|
||||
|
||||
# Add the head hinge at the bodys location, becomes the parent of the original head
|
||||
|
||||
@ -296,5 +296,15 @@ def main(obj, bone_definition, base_names, options):
|
||||
con.target = obj
|
||||
con.subtarget = neck_p.name
|
||||
|
||||
|
||||
# last step setup layers
|
||||
layers = get_layer_dict(options)
|
||||
lay = layers["extra"]
|
||||
for attr in ex_chain.attr_names:
|
||||
getattr(ex_chain, attr + "_b").layer = lay
|
||||
for attr in ex.attr_names:
|
||||
getattr(ex, attr + "_b").layer = lay
|
||||
|
||||
|
||||
# no blending the result of this
|
||||
return None
|
||||
|
@ -19,6 +19,7 @@
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
from rigify import get_layer_dict
|
||||
from rigify_utils import copy_bone_simple, get_side_name
|
||||
from rna_prop_ui import rna_idprop_ui_prop_get
|
||||
|
||||
@ -232,5 +233,11 @@ def main(obj, bone_definition, base_names, options):
|
||||
if x_direction(): # flip
|
||||
driver.expression = "-(%s)" % driver.expression
|
||||
|
||||
|
||||
# last step setup layers
|
||||
layers = get_layer_dict(options)
|
||||
arm.bones[control_name].layer = layers["extra"]
|
||||
|
||||
|
||||
# no blending the result of this
|
||||
return None
|
||||
|
@ -19,6 +19,7 @@
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
from rigify import get_layer_dict
|
||||
from rigify_utils import bone_class_instance, copy_bone_simple
|
||||
from rna_prop_ui import rna_idprop_ui_prop_get
|
||||
|
||||
@ -495,5 +496,20 @@ def main(obj, bone_definition, base_names, options):
|
||||
mod.coefficients[0] = - (i - 1)
|
||||
mod.coefficients[1] = spine_chain_len
|
||||
|
||||
|
||||
# last step setup layers
|
||||
layers = get_layer_dict(options)
|
||||
lay = layers["extra"]
|
||||
for attr in ex.attr_names:
|
||||
getattr(ex, attr + "_b").layer = lay
|
||||
for attr in ex_chain.attr_names:
|
||||
getattr(ex_chain, attr + "_b").layer = lay
|
||||
|
||||
lay = layers["main"]
|
||||
for attr in df.attr_names:
|
||||
getattr(df, attr + "_b").layer = lay
|
||||
for attr in rv_chain .attr_names:
|
||||
getattr(rv_chain , attr + "_b").layer = lay
|
||||
|
||||
# no support for blending chains
|
||||
return None
|
||||
|
@ -30,6 +30,8 @@ import os
|
||||
#
|
||||
# in debian install pylint pyflakes pep8 with apt-get/aptitude/etc
|
||||
#
|
||||
# on *nix run
|
||||
# python release/test/pep8.py > tmp.err 2>&1
|
||||
|
||||
# how many lines to read into the file, pep8 comment
|
||||
# should be directly after the licence header, ~20 in most cases
|
||||
|
Loading…
Reference in New Issue
Block a user