~thumper/nux/properties

« back to all changes in this revision

Viewing changes to NuxMesh/NMeshObject.h

  • Committer: Tim Penhey
  • Date: 2011-06-30 13:45:32 UTC
  • mfrom: (373.1.2 remove-nux-mesh)
  • Revision ID: tim.penhey@canonical.com-20110630134532-7tda1y8mgjp10q4o
Remove old CMakeLists.txt files (no longer using CMake), and removing old NuxMesh code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2010 Inalogic® Inc.
3
 
 *
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
7
 
 * of the License.
8
 
 *
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.
14
 
 *
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/>
17
 
 *
18
 
 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
19
 
 *
20
 
 */
21
 
 
22
 
 
23
 
#ifndef NMESHOBJECT_H
24
 
#define NMESHOBJECT_H
25
 
 
26
 
#include "NuxCore/NuxCore.h"
27
 
#include "NuxCore/Math/Vector2.h"
28
 
#include "NuxCore/Math/Vector3.h"
29
 
#include "NuxCore/Math/Vector4.h"
30
 
 
31
 
#if defined(NUX_OS_WINDOWS)
32
 
#include "GL/glew.h"
33
 
#include "GL/wglew.h"
34
 
#elif defined(NUX_OS_LINUX)
35
 
#define GLEW_MX
36
 
#include "GL/glew.h"
37
 
#include "GL/glxew.h"
38
 
#else
39
 
#error Fixme
40
 
#endif
41
 
 
42
 
#include "NWorldObject.h"
43
 
#include "SceneData.h"
44
 
 
45
 
namespace nux
46
 
{
47
 
 
48
 
  class Float3Set
49
 
  {
50
 
  public:
51
 
    Float3Set (int N)
52
 
    {
53
 
      Num = N;
54
 
      Pool = new nux::Vec3<float>[Num];
55
 
    }
56
 
    ~Float3Set()
57
 
    {
58
 
      delete [] Pool;
59
 
    }
60
 
    nux::Vec3<float>* Pool;
61
 
    int Num;
62
 
  };
63
 
 
64
 
  class Float4Set
65
 
  {
66
 
  public:
67
 
    Float4Set (int N)
68
 
    {
69
 
      Num = N;
70
 
      Pool = new nux::Vec4<float>[Num];
71
 
    }
72
 
    ~Float4Set()
73
 
    {
74
 
      delete [] Pool;
75
 
    }
76
 
    nux::Vec4<float>* Pool;
77
 
    int Num;
78
 
  };
79
 
 
80
 
  class Float2Set
81
 
  {
82
 
  public:
83
 
    Float2Set (int N)
84
 
    {
85
 
      Num = N;
86
 
      Pool = new nux::Vec2<float>[Num];
87
 
    }
88
 
    ~Float2Set()
89
 
    {
90
 
      delete [] Pool;
91
 
    }
92
 
    nux::Vec2<float>* Pool;
93
 
    int Num;
94
 
  };
95
 
 
96
 
  class AttributeIndexSet
97
 
  {
98
 
  public:
99
 
    AttributeIndexSet (int N)
100
 
    {
101
 
      Num = N;
102
 
      IndexPool = new Index3[Num];
103
 
    }
104
 
    ~AttributeIndexSet()
105
 
    {
106
 
      delete [] IndexPool;
107
 
    }
108
 
    Index3 *IndexPool;
109
 
    int Num;
110
 
  };
111
 
 
112
 
  class NMeshData
113
 
  {
114
 
  public:
115
 
    NMeshData (int NumTriangles);
116
 
    ~NMeshData();
117
 
 
118
 
    int GetNumTriangles() const
119
 
    {
120
 
      return m_NumTriangles;
121
 
    }
122
 
 
123
 
    void SetMatrix (nux::Matrix4 matrix)
124
 
    {
125
 
      m_Matrix = matrix;
126
 
    }
127
 
    nux::Matrix4 &GetMatrix()
128
 
    {
129
 
      return m_Matrix;
130
 
    }
131
 
    const nux::Matrix4 &GetMatrix() const
132
 
    {
133
 
      return m_Matrix;
134
 
    }
135
 
 
136
 
  public:
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.
144
 
 
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;
151
 
 
152
 
  private:
153
 
    int m_NumTriangles;
154
 
  };
155
 
 
156
 
  class NMeshObject: public NWorldObject
157
 
  {
158
 
  public:
159
 
    NMeshObject (NMeshData *meshdata = 0);
160
 
    ~NMeshObject();
161
 
 
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,
166
 
                                long triangleCount,
167
 
                                const unsigned int *triangleIndex,
168
 
                                nux::Vec3<float> *tangent,
169
 
                                nux::Vec3<float> *binormal);
170
 
 
171
 
    void CreateGLObjects();
172
 
    void DrawGLObjects();
173
 
    void RenderNormal();
174
 
 
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
183
 
    {
184
 
      return m_MinIndex;
185
 
    }
186
 
    unsigned int GetMaxIndex() const
187
 
    {
188
 
      return m_MaxIndex;
189
 
    }
190
 
    unsigned int GetNumPolygon() const
191
 
    {
192
 
      return m_NumPolygon;
193
 
    }
194
 
    bool HasNormal() const
195
 
    {
196
 
      return NumNormalAttributes > 0;
197
 
    }
198
 
    bool HasTangent() const
199
 
    {
200
 
      return NumTangentAttributes > 0;
201
 
    }
202
 
    bool HasBinormal() const
203
 
    {
204
 
      return NumBinormalAttributes > 0;
205
 
    }
206
 
    bool HasColor() const
207
 
    {
208
 
      return NumColorAttributes > 0;
209
 
    }
210
 
    bool HasTexCoord() const
211
 
    {
212
 
      return NumTextureAttributes > 0;
213
 
    }
214
 
    bool HasTangentSpace() const
215
 
    {
216
 
      return m_hasTangentSpace;
217
 
    }
218
 
 
219
 
    nux::Matrix4 &GetMatrix();
220
 
    const nux::Matrix4 &GetMatrix() const;
221
 
 
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;
229
 
 
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;
234
 
 
235
 
    GLuint GetOpenGLId (int index = 0) const
236
 
    {
237
 
      return m_OpenGLID[index];
238
 
    }
239
 
    GLuint m_OpenGLID[16];  // index 0 is reserved for vertex position.
240
 
    GLuint m_GLVBOIndexVertex;
241
 
    GLuint m_GLVBOBiNormalCustom;
242
 
    GLuint m_GLVBOTangentCustom;
243
 
 
244
 
    // Stats
245
 
    int m_MinIndex;
246
 
    int m_MaxIndex;
247
 
 
248
 
  public:
249
 
    NMeshData *m_MeshData;
250
 
    int m_NumPolygon;
251
 
 
252
 
    int NumColorAttributes;
253
 
    int NumTextureAttributes;
254
 
    int NumNormalAttributes;
255
 
    int NumTangentAttributes;
256
 
    int NumBinormalAttributes;
257
 
 
258
 
    int m_NormalIndex;
259
 
    int m_TangentIndex;
260
 
    int m_BinormalIndex;
261
 
    int m_Color0Index;
262
 
    int m_TexCoordIndex;
263
 
 
264
 
    bool m_hasTangentSpace;
265
 
    int m_TexCoordCount;
266
 
 
267
 
    nux::Matrix4 m_WorldMatrix;
268
 
 
269
 
  };
270
 
}
271
 
 
272
 
#endif // NMESHOBJECT_H