diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-05-05 19:51:40 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-05-05 20:10:57 +0300 |
commit | 792f4d5f69c3207176ef14ce9bee518b0ca66ea8 (patch) | |
tree | 481e3bb5bb11d65aaab690fe58a325ab83693d2b /rigify/utils/naming.py | |
parent | 9abf009f0a42b3b7260d2e90031a3f74e20f1f54 (diff) |
Rigify: new utilities for bone naming and driver creation, and some fixes.
- Added a utility for creating Transform Channel driver variables.
- Added a utility for deriving one bone name from another with suffix.
The bone name utility is inspired by get_bone_name from limb_utils.py
Diffstat (limited to 'rigify/utils/naming.py')
-rw-r--r-- | rigify/utils/naming.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/rigify/utils/naming.py b/rigify/utils/naming.py index 3af3d851..3983704a 100644 --- a/rigify/utils/naming.py +++ b/rigify/utils/naming.py @@ -37,6 +37,10 @@ def strip_trailing_number(s): return s[0:-4] if m else s +def strip_prefix(name): + return re.sub(r'^(?:ORG|MCH|DEF)-', '', name) + + def unique_name(collection, base_name): base_name = strip_trailing_number(base_name) count = 1 @@ -116,11 +120,27 @@ def deformer(name): make_deformer_name = deformer +_prefix_functions = { 'org': org, 'mch': mch, 'def': deformer, 'ctrl': lambda x: x } + + def insert_before_lr(name, text): - if name[-1] in ['l', 'L', 'r', 'R'] and name[-2] in ['.', '-', '_']: - return name[:-2] + text + name[-2:] - else: - return name + text + name_parts = re.match(r'^(.*?)((?:[._-][lLrR](?:\.\d+)?)?)$', name) + name_base, name_suffix = name_parts.groups() + return name_base + text + name_suffix + + +def make_derived_name(name, subtype, suffix=None): + """ Replaces the name prefix, and optionally adds the suffix (before .LR if found). + """ + assert(subtype in _prefix_functions) + + name = strip_prefix(name) + + if suffix: + name = insert_before_lr(name, suffix) + + return _prefix_functions[subtype](name) + def random_id(length=8): """ Generates a random alphanumeric id string. |