Beispiel #1
0
def remove_con(con_node):
    """
    Delete constraint node from the scene.

    :param con_node: Constraint PyNode.
    """
    log.debug("Deleting constraint node...")
    with UndoChunk():
        pmc.delete(con_node)
Beispiel #2
0
def create_con(conType, Offset, mOffset, weight, skipT, skipR, skipS):
    """
    Pass options from UI to constraint creator and data storage.

    :param conType: Type of constraint.
    :param Offset: Explicit X, Y, Z values to set offset to.
    :param mOffset: Maintain offset.
    :param weight: Explicit weight value to give to each target.
    :param skipT: List of channels to skip.
    :param skipR: List of channels to skip.
    :param skipS: List of channels to skip.
    """
    selection = pmc.ls(sl=True, type="transform")

    if len(selection) > 1:
        # Get selected objects
        obj = selection[-1]
        sel_objs = selection[:-1]

        log.debug("Selection: {}".format(selection))
        log.debug("Active object: {}".format(obj))
        log.debug("Target objects: {}".format(sel_objs))

        with UndoChunk():
            # Create constraint
            conObj = create_constraint(
                conType, obj, sel_objs,
                Offset, mOffset, weight,
                skipT, skipR, skipS
            )
            log.debug("Constraint object: {}".format(conObj))

            # Save data
            con_data = {
                "type": conType,
                "object": obj,
                "target": sel_objs,
                "con_node": conObj
            }
            _CMan.populate_list(con_data)

    else:
        log.error("Select two or more objects to create a constraint")
Beispiel #3
0
def _do_switch_on_off(con_tup, val):
    """
    Switch weight fully on or off.

    :param con_tup: Tuple of UI options and constraint node, targets and object.
    :param val: Value to set weights to. Should be 0 or 1.
    """
    MVis, Key, con_node, obj, targets = con_tup

    log.debug(con_tup)

    attr_list = get_connected_attr(con_node, obj)
    weight_list = get_weight_attr(con_node)
    offset_list = get_offset_attr(con_node)
    obj_mat = obj.getMatrix(worldSpace=True)

    log.debug("Attr list: {}".format(attr_list))
    log.debug("Weight list: {}".format(weight_list))
    log.debug("Offset list: {}".format(offset_list))

    with UndoChunk():
        if not MVis and not Key:
            try:
                # Blend attr
                get_blend_attr(con_node).set(val)
            except:
                pass

            # Weight attr
            for tgt in con_node.getTargetList():
                con_node.setWeight(val, tgt)

        elif MVis and not Key:
            try:
                # Blend attr
                get_blend_attr(con_node).set(val)
            except:
                pass

            # Weight attr
            for tgt in con_node.getTargetList():
                con_node.setWeight(val, tgt)

            # Update offset
            obj.setMatrix(obj_mat, worldSpace=True)
            update_offset(con_node, targets)

        elif MVis and Key:
            # Weight attr
            for attr, pynode in izip(weight_list, con_node.getTargetList()):
                con_node.setWeight(val, pynode)
                key_attr(attr, new_value=val, copy_previous=True)

            obj.setMatrix(obj_mat, worldSpace=True)
            # Key constrained attributes
            for attr in attr_list:
                key_attr(attr)
            # Update offset
            update_offset(con_node, targets)

            # Key offsets
            for attr in offset_list:
                key_attr(attr)

            try:
                # Blend attr
                blend_attr = get_blend_attr(con_node)
                blend_attr.set(val)
                key_attr(blend_attr, new_value=val, copy_previous=True)
            except:
                pass

        elif not MVis and Key:
            # Weight attr
            for attr, pynode in izip(weight_list, con_node.getTargetList()):
                con_node.setWeight(val, pynode)
                key_attr(attr, new_value=val, copy_previous=True)

            # Key constrained attributes
            for attr in attr_list:
                key_attr(attr, copy_previous=True)

            try:
                # Blend attr
                blend_attr = get_blend_attr(con_node)
                blend_attr.set(val)
                key_attr(blend_attr, new_value=val, copy_previous=True)
            except:
                pass
Beispiel #4
0
def switch_single(con_tup):
    """
    Switch constraint weight to a single defined target.

    :param con_tup: Tuple of UI options and constraint node, targets and object.
    """
    log.debug("Switching single...")
    MVis, Key, con_node, obj, targets, sel_tgt = con_tup

    log.debug(con_tup)

    attr_list = get_connected_attr(con_node, obj)
    weight_list = get_weight_attr(con_node)
    offset_list = get_offset_attr(con_node)
    obj_mat = obj.getMatrix(worldSpace=True)

    log.debug("Attr list: {}".format(attr_list))
    log.debug("Weight list: {}".format(weight_list))
    log.debug("Offset list: {}".format(offset_list))

    with UndoChunk():
        if not MVis and not Key:
            try:
                # Blend attr
                get_blend_attr(con_node).set(1)
            except:
                pass

            # Weight attr
            for tgt in con_node.getTargetList():
                log.debug("Target: {}".format(tgt))
                con_node.setWeight(1, tgt) if tgt == sel_tgt else con_node.setWeight(0, tgt)

        elif MVis and not Key:
            try:
                # Blend attr
                get_blend_attr(con_node).set(1)
            except:
                pass

            # Weight attr
            for tgt in con_node.getTargetList():
                log.debug("Target: {}".format(tgt))
                con_node.setWeight(1, tgt) if tgt == sel_tgt else con_node.setWeight(0, tgt)

            # Update offset
            obj.setMatrix(obj_mat, worldSpace=True)
            update_offset(con_node, targets)

        elif MVis and Key:
            # Weight attr
            for attr, pynode in izip(weight_list, con_node.getTargetList()):
                if pynode == sel_tgt:
                    con_node.setWeight(1, pynode)
                    key_attr(attr, new_value=1, copy_previous=True)
                else:
                    con_node.setWeight(0, pynode)
                    key_attr(attr, new_value=0, copy_previous=True)

            obj.setMatrix(obj_mat, worldSpace=True)
            # Key constrained attributes
            for attr in attr_list:
                log.debug("Attr: {}".format(attr))
                key_attr(attr)
            # Update offset
            update_offset(con_node, targets)

            # Key offsets
            for attr in offset_list:
                log.debug("Offset: {}".format(attr))
                key_attr(attr, copy_previous=True)

            try:
                # Blend attr
                blend_attr = get_blend_attr(con_node)
                blend_attr.set(1)
                key_attr(blend_attr, new_value=1, copy_previous=True)
            except:
                pass

        elif not MVis and Key:
            # Weight attr
            for attr, pynode in izip(weight_list, con_node.getTargetList()):
                if pynode == sel_tgt:
                    con_node.setWeight(1, pynode)
                    key_attr(attr, new_value=1, copy_previous=True)
                else:
                    con_node.setWeight(0, pynode)
                    key_attr(attr, new_value=0, copy_previous=True)

            # Key constrained attributes
            for attr in attr_list:
                log.debug("Attr: {}".format(attr))
                key_attr(attr)

            try:
                # Blend attr
                blend_attr = get_blend_attr(con_node)
                blend_attr.set(1)
                key_attr(blend_attr, new_value=1, copy_previous=True)
            except:
                pass