-
Notifications
You must be signed in to change notification settings - Fork 4
/
mesh_file.h
296 lines (220 loc) · 8.78 KB
/
mesh_file.h
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
#pragma once
#include "objects/base_object.h"
#include "IFF_file.h"
#include "PrimitiveType.h"
#include "objects/animated_object.h"
#include "objects/geometry_common.h"
#include <sstream>
#include <fbxsdk.h>
struct SortedIndex
{
std::vector<float> CoordinateDirection;
uint32_t IndexValue;
std::vector<uint16_t> Indicie;
};
class LODFileList : public Base_object
{
public:
LODFileList() { }
void AddLODFile(const std::string& name)
{
auto returnValue = std::find(m_LODFile.begin(), m_LODFile.end(), name);
if (returnValue == m_LODFile.end() || m_LODFile.empty())
m_LODFile.push_back(name); // Make sure there are duplicates
}
// overrides
virtual bool is_object_correct() const override { return true; }
virtual void store(const std::string& path, const Context& context) override { };
virtual std::set<std::string> get_referenced_objects() const override
{
std::set<std::string> names;
names.insert(m_LODFile.begin(), m_LODFile.end());
return move(names);
};
virtual void resolve_dependencies(const Context&) override { }
virtual void set_object_name(const std::string& name) override { m_name = name; }
virtual std::string get_object_name() const override { return m_name; }
private:
std::vector<std::string> m_LODFile;
std::string m_name;
};
class LODObject : public Base_object // This object contains data related to the LOD file listings. The boxes inside are meant for collision
{
public:
LODObject() { }
void AddLODName(const std::string& name)
{
auto returnValue = std::find(m_LODName.begin(), m_LODName.end(), name);
if (returnValue == m_LODName.end() || m_LODName.empty())
m_LODName.push_back(name); // Make sure there are duplicates
}
void AddBoundBox(std::vector<float> vec3)
{
m_BoundingBox.push_back(vec3);
}
void AddCenterPoint(std::vector<float> vec3)
{
m_centerPoints.push_back(vec3);
}
void AddRadius(float radius)
{
m_sphereRadius.push_back(radius);
}
void AddVertex(std::vector<float> vec3)
{
m_triangleVertices.push_back(vec3);
}
void AddIndex(uint32_t index)
{
m_indexList.push_back(index);
}
// overrides
virtual bool is_object_correct() const override { return true; }
virtual void store(const std::string& path, const Context& context) override { };
virtual std::set<std::string> get_referenced_objects() const override
{
std::set<std::string> names;
names.insert(m_LODName.begin(), m_LODName.end());
return move(names);
};
virtual void resolve_dependencies(const Context&) override { }
virtual void set_object_name(const std::string& name) override { m_name = name; }
virtual std::string get_object_name() const override { return m_name; }
private:
/* Some of these items, I will keep here for any future updates */
std::vector<std::string> m_LODName;
std::string m_name;
std::vector<std::vector<float>> m_BoundingBox;
std::vector<std::vector<float>> m_centerPoints;
std::vector<float> m_sphereRadius;
std::vector<std::vector<float>> m_triangleVertices;
std::vector<uint32_t> m_indexList;
};
/*
The LOD parser is only meant for Level of detail. It does not contain any mesh data.
The vertices and indicies that it contains are related to collision which for FBX this does not matter
*/
class LODParser : public IFF_visitor
{
public:
virtual void section_begin(const std::string& name, uint8_t* data_ptr, size_t data_size, uint32_t depth) override;
virtual void parse_data(const std::string& name, uint8_t* data_ptr, size_t data_size) override;
virtual bool is_object_parsed() const override;
std::shared_ptr<Base_object> get_parsed_object() const { return std::dynamic_pointer_cast<Base_object>(m_object); }
private:
std::shared_ptr<LODObject> m_object;
};
struct StaticMeshVertexInfo
{
std::vector<float> triangleVertices;
std::vector<float> triangleNormals;
std::vector<Graphics::Tex_coord> UVs;
};
class meshObject : public Base_object // This object contains shader data
{
public:
/* First class definitions */
class Shader_appliance
{
public:
Shader_appliance()
{
m_texels_array.reserve(8);
}
Shader_appliance(const std::string& name) : m_name(name) { }
const std::string& get_name() const { return m_name; }
std::vector<uint32_t>& get_light_indexes() { return m_light_indexes; }
std::vector<Graphics::Triangle_indexed>& get_triangles() { return m_triangles; }
std::vector<std::vector<float>>& get_normals() { return m_Normals; }
std::vector <std::vector<Graphics::Tex_coord>>& GetTexelArray() { return m_texels_array; }
void add_lighting_normal(const Geometry::Vector4& light_norm) { m_lighting_normals.emplace_back(light_norm); }
std::vector<Geometry::Vector4>& getNormalLighting() { return m_lighting_normals; }
void set_definition(const std::shared_ptr<Shader> shader_def) { m_shader_definition = shader_def; }
const std::shared_ptr<Shader>& get_definition() const { return m_shader_definition; }
void SetFlags(uint32_t flags) { m_flags = flags; }
int GetNumTextureCoordinateSets() { return (m_flags >> 8) & 0x0F; }
int getCoordinateSet(int textureCoordinateSet)
{
int shiftValue = 12 + (textureCoordinateSet * 2);
return ((m_flags >> shiftValue) & 0x03) + 1;
}
bool hasPosition() { return (m_flags & 0x00000001) != 0; }
bool isTransformed() { return (m_flags & 0x00000002) != 0; }
bool hasNormals() { return(m_flags & 0x00000004) != 0; }
bool hasPointSize() { return (m_flags & 0x00000020) != 0; }
bool hasColor0() { return (m_flags & 0x00000008) != 0; }
bool hasColor1() { return (m_flags & 0x00000010) != 0; }
void SetTextureCoordinateDim(int textureCoordinateSet, int dim)
{
const unsigned int shift = static_cast<unsigned int>(12 + (textureCoordinateSet * 2));
m_flags = (m_flags & ~(static_cast<unsigned int>(0x03) << shift)) | (static_cast<uint32_t>(dim - 1) << shift);
}
void SetNumberOfTextureCoordinateSets(int numberofTextures)
{
m_flags = (m_flags & ~(0b1111 << 8)) | (static_cast<uint32_t>(numberofTextures) << 8);
}
void setNumberofMeshVertices(uint32_t number) { m_NumberofMeshVertices = number; }
uint32_t getNumberofMeshVertices() { return m_NumberofMeshVertices; }
void AddVertex(std::vector<float> vec3) { m_triangleVertices.push_back(vec3); }
void AddNormal(std::vector<float> vec3) { m_Normals.push_back(vec3); }
std::vector<std::vector<float>>& GetTriangleVertices() { return m_triangleVertices; }
bool get32BitIndexState() { return m_is32BitIndex; }
void set32BitIndexState(bool state) { m_is32BitIndex = state; }
int getInfoCounter() { return m_InfoCounter; }
void AddInfoCounter() { m_InfoCounter++; }
private:
/* Some of these items, I will keep here for any future updates */
std::string m_name;
std::vector<uint32_t> m_light_indexes;
std::vector <std::vector<Graphics::Tex_coord>> m_texels_array;
std::vector<Graphics::Triangle_indexed> m_triangles;
std::shared_ptr<Shader> m_shader_definition;
std::vector<std::vector<float>> m_triangleVertices;
std::vector<std::vector<float>> m_Normals;
std::vector<Geometry::Vector4> m_lighting_normals;
uint32_t m_flags;
uint32_t m_NumberofMeshVertices = 0;
bool m_is32BitIndex = false;
int m_InfoCounter = 0;
};
/* Now functions */
meshObject() { }
// overrides
virtual bool is_object_correct() const override { return true; }
virtual void store(const std::string& path, const Context& context) override;
virtual std::set<std::string> get_referenced_objects() const override
{
std::set<std::string> names;
std::for_each(m_shaders.begin(), m_shaders.end(),
[&names](const Shader_appliance& shader) { names.insert(shader.get_name()); });
return names;
};
virtual void resolve_dependencies(const Context& context) override;
virtual void set_object_name(const std::string& name) override { m_name = name; }
virtual std::string get_object_name() const override { return m_name; }
Shader_appliance& get_current_shader() { assert(m_shaders.empty() == false); return m_shaders.back(); }
void add_new_shader(const std::string& name) { m_shaders.emplace_back(name); }
Shader_appliance &GetShader() { return m_shaders.back(); }
void SetShaderCount(uint16_t value)
{
m_ShaderCount = value;
m_shaders.reserve(value);
}
uint8_t GetShaderCount() { return m_ShaderCount; }
private:
std::string m_name;
std::vector<std::string> m_LODName;
std::vector<Shader_appliance> m_shaders;
int m_maxUVChannelCount = 0;
uint16_t m_ShaderCount = 1;// all shaders static objects have a value of 1
};
class meshParser : public IFF_visitor
{
public:
virtual void section_begin(const std::string& name, uint8_t* data_ptr, size_t data_size, uint32_t depth) override;
virtual void parse_data(const std::string& name, uint8_t* data_ptr, size_t data_size) override;
virtual bool is_object_parsed() const override;
std::shared_ptr<Base_object> get_parsed_object() const { return std::dynamic_pointer_cast<Base_object>(m_object); }
private:
std::shared_ptr<meshObject> m_object;
};