Uranium
Application Framework
Loading...
Searching...
No Matches
UM.Mesh.MeshBuilder.MeshBuilder Class Reference

Public Member Functions

None __init__ (self)
 
MeshData build (self)
 
None setCenterPosition (self, Optional[Vector] position)
 
Optional[VectorgetCenterPosition (self)
 
 setType (self, mesh_type)
 
 getType (self)
 
int getFaceCount (self)
 
Optional[numpy.ndarray] getVertices (self)
 
 setVertices (self, vertices)
 
 getVertexCount (self)
 
 getVertex (self, index)
 
 removeVertex (self, index)
 
 resetNormals (self)
 
 hasNormals (self)
 
Optional[numpy.ndarray] getNormals (self)
 
 hasIndices (self)
 
Optional[numpy.ndarray] getIndices (self)
 
 setIndices (self, indices)
 
 hasColors (self)
 
Optional[numpy.ndarray] getColors (self)
 
 hasUVCoordinates (self)
 
Optional[numpy.ndarray] getUVCoordinates (self)
 
Optional[str] getFileName (self)
 
None setFileName (self, Optional[str] file_name)
 
None reserveFaceCount (self, int num_faces)
 
 reserveVertexCount (self, num_vertices)
 
 reserveFaceAndVertexCount (self, num_faces, num_vertices)
 
None addVertex (self, float x, float y, float z)
 
 addVertexWithNormal (self, x, y, z, nx, ny, nz)
 
 addFaceByPoints (self, x0, y0, z0, x1, y1, z1, x2, y2, z2)
 
 addFaceWithNormals (self, x0, y0, z0, nx0, ny0, nz0, x1, y1, z1, nx1, ny1, nz1, x2, y2, z2, nx2, ny2, nz2)
 
 setVertexColor (self, index, color)
 
 setVertexUVCoordinates (self, index, u, v)
 
 addVertices (self, vertices)
 
 addIndices (self, indices)
 
 addColors (self, colors)
 
 addFacesWithColor (self, vertices, indices, colors)
 
 setColors (self, colors)
 
 calculateNormals (self, fast=False)
 
 addLine (self, v0, v1, color=None)
 
 addFace (self, v0, v1, v2, normal=None, color=None)
 
 addQuad (self, v0, v1, v2, v3, normal=None, color=None)
 
 addCube (self, width, height, depth, center=Vector(0, 0, 0), color=None)
 
 addArc (self, radius, axis, angle=math.pi *2, center=Vector(0, 0, 0), sections=32, color=None)
 
 addDonut (self, inner_radius, outer_radius, width, center=Vector(0, 0, 0), sections=32, color=None, angle=0, axis=Vector.Unit_Y)
 
 addPyramid (self, width, height, depth, angle=0, axis=Vector.Unit_Y, center=Vector(0, 0, 0), color=None)
 
 addConvexPolygon (self, hull_points, height, color=None)
 
 addConvexPolygonExtrusion (self, xy_points, y0, y1, color=None)
 

Protected Attributes

 _vertices
 
 _normals
 
 _indices
 
 _colors
 
 _uvs
 
 _vertex_count
 
 _face_count
 
 _type
 
 _file_name
 
 _center_position
 

Detailed Description

Builds new meshes by adding primitives.

This class functions in much the same way as a normal StringBuilder would.
Each instance of MeshBuilder creates one mesh. This mesh starts empty, but
you can add primitives to it via the various methods of this class. The
result can then be converted to a normal mesh.

Constructor & Destructor Documentation

◆ __init__()

None UM.Mesh.MeshBuilder.MeshBuilder.__init__ ( self)
Creates a new MeshBuilder with an empty mesh.

Member Function Documentation

◆ addArc()

UM.Mesh.MeshBuilder.MeshBuilder.addArc ( self,
radius,
axis,
angle = math.pi * 2,
center = Vector(0, 0, 0),
sections = 32,
color = None )
Add an arc to the mesh of this mesh builder.

An arc is a curve that is also a segment of a circle.

:param radius: The radius of the circle this arc is a segment of.
:param axis: The axis perpendicular to the plane on which the arc lies.
:param angle: (Optional) The length of the arc, in radians. If not
provided, the entire circle is used (2 pi).
:param center: (Optional) The position of the centre of the arc in space.
If no position is provided, the arc is centred around the coordinate
origin.
:param sections: (Optional) The resolution of the arc. The arc is
approximated by this number of line segments.
:param color: (Optional) The colour for the arc. If no colour is
provided, the colour is determined by the shader.

◆ addConvexPolygon()

UM.Mesh.MeshBuilder.MeshBuilder.addConvexPolygon ( self,
hull_points,
height,
color = None )
Create a mesh from points that represent a convex hull.
:param hull_points: list of xy values
:param height: the opengl y position of the generated mesh
:return: success

◆ addConvexPolygonExtrusion()

UM.Mesh.MeshBuilder.MeshBuilder.addConvexPolygonExtrusion ( self,
xy_points,
y0,
y1,
color = None )
Create an extrusion from xy coordinates that represent a convex polygon.
:param xy_points: list of xy values
:param y0: opengl y location 0
:param y1: opengl y location 1
:return: success

◆ addCube()

UM.Mesh.MeshBuilder.MeshBuilder.addCube ( self,
width,
height,
depth,
center = Vector(0, 0, 0),
color = None )
Add a rectangular cuboid to the mesh of this mesh builder.

A rectangular cuboid is a square block with arbitrary width, height and
depth.

:param width: The size of the rectangular cuboid in the X dimension.
:param height: The size of the rectangular cuboid in the Y dimension.
:param depth: The size of the rectangular cuboid in the Z dimension.
:param center: (Optional) The position of the centre of the rectangular
cuboid in space. If not provided, the cuboid is placed at the coordinate
origin.
:param color: (Optional) The colour for the rectangular cuboid. If no
colour is provided, the colour is determined by the shader.

◆ addDonut()

UM.Mesh.MeshBuilder.MeshBuilder.addDonut ( self,
inner_radius,
outer_radius,
width,
center = Vector(0, 0, 0),
sections = 32,
color = None,
angle = 0,
axis = Vector.Unit_Y )
Adds a torus to the mesh of this mesh builder.

The torus is the shape of a doughnut. This doughnut is delicious and
moist, but not very healthy.

:param inner_radius: The radius of the hole inside the torus. Must be
smaller than outer_radius.
:param outer_radius: The radius of the outside of the torus. Must be
larger than inner_radius.
:param width: The radius of the torus in perpendicular direction to its
perimeter. This is the "thickness".
:param center: (Optional) The position of the centre of the torus. If no
position is provided, the torus will be centred around the coordinate
origin.
:param sections: (Optional) The resolution of the torus in the
circumference. The resolution of the intersection of the torus cannot be
changed.
:param color: (Optional) The colour of the torus. If no colour is
provided, a colour will be determined by the shader.
:param angle: (Optional) An angle of rotation to rotate the torus by, in
radians.
:param axis: (Optional) An axis of rotation to rotate the torus around.
If no axis is provided and the angle of rotation is nonzero, the torus
will be rotated around the Y-axis.

◆ addFace()

UM.Mesh.MeshBuilder.MeshBuilder.addFace ( self,
v0,
v1,
v2,
normal = None,
color = None )
Adds a triangle to the mesh of this mesh builder.

:param v0: The first corner of the triangle.
:param v1: The second corner of the triangle.
:param v2: The third corner of the triangle.
:param normal: (Optional) The normal vector for the triangle. If no
normal vector is provided, it will be calculated automatically.
:param color: (Optional) The colour for the triangle. If no colour is
provided, the colour is determined by the shader.

◆ addFaceByPoints()

UM.Mesh.MeshBuilder.MeshBuilder.addFaceByPoints ( self,
x0,
y0,
z0,
x1,
y1,
z1,
x2,
y2,
z2 )
Add a face by providing three verts.

:param x0: x coordinate of first vertex.
:param y0: y coordinate of first vertex.
:param z0: z coordinate of first vertex.
:param x1: x coordinate of second vertex.
:param y1: y coordinate of second vertex.
:param z1: z coordinate of second vertex.
:param x2: x coordinate of third vertex.
:param y2: y coordinate of third vertex.
:param z2: z coordinate of third vertex.

◆ addFacesWithColor()

UM.Mesh.MeshBuilder.MeshBuilder.addFacesWithColor ( self,
vertices,
indices,
colors )
Add faces defined by indices into vertices with vertex colors defined by colors
Assumes vertices and colors have the same length.

:param vertices: is a numpy array where each row corresponds to a 3D point used to define the faces.
:param indices: consists of row triplet indices into the input :p vertices to build up the triangular faces.
:param colors: defines the color of each vertex in :p vertices.

◆ addFaceWithNormals()

UM.Mesh.MeshBuilder.MeshBuilder.addFaceWithNormals ( self,
x0,
y0,
z0,
nx0,
ny0,
nz0,
x1,
y1,
z1,
nx1,
ny1,
nz1,
x2,
y2,
z2,
nx2,
ny2,
nz2 )
Add a face by providing three vertices and the normals that go with those vertices.

:param x0: The X coordinate of the first vertex.
:param y0: The Y coordinate of the first vertex.
:param z0: The Z coordinate of the first vertex.
:param nx0: The X coordinate of the normal of the first vertex.
:param ny0: The Y coordinate of the normal of the first vertex.
:param nz0: The Z coordinate of the normal of the first vertex.

:param x1: The X coordinate of the second vertex.
:param y1: The Y coordinate of the second vertex.
:param z1: The Z coordinate of the second vertex.
:param nx1: The X coordinate of the normal of the second vertex.
:param ny1: The Y coordinate of the normal of the second vertex.
:param nz1: The Z coordinate of the normal of the second vertex.

:param x2: The X coordinate of the third vertex.
:param y2: The Y coordinate of the third vertex.
:param z2: The Z coordinate of the third vertex.
:param nx2: The X coordinate of the normal of the third vertex.
:param ny2: The Y coordinate of the normal of the third vertex.
:param nz2: The Z coordinate of the normal of the third vertex.

◆ addLine()

UM.Mesh.MeshBuilder.MeshBuilder.addLine ( self,
v0,
v1,
color = None )
Adds a 3-dimensional line to the mesh of this mesh builder.

:param v0: One endpoint of the line to add.
:param v1: The other endpoint of the line to add.
:param color: (Optional) The colour of the line, if any. If no colour is
provided, the colour is determined by the shader.

◆ addPyramid()

UM.Mesh.MeshBuilder.MeshBuilder.addPyramid ( self,
width,
height,
depth,
angle = 0,
axis = Vector.Unit_Y,
center = Vector(0, 0, 0),
color = None )
Adds a pyramid to the mesh of this mesh builder.

:param width: The width of the base of the pyramid.
:param height: The height of the pyramid (from base to notch).
:param depth: The depth of the base of the pyramid.
:param angle: (Optional) An angle of rotation to rotate the pyramid by,
in degrees.
:param axis: (Optional) An axis of rotation to rotate the pyramid around.
If no axis is provided and the angle of rotation is nonzero, the pyramid
will be rotated around the Y-axis.
:param center: (Optional) The position of the centre of the base of the
pyramid. If not provided, the pyramid will be placed on the coordinate
origin.
:param color: (Optional) The colour of the pyramid. If no colour is
provided, a colour will be determined by the shader.

◆ addQuad()

UM.Mesh.MeshBuilder.MeshBuilder.addQuad ( self,
v0,
v1,
v2,
v3,
normal = None,
color = None )
Add a quadrilateral to the mesh of this mesh builder.

The quadrilateral will be constructed as two triangles. v0 and v2 are
the two vertices across the diagonal of the quadrilateral.

:param v0: The first corner of the quadrilateral.
:param v1: The second corner of the quadrilateral.
:param v2: The third corner of the quadrilateral.
:param v3: The fourth corner of the quadrilateral.
:param normal: (Optional) The normal vector for the quadrilateral. Both
triangles will get the same normal vector, if provided. If no normal
vector is provided, the normal vectors for both triangles are computed
automatically.
:param color: (Optional) The colour for the quadrilateral. If no colour
is provided, the colour is determined by the shader.

◆ addVertex()

None UM.Mesh.MeshBuilder.MeshBuilder.addVertex ( self,
float x,
float y,
float z )
Add a vertex to the mesh.

:param x: x coordinate of vertex.
:param y: y coordinate of vertex.
:param z: z coordinate of vertex.

◆ addVertexWithNormal()

UM.Mesh.MeshBuilder.MeshBuilder.addVertexWithNormal ( self,
x,
y,
z,
nx,
ny,
nz )
Add a vertex to the mesh.

:param x: x coordinate of vertex.
:param y: y coordinate of vertex.
:param z: z coordinate of vertex.
:param nx: x part of normal.
:param ny: y part of normal.
:param nz: z part of normal.

◆ build()

MeshData UM.Mesh.MeshBuilder.MeshBuilder.build ( self)
Build a MeshData object.

:return: A Mesh data.

◆ calculateNormals()

UM.Mesh.MeshBuilder.MeshBuilder.calculateNormals ( self,
fast = False )
Calculate the normals of this mesh, assuming it was created by using addFace (eg; the verts are connected)

Keyword arguments:
- fast: A boolean indicating whether or not to use a fast method of normal calculation that assumes each triangle
is stored as a set of three unique vertices.

◆ getIndices()

Optional[numpy.ndarray] UM.Mesh.MeshBuilder.MeshBuilder.getIndices ( self)
Get the array of indices
:return: :type{numpy.ndarray}

◆ getNormals()

Optional[numpy.ndarray] UM.Mesh.MeshBuilder.MeshBuilder.getNormals ( self)
Return the list of vertex normals.

◆ getVertex()

UM.Mesh.MeshBuilder.MeshBuilder.getVertex ( self,
index )
Get a vertex by index

◆ getVertexCount()

UM.Mesh.MeshBuilder.MeshBuilder.getVertexCount ( self)
Get the number of vertices

◆ getVertices()

Optional[numpy.ndarray] UM.Mesh.MeshBuilder.MeshBuilder.getVertices ( self)
Get the array of vertices

◆ hasIndices()

UM.Mesh.MeshBuilder.MeshBuilder.hasIndices ( self)
Return whether this mesh has indices.

◆ hasNormals()

UM.Mesh.MeshBuilder.MeshBuilder.hasNormals ( self)
Return whether this mesh has vertex normals.

◆ reserveFaceAndVertexCount()

UM.Mesh.MeshBuilder.MeshBuilder.reserveFaceAndVertexCount ( self,
num_faces,
num_vertices )
Set the amount of faces and vertices before loading data to the mesh.

This way we can create the array before we fill it. This method will reserve
`num_vertices` amount of space for vertices, `num_vertices` amount of space
for colors and `num_faces` amount of space for indices.

:param num_faces: Number of faces for which memory must be reserved.
:param num_vertices: Number of vertices for which memory must be reserved.

◆ reserveFaceCount()

None UM.Mesh.MeshBuilder.MeshBuilder.reserveFaceCount ( self,
int num_faces )
Set the amount of faces before loading data to the mesh.

This way we can create the array before we fill it. This method will reserve
`(num_faces * 3)` amount of space for vertices, `(num_faces * 3)` amount of space
for normals and `num_faces` amount of space for indices.

:param num_faces: Number of faces for which memory must be reserved.

◆ reserveVertexCount()

UM.Mesh.MeshBuilder.MeshBuilder.reserveVertexCount ( self,
num_vertices )
Preallocate space for vertices before loading data to the mesh.

This way we can create the array before we fill it. This method will reserve
`num_vertices` amount of space for vertices. It deletes any existing normals
and indices but does not reserve space for them.

:param num_vertices: Number of verts to be reserved.

◆ setColors()

UM.Mesh.MeshBuilder.MeshBuilder.setColors ( self,
colors )
:param colors: is a vertexCount by 4 numpy array with floats in range of 0 to 1.

◆ setType()

UM.Mesh.MeshBuilder.MeshBuilder.setType ( self,
mesh_type )
Set the type of the mesh

:param mesh_type: MeshType enum

◆ setVertexColor()

UM.Mesh.MeshBuilder.MeshBuilder.setVertexColor ( self,
index,
color )
Sets the color for a vertex

:param index: :type{int} the index of the vertex in the vertices array.
:param color: :type{UM.Math.Color} the color of the vertex.

The documentation for this class was generated from the following file: