Update README.md
[tar-legacy.git] / MCDV / mdl.hpp
1 #pragma once
2 #include <string>
3 #include <vector>
4 #include <iostream>
5 #include <fstream>
6
7 #include "util.h"
8 #include "vector.h"
9
10 namespace mdl
11 {
12 #pragma pack(push, 1)
13
14 struct header
15 {
16 int id;
17 int version;
18
19 int checksum; // this has to be the same in the phy and vtx files to load!
20
21 char name[64];
22 int length;
23
24 vec3 eyeposition; // ideal eye position
25
26 vec3 illumposition; // illumination center
27
28 vec3 hull_min; // ideal movement hull size
29 vec3 hull_max;
30
31 vec3 view_bbmin; // clipping bounding box
32 vec3 view_bbmax;
33
34 int flags;
35
36 int numbones; // bones
37 int boneindex;
38
39 int numbonecontrollers; // bone controllers
40 int bonecontrollerindex;
41
42 int numhitboxsets;
43 int hitboxsetindex;
44
45 // file local animations? and sequences
46 //private:
47 int numlocalanim; // animations/poses
48 int localanimindex; // animation descriptions
49
50 int numlocalseq; // sequences
51 int localseqindex;
52
53 // raw textures
54 int numtextures;
55 int textureindex;
56
57 // raw textures search paths
58 int numcdtextures;
59 int cdtextureindex;
60
61 // replaceable textures tables
62 int numskinref;
63 int numskinfamilies;
64 int skinindex;
65
66 int numbodyparts;
67 int bodypartindex;
68
69 // queryable attachable points
70 //private:
71 int numlocalattachments;
72 int localattachmentindex;
73
74 // animation node to animation node transition graph
75 //private:
76 int numlocalnodes;
77 int localnodeindex;
78 int localnodenameindex;
79
80 int numflexdesc;
81 int flexdescindex;
82
83 int numflexcontrollers;
84 int flexcontrollerindex;
85
86 int numflexrules;
87 int flexruleindex;
88
89 int numikchains;
90 int ikchainindex;
91
92 int nummouths;
93 int mouthindex;
94
95 //private:
96 int numlocalposeparameters;
97 int localposeparamindex;
98
99 int surfacepropindex;
100
101 // Key values
102 int keyvalueindex;
103 int keyvaluesize;
104
105 int numlocalikautoplaylocks;
106 int localikautoplaylockindex;
107
108 // The collision model mass that jay wanted
109 float mass;
110 int contents;
111
112 // external animations, models, etc.
113 int numincludemodels;
114 int includemodelindex;
115
116 // for demand loaded animation blocks
117 int szanimblocknameindex;
118 int numanimblocks;
119 int animblockindex;
120
121 int bonetablebynameindex;
122 char constdirectionallightdot;
123 char rootLOD;
124 char numAllowedRootLODs;
125 char unused[1];
126 int unused4; // zero out if version < 47
127 int numflexcontrollerui;
128 int flexcontrolleruiindex;
129 float flVertAnimFixedPointScale;
130 int unused3[1];
131 int studiohdr2index;
132 int unused2[1];
133 };
134
135 // skin info
136 struct textureHeader
137 {
138 int name_offset; // Offset for null-terminated string
139 int flags;
140 int used; // ??
141
142 int unused; // ??
143
144 int material; // Placeholder for IMaterial
145 int client_material; // Placeholder for void*
146
147 int unused2[10];
148 };
149
150 #pragma pack(pop)
151 }
152
153 class mdl_model : public verboseControl
154 {
155 public:
156 mdl::header header;
157
158 mdl_model(std::string mdl, bool verbose)
159 {
160 this->use_verbose = verbose;
161 std::ifstream reader(mdl, std::ios::in | std::ios::binary);
162
163 if (!reader) {
164 throw std::exception("MDL::LOAD FAILED"); return;
165 }
166
167
168 reader.read((char*)&this->header, sizeof(this->header));
169 this->debug("Version", this->header.version);
170
171 //Read texture data
172 reader.seekg(this->header.cdtextureindex);
173
174 mdl::textureHeader test;
175 reader.read((char*)&test, sizeof(test));
176
177 reader.seekg(test.name_offset - sizeof(mdl::textureHeader), std::ios::cur);
178
179 std::string name = "";
180 while (true)
181 {
182 char c;
183 reader.read(&c, 1);
184
185 if (c == (char)0)
186 break;
187
188 name += c;
189 }
190
191 this->debug(name);
192
193
194 reader.close();
195 }
196
197 virtual ~mdl_model() {}
198 };