lugre_meshbuffer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef LUGRE_MESHBUFFER_H
00025 #define LUGRE_MESHBUFFER_H
00026
00027 #include "lugre_smartptr.h"
00028 #include <vector>
00029 #include <string>
00030 #include <Ogre.h>
00031 #include <OgreVector3.h>
00032
00033 class lua_State;
00034
00035 namespace Lugre {
00036
00037 class cBufferedMesh;
00038 class cBufferedSubMesh;
00039 class cBufferedVertexData;
00040
00041
00042 class cBufferedVertexData { public:
00043 cBufferedVertexData();
00044 ~cBufferedVertexData();
00045
00047 class cQuickData { public:
00048 char* mpFirst;
00049 int miOffsetToNext;
00050 cQuickData () : mpFirst(0),miOffsetToNext(0) {}
00051 inline void* Get (const int i) { return mpFirst ? &mpFirst[miOffsetToNext*i] : 0; }
00052 };
00053
00055 void SetFromVertexData (const Ogre::VertexData& pVertexData);
00056
00058 inline float* GetVertexPos (const int i) { return (float*)mQuickPos.Get(i); }
00059 inline Ogre::Vector3 GetVertexPosVec3 (const int i) { float* p = GetVertexPos(i); return Ogre::Vector3(p[0],p[1],p[2]); }
00060
00062 inline float* GetVertexTexCoord (const int i) { return (float*)mQuickTexCoord.Get(i); }
00063
00065 inline const char* GetVertexData (const int iSource,const int iVertex)
00066 { return &mDataBuffers[iSource][GetVertexSize(iSource)*iVertex]; }
00067
00069 inline const char* GetVertexData (const int iSource) { return mDataBuffers[iSource]; }
00070
00073 inline int GetVertexSize (const int iSource) { return mDataBufferVertexSize[iSource]; }
00074
00075 inline int GetVertexCount () { return miVertexCount; }
00076
00078 inline Ogre::VertexDeclaration* GetVertexDecl () { return mpVertexDecl; }
00079
00080 private:
00081 void SetQuickDataFromSemantic (cQuickData& pQuickData,const Ogre::VertexElementSemantic sem,const int i=0);
00082
00083 public:
00084 Ogre::VertexDeclaration* mpVertexDecl;
00085 cQuickData mQuickPos;
00086 cQuickData mQuickTexCoord;
00087 std::vector<char*> mDataBuffers;
00088 std::vector<int> mDataBufferVertexSize;
00089 int miVertexCount;
00090 };
00091
00096 class cBufferedMesh : public cSmartPointable { public:
00097 inline cBufferedSubMesh& GetSubMesh (const int iSubMeshIndex) { return mBufferedSubMeshes[iSubMeshIndex]; }
00098 inline int GetSubMeshCount () { return mBufferedSubMeshes.size(); }
00099 inline Ogre::AxisAlignedBox& GetBounds () { return mBounds; }
00100 inline const float GetBoundRad () { return mfBoundRad; }
00101 inline cBufferedVertexData& GetBufferedVertexData_Shared () { return mBufferedVertexData_Shared; }
00102
00103 cBufferedMesh();
00104
00106 void SetFromMesh (Ogre::Mesh& pMesh);
00107
00109 int RayPick (const Ogre::Vector3& vRayPos,const Ogre::Vector3& vRayDir,float* pfHitDist=0);
00110 int RayPick (const Ogre::Vector3& vRayPos,const Ogre::Vector3& vRayDir,const Ogre::Vector3& vPos,const Ogre::Quaternion& qRot,const Ogre::Vector3& vScale,float* pfHitDist=0);
00111
00113 static void LuaRegister (lua_State *L);
00114
00115 private:
00116 cBufferedVertexData mBufferedVertexData_Shared;
00117 Ogre::AxisAlignedBox mBounds;
00118 float mfBoundRad;
00119 std::vector<cBufferedSubMesh> mBufferedSubMeshes;
00120 };
00121
00122 class cBufferedSubMesh { public:
00123 cBufferedSubMesh();
00124
00125 inline int GetVertexCount () { return mBufferedVertexData.GetVertexCount(); }
00126 inline int GetIndexCount () { return mIndexData.size(); }
00127 inline bool GetUsesShared () { return mbUseSharedVertexData; }
00128 inline unsigned int* GetIndexData () { return &mIndexData[0]; }
00129 inline std::string& GetMatName () { return msMatName; }
00130 inline Ogre::MaterialPtr& GetMat () { return mpMat; }
00131 inline std::string& GetFormatHash () { return msFormatHash; }
00132 inline std::string& GetFormatHashWithColour () { return msFormatHashWithColour; }
00133 inline cBufferedVertexData& GetBufferedVertexData () { return mBufferedVertexData; }
00134
00136 void SetFromSubMesh (cBufferedMesh* pParent,Ogre::SubMesh& pSubMesh);
00137
00140 void SetMatName (const char* szMatName);
00141
00144 void TransformTexCoords (const float u0,const float v0,const float u1,const float v1);
00145
00146 private:
00147 cBufferedVertexData mBufferedVertexData;
00148 cBufferedMesh* mpParent;
00149 std::vector<unsigned int> mIndexData;
00150 std::string msMatName;
00151 Ogre::MaterialPtr mpMat;
00152 std::string msFormatHash;
00153 std::string msFormatHashWithColour;
00154 bool mbUseSharedVertexData;
00155 };
00156
00157
00159 cBufferedMesh* GetBufferedMesh (const char* szMeshName);
00160 };
00161
00162
00163 #endif