Skip to content

Commit d928cee

Browse files
committed
Support putting tweak controls on different layers for super_finger.
1 parent 83ff6e0 commit d928cee

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

rigs/limbs/super_finger.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from ...utils import strip_org, make_deformer_name, connected_children_names, make_mechanism_name
44
from ...utils import create_circle_widget, create_widget
55
from ...utils import MetarigError, align_bone_x_axis
6+
from ...utils import layout_layer_selection_ui
67
from rna_prop_ui import rna_idprop_ui_prop_get
78

89
script = """
@@ -20,6 +21,11 @@ def __init__(self, obj, bone_name, params):
2021
self.org_bones = [bone_name] + connected_children_names(obj, bone_name)
2122
self.params = params
2223

24+
if params.tweak_extra_layers:
25+
self.tweak_layers = list(params.tweak_layers)
26+
else:
27+
self.tweak_layers = None
28+
2329
if len(self.org_bones) <= 1:
2430
raise MetarigError("RIGIFY ERROR: Bone '%s': listen bro, that finger rig jusaint put tugetha rite. A little hint, use more than one bone!!" % (strip_org(bone_name)))
2531

@@ -303,6 +309,9 @@ def generate(self):
303309
# Assigning shapes to control bones
304310
create_circle_widget(self.obj, ctrl, radius=0.3, head_tail=0.5)
305311

312+
if self.tweak_layers:
313+
pb[ctrl].bone.layers = self.tweak_layers
314+
306315
# Create ctrl master widget
307316
w = create_widget(self.obj, master_name)
308317
if w is not None:
@@ -321,6 +330,9 @@ def generate(self):
321330
# Create tip control widget
322331
create_circle_widget(self.obj, tip_name, radius=0.3, head_tail=0.0)
323332

333+
if self.tweak_layers:
334+
pb[tip_name].bone.layers = self.tweak_layers
335+
324336
# Create UI
325337
controls_string = ", ".join(
326338
["'" + x + "'" for x in ctrl_chain]
@@ -336,6 +348,19 @@ def add_parameters(params):
336348
('-X', '-X manual', ''), ('-Y', '-Y manual', ''), ('-Z', '-Z manual', '')]
337349
params.primary_rotation_axis = bpy.props.EnumProperty(items=items, name="Primary Rotation Axis", default='automatic')
338350

351+
# Setting up extra tweak layers
352+
params.tweak_extra_layers = bpy.props.BoolProperty(
353+
name="tweak_extra_layers",
354+
default=False,
355+
description=""
356+
)
357+
358+
params.tweak_layers = bpy.props.BoolVectorProperty(
359+
size=32,
360+
description="Layers for the tweak controls to be on",
361+
default=tuple([i == 1 for i in range(0, 32)])
362+
)
363+
339364

340365
def parameters_ui(layout, params):
341366
""" Create the ui for the rig parameters.
@@ -344,6 +369,7 @@ def parameters_ui(layout, params):
344369
r.label(text="Bend rotation axis:")
345370
r.prop(params, "primary_rotation_axis", text="")
346371

372+
layout_layer_selection_ui(layout, params, "tweak_extra_layers", "tweak_layers")
347373

348374
def create_sample(obj):
349375
# generated by rigify.utils.write_metarig

utils.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,3 +1427,50 @@ def make_track_constraint_from_string(owner, target, subtarget, fstring):
14271427
const.target_space = constraint_space[cns_props[3][0]] if bool(cns_props[3]) else "LOCAL"
14281428
const.owner_space = constraint_space[cns_props[3][1]] if bool(cns_props[3]) else "LOCAL"
14291429
const.head_tail = float(cns_props[4]) if bool(cns_props[4]) else 0.0
1430+
1431+
1432+
#=============================================
1433+
# UI utilities
1434+
#=============================================
1435+
1436+
def layout_layer_selection_ui(layout, params, enable_option, layers_option):
1437+
r = layout.row()
1438+
r.prop(params, enable_option)
1439+
r.active = getattr(params, enable_option)
1440+
1441+
col = r.column(align=True)
1442+
row = col.row(align=True)
1443+
1444+
bone_layers = bpy.context.active_pose_bone.bone.layers[:]
1445+
1446+
for i in range(8): # Layers 0-7
1447+
icon = "NONE"
1448+
if bone_layers[i]:
1449+
icon = "LAYER_ACTIVE"
1450+
row.prop(params, layers_option, index=i, toggle=True, text="", icon=icon)
1451+
1452+
row = col.row(align=True)
1453+
1454+
for i in range(16, 24): # Layers 16-23
1455+
icon = "NONE"
1456+
if bone_layers[i]:
1457+
icon = "LAYER_ACTIVE"
1458+
row.prop(params, layers_option, index=i, toggle=True, text="", icon=icon)
1459+
1460+
col = r.column(align=True)
1461+
row = col.row(align=True)
1462+
1463+
for i in range(8, 16): # Layers 8-15
1464+
icon = "NONE"
1465+
if bone_layers[i]:
1466+
icon = "LAYER_ACTIVE"
1467+
row.prop(params, layers_option, index=i, toggle=True, text="", icon=icon)
1468+
1469+
row = col.row(align=True)
1470+
1471+
for i in range(24, 32): # Layers 24-31
1472+
icon = "NONE"
1473+
if bone_layers[i]:
1474+
icon = "LAYER_ACTIVE"
1475+
row.prop(params, layers_option, index=i, toggle=True, text="", icon=icon)
1476+

0 commit comments

Comments
 (0)