Ejemplo n.º 1
0
def validateJointType(link, adjust=False):
    """Validate the joint type of the specified link.
    
    If adjust is `True`, the validation errors are fixed on the fly.

    Args:
      link(bpy.types.Object): link representing the joint to validate
      adjust(bool, optional): if True, the validation errors are fixed on the fly. (Default value = False)

    Returns:
      : list(ValidateMessage) -- validation errors

    """
    import phobos.model.joints as jointmodel
    import phobos.utils.io as ioUtils

    errors = []
    if 'joint/type' not in link:
        errors.append(
            ValidateMessage("No joint type specified!", 'WARNING', link,
                            "phobos.define_joint_constraints", {}))
        # make sure we get no KeyErrors from this
        if adjust:
            link['joint/type'] = 'undefined'

    joint_type, crot = jointmodel.getJointType(link)

    # warn user if the constraints do not match the specified joint type
    if 'joint/type' in link and joint_type != link['joint/type']:
        if not adjust:
            errors.append(
                ValidateMessage(
                    "The specified joint type does not match the constraints:",
                    'WARNING',
                    link,
                    None,
                    {
                        'log_info':
                        str("'" + link['joint/type'] + "' should be set to '" +
                            joint_type + "' instead.")
                    },
                ))
        else:
            # fix joint type and assign new resource object
            link['joint/type'] = joint_type
            resource_obj = ioUtils.getResource(('joint', joint_type))
            if resource_obj:
                log("Assigned resource to {}.".format(link.name), 'DEBUG')
                link.pose.bones[0].custom_shape = resource_obj

            errors.append(
                ValidateMessage("Adjusted joint type to '" + joint_type + "'.",
                                'INFO', link, None, {}))

    return errors
Ejemplo n.º 2
0
def validateJointType(link, adjust=False):
    """Validate the joint type of the specified link.
    
    If adjust is `True`, the validation errors are fixed on the fly.

    Args:
      link(bpy.types.Object): link representing the joint to validate
      adjust(bool, optional): if True, the validation errors are fixed on the fly. (Default value = False)

    Returns:
      : list(ValidateMessage) -- validation errors

    """
    import phobos.model.joints as jointmodel
    import phobos.utils.io as ioUtils

    errors = []
    if 'joint/type' not in link:
        errors.append(
            ValidateMessage(
                "No joint type specified!", 'WARNING', link, "phobos.define_joint_constraints", {}
            )
        )
        # make sure we get no KeyErrors from this
        if adjust:
            link['joint/type'] = 'undefined'

    joint_type, crot = jointmodel.getJointType(link)

    # warn user if the constraints do not match the specified joint type
    if 'joint/type' in link and joint_type != link['joint/type']:
        if not adjust:
            errors.append(
                ValidateMessage(
                    "The specified joint type does not match the constraints:",
                    'WARNING',
                    link,
                    None,
                    {
                        'log_info': str(
                            "'"
                            + link['joint/type']
                            + "' should be set to '"
                            + joint_type
                            + "' instead."
                        )
                    },
                )
            )
        else:
            # fix joint type and assign new resource object
            link['joint/type'] = joint_type
            resource_obj = ioUtils.getResource(('joint', joint_type))
            if resource_obj:
                log("Assigned resource to {}.".format(link.name), 'DEBUG')
                link.pose.bones[0].custom_shape = resource_obj

            errors.append(
                ValidateMessage(
                    "Adjusted joint type to '" + joint_type + "'.", 'INFO', link, None, {}
                )
            )

    return errors