meshlabxml/create.py
def cylinder(script, up='z', height=1.0, radius=None, radius1=None,
             radius2=None, diameter=None, diameter1=None, diameter2=None,
             center=False, cir_segments=32, color=None):
    """Create a cylinder or cone primitive. Usage is based on OpenSCAD.
    # height = height of the cylinder
    # radius1 = radius of the cone on bottom end
    # radius2 = radius of the cone on top end
    # center = If true will center the height of the cone/cylinder around
    # the origin. Default is false, placing the base of the cylinder or radius1
    # radius of cone at the origin.
    #
    cir_segments Number of sides of the polygonal approximation of the cone

    color = specify a color name to apply vertex colors to the newly
    # created mesh
    """
    if radius is not None and diameter is None:
        if radius1 is None and diameter1 is None:
            radius1 = radius
        if radius2 is None and diameter2 is None:
            radius2 = radius
    if diameter is not None:
        if radius1 is None and diameter1 is None:
            radius1 = diameter / 2
        if radius2 is None and diameter2 is None:
            radius2 = diameter / 2
    if diameter1 is not None:
        radius1 = diameter1 / 2
    if diameter2 is not None:
        radius2 = diameter2 / 2
    if radius1 is None:
        radius1 = 1.0
    if radius2 is None:
        radius2 = radius1

    # Cylinder is created centered with Y up
    filter_xml = ''.join([
        '  <filter name="Cone">\n',
        '    <Param name="h" ',
        'value="%s" ' % height,
        'description="Height" ',
        'type="RichFloat" ',
        '/>\n',
        '    <Param name="r0" ',
        'value="%s" ' % radius1,
        'description="Radius 1" ',
        'type="RichFloat" ',
        '/>\n',
        '    <Param name="r1" ',
        'value="%s" ' % radius2,
        'description="Radius 2" ',
        'type="RichFloat" ',
        '/>\n',
        '    <Param name="subdiv" ',
        'value="%d" ' % cir_segments,
        'description="Side" ',
        'type="RichInt" ',
        '/>\n',
        '  </filter>\n'])
    util.write_filter(script, filter_xml)
    if isinstance(script, FilterScript):
        script.add_layer('Cone', change_layer=True)
    if not center:
        transform.translate(script, [0, height / 2, 0])
    if up.lower() == 'z':
        transform.rotate(script, axis='x', angle=90)  # rotate to Z up
    if color is not None:
        vert_color.function(script, color=color)
    return None
def cylinder(script, up='z', height=1.0, radius=None, radius1=None,
             radius2=None, diameter=None, diameter1=None, diameter2=None,
             center=False, cir_segments=32, color=None):
    """Create a cylinder or cone primitive. Usage is based on OpenSCAD.
    # height = height of the cylinder
    # radius1 = radius of the cone on bottom end
    # radius2 = radius of the cone on top end
    # center = If true will center the height of the cone/cylinder around
    # the origin. Default is false, placing the base of the cylinder or radius1
    # radius of cone at the origin.
    #
    cir_segments Number of sides of the polygonal approximation of the cone

    color = specify a color name to apply vertex colors to the newly
    # created mesh
    """
    if radius is not None and diameter is None:
        if radius1 is None and diameter1 is None:
            radius1 = radius
        if radius2 is None and diameter2 is None:
            radius2 = radius
    if diameter is not None:
        if radius1 is None and diameter1 is None:
            radius1 = diameter / 2
        if radius2 is None and diameter2 is None:
            radius2 = diameter / 2
    if diameter1 is not None:
        radius1 = diameter1 / 2
    if diameter2 is not None:
        radius2 = diameter2 / 2
    if radius1 is None:
        radius1 = 1.0
    if radius2 is None:
        radius2 = radius1

    # Cylinder is created centered with Y up
    filter_xml = ''.join([
        '  <filter name="Cone">\n',
        '    <Param name="h" ',
        'value="%s" ' % height,
        'description="Height" ',
        'type="RichFloat" ',
        '/>\n',
        '    <Param name="r0" ',
        'value="%s" ' % radius1,
        'description="Radius 1" ',
        'type="RichFloat" ',
        '/>\n',
        '    <Param name="r1" ',
        'value="%s" ' % radius2,
        'description="Radius 2" ',
        'type="RichFloat" ',
        '/>\n',
        '    <Param name="subdiv" ',
        'value="%d" ' % cir_segments,
        'description="Side" ',
        'type="RichInt" ',
        '/>\n',
        '  </filter>\n'])
    util.write_filter(script, filter_xml)
    if isinstance(script, FilterScript):
        script.add_layer('Cone', change_layer=True)
    if not center:
        transform.translate(script, [0, height / 2, 0])
    if up.lower() == 'z':
        transform.rotate(script, axis='x', angle=90)  # rotate to Z up
    if color is not None:
        vert_color.function(script, color=color)
    return None
def cylinder ( script , up = 'z' , height = 1.0 , radius = None , radius1 = None , radius2 = None , diameter = None , diameter1 = None , diameter2 = None , center = False , cir_segments = 32 , color = None ) : if radius is not None and diameter is None : if radius1 is None and diameter1 is None : radius1 = radius if radius2 is None and diameter2 is None : radius2 = radius if diameter is not None : if radius1 is None and diameter1 is None : radius1 = diameter / 2 if radius2 is None and diameter2 is None : radius2 = diameter / 2 if diameter1 is not None : radius1 = diameter1 / 2 if diameter2 is not None : radius2 = diameter2 / 2 if radius1 is None : radius1 = 1.0 if radius2 is None : radius2 = radius1 # Cylinder is created centered with Y up filter_xml = '' . join ( [ '  <filter name="Cone">\n' , '    <Param name="h" ' , 'value="%s" ' % height , 'description="Height" ' , 'type="RichFloat" ' , '/>\n' , '    <Param name="r0" ' , 'value="%s" ' % radius1 , 'description="Radius 1" ' , 'type="RichFloat" ' , '/>\n' , '    <Param name="r1" ' , 'value="%s" ' % radius2 , 'description="Radius 2" ' , 'type="RichFloat" ' , '/>\n' , '    <Param name="subdiv" ' , 'value="%d" ' % cir_segments , 'description="Side" ' , 'type="RichInt" ' , '/>\n' , '  </filter>\n' ] ) util . write_filter ( script , filter_xml ) if isinstance ( script , FilterScript ) : script . add_layer ( 'Cone' , change_layer = True ) if not center : transform . translate ( script , [ 0 , height / 2 , 0 ] ) if up . lower ( ) == 'z' : transform . rotate ( script , axis = 'x' , angle = 90 ) # rotate to Z up if color is not None : vert_color . function ( script , color = color ) return None
Create a cylinder or cone primitive. Usage is based on OpenSCAD.
    # height = height of the cylinder
    # radius1 = radius of the cone on bottom end
    # radius2 = radius of the cone on top end
    # center = If true will center the height of the cone/cylinder around
    # the origin. Default is false, placing the base of the cylinder or radius1
    # radius of cone at the origin.
    #
    cir_segments Number of sides of the polygonal approximation of the cone

    color = specify a color name to apply vertex colors to the newly
    # created mesh
Create a cylinder or cone primitive . Usage is based on OpenSCAD . # height = height of the cylinder # radius1 = radius of the cone on bottom end # radius2 = radius of the cone on top end # center = If true will center the height of the cone / cylinder around # the origin . Default is false placing the base of the cylinder or radius1 # radius of cone at the origin . # cir_segments Number of sides of the polygonal approximation of the cone