1 | // Copyright (C) 2012-2015 ChaosForge Ltd
|
---|
2 | // http://chaosforge.org/
|
---|
3 | //
|
---|
4 | // This file is part of Nova libraries.
|
---|
5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * @file md5_loader.hh
|
---|
9 | * @author Kornel Kisielewicz
|
---|
10 | * @brief md5 loader
|
---|
11 | */
|
---|
12 |
|
---|
13 | #ifndef NV_FORMATS_MD5_LOADER_HH
|
---|
14 | #define NV_FORMATS_MD5_LOADER_HH
|
---|
15 |
|
---|
16 | #include <nv/common.hh>
|
---|
17 | #include <nv/stl/array.hh>
|
---|
18 | #include <nv/interface/mesh_loader.hh>
|
---|
19 |
|
---|
20 | namespace nv
|
---|
21 | {
|
---|
22 |
|
---|
23 | struct md5_vtx_pnt
|
---|
24 | {
|
---|
25 | vec3 position;
|
---|
26 | vec3 normal;
|
---|
27 | vec3 tangent;
|
---|
28 | };
|
---|
29 |
|
---|
30 | struct md5_key_t
|
---|
31 | {
|
---|
32 | transform tform;
|
---|
33 | };
|
---|
34 |
|
---|
35 | struct md5_vtx_t
|
---|
36 | {
|
---|
37 | vec2 texcoord;
|
---|
38 | };
|
---|
39 |
|
---|
40 | struct md5_vtx_pntiw
|
---|
41 | {
|
---|
42 | vec3 position;
|
---|
43 | vec3 normal;
|
---|
44 | vec3 tangent;
|
---|
45 | ivec4 boneindex;
|
---|
46 | vec4 boneweight;
|
---|
47 | };
|
---|
48 |
|
---|
49 | class md5_loader : public mesh_loader
|
---|
50 | {
|
---|
51 | public:
|
---|
52 | enum file_type { UNKNOWN, MESH, ANIMATION };
|
---|
53 |
|
---|
54 | explicit md5_loader( string_table* strings ) : mesh_loader( strings ), m_type( UNKNOWN ), m_nodes( nullptr ) {}
|
---|
55 | virtual ~md5_loader();
|
---|
56 | virtual bool load( stream& source );
|
---|
57 | virtual data_channel_set* release_mesh_data( size_t index = 0 );
|
---|
58 | virtual size_t get_nodes_data_count() const { return 1; }
|
---|
59 | virtual mesh_nodes_data* release_mesh_nodes_data( size_t = 0 );
|
---|
60 | virtual mesh_data_pack* release_mesh_data_pack();
|
---|
61 | virtual size_t get_mesh_count() const { return m_meshes.size(); }
|
---|
62 |
|
---|
63 | struct md5_weight
|
---|
64 | {
|
---|
65 | size_t joint_id;
|
---|
66 | float bias;
|
---|
67 | vec3 pos;
|
---|
68 | };
|
---|
69 |
|
---|
70 | protected:
|
---|
71 | struct md5_joint_info
|
---|
72 | {
|
---|
73 | int flags;
|
---|
74 | size_t start_index;
|
---|
75 | };
|
---|
76 |
|
---|
77 | struct md5_weight_info
|
---|
78 | {
|
---|
79 | size_t start_weight;
|
---|
80 | size_t weight_count;
|
---|
81 | };
|
---|
82 |
|
---|
83 | protected:
|
---|
84 | void reset();
|
---|
85 | void build_frame_skeleton( mesh_nodes_data* nodes, uint32 index, const array_view<md5_joint_info>& joint_info, const array_view<transform>& base_frames, const array_view<float>& frame_data );
|
---|
86 | bool prepare_mesh( mesh_nodes_data* nodes, uint32 vtx_count, data_channel_set* mdata, md5_weight* weights, md5_weight_info* weight_info );
|
---|
87 | protected:
|
---|
88 | file_type m_type;
|
---|
89 | uint32 m_md5_version;
|
---|
90 | mesh_nodes_data* m_nodes;
|
---|
91 | dynamic_array<data_channel_set*> m_meshes;
|
---|
92 | };
|
---|
93 |
|
---|
94 | }
|
---|
95 |
|
---|
96 | #endif // NV_FORMATS_MD5_LOADER_HH
|
---|