Create the half-edge structure of the mesh This method returns true if the mesh is valid or false otherwise
| 115 | // Create the half-edge structure of the mesh |
| 116 | /// This method returns true if the mesh is valid or false otherwise |
| 117 | bool ConvexMesh::createHalfEdgeStructure(const PolygonVertexArray& polygonVertexArray, std::vector<Message>& errors) { |
| 118 | |
| 119 | bool isValid = true; |
| 120 | |
| 121 | // For each vertex of the mesh |
| 122 | const uint32 nbVertices = polygonVertexArray.getNbVertices(); |
| 123 | for (uint32 v=0; v < nbVertices; v++) { |
| 124 | mHalfEdgeStructure.addVertex(v); |
| 125 | } |
| 126 | |
| 127 | uint32 nbEdges = 0; |
| 128 | |
| 129 | // For each polygon face of the mesh |
| 130 | const uint32 nbFaces = polygonVertexArray.getNbFaces(); |
| 131 | for (uint32 f=0; f < nbFaces; f++) { |
| 132 | |
| 133 | // Get the polygon face |
| 134 | PolygonVertexArray::PolygonFace* face = polygonVertexArray.getPolygonFace(f); |
| 135 | |
| 136 | Array<uint32> faceVertices(mMemoryAllocator, face->nbVertices); |
| 137 | |
| 138 | // For each vertex of the face |
| 139 | for (uint32 v=0; v < face->nbVertices; v++) { |
| 140 | faceVertices.add(polygonVertexArray.getVertexIndexInFace(f, v)); |
| 141 | } |
| 142 | |
| 143 | nbEdges += face->nbVertices; |
| 144 | |
| 145 | // If the face has less than three vertices |
| 146 | if (faceVertices.size() < 3) { |
| 147 | |
| 148 | // Create a new error |
| 149 | errors.push_back(Message(std::string("The face with index " + std::to_string(f) + " has less than three vertices"))); |
| 150 | |
| 151 | isValid = false; |
| 152 | |
| 153 | RP3D_LOG("PhysicsCommon", Logger::Level::Error, Logger::Category::PhysicCommon, |
| 154 | "Error when creating a ConvexMesh: Mesh has a face with less than three vertices.", __FILE__, __LINE__); |
| 155 | } |
| 156 | |
| 157 | // Addd the face into the half-edge structure |
| 158 | mHalfEdgeStructure.addFace(faceVertices); |
| 159 | } |
| 160 | |
| 161 | nbEdges /= 2; |
| 162 | |
| 163 | // If the mesh is not valid (check Euler formula V + F - E = 2) (has duplicated vertices) |
| 164 | if (2 + nbEdges - polygonVertexArray.getNbFaces() != polygonVertexArray.getNbVertices()) { |
| 165 | |
| 166 | RP3D_LOG("PhysicsCommon", Logger::Level::Error, Logger::Category::PhysicCommon, |
| 167 | "Error when creating a ConvexMesh: input PolygonVertexArray is not valid. Mesh with duplicated vertices is not supported.", __FILE__, __LINE__); |
| 168 | |
| 169 | // Create a new error |
| 170 | errors.push_back(Message(std::string("Convex Mesh might have duplicated vertices (invalid Euler formula)"))); |
| 171 | |
| 172 | isValid = false; |
| 173 | } |
| 174 |
nothing calls this directly
no test coverage detected