Sun position: fix HDRI mouse wheel exposure setting alpha
[blender-addons.git] / rigify / utils / components.py
blob5c1ebcb6b82e6d5f3cce3b02af78f90b8b582a65
1 import bpy
3 from .naming import make_derived_name
4 from .bones import put_bone, copy_bone_position, align_bone_orientation
5 from .widgets_basic import create_pivot_widget
6 from .misc import force_lazy
8 from ..base_rig import RigComponent, stage
11 class CustomPivotControl(RigComponent):
12 """
13 A utility that generates a pivot control with a custom position.
15 Generates a control bone, and a MCH output bone.
16 """
18 def __init__(
19 self, rig, id_name, org_bone, *,
20 name=None, parent=None, position=None, matrix=None,
21 scale=1.0, scale_mch=None,
22 move_to=None, align_to=None, snap_to=None,
23 widget_axis=1.5, widget_cap=1.0, widget_square=True,
25 super().__init__(rig)
27 assert rig.generator.stage == 'generate_bones'
29 self.bones = rig.bones
30 self.id_name = id_name
32 self.parent = parent
33 self.scale = scale or 1
34 self.scale_mch = scale_mch or (self.scale * 0.7)
35 self.move_to = move_to
36 self.align_to = align_to
37 self.snap_to = snap_to
38 self.widget_axis = widget_axis
39 self.widget_cap = widget_cap
40 self.widget_square = widget_square
42 name = name or make_derived_name(org_bone, 'ctrl', '_pivot')
44 self.do_make_bones(org_bone, name, position, matrix)
46 @property
47 def control(self):
48 return self.ctrl
50 @property
51 def output(self):
52 return self.mch
54 def do_make_bones(self, org, name, position, matrix):
55 self.bones.ctrl[self.id_name] = self.ctrl = self.copy_bone(org, name, parent=not self.parent, scale=self.scale)
56 self.bones.mch[self.id_name] = self.mch = self.copy_bone(org, make_derived_name(name, 'mch'), scale=self.scale_mch)
58 if position or matrix:
59 put_bone(self.obj, self.ctrl, position, matrix=matrix)
60 put_bone(self.obj, self.mch, position, matrix=matrix)
62 def parent_bones(self):
63 if self.snap_to:
64 bone = force_lazy(self.snap_to)
65 copy_bone_position(self.obj, bone, self.ctrl, scale=self.scale)
66 copy_bone_position(self.obj, bone, self.mch, scale=self.scale_mch)
68 if self.move_to:
69 pos = self.get_bone(force_lazy(self.move_to)).head
70 put_bone(self.obj, self.ctrl, pos)
71 put_bone(self.obj, self.mch, pos)
73 if self.align_to:
74 self.align_to = force_lazy(self.align_to)
75 align_bone_orientation(self.obj, self.ctrl, self.align_to)
76 align_bone_orientation(self.obj, self.mch, self.align_to)
78 if self.parent:
79 self.set_bone_parent(self.ctrl, force_lazy(self.parent))
81 self.set_bone_parent(self.mch, self.ctrl)
83 def rig_bones(self):
84 self.make_constraint(self.mch, 'COPY_LOCATION', self.ctrl, space='LOCAL', invert_xyz=(True,)*3)
86 def generate_widgets(self):
87 create_pivot_widget(self.obj, self.ctrl, axis_size=self.widget_axis, cap_size=self.widget_cap, square=self.widget_square)