Struct TTriangle

Nested Relationships

Nested Types

Struct Documentation

struct TTriangle

A triangle (float coordinates) with RGBA colors (u8) and UV (texture coordinates) for each vertex. Note that not all the fields must be filled in, it depends on the consumer of the structure.

The structure is memory packed to 1-byte, to ensure it can be used in GPU memory vertex arrays without unexpected paddings.

See also

opengl::Scene, CSetOfTexturedTriangles

Public Functions

TTriangle() = default
inline explicit TTriangle(const mrpt::math::TPolygon3D &p)
inline explicit TTriangle(const mrpt::math::TPoint3Df &p1, const mrpt::math::TPoint3Df &p2, const mrpt::math::TPoint3Df &p3)

Constructor from 3 points (default normals are computed)

inline explicit TTriangle(const mrpt::math::TPoint3Df &p1, const mrpt::math::TPoint3Df &p2, const mrpt::math::TPoint3Df &p3, const mrpt::math::TVector3Df &n1, const mrpt::math::TVector3Df &n2, const mrpt::math::TVector3Df &n3)

Constructor from 3 points and its 3 normals

inline const float &x(size_t i) const
inline const float &y(size_t i) const
inline const float &z(size_t i) const
inline const uint8_t &r(size_t i) const
inline const uint8_t &g(size_t i) const
inline const uint8_t &b(size_t i) const
inline const uint8_t &a(size_t i) const
inline const float &u(size_t i) const
inline const float &v(size_t i) const
inline float &x(size_t i)
inline float &y(size_t i)
inline float &z(size_t i)
inline uint8_t &r(size_t i)
inline uint8_t &g(size_t i)
inline uint8_t &b(size_t i)
inline uint8_t &a(size_t i)
inline float &u(size_t i)
inline float &v(size_t i)
inline mrpt::math::TPoint3Df &vertex(size_t i)
inline const mrpt::math::TPoint3Df &vertex(size_t i) const
inline void setColor(const mrpt::img::TColor &c)

Sets the color of all vertices

inline void setColor(const mrpt::img::TColorf &c)
void computeNormals()

Compute the three normals from the cross-product of “v01 x v02”. Note that using this default normals will not lead to interpolated lighting in the fragment shaders, since all vertex are equal; a derived class should use custom, more accurate normals to enable soft lighting.

void computeTangents()

Compute tangent vectors from UV coordinates and vertex positions. Used for normal mapping when tangents are not provided by the mesh loader. All three vertices get the same tangent (flat tangent per triangle).

void readFrom(mrpt::serialization::CArchive &i)
void writeTo(mrpt::serialization::CArchive &o) const

Public Members

std::array<Vertex, 3> vertices
struct Vertex

Public Functions

inline void setColor(const mrpt::img::TColor &c)

Public Members

mrpt::math::TPointXYZfRGBAu8 xyzrgba
mrpt::math::TVector3Df normal

Must not be normalized.

mrpt::math::TVector2Df uv

texture coordinates (0,0)-(1,1)

mrpt::math::TVector3Df tangent

Tangent vector for normal mapping (0,0,0 if unset)