4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
29 #ifndef __RAS_MESHOBJECT
30 #define __RAS_MESHOBJECT
32 #if defined(WIN32) && !defined(FREE_WINDOWS)
33 // disable the STL warnings ("debug information length > 255")
34 #pragma warning (disable:4786)
41 #include "RAS_Polygon.h"
42 #include "RAS_MaterialBucket.h"
43 #include "MT_Transform.h"
45 #include "GEN_HashedPtr.h"
50 /* RAS_MeshObject is a mesh used for rendering. It stores polygons,
51 * but the actual vertices and index arrays are stored in material
52 * buckets, referenced by the list of RAS_MeshMaterials. */
57 unsigned int m_debugcolor;
63 static STR_String s_emptyname;
65 vector<class RAS_Polygon*> m_Polygons;
73 vector<int> m_cacheWeightIndex;
74 list<RAS_MeshMaterial> m_materials;
78 // for now, meshes need to be in a certain layer (to avoid sorting on lights in realtime)
79 RAS_MeshObject(Mesh* mesh);
80 virtual ~RAS_MeshObject();
84 void CheckWeightCache(struct Object* obj);
88 const STR_String& GetMaterialName(unsigned int matid);
89 const STR_String& GetTextureName(unsigned int matid);
91 RAS_MeshMaterial* GetMeshMaterial(unsigned int matid);
92 RAS_MeshMaterial* GetMeshMaterial(RAS_IPolyMaterial *mat);
93 int GetMaterialId(RAS_IPolyMaterial *mat);
95 list<RAS_MeshMaterial>::iterator GetFirstMaterial();
96 list<RAS_MeshMaterial>::iterator GetLastMaterial();
98 //unsigned int GetLightLayer();
101 void SetName(const char *name);
102 STR_String& GetName();
104 /* modification state */
106 void SetMeshModified(bool v){m_bMeshModified = v;}
108 /* original blender mesh */
109 Mesh* GetMesh() { return m_mesh; }
111 /* mesh construction */
113 virtual RAS_Polygon* AddPolygon(RAS_MaterialBucket *bucket, int numverts);
114 virtual void AddVertex(RAS_Polygon *poly, int i,
115 const MT_Point3& xyz,
117 const MT_Point2& uv2,
118 const MT_Vector4& tangent,
119 const unsigned int rgbacolor,
120 const MT_Vector3& normal,
124 void SchedulePolygons(int drawingmode);
126 /* vertex and polygon acces */
127 int NumVertices(RAS_IPolyMaterial* mat);
128 RAS_TexVert* GetVertex(unsigned int matid, unsigned int index);
129 const float* GetVertexLocation(unsigned int orig_index);
132 RAS_Polygon* GetPolygon(int num) const;
135 virtual void AddMeshUser(void *clientobj, SG_QList *head, RAS_Deformer* deformer);
137 void RemoveFromBuckets(void *clientobj);
138 void EndConversion() {
140 m_sharedvertex_map.clear(); // SharedVertex
141 vector<vector<SharedVertex> > shared_null(0);
142 shared_null.swap( m_sharedvertex_map ); /* really free the memory */
147 void DebugColor(unsigned int abgr);
148 void SetVertexColor(RAS_IPolyMaterial* mat,MT_Vector4 rgba);
150 /* polygon sorting by Z for alpha */
151 void SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transform);
154 bool HasColliderPolygon() {
155 int numpolys= NumPolygons();
156 for (int p=0; p<numpolys; p++)
157 if (m_Polygons[p]->IsCollider())
163 /* for construction to find shared vertices */
164 struct SharedVertex {
165 RAS_DisplayArray *m_darray;
169 vector<vector<SharedVertex> > m_sharedvertex_map;
172 #ifdef WITH_CXX_GUARDEDALLOC
174 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_MeshObject"); }
175 void operator delete( void *mem ) { MEM_freeN(mem); }
179 #endif //__RAS_MESHOBJECT