diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-05-07 20:13:29 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-05-07 20:13:29 +0300 |
commit | 215006e5a9c082d85c964397c35f3fe78270aa9c (patch) | |
tree | dc5916f7eae8dbc3d2f7f526fa8612f1ed47e6ad /rigify | |
parent | 42508e1815c6f9b1ec93f4aeb77cefa93072593d (diff) |
Rigify: improve widget placement, widget generation and make_driver.
- Take into account the custom shape settings of the bone when
creating and placing the custom widget object.
- Change write_widget to wrap the generated list text and fix
undefined variable errors if there are no verts/edges/faces.
- Automatically look up string to bone in self.make_driver().
Diffstat (limited to 'rigify')
-rw-r--r-- | rigify/utils/mechanism.py | 2 | ||||
-rw-r--r-- | rigify/utils/widgets.py | 49 |
2 files changed, 30 insertions, 21 deletions
diff --git a/rigify/utils/mechanism.py b/rigify/utils/mechanism.py index ffec8a4c..e4344ef1 100644 --- a/rigify/utils/mechanism.py +++ b/rigify/utils/mechanism.py @@ -286,4 +286,6 @@ class MechanismUtilityMixin(object): def make_driver(self, owner, prop, **args): assert(self.obj.mode == 'OBJECT') + if isinstance(owner, str): + owner = self.obj.pose.bones[owner] return make_driver(owner, prop, target_id=self.obj, **args) diff --git a/rigify/utils/widgets.py b/rigify/utils/widgets.py index 184429a3..8f1e3442 100644 --- a/rigify/utils/widgets.py +++ b/rigify/utils/widgets.py @@ -36,9 +36,16 @@ def obj_to_bone(obj, rig, bone_name): if bpy.context.mode == 'EDIT_ARMATURE': raise MetarigError("obj_to_bone(): does not work while in edit mode") - bone = rig.data.bones[bone_name] + bone = rig.pose.bones[bone_name] + scale = bone.custom_shape_scale - mat = rig.matrix_world @ bone.matrix_local + if bone.use_custom_shape_bone_size: + scale *= bone.length + + if bone.custom_shape_transform: + bone = bone.custom_shape_transform + + mat = rig.matrix_world @ bone.bone.matrix_local obj.location = mat.to_translation() @@ -47,7 +54,7 @@ def obj_to_bone(obj, rig, bone_name): scl = mat.to_scale() scl_avg = (scl[0] + scl[1] + scl[2]) / 3 - obj.scale = (bone.length * scl_avg), (bone.length * scl_avg), (bone.length * scl_avg) + obj.scale = (scale * scl_avg), (scale * scl_avg), (scale * scl_avg) def create_widget(rig, bone_name, bone_transform_name=None): @@ -133,28 +140,28 @@ def write_widget(obj): script += " if obj != None:\n" # Vertices - if len(obj.data.vertices) > 0: - script += " verts = [" - for v in obj.data.vertices: - script += "(" + str(v.co[0]) + "*size, " + str(v.co[1]) + "*size, " + str(v.co[2]) + "*size), " - script += "]\n" + script += " verts = [" + for v in obj.data.vertices: + script += "(" + str(v.co[0]) + "*size, " + str(v.co[1]) + "*size, " + str(v.co[2]) + "*size)," + script += "\n " + script += "]\n" # Edges - if len(obj.data.edges) > 0: - script += " edges = [" - for e in obj.data.edges: - script += "(" + str(e.vertices[0]) + ", " + str(e.vertices[1]) + "), " - script += "]\n" + script += " edges = [" + for i, e in enumerate(obj.data.edges): + script += "(" + str(e.vertices[0]) + ", " + str(e.vertices[1]) + ")," + script += "\n " if i % 10 == 9 else " " + script += "]\n" # Faces - if len(obj.data.polygons) > 0: - script += " faces = [" - for f in obj.data.polygons: - script += "(" - for v in f.vertices: - script += str(v) + ", " - script += "), " - script += "]\n" + script += " faces = [" + for i, f in enumerate(obj.data.polygons): + script += "(" + for v in f.vertices: + script += str(v) + ", " + script += ")," + script += "\n " if i % 10 == 9 else " " + script += "]\n" # Build mesh script += "\n mesh = obj.data\n" |