RAS_MeshObject.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  19. * All rights reserved.
  20. *
  21. * The Original Code is: all of this file.
  22. *
  23. * Contributor(s): none yet.
  24. *
  25. * ***** END GPL LICENSE BLOCK *****
  26. */
  27. /** \file RAS_MeshObject.h
  28. * \ingroup bgerast
  29. */
  30. #ifndef __RAS_MESHOBJECT_H__
  31. #define __RAS_MESHOBJECT_H__
  32. #ifdef _MSC_VER
  33. /* disable the STL warnings ("debug information length > 255") */
  34. # pragma warning (disable:4786)
  35. #endif
  36. #include <vector>
  37. #include <list>
  38. #include "RAS_MaterialBucket.h"
  39. #include "MT_Transform.h"
  40. #include "STR_String.h"
  41. struct Mesh;
  42. class RAS_Deformer;
  43. class RAS_Polygon;
  44. /* RAS_MeshObject is a mesh used for rendering. It stores polygons,
  45. * but the actual vertices and index arrays are stored in material
  46. * buckets, referenced by the list of RAS_MeshMaterials. */
  47. class RAS_MeshObject
  48. {
  49. private:
  50. /* unsigned int m_debugcolor; */ /* UNUSED */
  51. bool m_bModified;
  52. bool m_bMeshModified;
  53. STR_String m_name;
  54. static STR_String s_emptyname;
  55. vector<RAS_Polygon*> m_Polygons;
  56. /* polygon sorting */
  57. struct polygonSlot;
  58. struct backtofront;
  59. struct fronttoback;
  60. protected:
  61. vector<int> m_cacheWeightIndex;
  62. list<RAS_MeshMaterial> m_materials;
  63. Mesh* m_mesh;
  64. public:
  65. // for now, meshes need to be in a certain layer (to avoid sorting on lights in realtime)
  66. RAS_MeshObject(Mesh* mesh);
  67. virtual ~RAS_MeshObject();
  68. /* materials */
  69. int NumMaterials();
  70. const STR_String& GetMaterialName(unsigned int matid);
  71. const STR_String& GetTextureName(unsigned int matid);
  72. RAS_MeshMaterial* GetMeshMaterial(unsigned int matid);
  73. RAS_MeshMaterial* GetMeshMaterial(RAS_IPolyMaterial *mat);
  74. int GetMaterialId(RAS_IPolyMaterial *mat);
  75. list<RAS_MeshMaterial>::iterator GetFirstMaterial();
  76. list<RAS_MeshMaterial>::iterator GetLastMaterial();
  77. //unsigned int GetLightLayer();
  78. /* name */
  79. void SetName(const char *name);
  80. STR_String& GetName();
  81. /* modification state */
  82. bool MeshModified();
  83. void SetMeshModified(bool v) { m_bMeshModified = v; }
  84. /* original blender mesh */
  85. Mesh* GetMesh() { return m_mesh; }
  86. /* mesh construction */
  87. virtual RAS_Polygon* AddPolygon(RAS_MaterialBucket *bucket, int numverts);
  88. virtual void AddVertex(RAS_Polygon *poly, int i,
  89. const MT_Point3& xyz,
  90. const MT_Point2 uvs[RAS_TexVert::MAX_UNIT],
  91. const MT_Vector4& tangent,
  92. const unsigned int rgbacolor,
  93. const MT_Vector3& normal,
  94. bool flat,
  95. int origindex);
  96. void SchedulePolygons(int drawingmode);
  97. /* vertex and polygon acces */
  98. int NumVertices(RAS_IPolyMaterial* mat);
  99. RAS_TexVert* GetVertex(unsigned int matid, unsigned int index);
  100. const float* GetVertexLocation(unsigned int orig_index);
  101. int NumPolygons();
  102. RAS_Polygon* GetPolygon(int num) const;
  103. /* buckets */
  104. virtual void AddMeshUser(void *clientobj, SG_QList *head, RAS_Deformer* deformer);
  105. void RemoveFromBuckets(void *clientobj);
  106. void EndConversion();
  107. /* colors */
  108. void DebugColor(unsigned int abgr);
  109. void SetVertexColor(RAS_IPolyMaterial* mat,MT_Vector4 rgba);
  110. /* polygon sorting by Z for alpha */
  111. void SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transform);
  112. bool HasColliderPolygon();
  113. /* for construction to find shared vertices */
  114. struct SharedVertex {
  115. RAS_DisplayArray *m_darray;
  116. int m_offset;
  117. };
  118. vector<vector<SharedVertex> > m_sharedvertex_map;
  119. #ifdef WITH_CXX_GUARDEDALLOC
  120. MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_MeshObject")
  121. #endif
  122. };
  123. #endif /* __RAS_MESHOBJECT_H__ */