1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#![deny(missing_docs)]

//! A structure for storing and look up 3D geometry

extern crate range;
extern crate wavefront_obj as wobj;

pub use geometry::Geometry;
pub use object::Object;
pub use model::Model;

use std::marker::PhantomData;

mod geometry;
mod object;
mod model;

/// Add range to object `T`.
pub struct AddTo<T>(PhantomData<T>);

/// Implemented by vertex types.
pub trait Vertex {
    /// Sets position.
    fn set_position(&mut self, [f32; 3]);
    /// Sets texture coords.
    fn set_texture_coords(&mut self, [f32; 2]);
    /// Sets normal.
    fn set_normal(&mut self, [f32; 3]);
}

/// Description of vertex format.
pub enum VertexFormat {
    /// Vertex contains position coordinates.
    Position,
    /// Vertex contains position and texture coordinates.
    PositionTexture,
    /// Vertex contains position and normal coordinates.
    PositionNormal,
    /// Vertex contains both position, texture and normal coordinates.
    PositionTextureNormal,
}

/// An error with vertex format when adding to index and vertex buffer.
#[derive(Debug)]
pub enum VertexFormatError {
    /// The vertex format must be the same for an entire geometry object.
    ExpectedSameVertexFormatPerGeometry,
}