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

Builds new meshes by adding primitives. More...

Public Member Functions

 __init__ (self)
 Creates a new MeshBuilder with an empty mesh.
 
 build (self)
 Build a MeshData object.
 
 setCenterPosition (self, position)
 
 getCenterPosition (self)
 
 setType (self, mesh_type)
 Set the type of the mesh.
 
 getType (self)
 
 getFaceCount (self)
 
 getVertices (self)
 Get the array of vertices.
 
 setVertices (self, vertices)
 
 getVertexCount (self)
 Get the number of vertices.
 
 getVertex (self, index)
 Get a vertex by index.
 
 removeVertex (self, index)
 
 hasNormals (self)
 Return whether this mesh has vertex normals.
 
 getNormals (self)
 Return the list of vertex normals.
 
 hasIndices (self)
 Return whether this mesh has indices.
 
 getIndices (self)
 Get the array of indices.
 
 setIndices (self, indices)
 
 hasColors (self)
 
 getColors (self)
 
 hasUVCoordinates (self)
 
 getUVCoordinates (self)
 
 getFileName (self)
 
 setFileName (self, file_name)
 
 reserveFaceCount (self, num_faces)
 Set the amount of faces before loading data to the mesh.
 
 reserveVertexCount (self, num_vertices)
 Preallocate space for vertices before loading data to the mesh.
 
 reserveFaceAndVertexCount (self, num_faces, num_vertices)
 Set the amount of faces and vertices before loading data to the mesh.
 
 addVertex (self, x, y, z)
 Add a vertex to the mesh.
 
 addVertexWithNormal (self, x, y, z, nx, ny, nz)
 Add a vertex to the mesh.
 
 addFaceByPoints (self, x0, y0, z0, x1, y1, z1, x2, y2, z2)
 Add a face by providing three verts.
 
 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.
 
 setVertexColor (self, index, color)
 Sets the color for a vertex.
 
 setVertexUVCoordinates (self, index, u, v)
 
 addVertices (self, vertices)
 
 addIndices (self, indices)
 
 addColors (self, colors)
 
 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.
 
 setColors (self, colors)
 /param colors is a vertexCount by 4 numpy array with floats in range of 0 to 1.
 
 calculateNormals (self, fast=False)
 Calculate the normals of this mesh, assuming it was created by using addFace (eg; the verts are connected)
 
 addLine (self, v0, v1, color=None)
 Adds a 3-dimensional line to the mesh of this mesh builder.
 
 addFace (self, v0, v1, v2, normal=None, color=None)
 Adds a triangle to the mesh of this mesh builder.
 
 addQuad (self, v0, v1, v2, v3, normal=None, color=None)
 Add a quadrilateral to the mesh of this mesh builder.
 
 addCube (self, width, height, depth, center=Vector(0, 0, 0), color=None)
 Add a rectangular cuboid to the mesh of this mesh builder.
 
 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.
 
 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.
 
 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.
 
 addConvexPolygon (self, hull_points, height, color=None)
 Create a mesh from points that represent a convex hull.
 
 addConvexPolygonExtrusion (self, xy_points, y0, y1, color=None)
 Create an extrusion from xy coordinates that represent a convex polygon.
 

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.

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.

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.

◆ addConvexPolygon()

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

◆ addConvexPolygonExtrusion()

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

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

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.

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

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.

◆ addFace()

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.

◆ addFaceByPoints()

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.

◆ addFacesWithColor()

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.

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

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.

◆ addLine()

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.

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

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.

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

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.

◆ addVertex()

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.

◆ addVertexWithNormal()

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.

◆ build()

UM.Mesh.MeshBuilder.MeshBuilder.build (   self)

Build a MeshData object.

Returns
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()

UM.Mesh.MeshBuilder.MeshBuilder.getIndices (   self)

Get the array of indices.

Returns
numpy.ndarray

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

Parameters
num_facesNumber of faces for which memory must be reserved.
num_verticesNumber of vertices for which memory must be reserved.

◆ reserveFaceCount()

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.

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

Parameters
num_verticesNumber of verts to be reserved.

◆ setType()

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

Set the type of the mesh.

Parameters
mesh_typeMeshType enum

◆ setVertexColor()

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: