[][src]Struct tri_mesh::mesh_builder::MeshBuilder

pub struct MeshBuilder { /* fields omitted */ }

MeshBuilder contains functionality to build a mesh from either raw data (indices, positions, normals) or from simple geometric shapes (box, icosahedron, cylinder, ..) or from file source (.obj).

Methods

impl MeshBuilder[src]

pub fn new() -> Self[src]

Creates a new MeshBuilder instance.

pub fn with_indices(self, indices: Vec<u32>) -> Self[src]

Set the indices of each face, where the indices of face x is (i0, i1, i2) = (indices[3*x], indices[3*x+1], indices[3*x+2]).

Examples

let indices: Vec<u32> = vec![0, 1, 2,  0, 2, 3,  0, 3, 1];
let positions: Vec<f32> = vec![0.0, 0.0, 0.0,  1.0, 0.0, -0.5,  -1.0, 0.0, -0.5, 0.0, 0.0, 1.0];
let mesh = MeshBuilder::new().with_indices(indices).with_positions(positions).build()?;

assert_eq!(mesh.no_faces(), 3);
assert_eq!(mesh.no_vertices(), 4);

pub fn with_positions(self, positions: Vec<f32>) -> Self[src]

Set the positions of each vertex, where the position of vertex x is (x, y, z) = (positions[3*x], positions[3*x+1], positions[3*x+2]);

Examples

Build from positions (note: Use merge_overlapping_primitives if you want to merge unconnected but overlapping parts of the mesh):

let positions: Vec<f32> = vec![0.0, 0.0, 0.0,  1.0, 0.0, -0.5,  -1.0, 0.0, -0.5,
                                   0.0, 0.0, 0.0,  -1.0, 0.0, -0.5, 0.0, 0.0, 1.0,
                                   0.0, 0.0, 0.0,  0.0, 0.0, 1.0,  1.0, 0.0, -0.5];
let mesh = MeshBuilder::new().with_positions(positions).build()?;

assert_eq!(mesh.no_faces(), 3);
assert_eq!(mesh.no_vertices(), 9);

pub fn with_obj(self, source: String) -> Self[src]

Parses the .obj file and extracts the connectivity information (indices) and positions which is used to construct a mesh when the build method is called. If the .obj file contains multiple objects, all objects are added to the mesh, but they will not be connected.

Examples

let source = "o Cube
v 1.000000 -1.000000 -1.000000
#...
f 5 4 8".to_string();

let mesh = MeshBuilder::new().with_obj(source).build()?;

assert_eq!(mesh.no_faces(), 12);
assert_eq!(mesh.no_vertices(), 8);

pub fn build(self) -> Result<Mesh, Error>[src]

Builds the mesh. Returns the mesh if the definition is valid and otherwise an error.

Errors

If no positions are specified, NoPositionsSpecified error is returned.

pub fn cube(self) -> Self[src]

Creates a cube.

Examples

let mesh = MeshBuilder::new().cube().build()?;

assert_eq!(mesh.no_faces(), 12);
assert_eq!(mesh.no_vertices(), 8);

pub fn unconnected_cube(self) -> Self[src]

Creates a cube where each face is not connected to any other face.

pub fn icosahedron(self) -> Self[src]

Creates an icosahedron, i.e. a discretised sphere.

pub fn cylinder(self, x_subdivisions: usize, angle_subdivisions: usize) -> Self[src]

Creates a cylinder with the x-direction as axis, length 1 and radius 1. x_subdivisions defines the number of subdivisions in the x-direction and angle_subdivisions defines the number of circular subdivisions.

pub fn triangle(self) -> Self[src]

Creates a triangle in x = [-3, 3], y = [-1, 2] and z = 0 which covers a square in x = [-1, 1], y = [-1, 1] and z = 0.

pub fn square(self) -> Self[src]

Creates a square in x = [-1, 1], y = [-1, 1] and z = 0.

pub fn subdivided_triangle(self) -> Self[src]

Creates three connected triangles in x = [-3, 3], y = [-1, 2] and z = 0 which covers a square in x = [-1, 1], y = [-1, 1] and z = 0 and has a common vertex in (0, 0, 0).

Trait Implementations

impl Default for MeshBuilder[src]

impl Debug for MeshBuilder[src]

Auto Trait Implementations

impl Send for MeshBuilder

impl Sync for MeshBuilder

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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.