00001
00008 #ifndef _MSMODEL_H
00009 #define _MSMODEL_H
00010
00011 #include "model.h"
00012
00013 #include <gfx/mat4.h>
00014 #include <vector>
00015
00019 class MSModel : public Model {
00020 public:
00024 struct Mesh {
00025 int material_idx;
00026 vector<int> triangle_idx;
00027 };
00028
00033 struct Triangle {
00034 int vertex_idx[3];
00035 Vec3f normals[3];
00036 Vec3f s, t;
00037 };
00038
00042 struct Vertex {
00043 Vec3f pos;
00044 char bone_idx;
00045 };
00046
00050 struct Keyframe {
00051 int bone_idx;
00052 float time;
00053 Vec3f value;
00054 };
00055
00059 struct Bone {
00060 Mat4 relative;
00061 Mat4 absolute;
00062 Mat4 current;
00063
00064 vector<Keyframe> translate_frames;
00065 vector<Keyframe> rotate_frames;
00066
00067 int cur_translate_frame;
00068 int cur_rotate_frame;
00069
00070 int parent_idx;
00071 };
00072
00073 MSModel( string dir, string filename );
00074
00075 virtual ~MSModel( void );
00076
00077 virtual void render( void );
00078
00085 virtual void tick( double t );
00086
00090 void reload_textures( void );
00091
00096 bool load_model( string dir, string filename );
00097
00098 virtual Vec3 get_min( void ) { return _min; }
00099 virtual Vec3 get_max( void ) { return _max; }
00100
00101 virtual string get_info() { return "model=\"" + _filename + "\""; }
00102
00103 Vertex* get_vertices( void ) { return _vertices; }
00104 Triangle* get_triangles( void ) { return _triangles; }
00105
00106 int get_num_vertices( void ) { return _num_vertices; }
00107 int get_num_triangles( void ) { return _num_triangles; }
00108
00109 private:
00117 void _setup_bones( void );
00118
00122 void _reset_animation( void );
00123
00127 Vec3 _interp_keyframes( int curframe, const vector<Keyframe>& keyframes );
00128
00133 void _compare_bbox( Vec3 newpos );
00134 protected:
00135 string _dir;
00136 string _filename;
00137 Material* _materials;
00138 uint _num_materials;
00139 Mesh* _meshes;
00140 uint _num_meshes;
00141 Triangle* _triangles;
00142 uint _num_triangles;
00143 Vertex* _vertices;
00144 uint _num_vertices;
00145 Bone* _bones;
00146 uint _num_bones;
00147 double _time;
00148 double _curtime;
00149 Vec3 _min;
00150 Vec3 _max;
00151 };
00152
00153 #endif // header guard