14#ifdef LIBCARLA_INCLUDED_FROM_UE4
27 const std::string &new_name,
56 Mesh(
const std::vector<vertex_type> &vertices = {},
57 const std::vector<normal_type> &normals = {},
58 const std::vector<index_type> &indexes = {},
59 const std::vector<uv_type> &uvs = {})
86 void AddVertices(
const std::vector<vertex_type> &vertices);
98 void AddUVs(
const std::vector<uv_type> & uv);
101 void AddMaterial(
const std::string &material_name);
124 const std::vector<vertex_type> &
GetVertices()
const;
130 const std::vector<normal_type> &
GetNormals()
const;
132 const std::vector<index_type>&
GetIndexes()
const;
138 const std::vector<uv_type> &
GetUVs()
const;
157#ifdef LIBCARLA_INCLUDED_FROM_UE4
166 Mesh.Vertices.Add(FVector{1e2f * Vertex.x, 1e2f * Vertex.y, 1e2f * Vertex.z});
170 TArray<FTriIndices> TriIndices;
171 for (
auto i = 0u; i < Indexes.size(); i += 3)
173 FTriIndices Triangle;
175 Mesh.Triangles.Add(Indexes[i] - 1);
177 Mesh.Triangles.Add(Indexes[i + 2] - 1);
178 Mesh.Triangles.Add(Indexes[i + 1] - 1);
180 Triangle.v0 = Indexes[i] - 1;
181 Triangle.v1 = Indexes[i + 2] - 1;
182 Triangle.v2 = Indexes[i + 1] - 1;
183 TriIndices.Add(Triangle);
187 TArray<FVector> Normals;
188 Mesh.Normals.Init(FVector::UpVector,
Mesh.Vertices.Num());
190 for (
const auto &Triangle : TriIndices) {
192 const FVector U =
Mesh.Vertices[Triangle.v1] -
Mesh.Vertices[Triangle.v0];
193 const FVector V =
Mesh.Vertices[Triangle.v2] -
Mesh.Vertices[Triangle.v0];
194 Normal.X = (U.Y * V.Z) - (U.Z * V.Y);
195 Normal.Y = (U.Z * V.X) - (U.X * V.Z);
196 Normal.Z = (U.X * V.Y) - (U.Y * V.X);
198 Normal = Normal.GetSafeNormal(.0001f);
199 if (Normal != FVector::ZeroVector)
202 if (FVector::DotProduct(Normal, FVector(0,0,1)) < 0)
206 Mesh.Normals[Triangle.v0] = Normal;
207 Mesh.Normals[Triangle.v1] = Normal;
208 Mesh.Normals[Triangle.v2] = Normal;
212 for (
const auto uv :
GetUVs())
215 Mesh.UV0.Add(FVector2D{uv.x, uv.y});
auto end() const noexcept
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 中编码的网格的字符串。单位为米。
Mesh(const std::vector< vertex_type > &vertices={}, const std::vector< normal_type > &normals={}, const std::vector< index_type > &indexes={}, const std::vector< uv_type > &uvs={})
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
返回最后添加的顶点索引(顶点数)。
friend Mesh operator+(const Mesh &lhs, const Mesh &rhs)
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
A definition of a Carla Mesh.
MeshMaterial(const std::string &new_name, size_t start=0u, size_t end=0u)