14#ifdef LIBCARLA_INCLUDED_FROM_UE4
28 const std::string &new_name,
57 Mesh(
const std::vector<vertex_type> &vertices = {},
58 const std::vector<normal_type> &normals = {},
59 const std::vector<index_type> &indexes = {},
60 const std::vector<uv_type> &uvs = {})
87 void AddVertices(
const std::vector<vertex_type> &vertices);
99 void AddUVs(
const std::vector<uv_type> & uv);
102 void AddMaterial(
const std::string &material_name);
129 const std::vector<vertex_type> &
GetVertices()
const;
135 const std::vector<normal_type> &
GetNormals()
const;
137 const std::vector<index_type>&
GetIndexes()
const;
143 const std::vector<uv_type> &
GetUVs()
const;
162#ifdef LIBCARLA_INCLUDED_FROM_UE4
171 Mesh.Vertices.Add(FVector{1e2f * Vertex.x, 1e2f * Vertex.y, 1e2f * Vertex.z});
175 TArray<FTriIndices> TriIndices;
176 for (
auto i = 0u; i < Indexes.size(); i += 3)
178 FTriIndices Triangle;
180 Mesh.Triangles.Add(Indexes[i] - 1);
182 Mesh.Triangles.Add(Indexes[i + 2] - 1);
183 Mesh.Triangles.Add(Indexes[i + 1] - 1);
185 Triangle.v0 = Indexes[i] - 1;
186 Triangle.v1 = Indexes[i + 2] - 1;
187 Triangle.v2 = Indexes[i + 1] - 1;
188 TriIndices.Add(Triangle);
192 TArray<FVector> Normals;
193 Mesh.Normals.Init(FVector::UpVector,
Mesh.Vertices.Num());
195 for (
const auto &Triangle : TriIndices) {
197 const FVector U =
Mesh.Vertices[Triangle.v1] -
Mesh.Vertices[Triangle.v0];
198 const FVector V =
Mesh.Vertices[Triangle.v2] -
Mesh.Vertices[Triangle.v0];
199 Normal.X = (U.Y * V.Z) - (U.Z * V.Y);
200 Normal.Y = (U.Z * V.X) - (U.X * V.Z);
201 Normal.Z = (U.X * V.Y) - (U.Y * V.X);
203 Normal = Normal.GetSafeNormal(.0001f);
204 if (Normal != FVector::ZeroVector)
208 if (FVector::DotProduct(Normal, FVector(0,0,1)) < 0)
212 Mesh.Normals[Triangle.v0] = Normal;
213 Mesh.Normals[Triangle.v1] = Normal;
214 Mesh.Normals[Triangle.v2] = Normal;
218 for (
const auto uv :
GetUVs())
221 Mesh.UV0.Add(FVector2D{uv.x, uv.y});
Mesh data container, validator and exporter.
void AddIndex(index_type index)
Appends a index to the indexes list.
void AddVertex(vertex_type vertex)
Appends a vertex to the vertices list.
std::vector< vertex_type > _vertices
void AddVertices(const std::vector< vertex_type > &vertices)
Appends a vertex to the vertices list.
std::string GenerateOBJ() const
Returns a string containing the mesh encoded in OBJ.
void AddUV(uv_type uv)
Appends a vertex to the vertices list, they will be read 3 in 3.
Mesh & ConcatMesh(const Mesh &rhs, int num_vertices_to_link)
Merges two meshes into a single mesh
std::vector< index_type > _indexes
const std::vector< uv_type > & GetUVs() const
const std::vector< index_type > & GetIndexes() const
std::string GeneratePLY() const
Returns a string containing the mesh encoded in 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
Check if the mesh can be valid or not.
void AddUVs(const std::vector< uv_type > &uv)
Appends uvs.
std::string GenerateOBJForRecast() const
Returns a string containing the mesh encoded in OBJ.
size_t GetVerticesNum() const
void AddNormal(normal_type normal)
Appends a normal to the normal list.
std::vector< normal_type > _normals
std::vector< material_type > _materials
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.
Mesh & operator+=(const Mesh &rhs)
Merges two meshes into a single mesh
const std::vector< material_type > & GetMaterials() const
const std::vector< normal_type > & GetNormals() const
size_t GetLastVertexIndex() const
Returns the index of the last added vertex (number of vertices).
friend Mesh operator+(const Mesh &lhs, const Mesh &rhs)
void AddTriangleFan(const std::vector< vertex_type > &vertices)
Adds a triangle fan to the mesh, vertex order is counterclockwise.
std::vector< uv_type > _uvs
size_t GetIndexesNum() const
void AddTriangleStrip(const std::vector< vertex_type > &vertices)
Adds a triangle strip to the mesh, vertex order is counterclockwise.
const std::vector< vertex_type > & GetVertices() const
This file contains definitions of common data structures used in traffic manager.
A definition of a Carla Mesh.
Material that references the vertex index start and end of a mesh where it is affecting.
MeshMaterial(const std::string &new_name, size_t start=0u, size_t end=0u)