Create a convex mesh from a PolygonVertexArray describing vertices and faces The data (vertices, faces indices, ...) are copied from the PolygonVertexArray into the created ConvexMesh. * @param polygonVertexArray A pointer to the polygon vertex array to use to create the convex mesh * @param messages A reference to a vector of messages. This vector might contains errors that occured during the cr
| 605 | * @return A pointer to the created ConvexMesh instance or nullptr if errors occured during the creation |
| 606 | */ |
| 607 | ConvexMesh* PhysicsCommon::createConvexMesh(const PolygonVertexArray& polygonVertexArray, std::vector<Message>& messages) { |
| 608 | |
| 609 | MemoryAllocator& allocator = mMemoryManager.getHeapAllocator(); |
| 610 | |
| 611 | // Create the convex mesh |
| 612 | ConvexMesh* mesh = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(ConvexMesh))) ConvexMesh(allocator); |
| 613 | |
| 614 | // Create the half-edge structure of the mesh |
| 615 | bool isValid = mesh->init(polygonVertexArray, messages); |
| 616 | |
| 617 | // If the mesh is not valid |
| 618 | if (!isValid) { |
| 619 | mesh->~ConvexMesh(); |
| 620 | allocator.release(mesh, sizeof(ConvexMesh)); |
| 621 | return nullptr; |
| 622 | } |
| 623 | |
| 624 | // If the mesh is valid |
| 625 | |
| 626 | mConvexMeshes.add(mesh); |
| 627 | |
| 628 | return mesh; |
| 629 | } |
| 630 | |
| 631 | // Create a convex mesh from an array of vertices (automatically computing the convex hull using QuickHull) |
| 632 | /// The data (vertices) are copied from the VertexArray into the created ConvexMesh. |