Uranium
Application Framework
 All Classes Namespaces Files Functions Variables Pages
UM.Mesh.MeshBuilder.MeshBuilder Class Reference

Builds new meshes by adding primitives. More...

Public Member Functions

def __init__
 Creates a new MeshBuilder with an empty mesh. More...
 
def build
 Build a MeshData object. More...
 
def setCenterPosition
 
def getCenterPosition
 
def setType
 Set the type of the mesh. More...
 
def getType
 
def getFaceCount
 
def getVertices
 Get the array of vertices.
 
def setVertices
 
def getVertexCount
 Get the number of vertices.
 
def getVertex
 Get a vertex by index.
 
def removeVertex
 
def hasNormals
 Return whether this mesh has vertex normals. More...
 
def getNormals
 Return the list of vertex normals. More...
 
def hasIndices
 Return whether this mesh has indices. More...
 
def getIndices
 Get the array of indices. More...
 
def setIndices
 
def hasColors
 
def getColors
 
def hasUVCoordinates
 
def getUVCoordinates
 
def getFileName
 
def setFileName
 
def reserveFaceCount
 Set the amount of faces before loading data to the mesh. More...
 
def reserveVertexCount
 Preallocate space for vertices before loading data to the mesh. More...
 
def reserveFaceAndVertexCount
 Set the amount of faces and vertices before loading data to the mesh. More...
 
def addVertex
 Add a vertex to the mesh. More...
 
def addVertexWithNormal
 Add a vertex to the mesh. More...
 
def addFaceByPoints
 Add a face by providing three verts. More...
 
def addFaceWithNormals
 Add a face by providing three vertices and the normals that go with those vertices. More...
 
def setVertexColor
 Sets the color for a vertex. More...
 
def setVertexUVCoordinates
 
def addVertices
 
def addIndices
 
def addColors
 
def addFacesWithColor
 Add faces defined by indices into vertices with vetex colors defined by colors Assumes vertices and colors have the same length. More...
 
def setColors
 /param colors is a vertexCount by 4 numpy array with floats in range of 0 to 1. More...
 
def calculateNormals
 Calculate the normals of this mesh, assuming it was created by using addFace (eg; the verts are connected) More...
 
def addLine
 Adds a 3-dimensional line to the mesh of this mesh builder. More...
 
def addFace
 Adds a triangle to the mesh of this mesh builder. More...
 
def addQuad
 Add a quadrilateral to the mesh of this mesh builder. More...
 
def addCube
 Add a rectangular cuboid to the mesh of this mesh builder. More...
 
def addArc
 Add an arc to the mesh of this mesh builder. More...
 
def addDonut
 Adds a torus to the mesh of this mesh builder. More...
 
def addPyramid
 Adds a pyramid to the mesh of this mesh builder. More...
 
def addConvexPolygon
 Create a mesh from points that represent a convex hull. More...
 
def addConvexPolygonExtrusion
 Create an extrusion from xy coordinates that represent a convex polygon. More...
 

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

def UM.Mesh.MeshBuilder.MeshBuilder.__init__ (   self)

Creates a new MeshBuilder with an empty mesh.

Member Function Documentation

def UM.Mesh.MeshBuilder.MeshBuilder.addArc (   self,
  radius,
  axis,
  angle = math.pi * 2,
  center = Vector(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.

Parameters
radiusThe radius of the circle this arc is a segment of.
axisThe axis perpendicular to the plane on which the arc lies.
angle(Optional) The length of the arc, in radians. If not provided, the entire circle is used (2 pi).
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.
sections(Optional) The resolution of the arc. The arc is approximated by this number of line segments.
color(Optional) The colour for the arc. If no colour is provided, the colour is determined by the shader.
def UM.Mesh.MeshBuilder.MeshBuilder.addConvexPolygon (   self,
  hull_points,
  height,
  color = None 
)

Create a mesh from points that represent a convex hull.

Parameters
hull_pointslist of xy values
heightthe opengl y position of the generated mesh
Returns
success
def UM.Mesh.MeshBuilder.MeshBuilder.addConvexPolygonExtrusion (   self,
  xy_points,
  y0,
  y1,
  color = None 
)

Create an extrusion from xy coordinates that represent a convex polygon.

Parameters
xy_pointslist of xy values
y0,y1opengl y locations
Returns
success
def UM.Mesh.MeshBuilder.MeshBuilder.addCube (   self,
  width,
  height,
  depth,
  center = Vector(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.

Parameters
widthThe size of the rectangular cuboid in the X dimension.
heightThe size of the rectangular cuboid in the Y dimension.
depthThe size of the rectangular cuboid in the Z dimension.
center(Optional) The position of the centre of the rectangular cuboid in space. If not provided, the cuboid is placed at the coordinate origin.
color(Optional) The colour for the rectangular cuboid. If no colour is provided, the colour is determined by the shader.
def UM.Mesh.MeshBuilder.MeshBuilder.addDonut (   self,
  inner_radius,
  outer_radius,
  width,
  center = Vector(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.

Parameters
inner_radiusThe radius of the hole inside the torus. Must be smaller than outer_radius.
outer_radiusThe radius of the outside of the torus. Must be larger than inner_radius.
widthThe radius of the torus in perpendicular direction to its perimeter. This is the "thickness".
center(Optional) The position of the centre of the torus. If no position is provided, the torus will be centred around the coordinate origin.
sections(Optional) The resolution of the torus in the circumference. The resolution of the intersection of the torus cannot be changed.
color(Optional) The colour of the torus. If no colour is provided, a colour will be determined by the shader.
angle(Optional) An angle of rotation to rotate the torus by, in radians.
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.
def UM.Mesh.MeshBuilder.MeshBuilder.addFace (   self,
  v0,
  v1,
  v2,
  normal = None,
  color = None 
)

Adds a triangle to the mesh of this mesh builder.

Parameters
v0The first corner of the triangle.
v1The second corner of the triangle.
v2The third corner of the triangle.
normal(Optional) The normal vector for the triangle. If no normal vector is provided, it will be calculated automatically.
color(Optional) The colour for the triangle. If no colour is provided, the colour is determined by the shader.
def UM.Mesh.MeshBuilder.MeshBuilder.addFaceByPoints (   self,
  x0,
  y0,
  z0,
  x1,
  y1,
  z1,
  x2,
  y2,
  z2 
)

Add a face by providing three verts.

Parameters
x0x coordinate of first vertex.
y0y coordinate of first vertex.
z0z coordinate of first vertex.
x1x coordinate of second vertex.
y1y coordinate of second vertex.
z1z coordinate of second vertex.
x2x coordinate of third vertex.
y2y coordinate of third vertex.
z2z coordinate of third vertex.
def UM.Mesh.MeshBuilder.MeshBuilder.addFacesWithColor (   self,
  vertices,
  indices,
  colors 
)

Add faces defined by indices into vertices with vetex colors defined by colors Assumes vertices and colors have the same length.

Parameters
verticesis a numpy array where each row corresponds to a 3D point used to define the faces.
indicesconsists of row triplet indices into the input vertices to build up the triangular faces.
colorsdefines the color of each vertex in vertices.
def 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.

Parameters
x0The X coordinate of the first vertex.
y0The Y coordinate of the first vertex.
z0The Z coordinate of the first vertex.
nx0The X coordinate of the normal of the first vertex.
ny0The Y coordinate of the normal of the first vertex.
nz0The Z coordinate of the normal of the first vertex.
x1The X coordinate of the second vertex.
y1The Y coordinate of the second vertex.
z1The Z coordinate of the second vertex.
nx1The X coordinate of the normal of the second vertex.
ny1The Y coordinate of the normal of the second vertex.
nz1The Z coordinate of the normal of the second vertex.
x2The X coordinate of the third vertex.
y2The Y coordinate of the third vertex.
z2The Z coordinate of the third vertex.
nx2The X coordinate of the normal of the third vertex.
ny2The Y coordinate of the normal of the third vertex.
nz2The Z coordinate of the normal of the third vertex.
def UM.Mesh.MeshBuilder.MeshBuilder.addLine (   self,
  v0,
  v1,
  color = None 
)

Adds a 3-dimensional line to the mesh of this mesh builder.

Parameters
v0One endpoint of the line to add.
v1The other endpoint of the line to add.
color(Optional) The colour of the line, if any. If no colour is provided, the colour is determined by the shader.
def UM.Mesh.MeshBuilder.MeshBuilder.addPyramid (   self,
  width,
  height,
  depth,
  angle = 0,
  axis = Vector.Unit_Y,
  center = Vector(0, 0,
  color = None 
)

Adds a pyramid to the mesh of this mesh builder.

Parameters
widthThe width of the base of the pyramid.
heightThe height of the pyramid (from base to notch).
depthThe depth of the base of the pyramid.
angle(Optional) An angle of rotation to rotate the pyramid by, in degrees.
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.
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.
color(Optional) The colour of the pyramid. If no colour is provided, a colour will be determined by the shader.
def 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.

Parameters
v0The first corner of the quadrilateral.
v1The second corner of the quadrilateral.
v2The third corner of the quadrilateral.
v3The fourth corner of the quadrilateral.
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.
color(Optional) The colour for the quadrilateral. If no colour is provided, the colour is determined by the shader.
def UM.Mesh.MeshBuilder.MeshBuilder.addVertex (   self,
  x,
  y,
  z 
)

Add a vertex to the mesh.

Parameters
xx coordinate of vertex.
yy coordinate of vertex.
zz coordinate of vertex.
def UM.Mesh.MeshBuilder.MeshBuilder.addVertexWithNormal (   self,
  x,
  y,
  z,
  nx,
  ny,
  nz 
)

Add a vertex to the mesh.

Parameters
xx coordinate of vertex.
yy coordinate of vertex.
zz coordinate of vertex.
nxx part of normal.
nyy part of normal.
nzz part of normal.
def UM.Mesh.MeshBuilder.MeshBuilder.build (   self)

Build a MeshData object.

Returns
A Mesh data.
def 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.
def UM.Mesh.MeshBuilder.MeshBuilder.getIndices (   self)

Get the array of indices.

Returns
numpy.ndarray
def UM.Mesh.MeshBuilder.MeshBuilder.getNormals (   self)

Return the list of vertex normals.

def UM.Mesh.MeshBuilder.MeshBuilder.hasIndices (   self)

Return whether this mesh has indices.

def UM.Mesh.MeshBuilder.MeshBuilder.hasNormals (   self)

Return whether this mesh has vertex normals.

def 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.

Parameters
num_facesNumber of faces for which memory must be reserved.
num_verticesNumber of vertices for which memory must be reserved.
def UM.Mesh.MeshBuilder.MeshBuilder.reserveFaceCount (   self,
  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.

Parameters
num_facesNumber of faces for which memory must be reserved.
def 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.

Parameters
num_verticesNumber of verts to be reserved.
def UM.Mesh.MeshBuilder.MeshBuilder.setColors (   self,
  colors 
)

/param colors is a vertexCount by 4 numpy array with floats in range of 0 to 1.

def UM.Mesh.MeshBuilder.MeshBuilder.setType (   self,
  mesh_type 
)

Set the type of the mesh.

Parameters
mesh_typeMeshType enum
def UM.Mesh.MeshBuilder.MeshBuilder.setVertexColor (   self,
  index,
  color 
)

Sets the color for a vertex.

Parameters
indexint the index of the vertex in the vertices array.
colorUM.Math.Color the color of the vertex.

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