//! This module contains the structs needed to build faces. use std::fmt; #[derive(Copy, Clone, PartialEq)] /// The indices needed for each vertex of a face. pub struct FaceVertex { /// The index of the vertex. pub vertex: usize, /// The index of the texture coordinate, None if there is no texture coordinate. pub texture_coordinate: Option, /// The index of the normal, None if there is no normal. pub normal: Option, } impl FaceVertex { /// Creates a new face vertex from its attributes. pub fn new(vertex: usize, texture_coordinate: Option, normal: Option) -> FaceVertex { FaceVertex { vertex: vertex, texture_coordinate: texture_coordinate, normal: normal, } } } impl fmt::Debug for FaceVertex { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { let texture_coordinate = if let Some(tc) = self.texture_coordinate { tc.to_string() } else { "".to_owned() }; let normal = if let Some(n) = self.normal { n.to_string() } else { "".to_owned() }; write!(formatter, "{}/{}/{}", self.vertex, texture_coordinate, normal) } } #[derive(Clone, PartialEq, Debug)] /// A 3D Face. /// /// It contains exactly 3 face vertices, and the name of the corresponding material. pub struct Face { /// The first vertex of the face. pub a: FaceVertex, /// The second vertex of the face. pub b: FaceVertex, /// The third vertex of the face. pub c: FaceVertex, /// The name of the material, None if no material is specified. pub material_name: Option, /// Id of the face, number of the face in the original file. pub id: Option, } impl Face { /// Creates a new face from its attributes. /// /// Material name defaults to None. pub fn new(a: FaceVertex, b: FaceVertex, c: FaceVertex) -> Face { Face { a: a, b: b, c: c, material_name: None, id: None, } } }