Go to the documentation of this file.00001 #ifndef __NYTRO_MeshBuilder_H
00002 #define __NYTRO_MeshBuilder_H
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "system/nyCommon.h"
00012 #include "graphics/nyColor.h"
00013 #include "graphics/nyGeometryBuffer.h"
00014 #include "graphics/nyTexture.h"
00015 #include "graphics/nyShader.h"
00016 #include "math/nyMath.h"
00017
00018 namespace Nytro
00019 {
00020 namespace Scene
00021 {
00022 class MeshData;
00023 };
00024
00025 namespace Graphics
00026 {
00027 using namespace Scene;
00028 using namespace Math;
00029
00031 class NYTRO_API UvCoord
00032 {
00033 public:
00034
00035 float32 u, v;
00036
00037 UvCoord()
00038 {
00039 u = v = 0;
00040 }
00041
00042 UvCoord( float32 aU, float32 aV )
00043 {
00044 u = aU;
00045 v = aV;
00046 }
00047
00048 void set( float32 aU, float32 aV )
00049 {
00050 u = aU;
00051 v = aV;
00052 }
00053 };
00054
00056 class NYTRO_API Vertex
00057 {
00058 public:
00059
00060 Vector3D m_position;
00061 Vector3D m_normal, m_tangent, m_binormal;
00062 Color m_color;
00063 UvCoord m_uv;
00064 };
00065
00067 class NYTRO_API TriangleData
00068 {
00069 public:
00070
00071 Vector3D m_normal, m_tangent, m_binormal;
00072 uint32 m_indices[3];
00073 uint32 m_flags;
00074 };
00075
00077 class NYTRO_API MeshBuilder
00078 {
00079 public:
00080
00081 MeshBuilder();
00082 virtual ~MeshBuilder();
00083
00085 void beginMesh();
00087 void beginGeometryBuffer( uint32 aVertexComponents,
00088 EGeometryPrimitive aPrimType,
00089 uint32 aNumVerts = 0, uint32 aNumIndices = 0 );
00091 void beginVertex();
00093 void endVertex();
00095 void addTexture( Texture* pTexture );
00097 void setShader( Shader* pShader );
00099 void addVertex( const Vertex& rVtx );
00101 void addVector( const Vector3D& rVec );
00103 void addUvCoord( const UvCoord& rUV );
00105 void addFloat( float32 aFloat );
00107 void addColor( const Color& rColor );
00109 void addIndex( uint32 aIndex );
00111 static void getFaceTangent( const Vector3D &v0, const Vector3D &v1, const Vector3D &v2,
00112 const UvCoord &t0, const UvCoord &t1, const UvCoord &t2,
00113 Vector3D& rTangent );
00115 GeometryBuffer* endGeometryBuffer();
00117 GeometryBuffer* getCurrentGeometryBuffer();
00119 uint8* getCurrentGeometryVertexData();
00121 uint8* getCurrentGeometryIndexData();
00123 uint32 getCurrentGeometryVertexDataOffset();
00125 uint32 getCurrentGeometryIndexDataOffset();
00127 MeshData* endMesh();
00129 MeshData* getMesh();
00130
00131 protected:
00132
00134 bool checkVertexPool( uint32 aAddSize );
00136 bool checkIndexPool( uint32 aAddSize );
00138 EGeometryPrimitive m_primitiveType;
00140 MeshData* m_pMeshData;
00142 GeometryBuffer* m_pGeometryBuffer;
00144 uint8* m_pVertexData;
00146 uint8* m_pIndexData;
00148 uint8* m_pGbVertexData;
00150 uint8* m_pGbIndexData;
00152 uint32 m_vertexDataOffset;
00154 uint32 m_indexDataOffset;
00156 uint32 m_vertexDataSize,
00158 m_indexDataSize;
00160 uint32 m_bufferAllocAdvanceSize;
00162 uint32 m_vertexComponents;
00164 uint32 m_vertexCount,
00166 m_indexCount;
00167 };
00168 };
00169 };
00170
00171 #endif