Skip to content

Commit 0c91579

Browse files
angavriloveigen-value
authored andcommitted
Introduce a utility class for control bone layer selection UI.
Many rigs contain basically the same nontrivial code for selecting which layers to put bones on. This means a utility is necessary.
1 parent 0429a69 commit 0c91579

File tree

9 files changed

+135
-478
lines changed

9 files changed

+135
-478
lines changed

rigs/experimental/super_chain.py

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from ...utils import strip_org, make_deformer_name, connected_children_names
66
from ...utils import create_circle_widget, create_sphere_widget, create_widget, create_chain_widget
77
from ...utils import MetarigError, make_mechanism_name, create_cube_widget
8+
from ...utils import ControlLayersOption
89
from rna_prop_ui import rna_idprop_ui_prop_get
910
from ..limbs.limb_utils import get_bone_name
1011

@@ -65,12 +66,6 @@ def __init__(self, obj, bone_name, params):
6566
# if params.tail_pos:
6667
# self.tail_pos = params.tail_pos
6768

68-
# Assign values to tweak layers props if opted by user
69-
if params.tweak_extra_layers:
70-
self.tweak_layers = list(params.tweak_layers)
71-
else:
72-
self.tweak_layers = None
73-
7469
# Report error of user created less than the minimum of 4 bones for rig
7570
# if len(self.org_bones) <= 4:
7671
# raise MetarigError(
@@ -1030,9 +1025,7 @@ def locks_and_widgets(self, bones):
10301025
)
10311026

10321027
# Assigning layers to tweaks and ctrls
1033-
for bone in bones['chain']['tweak']:
1034-
if self.tweak_layers:
1035-
pb[bone].bone.layers = self.tweak_layers
1028+
ControlLayersOption.TWEAK.assign(self.params, pb, bones['chain']['tweak'])
10361029

10371030
# for bone in bones['chain']['ctrl']:
10381031
# if self.tweak_layers:
@@ -1259,18 +1252,7 @@ def add_parameters(params):
12591252
# description = 'Where the tail starts (change from 0 to enable)'
12601253
# )
12611254

1262-
# Setting up extra layers for the FK and tweak
1263-
params.tweak_extra_layers = bpy.props.BoolProperty(
1264-
name = "tweak_extra_layers",
1265-
default = True,
1266-
description = ""
1267-
)
1268-
1269-
params.tweak_layers = bpy.props.BoolVectorProperty(
1270-
size = 32,
1271-
description = "Layers for the tweak controls to be on",
1272-
default = tuple( [ i == 1 for i in range(0, 32) ] )
1273-
)
1255+
ControlLayersOption.TWEAK.add_parameters(params)
12741256

12751257

12761258
def parameters_ui(layout, params):
@@ -1303,45 +1285,7 @@ def parameters_ui(layout, params):
13031285
r = layout.row()
13041286
r.prop_search(params, 'conv_bone', pb, "bones", text="Convergence Bone")
13051287

1306-
r = layout.row()
1307-
r.prop(params, "tweak_extra_layers")
1308-
r.active = params.tweak_extra_layers
1309-
1310-
col = r.column(align=True)
1311-
row = col.row(align=True)
1312-
1313-
bone_layers = bpy.context.active_pose_bone.bone.layers[:]
1314-
1315-
for i in range(8):
1316-
icon = "NONE"
1317-
if bone_layers[i]:
1318-
icon = "LAYER_ACTIVE"
1319-
row.prop(params, "tweak_layers", index=i, toggle=True, text="", icon=icon)
1320-
1321-
row = col.row(align=True)
1322-
1323-
for i in range(16,24):
1324-
icon = "NONE"
1325-
if bone_layers[i]:
1326-
icon = "LAYER_ACTIVE"
1327-
row.prop(params, "tweak_layers", index=i, toggle=True, text="", icon=icon)
1328-
1329-
col = r.column(align=True)
1330-
row = col.row(align=True)
1331-
1332-
for i in range(8,16):
1333-
icon = "NONE"
1334-
if bone_layers[i]:
1335-
icon = "LAYER_ACTIVE"
1336-
row.prop(params, "tweak_layers", index=i, toggle=True, text="", icon=icon)
1337-
1338-
row = col.row(align=True)
1339-
1340-
for i in range(24,32):
1341-
icon = "NONE"
1342-
if bone_layers[i]:
1343-
icon = "LAYER_ACTIVE"
1344-
row.prop(params, "tweak_layers", index=i, toggle=True, text="", icon=icon)
1288+
ControlLayersOption.TWEAK.parameters_ui(layout, params)
13451289

13461290

13471291
def create_sample(obj):

rigs/limbs/arm.py

Lines changed: 7 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ...utils import create_limb_widget, connected_children_names
1111
from ...utils import align_bone_y_axis, align_bone_x_axis, align_bone_z_axis
1212
from ...rig_ui_template import UTILITIES_RIG_ARM, REGISTER_RIG_ARM
13+
from ...utils import ControlLayersOption
1314
from rna_prop_ui import rna_idprop_ui_prop_get
1415
from ..widgets import create_ikarrow_widget
1516
from math import trunc, pi
@@ -47,16 +48,6 @@ def __init__(self, obj, bone_name, params):
4748
self.rot_axis = params.rotation_axis
4849
self.auto_align_extremity = params.auto_align_extremity
4950

50-
# Assign values to tweak/FK layers props if opted by user
51-
if params.tweak_extra_layers:
52-
self.tweak_layers = list(params.tweak_layers)
53-
else:
54-
self.tweak_layers = None
55-
56-
if params.fk_extra_layers:
57-
self.fk_layers = list(params.fk_layers)
58-
else:
59-
self.fk_layers = None
6051

6152
def orient_org_bones(self):
6253

@@ -267,8 +258,7 @@ def create_tweak(self):
267258

268259
create_sphere_widget(self.obj, t, bone_transform_name=None)
269260

270-
if self.tweak_layers:
271-
pb[t].bone.layers = self.tweak_layers
261+
ControlLayersOption.TWEAK.assign(self.params, pb, tweaks['ctrl'])
272262

273263
return tweaks
274264

@@ -548,9 +538,7 @@ def create_fk(self, parent):
548538

549539
create_circle_widget(self.obj, ctrls[2], radius=0.4, head_tail=0.0)
550540

551-
for c in ctrls:
552-
if self.fk_layers:
553-
pb[c].bone.layers = self.fk_layers
541+
ControlLayersOption.FK.assign(self.params, pb, ctrls)
554542

555543
return {'ctrl': ctrls, 'mch': mch}
556544

@@ -1114,30 +1102,8 @@ def add_parameters(params):
11141102
)
11151103

11161104
# Setting up extra layers for the FK and tweak
1117-
params.tweak_extra_layers = bpy.props.BoolProperty(
1118-
name = "tweak_extra_layers",
1119-
default = True,
1120-
description = ""
1121-
)
1122-
1123-
params.tweak_layers = bpy.props.BoolVectorProperty(
1124-
size = 32,
1125-
description = "Layers for the tweak controls to be on",
1126-
default = tuple( [ i == 1 for i in range(0, 32) ] )
1127-
)
1128-
1129-
# Setting up extra layers for the FK and tweak
1130-
params.fk_extra_layers = bpy.props.BoolProperty(
1131-
name = "fk_extra_layers",
1132-
default = True,
1133-
description = ""
1134-
)
1135-
1136-
params.fk_layers = bpy.props.BoolVectorProperty(
1137-
size = 32,
1138-
description = "Layers for the FK controls to be on",
1139-
default = tuple( [ i == 1 for i in range(0, 32) ] )
1140-
)
1105+
ControlLayersOption.FK.add_parameters(params)
1106+
ControlLayersOption.TWEAK.add_parameters(params)
11411107

11421108

11431109
def parameters_ui(layout, params):
@@ -1157,46 +1123,8 @@ def parameters_ui(layout, params):
11571123
r = layout.row()
11581124
r.prop(params, "bbones")
11591125

1160-
bone_layers = bpy.context.active_pose_bone.bone.layers[:]
1161-
1162-
for layer in ['fk', 'tweak']:
1163-
r = layout.row()
1164-
r.prop(params, layer + "_extra_layers")
1165-
r.active = params.tweak_extra_layers
1166-
1167-
col = r.column(align=True)
1168-
row = col.row(align=True)
1169-
1170-
for i in range(8):
1171-
icon = "NONE"
1172-
if bone_layers[i]:
1173-
icon = "LAYER_ACTIVE"
1174-
row.prop(params, layer + "_layers", index=i, toggle=True, text="", icon=icon)
1175-
1176-
row = col.row(align=True)
1177-
1178-
for i in range(16, 24):
1179-
icon = "NONE"
1180-
if bone_layers[i]:
1181-
icon = "LAYER_ACTIVE"
1182-
row.prop(params, layer + "_layers", index=i, toggle=True, text="", icon=icon)
1183-
1184-
col = r.column(align=True)
1185-
row = col.row(align=True)
1186-
1187-
for i in range(8, 16):
1188-
icon = "NONE"
1189-
if bone_layers[i]:
1190-
icon = "LAYER_ACTIVE"
1191-
row.prop(params, layer + "_layers", index=i, toggle=True, text="", icon=icon)
1192-
1193-
row = col.row(align=True)
1194-
1195-
for i in range(24, 32):
1196-
icon = "NONE"
1197-
if bone_layers[i]:
1198-
icon = "LAYER_ACTIVE"
1199-
row.prop(params, layer + "_layers", index=i, toggle=True, text="", icon=icon)
1126+
ControlLayersOption.FK.parameters_ui(layout, params)
1127+
ControlLayersOption.TWEAK.parameters_ui(layout, params)
12001128

12011129

12021130
def create_sample(obj):

rigs/limbs/leg.py

Lines changed: 7 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from ...utils import create_limb_widget, connected_children_names
1212
from ...utils import align_bone_y_axis, align_bone_x_axis, align_bone_z_axis
1313
from ...rig_ui_template import UTILITIES_RIG_LEG, REGISTER_RIG_LEG
14+
from ...utils import ControlLayersOption
1415
from rna_prop_ui import rna_idprop_ui_prop_get
1516
from ..widgets import create_ikarrow_widget
1617
from math import trunc, pi
@@ -48,16 +49,6 @@ def __init__(self, obj, bone_name, params):
4849
self.rot_axis = params.rotation_axis
4950
self.auto_align_extremity = params.auto_align_extremity
5051

51-
# Assign values to tweak/FK layers props if opted by user
52-
if params.tweak_extra_layers:
53-
self.tweak_layers = list(params.tweak_layers)
54-
else:
55-
self.tweak_layers = None
56-
57-
if params.fk_extra_layers:
58-
self.fk_layers = list(params.fk_layers)
59-
else:
60-
self.fk_layers = None
6152

6253
def orient_org_bones(self):
6354

@@ -294,8 +285,7 @@ def create_tweak(self):
294285

295286
create_sphere_widget(self.obj, t, bone_transform_name=None)
296287

297-
if self.tweak_layers:
298-
pb[t].bone.layers = self.tweak_layers
288+
ControlLayersOption.TWEAK.assign(self.params, pb, tweaks['ctrl'])
299289

300290
return tweaks
301291

@@ -575,9 +565,7 @@ def create_fk(self, parent):
575565

576566
create_circle_widget(self.obj, ctrls[2], radius=0.4, head_tail=0.0)
577567

578-
for c in ctrls:
579-
if self.fk_layers:
580-
pb[c].bone.layers = self.fk_layers
568+
ControlLayersOption.FK.assign(self.params, pb, ctrls)
581569

582570
return {'ctrl': ctrls, 'mch': mch}
583571

@@ -1437,30 +1425,8 @@ def add_parameters(params):
14371425
)
14381426

14391427
# Setting up extra layers for the FK and tweak
1440-
params.tweak_extra_layers = bpy.props.BoolProperty(
1441-
name = "tweak_extra_layers",
1442-
default = True,
1443-
description = ""
1444-
)
1445-
1446-
params.tweak_layers = bpy.props.BoolVectorProperty(
1447-
size = 32,
1448-
description = "Layers for the tweak controls to be on",
1449-
default = tuple( [ i == 1 for i in range(0, 32) ] )
1450-
)
1451-
1452-
# Setting up extra layers for the FK and tweak
1453-
params.fk_extra_layers = bpy.props.BoolProperty(
1454-
name = "fk_extra_layers",
1455-
default = True,
1456-
description = ""
1457-
)
1458-
1459-
params.fk_layers = bpy.props.BoolVectorProperty(
1460-
size = 32,
1461-
description = "Layers for the FK controls to be on",
1462-
default = tuple( [ i == 1 for i in range(0, 32) ] )
1463-
)
1428+
ControlLayersOption.FK.add_parameters(params)
1429+
ControlLayersOption.TWEAK.add_parameters(params)
14641430

14651431

14661432
def parameters_ui(layout, params):
@@ -1480,46 +1446,8 @@ def parameters_ui(layout, params):
14801446
r = layout.row()
14811447
r.prop(params, "bbones")
14821448

1483-
bone_layers = bpy.context.active_pose_bone.bone.layers[:]
1484-
1485-
for layer in ['fk', 'tweak']:
1486-
r = layout.row()
1487-
r.prop(params, layer + "_extra_layers")
1488-
r.active = params.tweak_extra_layers
1489-
1490-
col = r.column(align=True)
1491-
row = col.row(align=True)
1492-
1493-
for i in range(8):
1494-
icon = "NONE"
1495-
if bone_layers[i]:
1496-
icon = "LAYER_ACTIVE"
1497-
row.prop(params, layer + "_layers", index=i, toggle=True, text="", icon=icon)
1498-
1499-
row = col.row(align=True)
1500-
1501-
for i in range(16, 24):
1502-
icon = "NONE"
1503-
if bone_layers[i]:
1504-
icon = "LAYER_ACTIVE"
1505-
row.prop(params, layer + "_layers", index=i, toggle=True, text="", icon=icon)
1506-
1507-
col = r.column(align=True)
1508-
row = col.row(align=True)
1509-
1510-
for i in range(8, 16):
1511-
icon = "NONE"
1512-
if bone_layers[i]:
1513-
icon = "LAYER_ACTIVE"
1514-
row.prop(params, layer + "_layers", index=i, toggle=True, text="", icon=icon)
1515-
1516-
row = col.row(align=True)
1517-
1518-
for i in range(24, 32):
1519-
icon = "NONE"
1520-
if bone_layers[i]:
1521-
icon = "LAYER_ACTIVE"
1522-
row.prop(params, layer + "_layers", index=i, toggle=True, text="", icon=icon)
1449+
ControlLayersOption.FK.parameters_ui(layout, params)
1450+
ControlLayersOption.TWEAK.parameters_ui(layout, params)
15231451

15241452

15251453
def create_sample(obj):

0 commit comments

Comments
 (0)