Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
MikktspaceWrap.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_MIKKWRAP
19#define INCLUDED_MIKKWRAP
20
22#include "graphics/ModelDef.h"
23#include "third_party/mikktspace/mikktspace.h"
24
25#include <vector>
26
28{
29
30public:
31
32 MikkTSpace(const CModelDefPtr& m, std::vector<float>& v, bool gpuSkinning);
33
34 void Generate();
35
36private:
37
38 SMikkTSpaceInterface m_Interface;
39 SMikkTSpaceContext m_Context;
40
42
43 std::vector<float>& m_NewVertices;
44
46
47 /**
48 * @param[in] pContext - Pointer to the MikkTSpace context.
49 * @returns - the number of faces (triangles/quads) on the mesh to be processed.
50 */
51 static int GetNumFaces(const SMikkTSpaceContext* pContext);
52
53 /**
54 * @param[in] pContext - Pointer to the MikkTSpace context.
55 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
56 * @returns - the number of faces (triangles/quads) on the mesh to be processed.
57 */
58 static int GetNumVerticesOfFace(const SMikkTSpaceContext* pContext, const int iFace);
59
60 /**
61 * @param[in] pContext - Pointer to the MikkTSpace context.
62 * @returns - The MikkTSpace.
63 */
64 static MikkTSpace* GetUserDataFromContext(const SMikkTSpaceContext* pContext);
65
66 /**
67 * @param[in] pContext - Pointer to the MikkTSpace context.
68 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
69 * @param[in] iVert - Number in the range { 0, 1, 2 } for triangles and { 0, 1, 2, 3 } for quads.
70 * @returns - The MikkTSpace.
71 */
72 static SModelVertex GetVertex(const SMikkTSpaceContext* pContext, const int iFace, const int iVert);
73
74 /**
75 * @param[in] pContext - Pointer to the MikkTSpace context.
76 * @param[out] fvPosOut - The array containing the face.
77 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
78 * @param[in] iVert - Number in the range { 0, 1, 2 } for triangles and { 0, 1, 2, 3 } for quads.
79 */
80 static void GetPosition(const SMikkTSpaceContext* pContext,
81 float* fvPosOut, const int iFace, const int iVert);
82
83 /**
84 * @param[in] pContext - Pointer to the MikkTSpace context.
85 * @param[out] fvNormOut iVert - The array containing the normal.
86 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
87 * @param[in] iVert - Number in the range { 0, 1, 2 } for triangles and { 0, 1, 2, 3 } for quads.
88 */
89 static void GetNormal(const SMikkTSpaceContext* pContext,
90 float* fvNormOut, const int iFace, const int iVert);
91
92 /**
93 * @param[in] pContext - Pointer to the MikkTSpace context.
94 * @param[out] fvTexcOut iVert - Array containing the UV.
95 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
96 * @param[in] iVert - Number in the range { 0, 1, 2 } for triangles and { 0, 1, 2, 3 } for quads.
97 */
98 static void GetTexCoord(const SMikkTSpaceContext* pContext,
99 float* fvTexcOut, const int iFace, const int iVert);
100
101 /**
102 * @brief This function is used to return tangent space results to the application.
103 * For normal maps it is sufficient to use the following simplified version of the bitangent which is generated at pixel/vertex level.
104 * fSign = bIsOrientationPreserving ? 1.0f : (-1.0f);
105 * bitangent = fSign * cross(vN, tangent);
106 * @param[in] pContext - Pointer to the MikkTSpace context.
107 * @param[in] fvTangent - fvTangent - The tangent vector.
108 * @param[in] fvBiTangent - The "real" bitangent vector. Not be perpendicular to fvTangent. However, both are perpendicular to the vertex normal.
109 * @param[in] fMagS - magniture of the fvTangent vector.
110 * @param[in] fMagT - magniture of the fvBiTangent vector.
111 * @param[in] bIsOrientationPreserving - Whether the orientation should be preserved.
112 * @param[in] iFace - Number in the range {0,1,2} for triangles and {0,1,2,3} for quads.
113 * @param[in] iVert - Array containing the position vector of the face.
114 */
115 static void SetTSpace(const SMikkTSpaceContext* pContext, const float* fvTangent,
116 const float* UNUSED(fvBiTangent), const float UNUSED(fMagS), const float UNUSED(fMagT),
117 const tbool bIsOrientationPreserving, const int iFace, const int iVert);
118
119};
120
121
122#endif // INCLUDED_MIKKWRAP
std::shared_ptr< CModelDef > CModelDefPtr
Definition: MeshManager.h:27
Definition: MikktspaceWrap.h:28
static void SetTSpace(const SMikkTSpaceContext *pContext, const float *fvTangent, const float *fvBiTangent, const float fMagS, const float fMagT, const tbool bIsOrientationPreserving, const int iFace, const int iVert)
This function is used to return tangent space results to the application.
Definition: MikktspaceWrap.cpp:93
MikkTSpace(const CModelDefPtr &m, std::vector< float > &v, bool gpuSkinning)
Definition: MikktspaceWrap.cpp:22
static SModelVertex GetVertex(const SMikkTSpaceContext *pContext, const int iFace, const int iVert)
Definition: MikktspaceWrap.cpp:139
std::vector< float > & m_NewVertices
Definition: MikktspaceWrap.h:43
static MikkTSpace * GetUserDataFromContext(const SMikkTSpaceContext *pContext)
Definition: MikktspaceWrap.cpp:134
const CModelDefPtr & m_Model
Definition: MikktspaceWrap.h:41
static void GetNormal(const SMikkTSpaceContext *pContext, float *fvNormOut, const int iFace, const int iVert)
Definition: MikktspaceWrap.cpp:68
SMikkTSpaceInterface m_Interface
Definition: MikktspaceWrap.h:38
static int GetNumFaces(const SMikkTSpaceContext *pContext)
Definition: MikktspaceWrap.cpp:47
static void GetTexCoord(const SMikkTSpaceContext *pContext, float *fvTexcOut, const int iFace, const int iVert)
Definition: MikktspaceWrap.cpp:79
static int GetNumVerticesOfFace(const SMikkTSpaceContext *pContext, const int iFace)
Definition: MikktspaceWrap.cpp:52
static void GetPosition(const SMikkTSpaceContext *pContext, float *fvPosOut, const int iFace, const int iVert)
Definition: MikktspaceWrap.cpp:57
SMikkTSpaceContext m_Context
Definition: MikktspaceWrap.h:39
bool m_GpuSkinning
Definition: MikktspaceWrap.h:45
void Generate()
Definition: MikktspaceWrap.cpp:42
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning.
Definition: code_annotation.h:40
Definition: ModelDef.h:108