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
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use std::os::raw::{c_float, c_uint};

use types::*;

pub const AI_MAX_FACE_INDICES: usize = 0x7fff;
pub const AI_MAX_BONE_WEIGHTS: usize = 0x7fffffff;
pub const AI_MAX_VERTICES: usize = 0x7fffffff;
pub const AI_MAX_FACES: usize = 0x7fffffff;
pub const AI_MAX_NUMBER_OF_COLOR_SETS: usize = 0x8;
pub const AI_MAX_NUMBER_OF_TEXTURECOORDS: usize = 0x8;

#[repr(C)]
pub struct AiFace {
    pub num_indices: c_uint,
    pub indices: *mut c_uint,
}

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct AiVertexWeight {
    pub vertex_id: c_uint,
    pub weight: c_float,
}

#[repr(C)]
pub struct AiBone {
    pub name: AiString,
    pub num_weights: c_uint,
    pub weights: *mut AiVertexWeight,
    pub offset_matrix: AiMatrix4x4,
}

bitflags! {
    #[repr(C)]
    pub struct AiPrimitiveType: c_uint {
        const AIPRIMITIVETYPE_POINT = 0x1;
        const AIPRIMITIVETYPE_LINE = 0x2;
        const AIPRIMITIVETYPE_TRIANGLE = 0x4;
        const AIPRIMITIVETYPE_POLYGON = 0x8;
    }
}

#[repr(C)]
pub struct AiAnimMesh {
    pub vertices: *mut AiVector3D,
    pub normals: *mut AiVector3D,
    pub tangents: *mut AiVector3D,
    pub bitangents: *mut AiVector3D,
    pub colors: [*mut AiColor4D; AI_MAX_NUMBER_OF_COLOR_SETS],
    pub texture_coords: [*mut AiVector3D; AI_MAX_NUMBER_OF_TEXTURECOORDS],
    pub num_vertices: c_uint,
    pub weight: c_float,
}

impl AiAnimMesh {
    pub fn has_positions(&self) -> bool {
        !self.vertices.is_null()
    }
    pub fn has_normals(&self) -> bool {
        !self.normals.is_null()
    }
    pub fn has_tangents_and_bitangents(&self) -> bool {
        !self.tangents.is_null()
    }
    pub fn has_vertex_colors(&self, index: usize) -> bool {
        index < AI_MAX_NUMBER_OF_COLOR_SETS && !self.colors[index].is_null()
    }
    pub fn has_texture_coords(&self, index: usize) -> bool {
        index < AI_MAX_NUMBER_OF_TEXTURECOORDS && !self.texture_coords[index].is_null()
    }
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AiMorphingMethod {
    VertexBlend = 0x1,
    MorphNormalized = 0x2,
    MorphRelative = 0x3,
}

#[repr(C)]
pub struct AiMesh {
    pub primitive_types: c_uint,
    pub num_vertices: c_uint,
    pub num_faces: c_uint,
    pub vertices: *mut AiVector3D,
    pub normals: *mut AiVector3D,
    pub tangents: *mut AiVector3D,
    pub bitangents: *mut AiVector3D,
    pub colors: [*mut AiColor4D; AI_MAX_NUMBER_OF_COLOR_SETS],
    pub texture_coords: [*mut AiVector3D; AI_MAX_NUMBER_OF_TEXTURECOORDS],
    pub num_uv_components: [c_uint; AI_MAX_NUMBER_OF_TEXTURECOORDS],
    pub faces: *mut AiFace,
    pub num_bones: c_uint,
    pub bones: *mut *mut AiBone,
    pub material_index: c_uint,
    pub name: AiString,
    pub num_anim_meshes: c_uint,
    pub anim_meshes: *mut *mut AiAnimMesh,
    pub method: c_uint,
}

impl AiMesh {
    pub fn has_positions(&self) -> bool {
        !self.vertices.is_null() && self.num_vertices > 0
    }
    pub fn has_faces(&self) -> bool {
        !self.faces.is_null() && self.num_faces > 0
    }
    pub fn has_normals(&self) -> bool {
        !self.normals.is_null() && self.num_vertices > 0
    }
    pub fn has_tangents_and_bitangents(&self) -> bool {
        !self.tangents.is_null() && self.num_vertices > 0
    }
    pub fn has_vertex_colors(&self, index: usize) -> bool {
        index < AI_MAX_NUMBER_OF_COLOR_SETS && !self.colors[index].is_null() &&
        self.num_vertices > 0
    }
    pub fn has_texture_coords(&self, index: usize) -> bool {
        index < AI_MAX_NUMBER_OF_TEXTURECOORDS && !self.texture_coords[index].is_null() &&
        self.num_vertices > 0
    }
    pub fn get_num_uv_channels(&self) -> usize {
        let mut n = 0;
        while n < AI_MAX_NUMBER_OF_TEXTURECOORDS && !self.texture_coords[n].is_null() {
            n += 1;
        }
        n
    }
    pub fn get_num_color_channels(&self) -> usize {
        let mut n = 0;
        while n < AI_MAX_NUMBER_OF_COLOR_SETS && !self.colors[n].is_null() {
            n += 1;
        }
        n
    }
    pub fn has_bones(&self) -> bool {
        !self.bones.is_null() && self.num_bones > 0
    }
}