meshlabxml/create.py
def grid(script, size=1.0, x_segments=1, y_segments=1, center=False,
         color=None):
    """2D square/plane/grid created on XY plane

    x_segments # Number of segments in the X direction.
    y_segments # Number of segments in the Y direction.
    center="false" # If true square will be centered on origin;
    otherwise it is place in the positive XY quadrant.


    """
    size = util.make_list(size, 2)
    filter_xml = ''.join([
        '  <filter name="Grid Generator">\n',
        '    <Param name="absScaleX" ',
        'value="{}" '.format(size[0]),
        'description="x scale" ',
        'type="RichFloat" ',
        '/>\n',
        '    <Param name="absScaleY" ',
        'value="{}" '.format(size[1]),
        'description="y scale" ',
        'type="RichFloat" ',
        '/>\n',
        '    <Param name="numVertX" ',
        'value="{:d}" '.format(x_segments + 1),
        'description="num vertices on x" ',
        'type="RichInt" ',
        '/>\n',
        '    <Param name="numVertY" ',
        'value="{:d}" '.format(y_segments + 1),
        'description="num vertices on y" ',
        'type="RichInt" ',
        '/>\n',
        '    <Param name="center" ',
        'value="false" ',
        'description="centered on origin" ',
        'type="RichBool" ',
        '/>\n',
        '  </filter>\n'])
    util.write_filter(script, filter_xml)
    if isinstance(script, FilterScript):
        script.add_layer('Grid Generator', change_layer=True)

    """This is to work around a bug in MeshLab whereby the Grid Generator does not
    create zero values for z. Ref bug #458: https://sourceforge.net/p/meshlab/bugs/458/"""
    transform.vert_function(script, z_func='rint(z)')

    """Note that the "center" parameter in the mlx script does not actually
    center the square, not sure what it is doing. Instead this is set to false,
    which places the plane in the -X,+Y quadrant, and it is translated to the
    appropriate position after creation.
    """
    if center:
        transform.translate(script, value=[size[0]/2, -size[1]/2, 0])
    else:
        transform.translate(script, value=[size[0], 0, 0])
    if color is not None:
        vert_color.function(script, color=color)
    return None
def grid(script, size=1.0, x_segments=1, y_segments=1, center=False,
         color=None):
    """2D square/plane/grid created on XY plane

    x_segments # Number of segments in the X direction.
    y_segments # Number of segments in the Y direction.
    center="false" # If true square will be centered on origin;
    otherwise it is place in the positive XY quadrant.


    """
    size = util.make_list(size, 2)
    filter_xml = ''.join([
        '  <filter name="Grid Generator">\n',
        '    <Param name="absScaleX" ',
        'value="{}" '.format(size[0]),
        'description="x scale" ',
        'type="RichFloat" ',
        '/>\n',
        '    <Param name="absScaleY" ',
        'value="{}" '.format(size[1]),
        'description="y scale" ',
        'type="RichFloat" ',
        '/>\n',
        '    <Param name="numVertX" ',
        'value="{:d}" '.format(x_segments + 1),
        'description="num vertices on x" ',
        'type="RichInt" ',
        '/>\n',
        '    <Param name="numVertY" ',
        'value="{:d}" '.format(y_segments + 1),
        'description="num vertices on y" ',
        'type="RichInt" ',
        '/>\n',
        '    <Param name="center" ',
        'value="false" ',
        'description="centered on origin" ',
        'type="RichBool" ',
        '/>\n',
        '  </filter>\n'])
    util.write_filter(script, filter_xml)
    if isinstance(script, FilterScript):
        script.add_layer('Grid Generator', change_layer=True)

    """This is to work around a bug in MeshLab whereby the Grid Generator does not
    create zero values for z. Ref bug #458: https://sourceforge.net/p/meshlab/bugs/458/"""
    transform.vert_function(script, z_func='rint(z)')

    """Note that the "center" parameter in the mlx script does not actually
    center the square, not sure what it is doing. Instead this is set to false,
    which places the plane in the -X,+Y quadrant, and it is translated to the
    appropriate position after creation.
    """
    if center:
        transform.translate(script, value=[size[0]/2, -size[1]/2, 0])
    else:
        transform.translate(script, value=[size[0], 0, 0])
    if color is not None:
        vert_color.function(script, color=color)
    return None
2D square/plane/grid created on XY plane

    x_segments # Number of segments in the X direction.
    y_segments # Number of segments in the Y direction.
    center="false" # If true square will be centered on origin;
    otherwise it is place in the positive XY quadrant.