2018-02-23 14:34:25 +01:00
|
|
|
//! Module containing all the logic for exporting 3D models.
|
|
|
|
|
|
|
|
pub mod obj;
|
|
|
|
|
|
|
|
use parser::Element;
|
|
|
|
use model::Model;
|
|
|
|
|
|
|
|
use std::io;
|
|
|
|
use std::io::Write;
|
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
/// An error occured during export.
|
|
|
|
pub enum ExportError {
|
|
|
|
/// An IO error occured when creating files or directories.
|
|
|
|
IoError(io::Error),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for ExportError {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
|
|
|
ExportError::IoError(ref e) =>
|
|
|
|
write!(f, "IoError occured: {}", e),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<io::Error> for ExportError {
|
|
|
|
fn from(e: io::Error) -> Self {
|
|
|
|
ExportError::IoError(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Exports a 3D model to a certain format.
|
|
|
|
pub trait Exporter {
|
|
|
|
/// The type of errors the exporter will return in case of errors.
|
|
|
|
///
|
|
|
|
/// The errors can be of many things, we can't know everything in this create, so this type
|
|
|
|
/// will enable you to use custom errors.
|
|
|
|
type Error;
|
|
|
|
|
|
|
|
/// Performs the export in the specified output directory.
|
|
|
|
fn export(&self, model: &Model, output_dir: &str) -> Result<(), Self::Error>;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Serialize a 3D element.
|
|
|
|
pub trait ElementSerializer {
|
|
|
|
|
|
|
|
/// Performs the serialization.
|
|
|
|
///
|
|
|
|
/// Writes the serialization on the output and returns Err if an error occured.
|
2018-04-10 13:37:08 +02:00
|
|
|
fn serialize<W: Write>(&self, element: Element, output: &mut W) -> Result<usize, ExportError>;
|
2018-02-23 14:34:25 +01:00
|
|
|
}
|