diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-09-14 09:15:14 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-09-14 09:30:00 +0300 |
commit | 9b693a6be0aa2b0b4825d30ac5034655dce9c0dd (patch) | |
tree | 2875d325828db8e5f447419dcacfdeab1951af63 /rigify/utils | |
parent | 3423174b37a0784dc12035ff3f2fb536835099e1 (diff) |
Rigify: update super_chain from the latest 2.79 version by MAD.
Differential Revision: https://developer.blender.org/D4624
Diffstat (limited to 'rigify/utils')
-rw-r--r-- | rigify/utils/widgets.py | 31 | ||||
-rw-r--r-- | rigify/utils/widgets_basic.py | 12 |
2 files changed, 38 insertions, 5 deletions
diff --git a/rigify/utils/widgets.py b/rigify/utils/widgets.py index fad1065a..6d83264a 100644 --- a/rigify/utils/widgets.py +++ b/rigify/utils/widgets.py @@ -21,6 +21,8 @@ import bpy import math +from mathutils import Matrix + from .errors import MetarigError from .collections import ensure_widget_collection @@ -132,13 +134,39 @@ def create_circle_polygon(number_verts, axis, radius=1.0, head_tail=0.0): return verts, edges +def adjust_widget_axis(obj, axis='y', offset=0.0): + mesh = obj.data + + if axis[0] == '-': + s = -1.0 + axis = axis[1] + else: + s = 1.0 + + trans_matrix = Matrix.Translation((0.0, offset, 0.0)) + rot_matrix = Matrix.Diagonal((1.0, s, 1.0, 1.0)) + + if axis == "x": + rot_matrix = Matrix.Rotation(-s*math.pi/2, 4, 'Z') + trans_matrix = Matrix.Translation((offset, 0.0, 0.0)) + + elif axis == "z": + rot_matrix = Matrix.Rotation(s*math.pi/2, 4, 'X') + trans_matrix = Matrix.Translation((0.0, 0.0, offset)) + + matrix = trans_matrix @ rot_matrix + + for vert in mesh.vertices: + vert.co = matrix @ vert.co + + def write_widget(obj): """ Write a mesh object as a python script for widget use. """ script = "" script += "def create_thing_widget(rig, bone_name, size=1.0, bone_transform_name=None):\n" script += " obj = create_widget(rig, bone_name, bone_transform_name)\n" - script += " if obj != None:\n" + script += " if obj is not None:\n" # Vertices script += " verts = [" @@ -168,7 +196,6 @@ def write_widget(obj): script += "\n mesh = obj.data\n" script += " mesh.from_pydata(verts, edges, faces)\n" script += " mesh.update()\n" - script += " mesh.update()\n" script += " return obj\n" script += " else:\n" script += " return None\n" diff --git a/rigify/utils/widgets_basic.py b/rigify/utils/widgets_basic.py index de04aecc..bb60237c 100644 --- a/rigify/utils/widgets_basic.py +++ b/rigify/utils/widgets_basic.py @@ -67,13 +67,16 @@ def create_cube_widget(rig, bone_name, radius=0.5, bone_transform_name=None): mesh.update() -def create_chain_widget(rig, bone_name, radius=0.5, invert=False, bone_transform_name=None): +def create_chain_widget(rig, bone_name, cube=False, radius=0.5, invert=False, bone_transform_name=None, axis="y", offset=0.0): """Creates a basic chain widget """ obj = create_widget(rig, bone_name, bone_transform_name) - if obj != None: + if obj is not None: r = radius - rh = radius/2 + if cube: + rh = r + else: + rh = radius/2 if invert: verts = [(rh, rh, rh), (r, -r, r), (-r, -r, r), (-rh, rh, rh), (rh, rh, -rh), (r, -r, -r), (-r, -r, -r), (-rh, rh, -rh)] else: @@ -82,6 +85,9 @@ def create_chain_widget(rig, bone_name, radius=0.5, invert=False, bone_transform mesh = obj.data mesh.from_pydata(verts, edges, []) mesh.update() + from .widgets import adjust_widget_axis + adjust_widget_axis(obj, axis=axis, offset=offset) + return obj def create_sphere_widget(rig, bone_name, bone_transform_name=None): |