21 std::cout <<
"Mesh validation error: there are no vertices in the mesh." << std::endl;
27 std::cout <<
"Mesh validation error: the index amount must be multiple of 3." << std::endl;
32 std::cout <<
"Mesh validation error: last material was not closed." << std::endl;
46 if (vertices.size() == 0) {
52 bool index_clockwise =
true;
54 index_clockwise = !index_clockwise;
55 if (index_clockwise) {
92 std::copy(vertices.begin(), vertices.end(), std::back_inserter(
_vertices));
108 const size_t open_index =
_indexes.size();
116 if (open_index % 3 != 0) {
117 std::cout <<
"open_index % 3 != 0" << std::endl;
120 _materials.emplace_back(material_name, open_index, 0);
124 const size_t close_index =
_indexes.size();
126 _materials.back().index_start == close_index ||
132 if (
_indexes.empty() || close_index % 3 != 0) {
144 std::stringstream out;
147 out <<
"# List of geometric vertices, with (x, y, z) coordinates." << std::endl;
149 out <<
"v " << v.x <<
" " << v.y <<
" " << v.z << std::endl;
153 out << std::endl <<
"# List of texture coordinates, in (u, v) coordinates, these will vary between 0 and 1." << std::endl;
154 for (
auto &vt :
_uvs) {
155 out <<
"vt " << vt.x <<
" " << vt.y << std::endl;
160 out << std::endl <<
"# List of vertex normals in (x, y, z) form; normals might not be unit vectors." << std::endl;
162 out <<
"vn " << vn.x <<
" " << vn.y <<
" " << vn.z << std::endl;
167 out << std::endl <<
"# Polygonal face element." << std::endl;
170 size_t index_counter = 0u;
175 if (it_m->index_end == index_counter) {
179 if (it_m->index_start == index_counter) {
180 out <<
"\nusemtl " << it_m->name << std::endl;
185 out <<
"f " << *it; ++it;
186 out <<
" " << *it; ++it;
187 out <<
" " << *it << std::endl; ++it;
200 std::stringstream out;
203 out <<
"# List of geometric vertices, with (x, y, z) coordinates." << std::endl;
206 out <<
"v " << v.x <<
" " << v.z <<
" " << v.y << std::endl;
210 out << std::endl <<
"# Polygonal face element." << std::endl;
213 size_t index_counter = 0u;
218 if (it_m->index_end == index_counter) {
222 if (it_m->index_start == index_counter) {
223 out <<
"\nusemtl " << it_m->name << std::endl;
229 out <<
"f " << *it; ++it;
230 const auto i_2 = *it; ++it;
231 const auto i_3 = *it; ++it;
232 out <<
" " << i_3 <<
" " << i_2 << std::endl;
242 return "Invalid Mesh";
245 std::stringstream out;
303 [=](
size_t index) {
return index + v_num;});
315 mat.index_start += i_num;
316 mat.index_end += i_num;
void AddUV(uv_type uv)
Appends a vertex to the vertices list, they will be read 3 in 3.
void AddVertex(vertex_type vertex)
Appends a vertex to the vertices list.
bool IsValid() const
Check if the mesh can be valid or not.
size_t GetVerticesNum() const
void AddNormal(normal_type normal)
Appends a normal to the normal list.
void AddTriangleFan(const std::vector< vertex_type > &vertices)
Adds a triangle fan to the mesh, vertex order is counterclockwise.
const std::vector< normal_type > & GetNormals() const
size_t GetIndexesNum() const
Mesh & operator+=(const Mesh &rhs)
Merges two meshes into a single mesh.
void AddIndex(index_type index)
Appends a index to the indexes list.
size_t GetLastVertexIndex() const
Returns the index of the last added vertex (number of vertices).
This file contains definitions of common data structures used in traffic manager. ...
const std::vector< index_type > & GetIndexes() const
void AddVertices(const std::vector< vertex_type > &vertices)
Appends a vertex to the vertices list.
friend Mesh operator+(const Mesh &lhs, const Mesh &rhs)
void AddMaterial(const std::string &material_name)
Starts applying a new material to the new added triangles.
void EndMaterial()
Stops applying the material to the new added triangles.
#define DEBUG_ASSERT(predicate)
Material that references the vertex index start and end of a mesh where it is affecting.
const std::vector< uv_type > & GetUVs() const
std::vector< material_type > _materials
const std::vector< material_type > & GetMaterials() const
void AddTriangleStrip(const std::vector< vertex_type > &vertices)
Adds a triangle strip to the mesh, vertex order is counterclockwise.
Mesh data container, validator and exporter.
std::string GenerateOBJ() const
Returns a string containing the mesh encoded in OBJ.
std::string GeneratePLY() const
Returns a string containing the mesh encoded in PLY.
std::string GenerateOBJForRecast() const
Returns a string containing the mesh encoded in OBJ.
std::vector< index_type > _indexes
std::vector< uv_type > _uvs
const std::vector< vertex_type > & GetVertices() const
std::vector< normal_type > _normals
std::vector< vertex_type > _vertices