50 lines
1.2 KiB
Rust
50 lines
1.2 KiB
Rust
|
//! This module contains the FaceVertex struct.
|
||
|
|
||
|
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<usize>,
|
||
|
|
||
|
/// The index of the normal, None if there is no normal.
|
||
|
pub normal: Option<usize>,
|
||
|
}
|
||
|
|
||
|
impl FaceVertex {
|
||
|
|
||
|
/// Creates a new face vertex from its attributes.
|
||
|
pub fn new(vertex: usize, texture_coordinate: Option<usize>, normal: Option<usize>) -> 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)
|
||
|
}
|
||
|
}
|