File: MikktspaceWrap.h

package info (click to toggle)
0ad 0.27.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 171,928 kB
  • sloc: cpp: 194,011; javascript: 19,098; ansic: 15,066; python: 6,328; sh: 1,695; perl: 1,575; java: 533; xml: 415; php: 192; makefile: 99
file content (122 lines) | stat: -rw-r--r-- 4,804 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* Copyright (C) 2021 Wildfire Games.
 * This file is part of 0 A.D.
 *
 * 0 A.D. is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * 0 A.D. is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef INCLUDED_MIKKWRAP
#define INCLUDED_MIKKWRAP

#include "graphics/MeshManager.h"
#include "graphics/ModelDef.h"
#include "third_party/mikktspace/mikktspace.h"

#include <vector>

class MikkTSpace
{

public:

	MikkTSpace(const CModelDefPtr& m, std::vector<float>& v, bool gpuSkinning);

	void Generate();

private:

	SMikkTSpaceInterface m_Interface;
	SMikkTSpaceContext m_Context;

	const CModelDefPtr& m_Model;

	std::vector<float>& m_NewVertices;

	bool m_GpuSkinning;

	/**
	 * @param[in] pContext - Pointer to the MikkTSpace context.
	 * @returns - the number of faces (triangles/quads) on the mesh to be processed.
	 */
	static int GetNumFaces(const SMikkTSpaceContext* pContext);

	/**
	 * @param[in] pContext - Pointer to the MikkTSpace context.
	 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
	 * @returns - the number of faces (triangles/quads) on the mesh to be processed.
	 */
	static int GetNumVerticesOfFace(const SMikkTSpaceContext* pContext, const int iFace);

	/**
	 * @param[in] pContext - Pointer to the MikkTSpace context.
	 * @returns - The MikkTSpace.
	 */
	static MikkTSpace* GetUserDataFromContext(const SMikkTSpaceContext* pContext);

	/**
	 * @param[in] pContext - Pointer to the MikkTSpace context.
	 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
	 * @param[in] iVert - Number in the range { 0, 1, 2 } for triangles and { 0, 1, 2, 3 } for quads.
	 * @returns - The MikkTSpace.
	 */
	static SModelVertex GetVertex(const SMikkTSpaceContext* pContext, const int iFace, const int iVert);

	/**
	 * @param[in] pContext - Pointer to the MikkTSpace context.
	 * @param[out] fvPosOut - The array containing the face.
	 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
	 * @param[in] iVert - Number in the range { 0, 1, 2 } for triangles and { 0, 1, 2, 3 } for quads.
	 */
	static void GetPosition(const SMikkTSpaceContext* pContext,
			float* fvPosOut, const int iFace, const int iVert);

	/**
	 * @param[in] pContext - Pointer to the MikkTSpace context.
	 * @param[out] fvNormOut iVert - The array containing the normal.
	 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
	 * @param[in] iVert - Number in the range { 0, 1, 2 } for triangles and { 0, 1, 2, 3 } for quads.
	 */
	static void GetNormal(const SMikkTSpaceContext* pContext,
			float* fvNormOut, const int iFace, const int iVert);

	/**
	 * @param[in] pContext - Pointer to the MikkTSpace context.
	 * @param[out] fvTexcOut iVert - Array containing the UV.
	 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
	 * @param[in] iVert - Number in the range { 0, 1, 2 } for triangles and { 0, 1, 2, 3 } for quads.
	 */
	static void GetTexCoord(const SMikkTSpaceContext* pContext,
			float* fvTexcOut, const int iFace, const int iVert);

	/**
	 * @brief This function is used to return tangent space results to the application.
	 * For normal maps it is sufficient to use the following simplified version of the bitangent which is generated at pixel/vertex level.
	 * fSign = bIsOrientationPreserving ? 1.0f : (-1.0f);
	 * bitangent = fSign * cross(vN, tangent);
	 * @param[in] pContext - Pointer to the MikkTSpace context.
	 * @param[in] fvTangent - fvTangent - The tangent vector.
	 * @param[in] fvBiTangent - The "real" bitangent vector. Not be perpendicular to fvTangent. However, both are perpendicular to the vertex normal.
	 * @param[in] fMagS - magniture of the fvTangent vector.
	 * @param[in] fMagT - magniture of the fvBiTangent vector.
	 * @param[in] bIsOrientationPreserving - Whether the orientation should be preserved.
	 * @param[in] iFace - Number in the range {0,1,2} for triangles and {0,1,2,3} for quads.
	 * @param[in] iVert - Array containing the position vector of the face.
	 */
	static void SetTSpace(const SMikkTSpaceContext* pContext, const float* fvTangent,
			const float* UNUSED(fvBiTangent), const float UNUSED(fMagS), const float UNUSED(fMagT),
			const tbool bIsOrientationPreserving, const int iFace, const int iVert);

};


#endif // INCLUDED_MIKKWRAP