Example #1
0
File: utils.py Project: Irmitya/zpy
 def blend(current, target):
     if (Is.digit(current) and Is.digit(target)) and not \
             (Is.string(current) or Is.string(target)):
         return (current * (1.0 - factor) + target * factor)
     elif (factor):
         return target
     else:
         return current
Example #2
0
File: New.py Project: Irmitya/zpy
def bone_group(rig, name='Group', color=None):
    ""

    if Is.posebone(rig):
        rig = rig.id_data
    group = rig.pose.bone_groups.new(name=name)

    if Is.string(color):
        group.color_set = color
        # DEFAULT = regular bone color (not unique)
        # THEME01 - THEME15 = Builtin color palettes
        # THEME16 - THEME20 = Black for user assigned templates
        # CUSTOM = manually set
    elif color is False:
        group.color_set = 'DEFAULT'
    elif color is True:
        from random import randrange as random
        rand = f"{random(1, 15):02}"
        group.color_set = f'THEME{rand}'
    elif color:
        group.color_set = 'CUSTOM'
        gc = group.colors
        if not Is.iterable(color):
            if Is.digit(color):
                color = [[color] * 3] * 3
            else:
                color = [color] * 3
        (gc.normal, gc.select, gc.active) = color

    return group
Example #3
0
File: utils.py Project: Irmitya/zpy
def name_split_hash(name):
    """Get the original name without the added hash"""

    split = name.rsplit('-')
    if Is.digit(split[-1]):
        name = split[0]

    return name
Example #4
0
File: utils.py Project: Irmitya/zpy
def multiply_matrix(*matrices):
    from mathutils import Matrix, Vector

    merge = Matrix()
    for mat in matrices:
        sym = '*' if Is.digit(mat) else '@'
        merge = eval(f'{merge!r} {sym} {mat!r}')

    return merge
Example #5
0
    def execute(self, context):
        for img in bpy.data.images:
            end = img.name[-4:]
            if end.startswith('.') and Is.digit(end[1:]) and len(end) == 4:
                ipre = bpy.data.images.get(img.name[:-4])
                if ipre:
                    img.user_remap(ipre)

        return {'FINISHED'}
Example #6
0
File: Set.py Project: Irmitya/zpy
def bone_group(bone, group, color=None):
    """
    Assign bone to group\\
    if group is text, find the group or create it first
    """

    if Is.string(group):
        bgs = bone.id_data.pose.bone_groups
        if group in bgs:
            group = bgs[group]
        else:
            from zpy import New
            group = New.bone_group(bone, name=group)

    if Is.string(color):
        group.color_set = color
        # DEFAULT = regular bone color (not unique)
        # THEME01 - THEME15 = Builtin color palettes
        # THEME16 - THEME20 = Black for user assigned templates
        # CUSTOM = manually set
    elif color is False:
        group.color_set = 'DEFAULT'
    elif color is True:
        from random import randrange as random
        rand = f"{random(1, 15):02}"
        group.color_set = f'THEME{rand}'
    elif color:
        group.color_set = 'CUSTOM'
        gc = group.colors
        if not Is.iterable(color):
            if Is.digit(color):
                color = [[color] * 3] * 3
            else:
                color = [color] * 3
        (gc.normal, gc.select, gc.active) = color

    bone.bone_group = group

    return group
Example #7
0
File: utils.py Project: Irmitya/zpy
def flip_name(name, split=False, only_split=False):
    if len(name) < 3:
        if split:
            return (name, "", "", "")
        else:
            return name

    is_set = False
    prefix = replace = previous = suffix = number = str()

    # /* We first check the case with a .### extension, let's find the last period */
    if (Is.digit(name[-1]) and ("." in name)):
        index = name.rsplit(".", 1)
        if Is.digit(index[1]):
            name = index[0]
            number = '.' + index[1]
        del index

    # /* first case; separator . - _ with extensions r R l L  */
    if ((len(name) > 1) and (name[-2] in (' .-_'))):
        is_set = True
        previous = name[-2:]
        sep = name[-2]
        if name[-1] == 'l':
            prefix = name[:-2]
            replace = sep + 'r'
        elif name[-1] == 'r':
            prefix = name[:-2]
            replace = sep + 'l'
        elif name[-1] == 'L':
            prefix = name[:-2]
            replace = sep + 'R'
        elif name[-1] == 'R':
            prefix = name[:-2]
            replace = sep + 'L'
        else:
            is_set = False
            previous = ""

    # /* case; beginning with r R l L, with separator after it */
    if ((not is_set) and (len(name) > 1) and (name[1] in (' .-_'))):
        is_set = True
        previous = name[:2]
        sep = name[1]
        if name[0] == 'l':
            replace = 'r' + sep
            suffix = name[2:]
        elif name[0] == 'r':
            replace = 'l' + sep
            suffix = name[2:]
        elif name[0] == 'L':
            replace = 'R' + sep
            suffix = name[2:]
        elif name[0] == 'R':
            replace = 'L' + sep
            suffix = name[2:]
        else:
            is_set = False
            previous = ""

    if (not is_set):
        prefix = name

        # /* hrms, why test for a separator? lets do the rule 'ultimate left or right' */
        if name.lower().startswith("right") or name.lower().endswith("right"):
            index = name.lower().index("right")
            replace = name[index:index + 5]
            previous = replace
            (prefix, suffix) = name.split(replace, 1)
            if replace[0] == "r":
                replace = "left"
            elif replace[1] == "I":
                replace = "LEFT"
            else:
                replace = "Left"
        elif name.lower().startswith("left") or name.lower().endswith("left"):
            index = name.lower().index("left")
            replace = name[index:index + 4]
            previous = replace
            (prefix, suffix) = name.split(replace, 1)
            if replace[0] == "l":
                replace = "right"
            elif replace[1] == "E":
                replace = "RIGHT"
            else:
                replace = "Right"

    if only_split:
        return (prefix, previous, suffix, number)
    elif split:
        return (prefix, replace, suffix, number)
    else:
        return prefix + replace + suffix + number