Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

RAS_MeshObject.h

Go to the documentation of this file.
00001 #ifndef __RAS_MESHOBJECT
00002 #define __RAS_MESHOBJECT
00003 
00004 
00005 #ifdef WIN32
00006 // disable the STL warnings ("debug information length > 255")
00007 #pragma warning (disable:4786)
00008 #endif
00009 
00010 #include <vector>
00011 #include <set>
00012 
00013 #include "RAS_Polygon.h"
00014 #include "MT_Transform.h"
00015 
00016 #include "KX_HashedPtr.h"
00017 
00018 class KX_ArrayOptimizer
00019 {
00020 public:
00021         KX_ArrayOptimizer() {};
00022         ~KX_ArrayOptimizer()

00023         {
00024                 int i=0;
00025                 
00026 
00027                 for (vector<KX_VertexArray*>::iterator itv = m_VertexArrayCache1.begin();
00028                 !(itv == m_VertexArrayCache1.end());itv++)
00029                 {
00030                         delete (*itv);
00031                 }
00032                 for (vector<KX_IndexArray*>::iterator iti = m_IndexArrayCache1.begin();
00033                 !(iti == m_IndexArrayCache1.end());iti++)
00034                 {
00035                         delete (*iti);
00036                 }
00037                 
00038                 m_TriangleArrayCount.clear();
00039                 m_VertexArrayCache1.clear();
00040                 m_IndexArrayCache1.clear();
00041 
00042         }
00043         vector<KX_VertexArray*>         m_VertexArrayCache1;
00044         vector<int>                                     m_TriangleArrayCount;
00045         vector<KX_IndexArray*>          m_IndexArrayCache1;
00046 
00047 };
00048 
00049 
00050 class RAS_MeshObject
00051 {
00052 
00053         enum    {       BUCKET_MAX_INDICES = 2048};//2048};//8192};
00054         enum    {       BUCKET_MAX_TRIANGLES = 1024};
00055 
00056         GEN_Map<class RAS_IPolyMaterial,KX_ArrayOptimizer*> m_matVertexArrayS;
00057         //vector<class RAS_IPolyMaterial*,KX_ArrayOptimizer> m_vertexArrays;
00058         KX_ArrayOptimizer*              GetArrayOptimizer(RAS_IPolyMaterial* polymat)

00059         {
00060                 KX_ArrayOptimizer** aop = (m_matVertexArrayS[*polymat]);
00061                 if (aop)
00062                         return *aop;
00063                 KX_ArrayOptimizer* ao = new KX_ArrayOptimizer();
00064                 m_matVertexArrayS.insert(*polymat,ao);
00065                 return ao;
00066         }
00067 
00068         set<class RAS_MaterialBucket*>          m_materials;
00069         //vector<RAS_Polygon*>          m_polygons;
00070         
00071         
00072         unsigned int                    m_debugcolor;
00073         bool                                    m_bModified;
00074 
00075         vector<class RAS_Polygon*>      m_Polygons;
00076         CCString                                        m_name;
00077 
00078 public:
00079         RAS_MeshObject() : m_bModified(true) {
00080                 
00081 
00082         };
00083         virtual ~RAS_MeshObject() {
00084                 for (vector<RAS_Polygon*>::iterator it=m_Polygons.begin();!(it==m_Polygons.end());it++)
00085                 {
00086                         delete (*it);
00087                 }
00088                 ClearArrayData();
00089         }
00090 
00091         int     NumMaterials() { return m_materials.size();}
00092         const CCString& GetMaterialName(int matid) { 
00093                 return (*m_materials.begin())->GetPolyMaterial()->GetMaterialName();
00094         }
00095 
00096         void AddPolygon(RAS_Polygon* poly)

00097         {
00098                 m_Polygons.push_back(poly);
00099         }
00100         void UpdateMaterialList();
00101 
00102         int             NumPolygons() { return m_Polygons.size();};
00103         RAS_Polygon*            GetPolygon(int num) { return m_Polygons[num];}
00104 
00105         void    Bucketize(double* oglmatrix,void* clientobj);
00106         void    RemoveFromBuckets(double* oglmatrix,void* clientobj);
00107         void    MarkVisible(double* oglmatrix,void* clientobj,bool visible);
00108 
00109         void DebugColor(unsigned int abgr)

00110         {
00111                 /*
00112                 int numpolys = NumPolygons();

00113                 for (int i=0;i<numpolys;i++)

00114                 {

00115                         RAS_Polygon* poly = m_polygons[i];

00116                         for (int v=0;v<poly->VertexCount();v++)

00117                         {

00118                                 RAS_TexVert* vtx = poly->GetVertex(v);

00119                                 vtx->setDebugRGBA(abgr);

00120                         }

00121                 }

00122                 */
00123                 m_debugcolor = abgr;
00124 
00125         }
00126 
00127         void    SchedulePolygons(int drawingmode,class RAS_IRasterizer* rasty);
00128         
00129         void    ClearArrayData();
00130         
00131         RAS_TexVert*                    GetVertex(short array,short index,RAS_IPolyMaterial* polymat);
00132         
00133         int             FindVertexArray(int numverts,RAS_IPolyMaterial* polymat);
00134         
00135         inline void     SchedulePoly(const KX_VertexIndex& idx,int numverts,RAS_IPolyMaterial* mat) {
00136                 
00137                 //int indexpos = m_IndexArrayCount[idx.m_vtxarray];
00138                 int indexidx=0;
00139                 //m_IndexArrayCount[idx.m_vtxarray] = indexpos + 3;
00140                 
00141                 KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);
00142                 ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(idx.m_indexarray[0]);
00143                 ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(idx.m_indexarray[1]);
00144                 ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(idx.m_indexarray[2]);
00145                 if (!mat->UsesTriangles()) //if (!m_bUseTriangles)
00146                 {       
00147                         //m_IndexArrayCount[idx.m_vtxarray] = indexpos+4;
00148                         ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(idx.m_indexarray[3]);
00149                 }
00150         }
00151         
00152         inline void ScheduleWireframePoly(const KX_VertexIndex& idx,int numverts,int edgecode,RAS_IPolyMaterial* mat) {
00153 
00154                                 //int indexpos = m_IndexArrayCount[idx.m_vtxarray];
00155                                                                                                 
00156                                 int edgetrace = 1<<(numverts-1);
00157                                 bool    drawedge = (edgecode & edgetrace)!=0;
00158                                 edgetrace = 1;
00159                                 int prevvert = idx.m_indexarray[numverts-1];
00160                                 KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);
00161                                 
00162                                 for (int v=0;v<numverts;v++)
00163                                 {
00164                                         unsigned int curvert = idx.m_indexarray[v];
00165                                         if (drawedge)
00166                                         {
00167                                         
00168                                                 ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(prevvert);
00169                                                 ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(curvert);
00170                                         }
00171                                         prevvert = curvert;
00172                                         drawedge = (edgecode & edgetrace)!=0;
00173                                         edgetrace*=2;
00174                                 }
00175                                 
00176                                 //m_IndexArrayCount[idx.m_vtxarray] = indexpos;
00177                 }
00178 
00179                 
00180                 
00181 
00182                 // find (and share) or add vertices
00183                 // for some speedup, only the last 20 added vertices are searched for equality
00184 
00185                 int FindOrAddVertex(int vtxarray,const MT_Point3& xyz,
00186                         const MT_Point2& uv,
00187                         const unsigned int rgbacolor,
00188                         const MT_Vector3& normal,RAS_IPolyMaterial* mat)

00189                 {
00190                         short newnormal[3];
00191                         newnormal[0]=(short)(normal[0] * 32767.0);
00192                         newnormal[1]=(short)(normal[1] * 32767.0);
00193                         newnormal[2]=(short)(normal[2] * 32767.0);
00194                         RAS_TexVert tempvert(xyz,uv,rgbacolor,newnormal);
00195                         KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);//*(m_matVertexArrays[*mat]);
00196 
00197 
00198                         int index=-1;
00199                         int numverts = ao->m_VertexArrayCache1[vtxarray]->size();//m_VertexArrayCount[vtxarray];
00200                         //for (int i=GEN_max(0,numverts-20);i<numverts;i++)
00201                         for (int i=GEN_max(0,numverts-16);i<numverts;i++)
00202                         {
00203                                 const RAS_TexVert&  vtx = (*ao->m_VertexArrayCache1[vtxarray])[i];
00204                                 if (tempvert.closeTo(&vtx))
00205                                 {
00206                                         index = i;
00207                                         break;
00208                                 }
00209 
00210                         }
00211                         if (index >= 0)
00212                                 return index;
00213 
00214                         // no vertex found, add one
00215                         ao->m_VertexArrayCache1[vtxarray]->push_back(tempvert);
00216 
00217                         return numverts;
00218                         
00219 
00220                 }
00221                 
00222                 const vecVertexArray&   GetVertexCache (RAS_IPolyMaterial* mat)

00223                 {
00224                         KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);//*(m_matVertexArrays[*mat]);
00225                         return ao->m_VertexArrayCache1;
00226                 }
00227                 const vecIndexArrays&   GetIndexCache (RAS_IPolyMaterial* mat)

00228                 {
00229                         KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);//*(m_matVertexArrays[*mat]);
00230                         return ao->m_IndexArrayCache1;
00231                 }
00232 
00233                 void SetName(CCString name)

00234                 {
00235                         m_name = name;
00236                 }
00237                 const CCString& GetName()

00238                 {
00239                         return m_name;
00240                 }
00241 };
00242 
00243 #endif //__RAS_MESHOBJECT

Generated at Thu Feb 1 13:03:08 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000