pub struct Mesh { /* fields omitted */ }
Represents a triangle mesh. Use the Mesh builder to construct a new mesh.
Methods to construct a Walker which is used for easy and efficient traversal of the mesh.
See Walker for more information and examples.
Creates a walker at the half-edge pointed to by the given vertex.
Creates a walker at the given half-edge.
Creates a walker at the half-edge pointed to by the given face.
Iterator over the vertex ids.
let mut sum_vertex_positions = Vec3::zero();
for vertex_id in mesh.vertex_iter() {
sum_vertex_positions += *mesh.vertex_position(vertex_id);
}
Iterator over the half-edge ids.
Note: Each edge is visited two times, one for each half-edge. If you want to visit the edges only once, then use edge_iter
instead.
let mut halfedge_length_average = 0.0;
let mut i = 0;
for halfedge_id in mesh.halfedge_iter() {
halfedge_length_average += mesh.edge_length(halfedge_id);
i += 1;
}
halfedge_length_average /= i as f32;
Iterator over the edges given as a half-edge id.
Note: Each edge is visited once. If you want to visit both half-edges of an edge, then use halfedge_iter
instead.
let mut edge_length_average = 0.0;
let mut i = 0;
for halfedge_id in mesh.edge_iter() {
edge_length_average += mesh.edge_length(halfedge_id);
i += 1;
}
edge_length_average /= i as f32;
Iterator over the face ids.
let mut sum_face_area = 0.0;
for face_id in mesh.face_iter() {
sum_face_area += mesh.face_area(face_id);
}
Iterator over the half-edges which starts in the given vertex, ie. the one-ring.
Note: If the given vertex is the only connection between two or more separate sets of faces,
then this iterator will only iterate the half-edges in one of the sets.
If the vertex is on the boundary, all half-edges are visited.
let mut one_ring_average_position = Vec3::zero();
let mut i = 0;
for halfedge_id in mesh.vertex_halfedge_iter(vertex_id) {
let walker = mesh.walker_from_halfedge(halfedge_id);
one_ring_average_position += *mesh.vertex_position(walker.vertex_id().unwrap());
i = i+1;
}
one_ring_average_position /= i as f32;
Iterator over the three half-edges connected to the given face.
let mut face_circumference = 0.0f32;
for halfedge_id in mesh.face_halfedge_iter(face_id) {
face_circumference += mesh.edge_length(halfedge_id);
}
Returns the connecting edge between the two vertices or None
if no edge is found.
Note: This method assumes that the mesh is properly connected.
See vertex_halfedge_iter for more information.
Returns whether or not the vertex is on a boundary.
Returns whether or not the edge is on a boundary.
Returns the vertex id of the two adjacent vertices to the given edge.
Returns the vertex id of the two adjacent vertices to the given edge
and ordered such that ordered_edge_vertices.0 < ordered_edge_vertices.1
.
Returns the vertex id of the three connected vertices to the given face.
Returns the vertex id of the three connected vertices to the given face
and ordered such that ordered_face_vertices.0 < ordered_face_vertices.1 < ordered_face_vertices.2
.
Returns the vertex position.
Returns the normal of the vertex given as the average of the normals of the neighbouring faces.
Returns the two positions of the vertices of either end of the given halfedge.
Returns the length of the specified edge
Returns the squared length of the specified edge
Returns the positions of the face vertices.
Returns the normal of the face.
Returns the area of the face.
Returns the center of the face given as the average of its vertex positions.
Flip the given edge such that the edge after the flip is connected to the
other pair of the four vertices connected to the two adjacent faces.
/\ /|\
/ \ / | \
/____\ --> / | \
\ / \ | /
\ / \ | /
\/ \|/
Returns an error if trying to flip an edge on the boundary or the flip will connect two vertices that are already connected by another edge.
Split the given edge into two.
Returns the id of the new vertex positioned at the given position.
Split the given face into three new faces.
Returns the id of the new vertex positioned at the given position.
Collapses the given edge. Consequently, the to adjacent faces are removed and
the two adjacent vertices are merged into one vertex
which position is the average of the original vertex positions.
Returns the merged vertex.
Note: This might make some faces degenerate.
Removes the given face and the adjacent edges if they are then not connected to any face.
Moves the vertices to pos + factor * (avg_pos - pos)
where pos
is the current position
and avg_pos
is the average position of the neighbouring vertices.
Collapse an edge of faces which has an area smaller than area_threshold
.
Removes edges and vertices that are not connected to a face.
Flip all edges in the mesh
- which is not on the boundary
- where the flip will improve the sum of the quality of the two faces adjacent to the edge
(The face quality is given as the circumscribed radius divided by the inscribed radius)
- where the dot product between the normals of the adjacent faces is smaller than
flattness_threshold
(1: Completely flat, 0: 90 degrees angle between normals)
- where the flip will not result in inverted triangles
Flip the orientation of all faces in the mesh, ie. such that the normal points in the opposite direction.
Fix the orientation of all faces in the mesh such that the orientation of each pair of neighbouring faces is aligned.
Moves the vertex to the specified position.
Moves the vertex by the specified vector, i.e. the new position is mesh.vertex_position(vertex_id) + value
.
Scales the entire mesh by applying the scale
to each vertex position.
let mut mesh = MeshBuilder::new().cube().build()?;
mesh.scale(2.0);
Translates the entire mesh by applying the translation
to each vertex position.
let mut mesh = MeshBuilder::new().cube().build()?;
mesh.translate(vec3(2.5, -1.0, 0.0));
Rotates the entire mesh by applying the given rotation
to each vertex position.
let mut mesh = MeshBuilder::new().cube().build()?;
mesh.apply_transformation(Mat4::from_angle_y(Deg(360.0)));
Transforms the entire mesh by applying the transformation
to each vertex position.
let mut mesh = MeshBuilder::new().cube().build()?;
mesh.apply_transformation(Mat4::from_translation(vec3(2.5, -1.0, 0.0)));
Merges the mesh together with the other
mesh.
The other
mesh primitives are copied to the current mesh (and other
is therefore not changed)
followed by merging of overlapping primitives.
Appends the other
mesh to this mesh which means that all the primitivess of
the other
mesh are copied to the current mesh. The other
mesh is therefore not changed.
Returns a clone a subset of this mesh.
Merges overlapping faces, edges and vertices.
Returns an error if the merging will result in a non-manifold mesh.
WARNING: DO NOT USE IN PRODUCTION!
This method tests if the mesh is valid, i.e. has correct connectivity and orientation and contains no degenerate triangles.
Intended only to be used in development and unit tests.
If the mesh is not valid, an IsNotValid error with a description of the problem is returned.
Returns the number of vertices in the mesh.
Returns the number of edges in the mesh.
Returns the number of half-edges in the mesh.
Returns the number of faces in the mesh.
Returns the face indices in an array (i0, i1, i2) = (indices[3*x], indices[3*x+1], indices[3*x+2])
.
let indices = mesh.indices_buffer();
for i in 0..indices.len()/3
{
println!("The indices of face {} is: ({}, {}, {})", i, indices[3*i], indices[3*i+1], indices[3*i+2]);
}
Returns the positions of the vertices in an array.
let positions = mesh.positions_buffer();
for i in 0..positions.len()/3
{
println!("The position of vertex with index {} is: ({}, {}, {})", i, positions[3*i], positions[3*i+1], positions[3*i+2]);
}
Returns the normals of the vertices in an array.
Note: The normals are computed from the connectivity and positions each time this method is invoked.
let normals = mesh.normals_buffer();
for i in 0..normals.len()/3
{
println!("The normal of vertex with index {} is: ({}, {}, {})", i, normals[3*i], normals[3*i+1], normals[3*i+2]);
}
Returns minimum and maximum coordinates of the axis aligned bounding box of the mesh.
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
type Owned = T
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String
. Read more
type Error = !
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static