Exemple #1
0
def get_curve_length(curve_name):
    """
    for nurbs curves only. get the curve length.
    :return: <float> curve length.
    """
    shape_fn = object_utils.get_shape_fn(curve_name)[0]
    return shape_fn.length()
Exemple #2
0
def get_param_length(curve_name):
    """
    for nurbs curves only. get the parameter length.
    :return: <float> curve length.
    """
    shape_fn = object_utils.get_shape_fn(curve_name)[0]
    return shape_fn.findParamFromLength(shape_fn.length())
Exemple #3
0
def get_closest_point(driver_name, mesh_name, as_point=False, tree_based=False):
    """
    uses the Function set Shape to get the closestPoint positions.
    :param driver_name: <str> the driving object.
    :param mesh_name:  <str> the mesh object.
    :param as_point: <bool> if True, return as a <OpenMaya.MPoint> object. Else return as a tuple(x, y, z).
    :param tree_based: <bool> get the closest point on nurbsSurface using treeBased algorithm.
    :return: <tuple> x, y, z. <OpenMaya.MPoint>.
    """
    shape_fn = object_utils.get_shape_fn(mesh_name)[0]
    # the get_shape_obj function returns a tuple of children items, so we only need one.
    shape_obj = object_utils.convert_list_to_str(object_utils.get_shape_obj(mesh_name))

    mesh_dag = object_utils.get_dag(mesh_name)
    try:
        driver_vector = transform_utils.Transform(driver_name).translate_values(as_m_vector=True, world=True)
    except RuntimeError:
        # object is incompatible with this method
        driver_vector = mesh_utils.get_component_position(driver_name, as_m_vector=True, world_space=True)

    # get the parent inverse matrix
    m_matrix = mesh_dag.inclusiveMatrixInverse()

    if object_utils.is_shape_nurbs_surface(mesh_name):
        m_point = OpenMaya.MPoint(driver_vector)
        if tree_based:
            m_nurb_intersect = OpenMaya.MNurbsIntersector()
            m_nurb_intersect.create(shape_obj, m_matrix)
            point_nurb = OpenMaya.MPointOnNurbs()
            m_nurb_intersect.getClosestPoint(m_point, point_nurb)
            result_point = point_nurb.getPoint()
        else:
            m_point *= m_matrix
            result_point = shape_fn.closestPoint(m_point)
        if as_point:
            return result_point
        return unpack_vector(result_point * mesh_dag.inclusiveMatrix())

    elif object_utils.is_shape_mesh(mesh_name):
        m_point = OpenMaya.MPoint(driver_vector)
        result_m_point = OpenMaya.MPoint()
        shape_fn.getClosestPoint(m_point, result_m_point)
        if as_point:
            return result_m_point
        return unpack_vector(result_m_point)

    elif object_utils.is_shape_nurbs_curve(mesh_name):
        m_point = OpenMaya.MPoint(driver_vector)
        m_point *= m_matrix
        result_point = shape_fn.closestPoint(m_point)
        if as_point:
            return result_point
        return unpack_vector(result_point * mesh_dag.inclusiveMatrix())

    else:
        OpenMaya.MGlobal.displayError("[ClosestPoint] :: Invalid object.")
        return False
Exemple #4
0
def get_closest_curve_distance(driver_name, curve_name):
    """
    for nurbs curves only. get the closest curve distance from the point given.
    :param driver_name: <str> the driving object.
    :param curve_name:  <str> the mesh object.
    :return: <tuple> normal value.
    """
    shape_fn = object_utils.get_shape_fn(curve_name)[0]
    c_point = get_closest_point(driver_name, curve_name, as_point=True)
    distance = shape_fn.distanceToPoint(c_point)
    return distance,
Exemple #5
0
def get_closest_normal(driver_name, mesh_name):
    """
    get the closest normal vector on nurbsSurface.
    :param driver_name: <str> the driving object.
    :param mesh_name:  <str> the mesh object.
    :return: <tuple> U, V,
    """
    shape_fn = object_utils.get_shape_fn(mesh_name)[0]
    if object_utils.is_shape_nurbs_surface(mesh_name):
        u, v = get_closest_uv(driver_name, mesh_name)
        return shape_fn.normal(u, v)
Exemple #6
0
def get_parameter_tangent(driver_name, curve_name):
    """
    for nurbs curves only. get the normal from parameter value.
    :param driver_name: <str> the driving object.
    :param curve_name:  <str> the mesh object.
    :return: <tuple> normal value.
    """
    shape_fn = object_utils.get_shape_fn(curve_name)[0]
    c_param = get_closest_parameter(driver_name, curve_name)
    tangent = object_utils.ScriptUtil(0.0, as_double_ptr=True)
    shape_fn.tangent(c_param, tangent.ptr)
    return tangent.get_double(),
Exemple #7
0
def get_closest_uv(driver_name, mesh_name):
    """
    get the closest point on surface UV values.
    :param driver_name: <str> the driving object.
    :param mesh_name:  <str> the mesh object.
    :return: <tuple> U, V,
    """
    shape_fn = object_utils.get_shape_fn(mesh_name)[0]
    if object_utils.is_shape_nurbs_surface(mesh_name):
        param_u = object_utils.ScriptUtil(0.0, as_double_ptr=True)
        param_v = object_utils.ScriptUtil(0.0, as_double_ptr=True)
        cpos = get_closest_point(driver_name, mesh_name, as_point=True)
        shape_fn.getParamAtPoint(cpos, param_u.ptr, param_v.ptr, OpenMaya.MSpace.kObject)
        return param_u.get_double(), param_v.get_double(),
Exemple #8
0
def get_closest_parameter(driver_name, curve_name, normalize=False):
    """
    for nurbs curves only. get the closest parameter value.
    :param driver_name: <str> the driving object.
    :param curve_name:  <str> the mesh object.
    :param normalize: <bool> if set True, returns a normalized parameter value.
    :return: <tuple> parameter value.
    """
    shape_fn = object_utils.get_shape_fn(curve_name)[0]
    cpoc = get_closest_point(driver_name, curve_name, as_point=True)
    param_u = object_utils.ScriptUtil(0.0, as_double_ptr=True)
    shape_fn.getParamAtPoint(cpoc, param_u.ptr)
    if normalize:
        return param_u.get_double() / get_param_length(curve_name)
    else:
        return param_u.get_double(),