Blender V2.61 - r43446

RAS_MeshObject.h

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