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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
extern crate mazth;

///md5mesh file format
pub mod mesh {

    use super::mazth::quat::Quat;
    
    #[derive(Debug, Clone)]
    pub struct Md5Mesh {
        pub _shader: String,
        pub _numverts: u64,
        pub _numtris: u64,
        pub _numweights: u64,
        pub _verts: Vec< Md5Vert >,
        pub _tris: Vec< Md5Tri >,
        pub _weights: Vec< Md5Weight >,
    }

    #[derive(Debug, Clone)]
    pub struct Md5Joint {
        pub _name: String,
        pub _parent_index: i64,
        pub _pos: [f32;3],
        pub _orient: [f32;3],
        pub _rot: Quat<f32>,
    }

    #[derive(Debug, Clone)]
    pub struct Md5Vert {
        pub _index: u64,
        pub _tex_coords: [f32;2],
        pub _weight_start: u64,
        pub _weight_count: u64,
        pub _normal: [f32;3],
        pub _pos: [f32;3],
    }

    #[derive(Debug)]
    #[derive(Copy)]
    #[derive(Clone)]
    pub struct Md5Tri {
        pub _index: u64,
        pub _vert_indices: [u64;3],
    }

    #[derive(Debug, Clone)]
    pub struct Md5Weight {
        pub _index: u64,
        pub _joint_index: u64,
        pub _weight_bias: f32,
        pub _pos: [f32;3],
    }

    #[derive(Debug, Clone)]
    pub struct Md5MeshRoot {
        pub _md5ver: u64,
        pub _cmdline: String,
        pub _numjoints: u64,
        pub _nummeshes: u64,
        pub _joints: Vec< Md5Joint >,
        pub _meshes: Vec< Md5Mesh >,
    }

    impl Md5MeshRoot {
        pub fn init() -> Md5MeshRoot {
            Md5MeshRoot {
                _md5ver: 0u64,
                _cmdline: String::from(""),
                _numjoints: 0u64,
                _nummeshes: 0u64,
                _joints: vec![],
                _meshes: vec![],
            }
        }
    }
}

///md5anim file format
pub mod anim {

    #[derive(Debug)]
    pub struct JointHierarchy {
        pub _name: String,
        pub _parent: i64,
        pub _flags: u64,
        pub _start_index: u64,
    }

    #[derive(Debug)]
    pub struct Bound {
        pub _min: [f32;3],
        pub _max: [f32;3],
    }

    #[derive(Debug)]
    pub struct FrameJoint {
        pub _index: u64,
        pub _pos: [f32;3],
        pub _orient: [f32;3],
    }

    #[derive(Debug, Default)]
    pub struct Frame {
        pub _index: u64,
        pub _data: Vec< f32 >,
    }

    #[derive(Debug)]
    pub struct Md5AnimRoot {
        pub _md5ver: u64,
        pub _cmdline: String,
        pub _numframes: u64,
        pub _numjoints: u64,
        pub _framerate: u64,
        pub _num_animated_components: u64,
        pub _hierarchy: Vec< JointHierarchy >,
        pub _bounds: Vec< Bound >,
        pub _baseframe: Vec< FrameJoint >,
        pub _frames: Vec< Frame >,
    }

    impl Md5AnimRoot {
        pub fn init() -> Md5AnimRoot {
            Md5AnimRoot {
                _md5ver: 0u64,
                _cmdline: String::from(""),
                _numframes: 0u64,
                _numjoints: 0u64,
                _framerate: 0u64,
                _num_animated_components: 0u64,
                _hierarchy: vec![],
                _bounds: vec![],
                _baseframe: vec![],
                _frames: vec![],
            }
        }
    }
}

///md5rig file format
pub mod rig {

    use super::mazth::quat::Quat;
    
    #[derive(Debug, Clone)]
    pub struct RigJoint {
        pub _name: String,
        pub _parent: i64,
        pub _pos: [f32;3],
        pub _orient: Quat<f32>,
    }

    #[derive(Debug, Clone)]
    pub struct PoseJoints {
        pub _joints: Vec< RigJoint >,
        // pub _bbox_lower: [f32;3], //todo
        // pub _bbox_upper: [f32;3],
    }

    #[derive(Debug, Clone)]
    pub struct PoseCollection {
        pub _frames: Vec< PoseJoints >,
        pub _framerate: u64,
    }
}

pub mod compute {
    ///md5compute format
    #[derive(Debug, Clone)]
    pub struct VertCompute {
        pub _pos: [f32;3],
        pub _normal: [f32;3],
        pub _tc: [f32;2],
    }

    #[derive(Debug, Clone)]
    pub struct MeshCompute {
        pub _verts: Vec< VertCompute >,
    }

    #[derive(Debug, Clone)]
    pub struct ComputeCollection {
        // pub _meshcomputes: Vec< MeshCompute >, //use batch instead
        pub _bbox_lower: [f32;3],
        pub _bbox_upper: [f32;3],

        pub _batch_vert: Vec< f32 >,
        pub _batch_normal: Vec< f32 >,
        pub _batch_tc: Vec< f32 >,
    }
}