diff options
| author | Sheikh Dawood Abdul Ajees <[email protected]> | 2018-01-26 19:43:03 -0600 |
|---|---|---|
| committer | Sheikh Dawood Abdul Ajees <[email protected]> | 2018-01-26 19:43:03 -0600 |
| commit | b6db9a56548cd1c41bee309e721d76ea2c9320da (patch) | |
| tree | 1f0436b187db50c21e576b4f4d491530113c91bc /PhysX_3.4/Source/GeomUtils | |
| parent | PhysX 3.4.1, APEX 1.4.1 Release @23307153 (diff) | |
| download | physx-3.4-b6db9a56548cd1c41bee309e721d76ea2c9320da.tar.xz physx-3.4-b6db9a56548cd1c41bee309e721d76ea2c9320da.zip | |
PhysX 3.4, APEX 1.4 patch release @23472123
Diffstat (limited to 'PhysX_3.4/Source/GeomUtils')
| -rw-r--r-- | PhysX_3.4/Source/GeomUtils/src/GuMeshFactory.cpp | 15 | ||||
| -rw-r--r-- | PhysX_3.4/Source/GeomUtils/src/GuSerialize.cpp | 9 | ||||
| -rw-r--r-- | PhysX_3.4/Source/GeomUtils/src/GuSerialize.h | 42 | ||||
| -rw-r--r-- | PhysX_3.4/Source/GeomUtils/src/convex/GuConvexMesh.cpp | 5 | ||||
| -rw-r--r-- | PhysX_3.4/Source/GeomUtils/src/mesh/GuBV32.cpp | 9 | ||||
| -rw-r--r-- | PhysX_3.4/Source/GeomUtils/src/mesh/GuBV32.h | 2 | ||||
| -rw-r--r-- | PhysX_3.4/Source/GeomUtils/src/mesh/GuBV4.cpp | 71 | ||||
| -rw-r--r-- | PhysX_3.4/Source/GeomUtils/src/mesh/GuBV4.h | 2 | ||||
| -rw-r--r-- | PhysX_3.4/Source/GeomUtils/src/mesh/GuMeshData.h | 3 | ||||
| -rw-r--r-- | PhysX_3.4/Source/GeomUtils/src/mesh/GuRTree.cpp | 47 | ||||
| -rw-r--r-- | PhysX_3.4/Source/GeomUtils/src/mesh/GuRTree.h | 5 |
11 files changed, 114 insertions, 96 deletions
diff --git a/PhysX_3.4/Source/GeomUtils/src/GuMeshFactory.cpp b/PhysX_3.4/Source/GeomUtils/src/GuMeshFactory.cpp index d55193d5..7ffd5c72 100644 --- a/PhysX_3.4/Source/GeomUtils/src/GuMeshFactory.cpp +++ b/PhysX_3.4/Source/GeomUtils/src/GuMeshFactory.cpp @@ -322,7 +322,7 @@ static TriangleMeshData* loadMeshData(PxInputStream& stream) // PT: TODO better if(midphaseID==PxMeshMidPhase::eBVH33) { - if(!static_cast<RTreeTriangleData*>(data)->mRTree.load(stream, version)) + if(!static_cast<RTreeTriangleData*>(data)->mRTree.load(stream, version, mismatch)) { Ps::getFoundation().error(PxErrorCode::eINTERNAL_ERROR, __FILE__, __LINE__, "RTree binary image load error."); PX_DELETE(data); @@ -332,7 +332,7 @@ static TriangleMeshData* loadMeshData(PxInputStream& stream) else if(midphaseID==PxMeshMidPhase::eBVH34) { BV4TriangleData* bv4data = static_cast<BV4TriangleData*>(data); - if(!bv4data->mBV4Tree.load(stream, version)) + if(!bv4data->mBV4Tree.load(stream, mismatch)) { Ps::getFoundation().error(PxErrorCode::eINTERNAL_ERROR, __FILE__, __LINE__, "BV4 binary image load error."); PX_DELETE(data); @@ -350,13 +350,8 @@ static TriangleMeshData* loadMeshData(PxInputStream& stream) else PX_ASSERT(0); // Import local bounds - data->mGeomEpsilon = readFloat(mismatch, stream); - data->mAABB.minimum.x = readFloat(mismatch, stream); - data->mAABB.minimum.y = readFloat(mismatch, stream); - data->mAABB.minimum.z = readFloat(mismatch, stream); - data->mAABB.maximum.x = readFloat(mismatch, stream); - data->mAABB.maximum.y = readFloat(mismatch, stream); - data->mAABB.maximum.z = readFloat(mismatch, stream); + data->mGeomEpsilon = readFloat(mismatch, stream); + readFloatBuffer(&data->mAABB.minimum.x, 6, mismatch, stream); PxU32 nb = readDword(mismatch, stream); if(nb) @@ -483,7 +478,7 @@ static TriangleMeshData* loadMeshData(PxInputStream& stream) //read BV32 data->mGRB_BV32Tree = PX_NEW(BV32Tree); BV32Tree* bv32Tree = static_cast<BV32Tree*>(data->mGRB_BV32Tree); - if (!bv32Tree->load(stream, version)) + if (!bv32Tree->load(stream, mismatch)) { Ps::getFoundation().error(PxErrorCode::eINTERNAL_ERROR, __FILE__, __LINE__, "BV32 binary image load error."); PX_DELETE(data); diff --git a/PhysX_3.4/Source/GeomUtils/src/GuSerialize.cpp b/PhysX_3.4/Source/GeomUtils/src/GuSerialize.cpp index 244795ff..90285695 100644 --- a/PhysX_3.4/Source/GeomUtils/src/GuSerialize.cpp +++ b/PhysX_3.4/Source/GeomUtils/src/GuSerialize.cpp @@ -365,16 +365,9 @@ void Gu::ReadIndices(PxU16 maxIndex, PxU32 nbIndices, PxU16* indices, PxInputStr stream.read(tmp, nbIndices*sizeof(PxU8)); for(PxU32 i=0;i<nbIndices;i++) indices[i] = tmp[i]; -// for(PxU32 i=0;i<nbIndices;i++) -// indices[i] = stream.ReadByte(); } else { - PxU16* tmp = reinterpret_cast<PxU16*>(PxAlloca(nbIndices*sizeof(PxU16))); - readWordBuffer(tmp, nbIndices, platformMismatch, stream); - for(PxU32 i=0;i<nbIndices;i++) - indices[i] = tmp[i]; -// for(PxU32 i=0;i<nbIndices;i++) -// indices[i] = ReadWord(platformMismatch, stream); + readWordBuffer(indices, nbIndices, platformMismatch, stream); } } diff --git a/PhysX_3.4/Source/GeomUtils/src/GuSerialize.h b/PhysX_3.4/Source/GeomUtils/src/GuSerialize.h index 6afa1a98..d5f4c491 100644 --- a/PhysX_3.4/Source/GeomUtils/src/GuSerialize.h +++ b/PhysX_3.4/Source/GeomUtils/src/GuSerialize.h @@ -34,6 +34,7 @@ #include "foundation/PxIO.h" #include "CmPhysXCommon.h" #include "PxPhysXCommonConfig.h" +#include "PsUtilities.h" namespace physx { @@ -134,6 +135,47 @@ PX_PHYSX_COMMON_API PxU16 computeMaxIndex(const PxU16* indices, PxU32 nbIndices PX_PHYSX_COMMON_API void storeIndices(PxU32 maxIndex, PxU32 nbIndices, const PxU32* indices, PxOutputStream& stream, bool platformMismatch); PX_PHYSX_COMMON_API void readIndices(PxU32 maxIndex, PxU32 nbIndices, PxU32* indices, PxInputStream& stream, bool platformMismatch); + // PT: see PX-1163 + PX_FORCE_INLINE bool readBigEndianVersionNumber(PxInputStream& stream, bool mismatch_, PxU32& fileVersion, bool& mismatch) + { + // PT: allright this is going to be subtle: + // - in version 1 the data was always saved in big-endian format + // - *including the version number*! + // - so we cannot just read the version "as usual" using the passed mismatch param + + // PT: mismatch value for version 1 + mismatch = (shdfnd::littleEndian() == 1); + + const PxU32 rawFileVersion = readDword(false, stream); + if(rawFileVersion==1) + { + // PT: this is a version-1 file with no flip + fileVersion = 1; + PX_ASSERT(!mismatch); + } + else + { + PxU32 fileVersionFlipped = rawFileVersion; + flip(fileVersionFlipped); + if(fileVersionFlipped==1) + { + // PT: this is a version-1 file with flip + fileVersion = 1; + PX_ASSERT(mismatch); + } + else + { + // PT: this is at least version 2 so we can process it "as usual" + mismatch = mismatch_; + fileVersion = mismatch_ ? fileVersionFlipped : rawFileVersion; + } + } + + PX_ASSERT(fileVersion<=2); + if(fileVersion>2) + return false; + return true; + } // PT: TODO: copied from IceSerialize.h, still needs to be refactored/cleaned up. namespace Gu diff --git a/PhysX_3.4/Source/GeomUtils/src/convex/GuConvexMesh.cpp b/PhysX_3.4/Source/GeomUtils/src/convex/GuConvexMesh.cpp index d3c0b842..f867f865 100644 --- a/PhysX_3.4/Source/GeomUtils/src/convex/GuConvexMesh.cpp +++ b/PhysX_3.4/Source/GeomUtils/src/convex/GuConvexMesh.cpp @@ -361,10 +361,7 @@ bool Gu::ConvexMesh::load(PxInputStream& stream) */ // TEST_INTERNAL_OBJECTS - mHullData.mInternal.mRadius = readFloat(mismatch, stream); - mHullData.mInternal.mExtents[0] = readFloat(mismatch, stream); - mHullData.mInternal.mExtents[1] = readFloat(mismatch, stream); - mHullData.mInternal.mExtents[2] = readFloat(mismatch, stream); + readFloatBuffer(&mHullData.mInternal.mRadius, 4, mismatch, stream); PX_ASSERT(PxVec3(mHullData.mInternal.mExtents[0], mHullData.mInternal.mExtents[1], mHullData.mInternal.mExtents[2]).isFinite()); PX_ASSERT(mHullData.mInternal.mExtents[0] != 0.0f); diff --git a/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV32.cpp b/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV32.cpp index f81da1b5..5a6682b1 100644 --- a/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV32.cpp +++ b/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV32.cpp @@ -114,10 +114,9 @@ void BV32Tree::importExtraData(PxDeserializationContext& context) } //~PX_SERIALIZATION -bool BV32Tree::load(PxInputStream& stream, PxU32 meshVersion) +bool BV32Tree::load(PxInputStream& stream, bool mismatch_) { PX_ASSERT(!mUserAllocated); - PX_UNUSED(meshVersion); release(); @@ -126,9 +125,9 @@ bool BV32Tree::load(PxInputStream& stream, PxU32 meshVersion) if (a != 'B' || b != 'V' || c != '3' || d != '2') return false; - const PxU32 version = 1; - const bool mismatch = (shdfnd::littleEndian() == 1); - if (readDword(mismatch, stream) != version) + bool mismatch; + PxU32 fileVersion; + if(!readBigEndianVersionNumber(stream, mismatch_, fileVersion, mismatch)) return false; mLocalBounds.mCenter.x = readFloat(mismatch, stream); diff --git a/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV32.h b/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV32.h index 051dc6be..45e1e88a 100644 --- a/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV32.h +++ b/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV32.h @@ -117,7 +117,7 @@ namespace physx PX_PHYSX_COMMON_API BV32Tree(SourceMesh* meshInterface, const PxBounds3& localBounds); PX_PHYSX_COMMON_API ~BV32Tree(); - bool load(PxInputStream& stream, PxU32 meshVersion); // converts to proper endian at load time + bool load(PxInputStream& stream, bool mismatch); void calculateLeafNode(BV32Data& node); void createSOAformatNode(BV32DataPacked& packedData, const BV32Data& node, const PxU32 childOffset, PxU32& currentIndex, PxU32& nbPackedNodes); diff --git a/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV4.cpp b/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV4.cpp index a4e90824..57acd0c7 100644 --- a/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV4.cpp +++ b/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV4.cpp @@ -205,10 +205,17 @@ void BV4Tree::importExtraData(PxDeserializationContext& context) } //~PX_SERIALIZATION -bool BV4Tree::load(PxInputStream& stream, PxU32 meshVersion) +#ifdef GU_BV4_QUANTIZED_TREE + static const PxU32 BVDataPackedNb = sizeof(BVDataPacked)/sizeof(PxU16); + PX_COMPILE_TIME_ASSERT(BVDataPackedNb * sizeof(PxU16) == sizeof(BVDataPacked)); +#else + static const PxU32 BVDataPackedNb = sizeof(BVDataPacked)/sizeof(float); + PX_COMPILE_TIME_ASSERT(BVDataPackedNb * sizeof(float) == sizeof(BVDataPacked)); +#endif + +bool BV4Tree::load(PxInputStream& stream, bool mismatch_) { PX_ASSERT(!mUserAllocated); - PX_UNUSED(meshVersion); release(); @@ -217,25 +224,19 @@ bool BV4Tree::load(PxInputStream& stream, PxU32 meshVersion) if(a!='B' || b!='V' || c!='4' || d!=' ') return false; - const PxU32 version = 1; - const bool mismatch = (shdfnd::littleEndian() == 1); - if(readDword(mismatch, stream) != version) + bool mismatch; + PxU32 fileVersion; + if(!readBigEndianVersionNumber(stream, mismatch_, fileVersion, mismatch)) return false; - mLocalBounds.mCenter.x = readFloat(mismatch, stream); - mLocalBounds.mCenter.y = readFloat(mismatch, stream); - mLocalBounds.mCenter.z = readFloat(mismatch, stream); + readFloatBuffer(&mLocalBounds.mCenter.x, 3, mismatch, stream); mLocalBounds.mExtentsMagnitude = readFloat(mismatch, stream); mInitData = readDword(mismatch, stream); #ifdef GU_BV4_QUANTIZED_TREE - mCenterOrMinCoeff.x = readFloat(mismatch, stream); - mCenterOrMinCoeff.y = readFloat(mismatch, stream); - mCenterOrMinCoeff.z = readFloat(mismatch, stream); - mExtentsOrMaxCoeff.x = readFloat(mismatch, stream); - mExtentsOrMaxCoeff.y = readFloat(mismatch, stream); - mExtentsOrMaxCoeff.z = readFloat(mismatch, stream); + readFloatBuffer(&mCenterOrMinCoeff.x, 3, mismatch, stream); + readFloatBuffer(&mExtentsOrMaxCoeff.x, 3, mismatch, stream); #endif const PxU32 nbNodes = readDword(mismatch, stream); mNbNodes = nbNodes; @@ -250,15 +251,47 @@ bool BV4Tree::load(PxInputStream& stream, PxU32 meshVersion) mNodes = nodes; Cm::markSerializedMem(nodes, sizeof(BVDataPacked)*nbNodes); - for(PxU32 i=0;i<nbNodes;i++) + if(1) + { +#ifdef GU_BV4_QUANTIZED_TREE + readWordBuffer(&nodes[0].mAABB.mData[0].mExtents, BVDataPackedNb * nbNodes, false, stream); +#else + readFloatBuffer(&nodes[0].mAABB.mCenter.x, BVDataPackedNb * nbNodes, false, stream); +#endif + if(mismatch) + { + for(PxU32 i=0;i<nbNodes;i++) + { + BVDataPacked& node = nodes[i]; + for(PxU32 j=0;j<3;j++) + { +#ifdef GU_BV4_QUANTIZED_TREE + flip(node.mAABB.mData[j].mExtents); + flip(node.mAABB.mData[j].mCenter); +#else + flip(node.mAABB.mExtents[j]); + flip(node.mAABB.mCenter[j]); +#endif + } + flip(node.mData); + } + } + + + } + else { - BVDataPacked& node = nodes[i]; + // PT: initial slower code is like this: + for(PxU32 i=0;i<nbNodes;i++) + { + BVDataPacked& node = nodes[i]; #ifdef GU_BV4_QUANTIZED_TREE - readWordBuffer(&node.mAABB.mData[0].mExtents, 6, mismatch, stream); + readWordBuffer(&node.mAABB.mData[0].mExtents, 6, mismatch, stream); #else - readFloatBuffer(&node.mAABB.mCenter.x, 6, mismatch, stream); + readFloatBuffer(&node.mAABB.mCenter.x, 6, mismatch, stream); #endif - node.mData = readDword(mismatch, stream); + node.mData = readDword(mismatch, stream); + } } } else mNodes = NULL; diff --git a/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV4.h b/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV4.h index d9083cc6..c6d02c1f 100644 --- a/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV4.h +++ b/PhysX_3.4/Source/GeomUtils/src/mesh/GuBV4.h @@ -226,7 +226,7 @@ namespace Gu PX_PHYSX_COMMON_API BV4Tree(SourceMesh* meshInterface, const PxBounds3& localBounds); PX_PHYSX_COMMON_API ~BV4Tree(); - bool load(PxInputStream& stream, PxU32 meshVersion); // converts to proper endian at load time + bool load(PxInputStream& stream, bool mismatch); void reset(); void operator = (BV4Tree& v); diff --git a/PhysX_3.4/Source/GeomUtils/src/mesh/GuMeshData.h b/PhysX_3.4/Source/GeomUtils/src/mesh/GuMeshData.h index e7af8aee..fe92c4af 100644 --- a/PhysX_3.4/Source/GeomUtils/src/mesh/GuMeshData.h +++ b/PhysX_3.4/Source/GeomUtils/src/mesh/GuMeshData.h @@ -43,9 +43,6 @@ namespace physx { - -#define RTREE_COOK_VERSION 1 - namespace Gu { // 1: support stackless collision trees for non-recursive collision queries diff --git a/PhysX_3.4/Source/GeomUtils/src/mesh/GuRTree.cpp b/PhysX_3.4/Source/GeomUtils/src/mesh/GuRTree.cpp index ff9f6cd3..f43c1c3e 100644 --- a/PhysX_3.4/Source/GeomUtils/src/mesh/GuRTree.cpp +++ b/PhysX_3.4/Source/GeomUtils/src/mesh/GuRTree.cpp @@ -59,41 +59,7 @@ namespace physx namespace Gu { ///////////////////////////////////////////////////////////////////////// -PxU32 RTree::mVersion = 1; - -bool RTree::save(PxOutputStream& stream) const -{ - // save the RTree root structure followed immediately by RTreePage pages to an output stream - bool mismatch = (Ps::littleEndian() == 1); - writeChunk('R', 'T', 'R', 'E', stream); - writeDword(mVersion, mismatch, stream); - writeFloatBuffer(&mBoundsMin.x, 4, mismatch, stream); - writeFloatBuffer(&mBoundsMax.x, 4, mismatch, stream); - writeFloatBuffer(&mInvDiagonal.x, 4, mismatch, stream); - writeFloatBuffer(&mDiagonalScaler.x, 4, mismatch, stream); - writeDword(mPageSize, mismatch, stream); - writeDword(mNumRootPages, mismatch, stream); - writeDword(mNumLevels, mismatch, stream); - writeDword(mTotalNodes, mismatch, stream); - writeDword(mTotalPages, mismatch, stream); - PxU32 unused = 0; // backwards compatibility - writeDword(unused, mismatch, stream); - for (PxU32 j = 0; j < mTotalPages; j++) - { - writeFloatBuffer(mPages[j].minx, RTREE_N, mismatch, stream); - writeFloatBuffer(mPages[j].miny, RTREE_N, mismatch, stream); - writeFloatBuffer(mPages[j].minz, RTREE_N, mismatch, stream); - writeFloatBuffer(mPages[j].maxx, RTREE_N, mismatch, stream); - writeFloatBuffer(mPages[j].maxy, RTREE_N, mismatch, stream); - writeFloatBuffer(mPages[j].maxz, RTREE_N, mismatch, stream); - WriteDwordBuffer(mPages[j].ptrs, RTREE_N, mismatch, stream); - } - - return true; -} - -///////////////////////////////////////////////////////////////////////// -bool RTree::load(PxInputStream& stream, PxU32 meshVersion) +bool RTree::load(PxInputStream& stream, PxU32 meshVersion, bool mismatch_) // PT: 'meshVersion' is the PX_MESH_VERSION from cooked file { PX_UNUSED(meshVersion); @@ -104,8 +70,9 @@ bool RTree::load(PxInputStream& stream, PxU32 meshVersion) if(a!='R' || b!='T' || c!='R' || d!='E') return false; - bool mismatch = (Ps::littleEndian() == 1); - if(readDword(mismatch, stream) != mVersion) + bool mismatch; + PxU32 fileVersion; + if(!readBigEndianVersionNumber(stream, mismatch_, fileVersion, mismatch)) return false; readFloatBuffer(&mBoundsMin.x, 4, mismatch, stream); @@ -118,10 +85,9 @@ bool RTree::load(PxInputStream& stream, PxU32 meshVersion) mTotalNodes = readDword(mismatch, stream); mTotalPages = readDword(mismatch, stream); PxU32 unused = readDword(mismatch, stream); PX_UNUSED(unused); // backwards compatibility - mPages = static_cast<RTreePage*>( - Ps::AlignedAllocator<128>().allocate(sizeof(RTreePage)*mTotalPages, __FILE__, __LINE__)); + mPages = static_cast<RTreePage*>(Ps::AlignedAllocator<128>().allocate(sizeof(RTreePage)*mTotalPages, __FILE__, __LINE__)); Cm::markSerializedMem(mPages, sizeof(RTreePage)*mTotalPages); - for (PxU32 j = 0; j < mTotalPages; j++) + for(PxU32 j=0; j<mTotalPages; j++) { readFloatBuffer(mPages[j].minx, RTREE_N, mismatch, stream); readFloatBuffer(mPages[j].miny, RTREE_N, mismatch, stream); @@ -131,7 +97,6 @@ bool RTree::load(PxInputStream& stream, PxU32 meshVersion) readFloatBuffer(mPages[j].maxz, RTREE_N, mismatch, stream); ReadDwordBuffer(mPages[j].ptrs, RTREE_N, mismatch, stream); } - return true; } diff --git a/PhysX_3.4/Source/GeomUtils/src/mesh/GuRTree.h b/PhysX_3.4/Source/GeomUtils/src/mesh/GuRTree.h index 19004952..a14bfee5 100644 --- a/PhysX_3.4/Source/GeomUtils/src/mesh/GuRTree.h +++ b/PhysX_3.4/Source/GeomUtils/src/mesh/GuRTree.h @@ -138,8 +138,7 @@ namespace Gu { ~RTree() { release(); } PX_INLINE void release(); - bool save(PxOutputStream& stream) const; // always saves as big endian - bool load(PxInputStream& stream, PxU32 meshVersion); // converts to proper endian at load time + bool load(PxInputStream& stream, PxU32 meshVersion, bool mismatch); //////////////////////////////////////////////////////////////////////////// // QUERIES @@ -216,8 +215,6 @@ namespace Gu { PxU32 mFlags; enum { USER_ALLOCATED = 0x1, IS_EDGE_SET = 0x2 }; RTreePage* mPages; - static PxU32 mVersion; - protected: typedef PxU32 NodeHandle; #if PX_ENABLE_DYNAMIC_MESH_RTREE |