diff options
Diffstat (limited to 'PhysX_3.4/Source/PhysXCooking/src/convex')
18 files changed, 130 insertions, 31 deletions
diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/BigConvexDataBuilder.cpp b/PhysX_3.4/Source/PhysXCooking/src/convex/BigConvexDataBuilder.cpp index 5ab5965d..f7ef03dd 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/BigConvexDataBuilder.cpp +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/BigConvexDataBuilder.cpp @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/BigConvexDataBuilder.h b/PhysX_3.4/Source/PhysXCooking/src/convex/BigConvexDataBuilder.h index 2abf5993..00c1db44 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/BigConvexDataBuilder.h +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/BigConvexDataBuilder.h @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullBuilder.cpp b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullBuilder.cpp index c9c8c678..cc9d8b12 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullBuilder.cpp +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullBuilder.cpp @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullBuilder.h b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullBuilder.h index a00c0506..7d2215e2 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullBuilder.h +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullBuilder.h @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.cpp b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.cpp index 92ffc888..90e8a66b 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.cpp +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.cpp @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. @@ -127,12 +127,62 @@ namespace local } + +////////////////////////////////////////////////////////////////////////// +// shift vertices around origin and normalize point cloud, remove duplicates! +bool ConvexHullLib::shiftAndcleanupVertices(PxU32 svcount, const PxVec3* svertices, PxU32 stride, + PxU32& vcount, PxVec3* vertices, PxVec3& scale, PxVec3& center) +{ + mShiftedVerts = reinterpret_cast<PxVec3*> (PX_ALLOC_TEMP(sizeof(PxVec3)*svcount, "PxVec3")); + const char* vtx = reinterpret_cast<const char *> (svertices); + PxBounds3 bounds; + bounds.setEmpty(); + + // get the bounding box + for (PxU32 i = 0; i < svcount; i++) + { + const PxVec3& p = *reinterpret_cast<const PxVec3 *> (vtx); + vtx += stride; + + bounds.include(p); + } + mOriginShift = bounds.getCenter(); + vtx = reinterpret_cast<const char *> (svertices); + for (PxU32 i = 0; i < svcount; i++) + { + const PxVec3& p = *reinterpret_cast<const PxVec3 *> (vtx); + vtx += stride; + + mShiftedVerts[i] = p - mOriginShift; + } + return cleanupVertices(svcount, mShiftedVerts, sizeof(PxVec3), vcount, vertices, scale, center); +} + +////////////////////////////////////////////////////////////////////////// +// Shift verts/planes in the desc back +void ConvexHullLib::shiftConvexMeshDesc(PxConvexMeshDesc& desc) +{ + PX_ASSERT(mConvexMeshDesc.flags & PxConvexFlag::eSHIFT_VERTICES); + + PxVec3* points = reinterpret_cast<PxVec3*>(const_cast<void*>(desc.points.data)); + for(PxU32 i = 0; i < desc.points.count; i++) + { + points[i] = points[i] + mOriginShift; + } + + PxHullPolygon* polygons = reinterpret_cast<PxHullPolygon*>(const_cast<void*>(desc.polygons.data)); + for(PxU32 i = 0; i < desc.polygons.count; i++) + { + polygons[i].mPlane[3] -= PxVec3(polygons[i].mPlane[0], polygons[i].mPlane[1], polygons[i].mPlane[2]).dot(mOriginShift); + } +} + ////////////////////////////////////////////////////////////////////////// // normalize point cloud, remove duplicates! bool ConvexHullLib::cleanupVertices(PxU32 svcount, const PxVec3* svertices, PxU32 stride, PxU32& vcount, PxVec3* vertices, PxVec3& scale, PxVec3& center) { - if ( svcount == 0 ) + if (svcount == 0) return false; const PxVec3* verticesToClean = svertices; @@ -296,4 +346,7 @@ ConvexHullLib::~ConvexHullLib() { if (mSwappedIndices) PX_FREE(mSwappedIndices); + + if(mShiftedVerts) + PX_FREE(mShiftedVerts); } diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.h b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.h index 19ab68fe..cd8f766e 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.h +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.h @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. @@ -45,7 +45,8 @@ namespace physx public: // functions ConvexHullLib(const PxConvexMeshDesc& desc, const PxCookingParams& params) - : mConvexMeshDesc(desc), mCookingParams(params), mSwappedIndices(NULL) + : mConvexMeshDesc(desc), mCookingParams(params), mSwappedIndices(NULL), + mShiftedVerts(NULL) { } @@ -70,12 +71,25 @@ namespace physx PxVec3& scale, // scale PxVec3& center); // center + // shift vertices around origin and clean input vertices from duplicates, normalize etc. + bool shiftAndcleanupVertices(PxU32 svcount, // input vertex count + const PxVec3* svertices, // vertices + PxU32 stride, // stride + PxU32& vcount, // output number of vertices + PxVec3* vertices, // location to store the results. + PxVec3& scale, // scale + PxVec3& center); // center + void swapLargestFace(PxConvexMeshDesc& desc); + void shiftConvexMeshDesc(PxConvexMeshDesc& desc); + protected: const PxConvexMeshDesc& mConvexMeshDesc; const PxCookingParams& mCookingParams; - PxU32* mSwappedIndices; + PxU32* mSwappedIndices; + PxVec3 mOriginShift; + PxVec3* mShiftedVerts; }; } diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullUtils.cpp b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullUtils.cpp index cf921a16..947a674c 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullUtils.cpp +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullUtils.cpp @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullUtils.h b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullUtils.h index 5178b043..ccdcd70e 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullUtils.h +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullUtils.h @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexMeshBuilder.cpp b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexMeshBuilder.cpp index 540d838d..bfdf0bef 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexMeshBuilder.cpp +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexMeshBuilder.cpp @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexMeshBuilder.h b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexMeshBuilder.h index 9d584c95..cdfe0376 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexMeshBuilder.h +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexMeshBuilder.h @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexPolygonsBuilder.cpp b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexPolygonsBuilder.cpp index 44725819..68b53230 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexPolygonsBuilder.cpp +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexPolygonsBuilder.cpp @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexPolygonsBuilder.h b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexPolygonsBuilder.h index 52044eb0..2ee991af 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexPolygonsBuilder.h +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexPolygonsBuilder.h @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/InflationConvexHullLib.cpp b/PhysX_3.4/Source/PhysXCooking/src/convex/InflationConvexHullLib.cpp index 8f60275c..392a890a 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/InflationConvexHullLib.cpp +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/InflationConvexHullLib.cpp @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. @@ -572,20 +572,34 @@ PxConvexMeshCookingResult::Enum InflationConvexHullLib::createConvexHull() PxConvexMeshCookingResult::Enum res = PxConvexMeshCookingResult::eFAILURE; PxU32 vcount = mConvexMeshDesc.points.count; - if ( vcount < 8 ) + if (vcount < 8) vcount = 8; - // allocate additional vec3 for V4 safe load in VolumeInteration + // allocate additional vec3 for V4 safe load in VolumeIntegration PxVec3* vsource = reinterpret_cast<PxVec3*> (PX_ALLOC_TEMP( sizeof(PxVec3)*vcount + 1, "PxVec3")); PxVec3 scale; PxVec3 center; PxU32 ovcount; // cleanup the vertices first - if(!cleanupVertices(mConvexMeshDesc.points.count, reinterpret_cast<const PxVec3*> (mConvexMeshDesc.points.data), mConvexMeshDesc.points.stride, - ovcount, vsource, scale, center )) - return res; - + if(mConvexMeshDesc.flags & PxConvexFlag::eSHIFT_VERTICES) + { + if(!shiftAndcleanupVertices(mConvexMeshDesc.points.count, reinterpret_cast<const PxVec3*> (mConvexMeshDesc.points.data), mConvexMeshDesc.points.stride, + ovcount, vsource, scale, center )) + { + PX_FREE(vsource); + return res; + } + } + else + { + if(!cleanupVertices(mConvexMeshDesc.points.count, reinterpret_cast<const PxVec3*> (mConvexMeshDesc.points.data), mConvexMeshDesc.points.stride, + ovcount, vsource, scale, center )) + { + PX_FREE(vsource); + return res; + } + } // scale vertices back to their original size. for (PxU32 i=0; i<ovcount; i++) { @@ -1456,6 +1470,9 @@ void InflationConvexHullLib::fillConvexMeshDesc(PxConvexMeshDesc& outDesc) outDesc.polygons.data = mHullResult.mPolygons; swapLargestFace(outDesc); + + if(mConvexMeshDesc.flags & PxConvexFlag::eSHIFT_VERTICES) + shiftConvexMeshDesc(outDesc); } ////////////////////////////////////////////////////////////////////////// diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/InflationConvexHullLib.h b/PhysX_3.4/Source/PhysXCooking/src/convex/InflationConvexHullLib.h index 8369691f..154c495e 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/InflationConvexHullLib.h +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/InflationConvexHullLib.h @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/QuickHullConvexHullLib.cpp b/PhysX_3.4/Source/PhysXCooking/src/convex/QuickHullConvexHullLib.cpp index 13b88364..15d34b6e 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/QuickHullConvexHullLib.cpp +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/QuickHullConvexHullLib.cpp @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. @@ -1744,11 +1744,23 @@ PxConvexMeshCookingResult::Enum QuickHullConvexHullLib::createConvexHull() PxU32 outvcount; // cleanup the vertices first - if(!cleanupVertices(mConvexMeshDesc.points.count, reinterpret_cast<const PxVec3*> (mConvexMeshDesc.points.data), mConvexMeshDesc.points.stride, - outvcount, outvsource, scale, center )) + if(mConvexMeshDesc.flags & PxConvexFlag::eSHIFT_VERTICES) { - PX_FREE(outvsource); - return res; + if(!shiftAndcleanupVertices(mConvexMeshDesc.points.count, reinterpret_cast<const PxVec3*> (mConvexMeshDesc.points.data), mConvexMeshDesc.points.stride, + outvcount, outvsource, scale, center )) + { + PX_FREE(outvsource); + return res; + } + } + else + { + if(!cleanupVertices(mConvexMeshDesc.points.count, reinterpret_cast<const PxVec3*> (mConvexMeshDesc.points.data), mConvexMeshDesc.points.stride, + outvcount, outvsource, scale, center )) + { + PX_FREE(outvsource); + return res; + } } // scale vertices back to their original size. @@ -2189,6 +2201,9 @@ void QuickHullConvexHullLib::fillConvexMeshDesc(PxConvexMeshDesc& desc) fillConvexMeshDescFromCroppedHull(desc); else fillConvexMeshDescFromQuickHull(desc); + + if(mConvexMeshDesc.flags & PxConvexFlag::eSHIFT_VERTICES) + shiftConvexMeshDesc(desc); } ////////////////////////////////////////////////////////////////////////// diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/QuickHullConvexHullLib.h b/PhysX_3.4/Source/PhysXCooking/src/convex/QuickHullConvexHullLib.h index ad077654..b8e657a9 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/QuickHullConvexHullLib.h +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/QuickHullConvexHullLib.h @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/VolumeIntegration.cpp b/PhysX_3.4/Source/PhysXCooking/src/convex/VolumeIntegration.cpp index f388a32c..4ccb53b0 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/VolumeIntegration.cpp +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/VolumeIntegration.cpp @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/VolumeIntegration.h b/PhysX_3.4/Source/PhysXCooking/src/convex/VolumeIntegration.h index 559dc2f9..fd628ee6 100644 --- a/PhysX_3.4/Source/PhysXCooking/src/convex/VolumeIntegration.h +++ b/PhysX_3.4/Source/PhysXCooking/src/convex/VolumeIntegration.h @@ -23,7 +23,7 @@ // components in life support devices or systems without express written approval of // NVIDIA Corporation. // -// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |