recastPolyList.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _RECAST_POLYLIST_H_
  23. #define _RECAST_POLYLIST_H_
  24. #include "collision/abstractPolyList.h"
  25. #include "core/util/tVector.h"
  26. #ifndef CHUNKYTRIMESH_H
  27. #include "ChunkyTriMesh.h"
  28. #endif
  29. /// Represents polygons in the same manner as the .obj file format. Handy for
  30. /// padding data to Recast, since it expects this data format. At the moment,
  31. /// this class only accepts triangles.
  32. /// @see AbstractPolyList
  33. class RecastPolyList : public AbstractPolyList {
  34. public:
  35. /// @name AbstractPolyList
  36. /// @{
  37. bool isEmpty() const override;
  38. U32 addPoint(const Point3F &p) override;
  39. U32 addPlane(const PlaneF &plane) override;
  40. void begin(BaseMatInstance *material, U32 surfaceKey) override;
  41. void plane(U32 v1, U32 v2, U32 v3) override;
  42. void plane(const PlaneF& p) override;
  43. void plane(const U32 index) override;
  44. void vertex(U32 vi) override;
  45. void end() override;
  46. /// @}
  47. /// @name Data interface
  48. /// @{
  49. U32 getVertCount() const;
  50. const F32 *getVerts() const;
  51. const F32* getNormals() const;
  52. U32 getTriCount() const;
  53. const S32 *getTris() const;
  54. void clear();
  55. /// @}
  56. void renderWire() const;
  57. /// Default constructor.
  58. RecastPolyList();
  59. /// Default destructor.
  60. ~RecastPolyList();
  61. rcChunkyTriMesh* getChunkyMesh();
  62. protected:
  63. /// Number of vertices defined.
  64. U32 nverts;
  65. /// Array of vertex coordinates. Size nverts*3
  66. F32 *verts;
  67. /// Size of vertex array.
  68. U32 vertcap;
  69. // Number of normals defined.
  70. U32 nnormals;
  71. // Array of normals (xyz in float array)
  72. F32* normals;
  73. // Size of normal array (matches verts)
  74. U32 normalcap;
  75. /// Number of triangles defined.
  76. U32 ntris;
  77. /// Array of triangle vertex indices. Size ntris*3
  78. S32 *tris;
  79. /// Size of triangle array.
  80. U32 tricap;
  81. /// Index of vertex we're adding to the current triangle.
  82. U8 vidx;
  83. /// Store a list of planes - not actually used.
  84. Vector<PlaneF> planes;
  85. /// Another inherited utility function.
  86. const PlaneF& getIndexedPlane(const U32 index) override { return planes[index]; }
  87. rcChunkyTriMesh* mChunkyMesh;
  88. private:
  89. };
  90. #endif