diff --git a/mikktspace-sys/src/lib.rs b/mikktspace-sys/src/lib.rs index f0644a98e5..84f7a6876b 100644 --- a/mikktspace-sys/src/lib.rs +++ b/mikktspace-sys/src/lib.rs @@ -4,6 +4,7 @@ mod ffi; use std::os::raw::*; use std::mem; +/// Rust FFI for the MikkTSpace implementation. const INTERFACE: ffi::SMikkTSpaceInterface = ffi::SMikkTSpaceInterface { m_getNumFaces: faces, m_getNumVerticesOfFace: vertices, @@ -15,7 +16,26 @@ const INTERFACE: ffi::SMikkTSpaceInterface = ffi::SMikkTSpaceInterface { }; pub struct Context { - faces: i32, + faces: Box>, + positions: Box>, + tex_coords: Box>, + normals: Box>, +} + +/// Specifies whether a face is a triangle or a quad. +pub enum Face { + Triangle, + Quad, +} + +impl Face { + /// Returns the number of vertices bound by this face. + pub fn vertices(&self) -> i32 { + match self { + &Face::Triangle { .. } => 3, + &Face::Quad { .. } => 4, + } + } } /// Returns the number of faces (triangles/quads) on the mesh to be processed. @@ -23,7 +43,7 @@ pub struct Context { extern "C" fn faces(pContext: *const ffi::SMikkTSpaceContext) -> c_int { unsafe { let m: *const Context = mem::transmute(pContext); - (*m).faces as c_int + (*m).faces.len() as c_int } } @@ -36,7 +56,7 @@ extern "C" fn vertices( ) -> c_int { unsafe { let _: *const Context = mem::transmute(pContext); - unimplemented!() + 3 } } @@ -114,16 +134,19 @@ extern "C" fn set_tspace( } impl Context { - pub fn new() -> Self { + /// Constructor for a MikkTSpace `Context`. + pub fn new(faces: F, positions: P, tex_coords: T, normals: N) -> Self + where + F: 'static + ExactSizeIterator, + P: 'static + ExactSizeIterator, + T: 'static + ExactSizeIterator, + N: 'static + ExactSizeIterator, + { Context { - faces: 3, + faces: Box::new(faces), + positions: Box::new(positions), + tex_coords: Box::new(tex_coords), + normals: Box::new(normals), } } } - -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - } -}