diff options
Diffstat (limited to 'PhysX_3.4/Source/PhysXCooking')
| -rw-r--r-- | PhysX_3.4/Source/PhysXCooking/src/Cooking.cpp | 22 | ||||
| -rw-r--r-- | PhysX_3.4/Source/PhysXCooking/src/Cooking.h | 6 | ||||
| -rw-r--r-- | PhysX_3.4/Source/PhysXCooking/src/convex/QuickHullConvexHullLib.cpp | 68 |
3 files changed, 63 insertions, 33 deletions
diff --git a/PhysX_3.4/Source/PhysXCooking/src/Cooking.cpp b/PhysX_3.4/Source/PhysXCooking/src/Cooking.cpp index b53884da..dc8c6a92 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/Cooking.cpp +++ b/PhysX_3.4/Source/PhysXCooking/src/Cooking.cpp @@ -127,8 +127,6 @@ bool Cooking::cookTriangleMesh(TriangleMeshBuilder& builder, const PxTriangleMes *condition = PxTriangleMeshCookingResult::eSUCCESS; if(!builder.loadFromDesc(desc, condition, false)) { - if (condition) - *condition = PxTriangleMeshCookingResult::eFAILURE; return false; } @@ -150,13 +148,17 @@ bool Cooking::cookTriangleMesh(const PxTriangleMeshDesc& desc, PxOutputStream& s } } -PxTriangleMesh* Cooking::createTriangleMesh(TriangleMeshBuilder& builder, const PxTriangleMeshDesc& desc, PxPhysicsInsertionCallback& insertionCallback) const +PxTriangleMesh* Cooking::createTriangleMesh(TriangleMeshBuilder& builder, const PxTriangleMeshDesc& desc, PxPhysicsInsertionCallback& insertionCallback, PxTriangleMeshCookingResult::Enum* condition) const { // cooking code does lots of float bitwise reinterpretation that generates exceptions PX_FPU_GUARD; - if(!builder.loadFromDesc(desc, NULL, false)) + if (condition) + *condition = PxTriangleMeshCookingResult::eSUCCESS; + if(!builder.loadFromDesc(desc, condition, false)) + { return NULL; + } // check if the indices can be moved from 32bits to 16bits if(!(mParams.meshPreprocessParams & PxMeshPreprocessingFlag::eFORCE_32BIT_INDICES)) @@ -171,17 +173,17 @@ PxTriangleMesh* Cooking::createTriangleMesh(TriangleMeshBuilder& builder, const return static_cast<PxTriangleMesh*>(insertionCallback.buildObjectFromData(type, &builder.getMeshData())); } -PxTriangleMesh* Cooking::createTriangleMesh(const PxTriangleMeshDesc& desc, PxPhysicsInsertionCallback& insertionCallback) const +PxTriangleMesh* Cooking::createTriangleMesh(const PxTriangleMeshDesc& desc, PxPhysicsInsertionCallback& insertionCallback, PxTriangleMeshCookingResult::Enum* condition) const { if((mParams.midphaseDesc.getType() == PxMeshMidPhase::eINVALID) || (mParams.midphaseDesc.getType() == PxMeshMidPhase::eBVH33)) { RTreeTriangleMeshBuilder builder(mParams); - return createTriangleMesh(builder, desc, insertionCallback); + return createTriangleMesh(builder, desc, insertionCallback, condition); } else { BV4TriangleMeshBuilder builder(mParams); - return createTriangleMesh(builder, desc, insertionCallback); + return createTriangleMesh(builder, desc, insertionCallback, condition); } } @@ -323,7 +325,7 @@ bool Cooking::cookConvexMesh(const PxConvexMeshDesc& desc_, PxOutputStream& stre ////////////////////////////////////////////////////////////////////////// // cook convex mesh from given desc, copy the results into internal convex mesh // and insert the mesh into PxPhysics -PxConvexMesh* Cooking::createConvexMesh(const PxConvexMeshDesc& desc_, PxPhysicsInsertionCallback& insertionCallback) const +PxConvexMesh* Cooking::createConvexMesh(const PxConvexMeshDesc& desc_, PxPhysicsInsertionCallback& insertionCallback, PxConvexMeshCookingResult::Enum* condition) const { PX_FPU_GUARD; // choose cooking library if needed @@ -352,7 +354,7 @@ PxConvexMesh* Cooking::createConvexMesh(const PxConvexMeshDesc& desc_, PxPhysics // cook the mesh ConvexMeshBuilder meshBuilder(mParams.buildGPUData); - if (!cookConvexMeshInternal(desc, meshBuilder, hullLib, NULL)) + if (!cookConvexMeshInternal(desc, meshBuilder, hullLib, condition)) { if(hullLib) PX_DELETE(hullLib); @@ -369,6 +371,8 @@ PxConvexMesh* Cooking::createConvexMesh(const PxConvexMeshDesc& desc_, PxPhysics Gu::ConvexMesh* convexMesh = static_cast<Gu::ConvexMesh*>(insertionCallback.buildObjectFromData(PxConcreteType::eCONVEX_MESH, &meshData)); if (!convexMesh) { + if(condition) + *condition = PxConvexMeshCookingResult::eFAILURE; if (hullLib) PX_DELETE(hullLib); return NULL; diff --git a/PhysX_3.4/Source/PhysXCooking/src/Cooking.h b/PhysX_3.4/Source/PhysXCooking/src/Cooking.h index 220ce386..0ba6bbf6 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/Cooking.h +++ b/PhysX_3.4/Source/PhysXCooking/src/Cooking.h @@ -50,11 +50,11 @@ public: virtual const PxCookingParams& getParams() const; virtual bool platformMismatch() const; virtual bool cookTriangleMesh(const PxTriangleMeshDesc& desc, PxOutputStream& stream, PxTriangleMeshCookingResult::Enum* condition = NULL) const; - virtual PxTriangleMesh* createTriangleMesh(const PxTriangleMeshDesc& desc, PxPhysicsInsertionCallback& insertionCallback) const; + virtual PxTriangleMesh* createTriangleMesh(const PxTriangleMeshDesc& desc, PxPhysicsInsertionCallback& insertionCallback, PxTriangleMeshCookingResult::Enum* condition = NULL) const; virtual bool validateTriangleMesh(const PxTriangleMeshDesc& desc) const; virtual bool cookConvexMesh(const PxConvexMeshDesc& desc, PxOutputStream& stream, PxConvexMeshCookingResult::Enum* condition) const; - virtual PxConvexMesh* createConvexMesh(const PxConvexMeshDesc& desc, PxPhysicsInsertionCallback& insertionCallback) const; + virtual PxConvexMesh* createConvexMesh(const PxConvexMeshDesc& desc, PxPhysicsInsertionCallback& insertionCallback, PxConvexMeshCookingResult::Enum* condition) const; virtual bool validateConvexMesh(const PxConvexMeshDesc& desc) const; virtual bool computeHullPolygons(const PxSimpleTriangleMesh& mesh, PxAllocatorCallback& inCallback,PxU32& nbVerts, PxVec3*& vertices, PxU32& nbIndices, PxU32*& indices, PxU32& nbPolygons, PxHullPolygon*& hullPolygons) const; @@ -76,7 +76,7 @@ public: private: bool cookConvexMeshInternal(const PxConvexMeshDesc& desc, ConvexMeshBuilder& meshBuilder, ConvexHullLib* hullLib, PxConvexMeshCookingResult::Enum* condition) const; bool cookTriangleMesh(TriangleMeshBuilder& builder, const PxTriangleMeshDesc& desc, PxOutputStream& stream, PxTriangleMeshCookingResult::Enum* condition) const; - PxTriangleMesh* createTriangleMesh(TriangleMeshBuilder& builder, const PxTriangleMeshDesc& desc, PxPhysicsInsertionCallback& insertionCallback) const; + PxTriangleMesh* createTriangleMesh(TriangleMeshBuilder& builder, const PxTriangleMeshDesc& desc, PxPhysicsInsertionCallback& insertionCallback, PxTriangleMeshCookingResult::Enum* condition) const; private: PxCookingParams mParams; diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/QuickHullConvexHullLib.cpp b/PhysX_3.4/Source/PhysXCooking/src/convex/QuickHullConvexHullLib.cpp index b9d0adfc..5d933f73 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/QuickHullConvexHullLib.cpp +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/QuickHullConvexHullLib.cpp @@ -1449,53 +1449,79 @@ namespace local PX_ALLOCA(edges, QuickHullHalfEdge, (face1.numEdges + face2.numEdges)); PxMemSet(edges, 0, (face1.numEdges + face2.numEdges)*sizeof(QuickHullHalfEdge)); QuickHullFace mergedFace; - mergedFace.edge = &edges[0]; + mergedFace.edge = &edges[0]; // copy the first face edges PxU32 currentEdge = 0; - QuickHullHalfEdge* copyHe = he.next; - while (copyHe != &he) + const QuickHullHalfEdge* heTwin = NULL; + const QuickHullHalfEdge* heCopy = NULL; + const QuickHullHalfEdge* startEdge = (face1.edge != &he) ? face1.edge : face1.edge->next; + const QuickHullHalfEdge* copyHe = startEdge; + do { edges[currentEdge].face = &mergedFace; edges[currentEdge].tail = copyHe->tail; - edges[currentEdge].next = &edges.mPointer[currentEdge + 1]; + if(copyHe == &he) + { + heTwin = copyHe->twin; + heCopy = &edges[currentEdge]; + } + const PxU32 nextIndex = (copyHe->next == startEdge) ? 0 : currentEdge + 1; + const PxU32 prevIndex = (currentEdge == 0) ? face1.numEdges - 1 : currentEdge - 1; + edges[currentEdge].next = &edges.mPointer[nextIndex]; + edges[currentEdge].prev = &edges.mPointer[prevIndex]; currentEdge++; copyHe = copyHe->next; - } + } while (copyHe != startEdge); // copy the second face edges - copyHe = he.twin->next; - while (copyHe != he.twin) + copyHe = face2.edge; + do { edges[currentEdge].face = &mergedFace; edges[currentEdge].tail = copyHe->tail; - edges[currentEdge].next = &edges.mPointer[currentEdge + 1]; + if(heTwin == copyHe) + heTwin = &edges[currentEdge]; + const PxU32 nextIndex = (copyHe->next == face2.edge) ? face1.numEdges : currentEdge + 1; + const PxU32 prevIndex = (currentEdge == face1.numEdges) ? face1.numEdges + face2.numEdges - 1 : currentEdge - 1; + edges[currentEdge].next = &edges.mPointer[nextIndex]; + edges[currentEdge].prev = &edges.mPointer[prevIndex]; currentEdge++; copyHe = copyHe->next; - } - edges[--currentEdge].next = &edges.mPointer[0]; + } while (copyHe != face2.edge); + + PX_ASSERT(heTwin); + + QuickHullHalfEdge* hedgeAdjPrev = heCopy->prev; + QuickHullHalfEdge* hedgeAdjNext = heCopy->next; + QuickHullHalfEdge* hedgeOppPrev = heTwin->prev; + QuickHullHalfEdge* hedgeOppNext = heTwin->next; + + hedgeOppPrev->next = hedgeAdjNext; + hedgeAdjNext->prev = hedgeOppPrev; + + hedgeAdjPrev->next = hedgeOppNext; + hedgeOppNext->prev = hedgeAdjPrev; // compute normal and centroid mergedFace.computeNormalAndCentroid(); // test the vertex distance - float maxDist = mPlaneTolerance; - QuickHullHalfEdge* qhe = mergedFace.edge; - do + const float maxDist = mPlaneTolerance; + for(PxU32 iVerts=0; iVerts< mNumVertices; iVerts++) { - const QuickHullVertex& vertex = qhe->tail; + const QuickHullVertex& vertex = mVerticesList[iVerts]; const float dist = mergedFace.distanceToPlane(vertex.point); if (dist > maxDist) { return false; } - qhe = qhe->next; - } while (qhe != mergedFace.edge); + } // check the convexity - qhe = mergedFace.edge; + QuickHullHalfEdge* qhe = mergedFace.edge; do { const QuickHullVertex& vertex = qhe->tail; @@ -1525,10 +1551,10 @@ namespace local QuickHullHalfEdge* hedgeOpp = he.twin; - QuickHullHalfEdge* hedgeAdjPrev = he.prev; - QuickHullHalfEdge* hedgeAdjNext = he.next; - QuickHullHalfEdge* hedgeOppPrev = hedgeOpp->prev; - QuickHullHalfEdge* hedgeOppNext = hedgeOpp->next; + hedgeAdjPrev = he.prev; + hedgeAdjNext = he.next; + hedgeOppPrev = hedgeOpp->prev; + hedgeOppNext = hedgeOpp->next; // check if we are lining up with the face in adjPrev dir while (hedgeAdjPrev->getOppositeFace() == oppFace) |