1 /******************************************************************************** 2 * ReactPhysics3D physics library, http://www.reactphysics3d.com * 3 * Copyright (c) 2010-2020 Daniel Chappuis * 4 ********************************************************************************* 5 * * 6 * This software is provided 'as-is', without any express or implied warranty. * 7 * In no event will the authors be held liable for any damages arising from the * 8 * use of this software. * 9 * * 10 * Permission is granted to anyone to use this software for any purpose, * 11 * including commercial applications, and to alter it and redistribute it * 12 * freely, subject to the following restrictions: * 13 * * 14 * 1. The origin of this software must not be misrepresented; you must not claim * 15 * that you wrote the original software. If you use this software in a * 16 * product, an acknowledgment in the product documentation would be * 17 * appreciated but is not required. * 18 * * 19 * 2. Altered source versions must be plainly marked as such, and must not be * 20 * misrepresented as being the original software. * 21 * * 22 * 3. This notice may not be removed or altered from any source distribution. * 23 * * 24 ********************************************************************************/ 25 26 #ifndef REACTPHYSICS3D_TRIANGLE_MESH_H 27 #define REACTPHYSICS3D_TRIANGLE_MESH_H 28 29 // Libraries 30 #include <cassert> 31 #include <reactphysics3d/containers/List.h> 32 #include <reactphysics3d/memory/MemoryAllocator.h> 33 34 namespace reactphysics3d { 35 36 // Declarations 37 class TriangleVertexArray; 38 39 // Class TriangleMesh 40 /** 41 * This class represents a mesh made of triangles. A TriangleMesh contains 42 * one or several parts. Each part is a set of triangles represented in a 43 * TriangleVertexArray object describing all the triangles vertices of the part. 44 * A TriangleMesh object can be used to create a ConcaveMeshShape from a triangle 45 * mesh for instance. 46 */ 47 class TriangleMesh { 48 49 protected: 50 51 /// All the triangle arrays of the mesh (one triangle array per part) 52 List<TriangleVertexArray*> mTriangleArrays; 53 54 /// Constructor 55 TriangleMesh(reactphysics3d::MemoryAllocator& allocator); 56 57 public: 58 59 /// Destructor 60 ~TriangleMesh(); 61 62 /// Add a subpart of the mesh 63 void addSubpart(TriangleVertexArray* triangleVertexArray); 64 65 /// Return a pointer to a given subpart (triangle vertex array) of the mesh 66 TriangleVertexArray* getSubpart(uint indexSubpart) const; 67 68 /// Return the number of subparts of the mesh 69 uint getNbSubparts() const; 70 71 72 // ---------- Friendship ---------- // 73 74 friend class PhysicsCommon; 75 }; 76 77 // Add a subpart of the mesh 78 /** 79 * @param triangleVertexArray Pointer to the TriangleVertexArray to add into the mesh 80 */ addSubpart(TriangleVertexArray * triangleVertexArray)81inline void TriangleMesh::addSubpart(TriangleVertexArray* triangleVertexArray) { 82 mTriangleArrays.add(triangleVertexArray ); 83 } 84 85 // Return a pointer to a given subpart (triangle vertex array) of the mesh 86 /** 87 * @param indexSubpart The index of the sub-part of the mesh 88 * @return A pointer to the triangle vertex array of a given sub-part of the mesh 89 */ getSubpart(uint indexSubpart)90inline TriangleVertexArray* TriangleMesh::getSubpart(uint indexSubpart) const { 91 assert(indexSubpart < mTriangleArrays.size()); 92 return mTriangleArrays[indexSubpart]; 93 } 94 95 // Return the number of sub-parts of the mesh 96 /** 97 * @return The number of sub-parts of the mesh 98 */ getNbSubparts()99inline uint TriangleMesh::getNbSubparts() const { 100 return mTriangleArrays.size(); 101 } 102 103 } 104 105 #endif 106 107