-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wmb.hpp
305 lines (263 loc) · 5.62 KB
/
wmb.hpp
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#ifndef WMB_HPP
#define WMB_HPP
#include <glm/glm.hpp>
#include <string>
#include <optional>
#include <vector>
#include <cstddef>
#include <variant>
#include <array>
#include <bitset>
namespace WMB
{
struct Euler
{
float pan, tilt, roll;
};
struct Texture
{
enum Format
{
RGBA8888 = 5,
RGB888 = 4,
RGB565 = 2,
DDS = 6
};
std::string name;
unsigned int width, height;
Format format;
bool hasMipMaps;
std::vector<std::vector<std::byte>> levels;
std::vector<std::byte> & data() {
return levels.at(0);
}
std::vector<std::byte> const & data() const {
return levels.at(0);
}
};
struct Lightmap
{
unsigned int width, height;
std::optional<unsigned int> object; // object for terrain lightmap or nullopt
std::vector<std::byte> data; // encoded in BGR
};
struct Material
{
std::string name;
bool isDefault;
};
struct Vertex
{
glm::vec3 position; // position
glm::vec2 uv; // texture coordinates
glm::vec2 lightmap; // lightmap coordinates
};
struct Triangle
{
uint16_t v1,v2,v3; // indices into the VERTEX array
uint16_t skin; // index into the SKIN array
};
struct Skin
{
enum Flags
{
FLAT = 1,
SKY = 2,
PASSABLE = 6,
SMOOTH = 14,
FLAG1 = 16,
FLAG2 = 17,
FLAG3 = 18,
FLAG4 = 19,
FLAG5 = 20,
FLAG6 = 21,
FLAG7 = 22,
FLAG8 = 23,
};
uint16_t texture; // index into the textures list
uint16_t lightmap; // index into the lightmaps list
unsigned int material; // index into the MATERIAL_INFO array
float ambient, albedo;
std::bitset<32> flags; // bit 1 = flat (no lightmap), bit 2 = sky, bit 14 = smooth
bool isFlat() const { return flags.test(FLAT); }
bool isSky() const { return flags.test(SKY); }
bool isSmooth() const { return flags.test(SMOOTH); }
};
struct Block
{
glm::vec3 bbMin; // bounding box
glm::vec3 bbMax; // bounding box
std::vector<Vertex> vertices;
std::vector<Triangle> triangles;
std::vector<Skin> skins;
};
struct Info
{
float azimuth; // sun azimuth
float elevation; // sun elevation
float gamma; // light level at black
unsigned int lightMapSize;
glm::vec4 sunColor, ambientColor; // color double word, ARGB
glm::vec4 fogColor[4];
};
struct Position
{
std::string name;
glm::vec3 origin;
Euler angle;
};
struct Light
{
enum Flags
{
HIGHRES = 0,
DYNAMIC = 1,
STATIC = 2,
CAST = 3,
};
glm::vec3 origin;
glm::vec3 color;
float range;
std::bitset<32> flags;
bool isHighRes() const {
return flags.test(HIGHRES);
}
bool isDynamic() const {
return flags.test(DYNAMIC);
}
bool isStatic() const {
return flags.test(STATIC);
}
bool isCasting() const {
return flags.test(CAST);
}
};
struct Sound
{
glm::vec3 origin;
float volume;
long range;
std::bitset<32> flags; // hurr?
std::string fileName;
};
struct PathNode
{
glm::vec3 position;
std::array<float, 6> skills;
};
struct PathEdge
{
unsigned int node1, node2; // node numbers of the edge, starting with 1
float length;
float bezier;
float weight;
float skill;
};
struct Path
{
std::string name;
std::vector<PathNode> nodes;
std::vector<PathEdge> edges;
};
struct Entity
{
enum Flags
{
FLAG1 = 0,
FLAG2 = 1,
FLAG3 = 2,
FLAG4 = 3,
FLAG5 = 4,
FLAG6 = 5,
FLAG7 = 6,
FLAG8 = 7,
INVISIBLE = 8,
PASSABLE = 9,
TRANSLUCENT = 10, // transparent
OVERLAY = 12, // for models and panels
SPOTLIGHT = 13,
ZNEAR = 14,
NOFILTER = 16, // point filtering
UNLIT = 17, // no light from environment
SHADOW = 18, // cast dynamic shadows
LIGHT = 19, // tinted by own light color
NOFOG = 20, // ignores fog
BRIGHT = 21, // additive blending
DECAL = 22, // sprite without backside
METAL = 22, // use metal material
CAST = 23, // don't receive shadows
POLYGON = 26, // polygonal collision detection
};
bool isOldEntity;
glm::vec3 origin;
Euler angle;
glm::vec3 scale;
std::string name;
std::string fileName;
std::string action;
std::array<float, 20> skill;
std::bitset<32> flags;
float ambient;
float albedo;
std::optional<unsigned long> path; // attached path index
std::optional<unsigned long> attachedEntity; // attached entity index
std::string material;
std::string string1;
std::string string2;
};
struct Region
{
std::string name;
glm::vec3 minimum;
glm::vec3 maximum;
};
enum class ObjectType
{
Position = 0,
Light = 1,
Sound = 2,
Path = 3,
Entity = 4,
Region = 5,
};
struct Level
{
Info info;
std::vector<Texture> textures;
std::vector<Material> materials;
std::vector<Lightmap> lightmaps;
std::vector<Lightmap> terrain_lightmaps;
std::vector<Block> blocks;
std::vector<std::variant<
Position,
Light,
Sound,
Path,
Entity,
Region
>> objects;
};
struct LoadOptions
{
enum CoordinateSystem
{
Gamestudio = 0,
OpenGL = 1,
DirectX = 2,
};
enum Flags
{
LOG_WARNINGS = 0,
LOG_ERRORS = 1,
LOG_VERBOSE = 2
};
//! Converts the WMB coordinates into the given coordinate system.
CoordinateSystem targetCoordinateSystem = Gamestudio;
std::bitset<3> flags = LOG_WARNINGS | LOG_ERRORS;
bool log_warnings() const { return flags.test(LOG_WARNINGS); }
bool log_errors() const { return flags.test(LOG_ERRORS); }
bool log_verbose() const { return flags.test(LOG_VERBOSE); }
};
std::optional<Level> load(std::string const & fileName, LoadOptions const & options = LoadOptions());
}
#endif // WMB_HPP