diff options
Diffstat (limited to 'rigify/utils.py')
-rw-r--r-- | rigify/utils.py | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/rigify/utils.py b/rigify/utils.py index 32f845b8..ee5856c7 100644 --- a/rigify/utils.py +++ b/rigify/utils.py @@ -26,7 +26,7 @@ import random import time import re import os -from mathutils import Vector, Matrix +from mathutils import Vector, Matrix, Color from rna_prop_ui import rna_idprop_ui_prop_get RIG_DIR = "rigs" # Name of the directory where rig types are kept @@ -51,6 +51,7 @@ outdated_types = {"pitchipoy.limbs.super_limb": "limbs.super_limb", "pitchipoy.simple_tentacle": "limbs.simple_tentacle", "pitchipoy.super_face": "faces.super_face", "pitchipoy.super_palm": "limbs.super_palm", + "pitchipoy.super_copy": "basic.super_copy", "palm": "limbs.super_palm", "basic.copy": "basic.super_copy"} @@ -954,7 +955,7 @@ def get_layers(layers): return [x in layers for x in range(0, 32)] -def write_metarig(obj, layers=False, func_name="create"): +def write_metarig(obj, layers=False, func_name="create", groups=False): """ Write a metarig as a python script, this rig is to have all info needed for generating the real rig with rigify. @@ -962,6 +963,7 @@ def write_metarig(obj, layers=False, func_name="create"): code = [] code.append("import bpy\n\n") + code.append("from mathutils import Color\n\n") code.append("def %s(obj):" % func_name) code.append(" # generated by rigify.utils.write_metarig") @@ -971,6 +973,23 @@ def write_metarig(obj, layers=False, func_name="create"): arm = obj.data + # Rigify bone group colors info + if groups and len(arm.rigify_colors) > 0: + code.append("\n for i in range(" + str(len(arm.rigify_colors)) + "):") + code.append(" arm.rigify_colors.add()\n") + + for i in range(len(arm.rigify_colors)): + name = arm.rigify_colors[i].name + active = arm.rigify_colors[i].active + normal = arm.rigify_colors[i].normal + select = arm.rigify_colors[i].select + standard_colors_lock = arm.rigify_colors[i].standard_colors_lock + code.append(' arm.rigify_colors[' + str(i) + '].name = "' + name + '"') + code.append(' arm.rigify_colors[' + str(i) + '].active = Color(' + str(active[:]) + ')') + code.append(' arm.rigify_colors[' + str(i) + '].normal = Color(' + str(normal[:]) + ')') + code.append(' arm.rigify_colors[' + str(i) + '].select = Color(' + str(select[:]) + ')') + code.append(' arm.rigify_colors[' + str(i) + '].standard_colors_lock = ' + str(standard_colors_lock)) + # Rigify layer layout info if layers and len(arm.rigify_layers) > 0: code.append("\n for i in range(" + str(len(arm.rigify_layers)) + "):") @@ -979,8 +998,12 @@ def write_metarig(obj, layers=False, func_name="create"): for i in range(len(arm.rigify_layers)): name = arm.rigify_layers[i].name row = arm.rigify_layers[i].row + set = arm.rigify_layers[i].set + group = arm.rigify_layers[i].group code.append(' arm.rigify_layers[' + str(i) + '].name = "' + name + '"') code.append(' arm.rigify_layers[' + str(i) + '].row = ' + str(row)) + code.append(' arm.rigify_layers[' + str(i) + '].set = ' + str(set)) + code.append(' arm.rigify_layers[' + str(i) + '].group = ' + str(group)) # write parents first bones = [(len(bone.parent_recursive), bone.name) for bone in arm.edit_bones] @@ -1118,3 +1141,31 @@ def random_id(length=8): text += random.choice(chars) text += str(hex(int(time.time())))[2:][-tlength:].rjust(tlength, '0')[::-1] return text + + +#============================================= +# Color correction functions +#============================================= + +def linsrgb_to_srgb (linsrgb): + """Convert physically linear RGB values into sRGB ones. The transform is + uniform in the components, so *linsrgb* can be of any shape. + + *linsrgb* values should range between 0 and 1, inclusively. + + """ + # From Wikipedia, but easy analogue to the above. + gamma = 1.055 * linsrgb**(1./2.4) - 0.055 + scale = linsrgb * 12.92 + # return np.where (linsrgb > 0.0031308, gamma, scale) + if linsrgb > 0.0031308: + return gamma + return scale + + +def gamma_correct(color): + + corrected_color = Color() + for i, component in enumerate(color): + corrected_color[i] = linsrgb_to_srgb(color[i]) + return corrected_color |