sculpto
Public Member Functions | Static Public Member Functions | List of all members
scl::topology::trimesh Class Reference

#include <trimesh.h>

Inheritance diagram for scl::topology::trimesh:
scl::topology::basis< vertex > scl::topology::cube

Public Member Functions

 trimesh ()
 
 trimesh (const std::vector< vertex > &Vertices, const std::vector< u32 > &Indieces)
 
 trimesh (const std::vector< vertex > &&Vertices, const std::vector< u32 > &&Indieces)
 
 ~trimesh () override=default
 
virtual void EvaluateBoundBox ()
 
virtual void EvaluateNormals ()
 
virtual void EvaluateTangentSpace ()
 
- Public Member Functions inherited from scl::topology::basis< vertex >
const mesh_type GetType () const
 
const std::vector< vertexGetVertices () const
 
const std::vector< u32GetIndices () const
 
const vec3GetBoundMin () const
 
const vec3GetBoundMax () const
 
std::vector< vertex >::const_iterator cbegin () const
 
std::vector< vertex >::const_iterator cend () const
 
 basis (mesh_type MeshType)
 
 basis (mesh_type MeshType, const std::vector< vertex > &Vertices, const std::vector< u32 > &Indices)
 
 basis (mesh_type MeshType, std::vector< vertex > &&Vertices, std::vector< u32 > &&Indices)
 
virtual ~basis ()=default
 

Static Public Member Functions

static bool EvaluateTriangleTangentSpace (vertex &P0, vertex &P1, vertex &P2)
 
static void EvaluateVertexOrthoganalTBNBasis (vertex &P)
 

Additional Inherited Members

- Public Attributes inherited from scl::topology::basis< vertex >
mesh_type MeshType
 
std::vector< vertexVertices
 
std::vector< u32Indices
 
vec3 Min
 
vec3 Max
 

Detailed Description

Topology object triangles mesh class.

Definition at line 17 of file trimesh.h.

Constructor & Destructor Documentation

◆ trimesh() [1/3]

scl::topology::trimesh::trimesh ( )
inline

Topology object triangles mesh default cconstructor.

Definition at line 21 of file trimesh.h.

◆ trimesh() [2/3]

scl::topology::trimesh::trimesh ( const std::vector< vertex > &  Vertices,
const std::vector< u32 > &  Indieces 
)
  • Topology object triangles mesh default cconstructor.
Parameters
Vertices- triangle mesh vertices.
Indieces- triangle mesh vertices indices.

Definition at line 12 of file trimesh.cpp.

12 :
14{
15}
std::vector< vertex > Vertices
Definition: basis.h:22
std::vector< u32 > Indices
Definition: basis.h:23

◆ trimesh() [3/3]

scl::topology::trimesh::trimesh ( const std::vector< vertex > &&  Vertices,
const std::vector< u32 > &&  Indieces 
)
  • Topology object triangles mesh default cconstructor.
Parameters
Vertices- triangle mesh vertices.
Indieces- triangle mesh vertices indices.

Definition at line 17 of file trimesh.cpp.

◆ ~trimesh()

scl::topology::trimesh::~trimesh ( )
overridedefault

Topology object triangles mesh default destructor.

Member Function Documentation

◆ EvaluateBoundBox()

void scl::topology::trimesh::EvaluateBoundBox ( )
virtual
  • Topology object mesh bound box evaluation function.
Parameters
None.
Returns
None.

Definition at line 22 of file trimesh.cpp.

23{
24 vec3 min = Vertices[0].Position;
25 vec3 max = Vertices[0].Position;
26
27 for (INT i = 1; i < Vertices.size(); i++)
28 min = vec3::Min(min, Vertices[i].Position),
29 max = vec3::Max(max, Vertices[i].Position);
30 Min = min, Max = max;
31}
static vec3 Max(const vec3 &A, const vec3 &B)
Definition: vec3.h:148
static vec3 Min(const vec3 &A, const vec3 &B)
Definition: vec3.h:140
math::vec3< float > vec3
Definition: base.h:38

◆ EvaluateNormals()

void scl::topology::trimesh::EvaluateNormals ( )
virtual
  • Topology object mesh vertices normals evaluation function.
Parameters
None.
Returns
None.

Definition at line 33 of file trimesh.cpp.

34{
35 for (INT i = 0; i < Indices.size(); i += 3)
36 {
37 vec3 A = Vertices[Indices[i + 1]].Position - Vertices[Indices[i]].Position;
38 vec3 B = Vertices[Indices[i + 2]].Position - Vertices[Indices[i]].Position;
39 vec3 N = A.Cross(B).Normalized();
40
41 Vertices[Indices[i + 0]].Normal = vec3(Vertices[Indices[i + 0]].Normal + N).Normalized();
42 Vertices[Indices[i + 1]].Normal = vec3(Vertices[Indices[i + 1]].Normal + N).Normalized();
43 Vertices[Indices[i + 2]].Normal = vec3(Vertices[Indices[i + 2]].Normal + N).Normalized();
44 }
45}
vec3 Normalized() const
Definition: vec3.h:190

◆ EvaluateTangentSpace()

void scl::topology::trimesh::EvaluateTangentSpace ( )
virtual
  • Topology object mesh vertices tangent space evaluation function.
Parameters
None.
Returns
None.

Z or Y dominant axes

X dominant axis

Definition at line 47 of file trimesh.cpp.

48{
49 bool is_ok = true;
50 for (INT i = 0; i < Indices.size() && is_ok; i += 3)
52 Vertices[Indices[i + 1]],
53 Vertices[Indices[i + 2]]);
54 if (is_ok)
56 else
57 for (auto &V : Vertices)
58 {
59 vec3 N = V.Normal;
60
61 if (N.Z > N.X && N.Z > N.Y || N.Y > N.X && N.Y > N.Z)
63 V.Tangent = vec3(1, 0, 0);
64 else
66 V.Tangent = vec3(0, 1, 0);
67 V.Bitangent = N.Cross(V.Tangent).Normalized();
68 V.Tangent = V.Bitangent.Cross(N).Normalized();
69 }
70}
static bool EvaluateTriangleTangentSpace(vertex &P0, vertex &P1, vertex &P2)
Definition: trimesh.cpp:72
static void EvaluateVertexOrthoganalTBNBasis(vertex &P)
Definition: trimesh.cpp:95

◆ EvaluateTriangleTangentSpace()

bool scl::topology::trimesh::EvaluateTriangleTangentSpace ( vertex P0,
vertex P1,
vertex P2 
)
static
  • Evaluate tangent space of single triangle function.
Parameters
P0,P1,P2- triangle vertices.
Returns
None.

Definition at line 72 of file trimesh.cpp.

73{
74 float s1 = P1.TexCoords.X - P0.TexCoords.X;
75 float s2 = P2.TexCoords.X - P0.TexCoords.X;
76 float t1 = P1.TexCoords.Y - P0.TexCoords.Y;
77 float t2 = P2.TexCoords.Y - P0.TexCoords.Y;
78 float det = s1 * t2 - s2 * t1;
79
80 if (det != 0)
81 {
82 vec3 E1 = P1.Position - P0.Position;
83 vec3 E2 = P2.Position - P0.Position;
84 vec3 T = ((E1 * t2 - E2 * t1) / det).Normalized();
85 vec3 B = ((E2 * s1 - E1 * s2) / det).Normalized();
86
87 P0.Tangent += T; P0.Bitangent += B;
88 P1.Tangent += T; P1.Bitangent += B;
89 P2.Tangent += T; P2.Bitangent += B;
90 return true;
91 }
92 return false;
93}

◆ EvaluateVertexOrthoganalTBNBasis()

void scl::topology::trimesh::EvaluateVertexOrthoganalTBNBasis ( vertex P)
static
  • Evaluate orthoganal tangent space basis of vertex function.
Parameters
P- vertex to evaluate orthoganal tangent space basis.
Returns
None.

Definition at line 95 of file trimesh.cpp.

96{
97 P.Normal.Normalize(), P.Tangent.Normalize(), P.Bitangent.Normalize();
98
99 P.Tangent = (P.Tangent - P.Normal * P.Normal.Dot(P.Tangent)).Normalized();
100 P.Bitangent = (P.Bitangent - P.Normal * P.Normal.Dot(P.Bitangent) - P.Tangent * P.Tangent.Dot(P.Bitangent)).Normalized();
101}

The documentation for this class was generated from the following files: