2
* Copyright 2010 Inalogic® Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License, as
6
* published by the Free Software Foundation; either version 2.1 or 3.0
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranties of
11
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12
* PURPOSE. See the applicable version of the GNU Lesser General Public
13
* License for more details.
15
* You should have received a copy of both the GNU Lesser General Public
16
* License along with this program. If not, see <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jaytaoko@inalogic.com>
26
#include "NuxCore/NuxCore.h"
27
#include "NuxCore/Math/Vector2.h"
28
#include "NuxCore/Math/Vector3.h"
29
#include "NuxCore/Math/Vector4.h"
31
#if defined(NUX_OS_WINDOWS)
34
#elif defined(NUX_OS_LINUX)
42
#include "NWorldObject.h"
43
#include "SceneData.h"
54
Pool = new nux::Vec3<float>[Num];
60
nux::Vec3<float>* Pool;
70
Pool = new nux::Vec4<float>[Num];
76
nux::Vec4<float>* Pool;
86
Pool = new nux::Vec2<float>[Num];
92
nux::Vec2<float>* Pool;
96
class AttributeIndexSet
99
AttributeIndexSet (int N)
102
IndexPool = new Index3[Num];
115
NMeshData (int NumTriangles);
118
int GetNumTriangles() const
120
return m_NumTriangles;
123
void SetMatrix (nux::Matrix4 matrix)
127
nux::Matrix4 &GetMatrix()
131
const nux::Matrix4 &GetMatrix() const
137
nux::Matrix4 m_Matrix;
138
std::vector<Float4Set *> VertexSetArray; // There should be only one element in this array
139
std::vector<Float2Set *> TextureSetArray; // There can be 0 or more elements in this array. All the elements have the TEXTURE semantic.
140
std::vector<Float4Set *> ColorSetArray; // There can be 0 or more elements in this array. All the elements have the COLOR semantic.
141
std::vector<Float3Set *> NormalSetArray; // There can be 0 or more elements in this array. All the elements have the NORMAL semantic.
142
std::vector<Float4Set *> TangentSetArray; // There can be 0 or 1 elements in this array. The element have the TANGENT semantic.
143
std::vector<Float4Set *> BinormalSetArray; // There can be 0 or 1 elements in this array. The element have the BINORMAL semantic.
145
std::vector<AttributeIndexSet *> VertexSetIndexArray;
146
std::vector<AttributeIndexSet *> NormalSetIndexArray;
147
std::vector<AttributeIndexSet *> ColorSetIndexArray;
148
std::vector<AttributeIndexSet *> TextureSetIndexArray;
149
std::vector<AttributeIndexSet *> TangentSetIndexArray;
150
std::vector<AttributeIndexSet *> BinormalSetIndexArray;
156
class NMeshObject: public NWorldObject
159
NMeshObject (NMeshData *meshdata = 0);
162
void CreateVertexBuffer (NMeshData *meshdata);
163
void CalculateTangentArray (const nux::Vec4<float> *vertex,
164
const nux::Vec3<float> *normal,
165
const nux::Vec2<float> *texcoord,
167
const unsigned int *triangleIndex,
168
nux::Vec3<float> *tangent,
169
nux::Vec3<float> *binormal);
171
void CreateGLObjects();
172
void DrawGLObjects();
175
unsigned int GetVertexBufferSize();
176
unsigned int GetNormalBufferSize();
177
unsigned int GetColorBufferSize();
178
unsigned int GetTextureBufferSize();
179
unsigned int GetIndexBufferSize();
180
unsigned int GetNumVertex();
181
unsigned int GetNumIndex(); // The number of index used to draw may be more or less than the number of vertices. Depending on what you want to do...
182
unsigned int GetMinIndex() const
186
unsigned int GetMaxIndex() const
190
unsigned int GetNumPolygon() const
194
bool HasNormal() const
196
return NumNormalAttributes > 0;
198
bool HasTangent() const
200
return NumTangentAttributes > 0;
202
bool HasBinormal() const
204
return NumBinormalAttributes > 0;
206
bool HasColor() const
208
return NumColorAttributes > 0;
210
bool HasTexCoord() const
212
return NumTextureAttributes > 0;
214
bool HasTangentSpace() const
216
return m_hasTangentSpace;
219
nux::Matrix4 &GetMatrix();
220
const nux::Matrix4 &GetMatrix() const;
222
std::vector<unsigned int> m_IndexArray;
223
nux::Vec4<float>* m_VertexArray;
224
nux::Vec4<float>** m_ColorArray; // <--- this should be RGBA
225
nux::Vec3<float>** m_NormalArray;
226
nux::Vec3<float>** m_TangentArrayXSI;
227
nux::Vec3<float>** m_BinormalArrayXSI;
228
nux::Vec2<float>** m_TextureArray;
230
// Computed with just the normal and the texture coordinates
231
// See http://www.terathon.com/code/tangent.html
232
nux::Vec3<float>* m_TangentArrayCustom;
233
nux::Vec3<float>* m_BinormalArrayCustom;
235
GLuint GetOpenGLId (int index = 0) const
237
return m_OpenGLID[index];
239
GLuint m_OpenGLID[16]; // index 0 is reserved for vertex position.
240
GLuint m_GLVBOIndexVertex;
241
GLuint m_GLVBOBiNormalCustom;
242
GLuint m_GLVBOTangentCustom;
249
NMeshData *m_MeshData;
252
int NumColorAttributes;
253
int NumTextureAttributes;
254
int NumNormalAttributes;
255
int NumTangentAttributes;
256
int NumBinormalAttributes;
264
bool m_hasTangentSpace;
267
nux::Matrix4 m_WorldMatrix;
272
#endif // NMESHOBJECT_H