meshlabxml/transform.py
def deform2curve(script, curve=mp_func.torus_knot('t'), step=0.001):
    """ Deform a mesh along a parametric curve function

    Provide a parametric curve function with z as the parameter. This will
    deform the xy cross section of the mesh along the curve as z increases.

    Source: http://blackpawn.com/texts/pqtorus/

    Methodology:
    T  = P' - P
    N1 = P' + P
    B  = T x N1
    N  = B x T

    newPoint = point.x*N + point.y*B

    """
    curve_step = []
    for idx, val in enumerate(curve):
        curve[idx] = val.replace('t', 'z')
        curve_step.append(val.replace('t', 'z+{}'.format(step)))

    tangent = mp_func.v_subtract(curve_step, curve)
    normal1 = mp_func.v_add(curve_step, curve)
    bee = mp_func.v_cross(tangent, normal1)
    normal = mp_func.v_cross(bee, tangent)
    bee = mp_func.v_normalize(bee)
    normal = mp_func.v_normalize(normal)

    new_point = mp_func.v_add(mp_func.v_multiply('x', normal), mp_func.v_multiply('y', bee))
    function = mp_func.v_add(curve, new_point)

    vert_function(script, x_func=function[0], y_func=function[1], z_func=function[2])
    return function
def deform2curve(script, curve=mp_func.torus_knot('t'), step=0.001):
    """ Deform a mesh along a parametric curve function

    Provide a parametric curve function with z as the parameter. This will
    deform the xy cross section of the mesh along the curve as z increases.

    Source: http://blackpawn.com/texts/pqtorus/

    Methodology:
    T  = P' - P
    N1 = P' + P
    B  = T x N1
    N  = B x T

    newPoint = point.x*N + point.y*B

    """
    curve_step = []
    for idx, val in enumerate(curve):
        curve[idx] = val.replace('t', 'z')
        curve_step.append(val.replace('t', 'z+{}'.format(step)))

    tangent = mp_func.v_subtract(curve_step, curve)
    normal1 = mp_func.v_add(curve_step, curve)
    bee = mp_func.v_cross(tangent, normal1)
    normal = mp_func.v_cross(bee, tangent)
    bee = mp_func.v_normalize(bee)
    normal = mp_func.v_normalize(normal)

    new_point = mp_func.v_add(mp_func.v_multiply('x', normal), mp_func.v_multiply('y', bee))
    function = mp_func.v_add(curve, new_point)

    vert_function(script, x_func=function[0], y_func=function[1], z_func=function[2])
    return function
Deform a mesh along a parametric curve function

    Provide a parametric curve function with z as the parameter. This will
    deform the xy cross section of the mesh along the curve as z increases.

    Source: http://blackpawn.com/texts/pqtorus/

    Methodology:
    T  = P' - P
    N1 = P' + P
    B  = T x N1
    N  = B x T

    newPoint = point.x*N + point.y*B