Blender  V2.59
RAS_MeshObject.h
Go to the documentation of this file.
00001 /*
00002  * $Id: RAS_MeshObject.h 36523 2011-05-06 20:18:42Z blendix $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00034 #ifndef __RAS_MESHOBJECT
00035 #define __RAS_MESHOBJECT
00036 
00037 #if defined(WIN32) && !defined(FREE_WINDOWS)
00038 // disable the STL warnings ("debug information length > 255")
00039 #pragma warning (disable:4786)
00040 #endif
00041 
00042 #include <vector>
00043 #include <set>
00044 #include <list>
00045 
00046 #include "RAS_Polygon.h"
00047 #include "RAS_MaterialBucket.h"
00048 #include "MT_Transform.h"
00049 
00050 #include "CTR_HashedPtr.h"
00051 
00052 struct Mesh;
00053 class RAS_Deformer;
00054 
00055 /* RAS_MeshObject is a mesh used for rendering. It stores polygons,
00056  * but the actual vertices and index arrays are stored in material
00057  * buckets, referenced by the list of RAS_MeshMaterials. */
00058 
00059 class RAS_MeshObject
00060 {
00061 private:
00062         unsigned int                            m_debugcolor;
00063 
00064         bool                                            m_bModified;
00065         bool                                            m_bMeshModified;
00066 
00067         STR_String                                      m_name;
00068         static STR_String                       s_emptyname;
00069 
00070         vector<class RAS_Polygon*>      m_Polygons;
00071 
00072         /* polygon sorting */
00073         struct polygonSlot;
00074         struct backtofront;
00075         struct fronttoback;
00076 
00077 protected:
00078         vector<int>                                             m_cacheWeightIndex;
00079         list<RAS_MeshMaterial>                  m_materials;
00080         Mesh*                                                   m_mesh;
00081 
00082 public:
00083         // for now, meshes need to be in a certain layer (to avoid sorting on lights in realtime)
00084         RAS_MeshObject(Mesh* mesh);
00085         virtual ~RAS_MeshObject();
00086 
00087 
00088         // for shape keys, 
00089         void CheckWeightCache(struct Object* obj);
00090         
00091         /* materials */
00092         int                                     NumMaterials();
00093         const STR_String&       GetMaterialName(unsigned int matid);
00094         const STR_String&       GetTextureName(unsigned int matid);
00095 
00096         RAS_MeshMaterial*       GetMeshMaterial(unsigned int matid);
00097         RAS_MeshMaterial*       GetMeshMaterial(RAS_IPolyMaterial *mat);
00098         int                                     GetMaterialId(RAS_IPolyMaterial *mat);
00099 
00100         list<RAS_MeshMaterial>::iterator GetFirstMaterial();
00101         list<RAS_MeshMaterial>::iterator GetLastMaterial();
00102 
00103         //unsigned int          GetLightLayer();
00104 
00105         /* name */
00106         void                            SetName(const char *name);
00107         STR_String&                     GetName();
00108 
00109         /* modification state */
00110         bool                            MeshModified();
00111         void                            SetMeshModified(bool v){m_bMeshModified = v;}
00112 
00113         /* original blender mesh */
00114         Mesh*                           GetMesh() { return m_mesh; }
00115 
00116         /* mesh construction */
00117         
00118         virtual RAS_Polygon*    AddPolygon(RAS_MaterialBucket *bucket, int numverts);
00119         virtual void                    AddVertex(RAS_Polygon *poly, int i,
00120                                                         const MT_Point3& xyz,
00121                                                         const MT_Point2& uv,
00122                                                         const MT_Point2& uv2,
00123                                                         const MT_Vector4& tangent,
00124                                                         const unsigned int rgbacolor,
00125                                                         const MT_Vector3& normal,
00126                                                         bool flat,
00127                                                         int origindex);
00128 
00129         void                                    SchedulePolygons(int drawingmode);
00130 
00131         /* vertex and polygon acces */
00132         int                                     NumVertices(RAS_IPolyMaterial* mat);
00133         RAS_TexVert*            GetVertex(unsigned int matid, unsigned int index);
00134         const float*            GetVertexLocation(unsigned int orig_index);
00135 
00136         int                                     NumPolygons();
00137         RAS_Polygon*            GetPolygon(int num) const;
00138         
00139         /* buckets */
00140         virtual void            AddMeshUser(void *clientobj, SG_QList *head, RAS_Deformer* deformer);
00141 
00142         void                            RemoveFromBuckets(void *clientobj);
00143         void                            EndConversion() {
00144 #if 0
00145                 m_sharedvertex_map.clear(); // SharedVertex
00146                 vector<vector<SharedVertex> >   shared_null(0);
00147                 shared_null.swap( m_sharedvertex_map ); /* really free the memory */
00148 #endif
00149         }
00150 
00151         /* colors */
00152         void                            DebugColor(unsigned int abgr);
00153         void                            SetVertexColor(RAS_IPolyMaterial* mat,MT_Vector4 rgba);
00154         
00155         /* polygon sorting by Z for alpha */
00156         void                            SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transform);
00157 
00158 
00159         bool                            HasColliderPolygon() {
00160                 int numpolys= NumPolygons();
00161                 for (int p=0; p<numpolys; p++)
00162                         if (m_Polygons[p]->IsCollider())
00163                                 return true;
00164                 
00165                 return false;
00166         }
00167 
00168         /* for construction to find shared vertices */
00169         struct SharedVertex {
00170                 RAS_DisplayArray *m_darray;
00171                 int m_offset;
00172         };
00173 
00174         vector<vector<SharedVertex> >   m_sharedvertex_map;
00175         
00176         
00177 #ifdef WITH_CXX_GUARDEDALLOC
00178 public:
00179         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_MeshObject"); }
00180         void operator delete( void *mem ) { MEM_freeN(mem); }
00181 #endif
00182 };
00183 
00184 #endif //__RAS_MESHOBJECT
00185