23 std::cout <<
"Mesh validation error: there are no vertices in the mesh." << std::endl;
29 std::cout <<
"Mesh validation error: the index amount must be multiple of 3." << std::endl;
34 std::cout <<
"Mesh validation error: last material was not closed." << std::endl;
54 if (vertices.size() == 0) {
70 bool index_clockwise =
true;
76 index_clockwise =!index_clockwise;
77 if (index_clockwise) {
125 std::copy(vertices.begin(), vertices.end(), std::back_inserter(
_vertices));
141 std::copy(uv.begin(), uv.end(), std::back_inserter(
_uvs));
145 const size_t open_index =
_indexes.size();
153 if (open_index % 3 != 0) {
154 std::cout <<
"open_index % 3 != 0" << std::endl;
157 _materials.emplace_back(material_name, open_index, 0);
161 const size_t close_index =
_indexes.size();
163 _materials.back().index_start == close_index ||
169 if (
_indexes.empty() || close_index % 3 != 0) {
181 std::stringstream out;
184 out <<
"# List of geometric vertices, with (x, y, z) coordinates." << std::endl;
186 out <<
"v " << v.x <<
" " << v.y <<
" " << v.z << std::endl;
190 out << std::endl <<
"# List of texture coordinates, in (u, v) coordinates, these will vary between 0 and 1." << std::endl;
191 for (
auto &vt :
_uvs) {
192 out <<
"vt " << vt.x <<
" " << vt.y << std::endl;
197 out << std::endl <<
"# List of vertex normals in (x, y, z) form; normals might not be unit vectors." << std::endl;
199 out <<
"vn " << vn.x <<
" " << vn.y <<
" " << vn.z << std::endl;
204 out << std::endl <<
"# Polygonal face element." << std::endl;
207 size_t index_counter = 0u;
212 if (it_m->index_end == index_counter) {
216 if (it_m->index_start == index_counter) {
217 out <<
"\nusemtl " << it_m->name << std::endl;
222 out <<
"f " << *it; ++it;
223 out <<
" " << *it; ++it;
224 out <<
" " << *it << std::endl; ++it;
237 std::stringstream out;
240 out <<
"# List of geometric vertices, with (x, y, z) coordinates." << std::endl;
243 out <<
"v " << v.x <<
" " << v.z <<
" " << v.y << std::endl;
247 out << std::endl <<
"# Polygonal face element." << std::endl;
250 size_t index_counter = 0u;
255 if (it_m->index_end == index_counter) {
259 if (it_m->index_start == index_counter) {
260 out <<
"\nusemtl " << it_m->name << std::endl;
264 out <<
"f " << *it; ++it;
265 const auto i_2 = *it; ++it;
266 const auto i_3 = *it; ++it;
267 out <<
" " << i_3 <<
" " << i_2 << std::endl;
277 return "Invalid Mesh";
280 std::stringstream out;
341 const size_t vertex_to_start_concating = v_num - num_vertices_to_link;
342 for(
size_t i = 1; i < num_vertices_to_link; ++i ) {
343 _indexes.push_back( vertex_to_start_concating + i );
344 _indexes.push_back( vertex_to_start_concating + i + 1 );
347 _indexes.push_back( vertex_to_start_concating + i + 1);
356 [=](
size_t index) {return index + v_num; });
368 mat.index_start += i_num;
369 mat.index_end += i_num;
394 [=](
size_t index) {return index + v_num;});
406 mat.index_start += i_num;
407 mat.index_end += i_num;
#define DEBUG_ASSERT(predicate)
void AddIndex(index_type index)
将索引附加到索引列表。
void AddVertex(vertex_type vertex)
将顶点附加到顶点列表。
std::vector< vertex_type > _vertices
void AddVertices(const std::vector< vertex_type > &vertices)
将顶点附加到顶点列表。
std::string GenerateOBJ() const
返回包含 OBJ 中编码的网格的字符串。单位为米。它位于虚幻空间中。
void AddUV(uv_type uv)
将一个顶点附加到顶点列表,它们将被读取 3 个中的 3 个。
Mesh & ConcatMesh(const Mesh &rhs, int num_vertices_to_link)
将两个网格合并为一个网格
std::vector< index_type > _indexes
const std::vector< uv_type > & GetUVs() const
const std::vector< index_type > & GetIndexes() const
std::string GeneratePLY() const
返回包含 PLY 中编码的网格的字符串。单位为米。
bool IsValid() const
检查网格是否有效。
void AddUVs(const std::vector< uv_type > &uv)
添加纹理映射坐标(Texture-Mapping Coordinates, UV)
std::string GenerateOBJForRecast() const
返回包含 OBJ 中编码的网格的字符串。单位为米。 此函数导出 OBJ 文件,供 Recast 库专门使用。更改构建面的方向和坐标空间。
size_t GetVerticesNum() const
void AddNormal(normal_type normal)
将法线附加到法线列表。
std::vector< normal_type > _normals
std::vector< material_type > _materials
void AddMaterial(const std::string &material_name)
开始将新材质应用到新添加的三角形。
void EndMaterial()
停止将材质应用到新添加的三角形。
Mesh & operator+=(const Mesh &rhs)
将两个网格合并为一个网格
const std::vector< material_type > & GetMaterials() const
const std::vector< normal_type > & GetNormals() const
size_t GetLastVertexIndex() const
返回最后添加的顶点索引(顶点数)。
void AddTriangleFan(const std::vector< vertex_type > &vertices)
向网格添加三角形扇形,顶点顺序为逆时针。
std::vector< uv_type > _uvs
size_t GetIndexesNum() const
void AddTriangleStrip(const std::vector< vertex_type > &vertices)
向网格添加三角形带,顶点顺序为逆时针。
const std::vector< vertex_type > & GetVertices() const
Mesh operator+(const Mesh &lhs, const Mesh &rhs)