diff options
| author | Bryan Galdrikian <[email protected]> | 2019-05-03 00:25:46 -0700 |
|---|---|---|
| committer | Bryan Galdrikian <[email protected]> | 2019-05-03 00:25:46 -0700 |
| commit | 74b64a27f8e07b1b0b47b809b1a060518fa11a97 (patch) | |
| tree | 34cca01711be56892c149706f02ba7358d87ec54 /sdk/extensions/authoringCommon | |
| parent | Fixing chunk reorder bug in BlastTool, when importing a prefractured mesh (diff) | |
| download | blast-1.1.5_pre1.tar.xz blast-1.1.5_pre1.zip | |
Blast SDK 1.1.5 prerelease #1v1.1.5_pre1
Diffstat (limited to 'sdk/extensions/authoringCommon')
9 files changed, 489 insertions, 488 deletions
diff --git a/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringAccelerator.h b/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringAccelerator.h index fdbc524..facd6a7 100644 --- a/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringAccelerator.h +++ b/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringAccelerator.h @@ -54,7 +54,7 @@ namespace Nv \param[in] ed Edge buffer \param[in] fc Facet which should be tested. */ - virtual void setState(const physx::PxBounds3* bounds) = 0; + virtual void setState(const NvcBounds3* bounds) = 0; /** Set state of accelerator to return all facets which possibly can intersect given facet. @@ -67,7 +67,7 @@ namespace Nv Set state of accelerator to return all facets which possibly can cover given point. Needed for testing whether point is inside mesh. \param[in] point Point which should be tested. */ - virtual void setState(const physx::PxVec3& point) = 0; + virtual void setState(const NvcVec3& point) = 0; /** Recieve next facet for setted state. \return Next facet index, or -1 if no facets left. @@ -92,15 +92,15 @@ namespace Nv \param[in] count Mesh facets count for which accelerator should be built. */ DummyAccelerator(int32_t count); - virtual void setState(const physx::PxBounds3* bounds) override; + virtual void setState(const NvcBounds3* bounds) override; virtual void setState(const Vertex* pos, const Edge* ed, const Facet& fc) override; - virtual void setState(const physx::PxVec3& point) override; + virtual void setState(const NvcVec3& point) override; virtual int32_t getNextFacet() override; virtual void setPointCmpDirection(int32_t dir) override {}; private: - int32_t count; - int32_t current; + int32_t m_count; + int32_t m_current; }; struct SegmentToIndex @@ -132,12 +132,12 @@ namespace Nv void setMesh(const Nv::Blast::Mesh* m); private: - int32_t mResolution; - int32_t r3; - int32_t mappedFacetCount; - physx::PxVec3 spos; - physx::PxVec3 deltas; - std::vector< std::vector<int32_t> > mSpatialMap; + int32_t m_resolution; + int32_t m_r3; + int32_t m_mappedFacetCount; + NvcVec3 m_spos; + NvcVec3 m_deltas; + std::vector< std::vector<int32_t> > m_spatialMap; }; class GridWalker : public SpatialAccelerator // Iterator to traverse the grid @@ -145,22 +145,22 @@ namespace Nv public: GridWalker(Grid* grd); - virtual void setState(const physx::PxBounds3* bounds) override; + virtual void setState(const NvcBounds3* bounds) override; virtual void setState(const Vertex* pos, const Edge* ed, const Facet& fc) override; - virtual void setState(const physx::PxVec3& point) override; + virtual void setState(const NvcVec3& point) override; virtual int32_t getNextFacet() override; virtual void setPointCmpDirection(int32_t dir) override; private: - Grid* mGrid; + Grid* m_grid; // Iterator data - std::vector<uint32_t> alreadyGotFlag; - uint32_t alreadyGotValue; - std::vector<int32_t> cellList; - int32_t gotCells; - int32_t mIteratorCell; - int32_t mIteratorFacet; - int32_t pointCmdDir; + std::vector<uint32_t> m_alreadyGotFlag; + uint32_t m_alreadyGotValue; + std::vector<int32_t> m_cellList; + int32_t m_gotCells; + int32_t m_iteratorCell; + int32_t m_iteratorFacet; + int32_t m_pointCmdDir; }; @@ -172,8 +172,8 @@ namespace Nv */ SweepingAccelerator(Nv::Blast::Mesh* in); virtual void setState(const Vertex* pos, const Edge* ed, const Facet& fc) override; - virtual void setState(const physx::PxBounds3* bounds) override; - virtual void setState(const physx::PxVec3& point) override; + virtual void setState(const NvcBounds3* bounds) override; + virtual void setState(const NvcVec3& point) override; virtual int32_t getNextFacet() override; virtual void setPointCmpDirection(int32_t dir) override {}; private: @@ -182,21 +182,21 @@ namespace Nv /* For fast point test. */ - std::vector<std::vector<uint32_t> > xSegm; - std::vector<std::vector<uint32_t> > ySegm; - std::vector<std::vector<uint32_t> > zSegm; - std::vector<uint32_t> indices; - std::vector<uint32_t> foundx; - std::vector<uint32_t> foundy; + std::vector<std::vector<uint32_t> > m_xSegm; + std::vector<std::vector<uint32_t> > m_ySegm; + std::vector<std::vector<uint32_t> > m_zSegm; + std::vector<uint32_t> m_indices; + std::vector<uint32_t> m_foundx; + std::vector<uint32_t> m_foundy; - uint32_t iterId; - int32_t current; - uint32_t facetCount; + uint32_t m_iterId; + int32_t m_current; + uint32_t m_facetCount; - physx::PxVec3 minimal; - physx::PxVec3 maximal; + NvcVec3 m_minimal; + NvcVec3 m_maximal; - physx::PxVec3 rescale; + NvcVec3 m_rescale; }; @@ -218,27 +218,26 @@ namespace Nv virtual ~BBoxBasedAccelerator(); int32_t getNextFacet() override; void setState(const Vertex* pos, const Edge* ed, const Facet& fc) override; - void setState(const physx::PxBounds3* bounds) override; - void setState(const physx::PxVec3& p) override; + void setState(const NvcBounds3* bounds) override; + void setState(const NvcVec3& p) override; void setPointCmpDirection(int32_t dir) override {}; private: void buildAccelStructure(const Vertex* pos, const Edge* edges, const Facet* fc, int32_t facetCount); - int32_t mResolution; - physx::PxBounds3 mBounds; - std::vector< std::vector<int32_t> > mSpatialMap; - std::vector<physx::PxBounds3> mCells; + int32_t m_resolution; + NvcBounds3 m_bounds; + std::vector< std::vector<int32_t> > m_spatialMap; + std::vector<NvcBounds3> m_cells; // Iterator data - std::vector<uint32_t> alreadyGotFlag; - uint32_t alreadyGotValue; - std::vector<int32_t> cellList; - int32_t gotCells; - //std::vector<int32_t> cellList; - int32_t mIteratorCell; - int32_t mIteratorFacet; + std::vector<uint32_t> m_alreadyGotFlag; + uint32_t m_alreadyGotValue; + std::vector<int32_t> m_cellList; + int32_t m_gotCells; + int32_t m_iteratorCell; + int32_t m_iteratorFacet; }; } // namespace Blast diff --git a/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringConvexMeshBuilder.h b/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringConvexMeshBuilder.h new file mode 100644 index 0000000..7565174 --- /dev/null +++ b/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringConvexMeshBuilder.h @@ -0,0 +1,74 @@ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved. + + +#ifndef NVBLASTEXTAUTHORINGCONVEXMESHBUILDER_H +#define NVBLASTEXTAUTHORINGCONVEXMESHBUILDER_H + +#include "NvCTypes.h" + +namespace Nv +{ +namespace Blast +{ + +struct CollisionHull; + +/** + ConvexMeshBuilder provides routine to build collision hulls from array of vertices. + Collision hull is built as convex hull of provided point set. + If due to some reason building of convex hull is failed, collision hull is built as bounding box of vertex set. + PhysX implementation can be found in NvBlastExtPx. +*/ +class ConvexMeshBuilder +{ +public: + + /** + Release ConvexMeshBuilder memory + */ + virtual void release() = 0; + + /** + Method creates CollisionHull from provided array of vertices. + \param[in] verticesCount Number of vertices + \param[in] vertexData Vertex array of some object, for which collision geometry should be built + \param[out] output Reference on CollisionHull object in which generated geometry should be saved + */ + virtual CollisionHull* buildCollisionGeometry(uint32_t verticesCount, const NvcVec3* vertexData) = 0; + + /** + Release CollisionHull memory. + */ + virtual void releaseCollisionHull(CollisionHull* hull) const = 0; +}; + +} // namespace Blast +} // namespace Nv + + +#endif // ifndef NVBLASTEXTAUTHORINGCONVEXMESHBUILDER_H diff --git a/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringMesh.h b/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringMesh.h index b8a8b72..7fc079f 100644 --- a/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringMesh.h +++ b/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringMesh.h @@ -113,12 +113,12 @@ public: /** Return reference on mesh bounding box. */ - virtual const physx::PxBounds3& getBoundingBox() const = 0; + virtual const NvcBounds3& getBoundingBox() const = 0; /** Return writable reference on mesh bounding box. */ - virtual physx::PxBounds3& getBoundingBoxWritable() = 0; + virtual NvcBounds3& getBoundingBoxWritable() = 0; /** @@ -156,7 +156,7 @@ public: /** Get pointer on facet bounding box, if not calculated return nullptr. */ - virtual const physx::PxBounds3* getFacetBound(uint32_t index) const = 0; + virtual const NvcBounds3* getFacetBound(uint32_t index) const = 0; }; diff --git a/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringPatternGenerator.h b/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringPatternGenerator.h index e446109..d53dacc 100644 --- a/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringPatternGenerator.h +++ b/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringPatternGenerator.h @@ -113,7 +113,7 @@ namespace Nv virtual DamagePattern* generateRegularRadialPattern(const RegularRadialPatternDesc* desc) = 0; - virtual DamagePattern* generateVoronoiPattern(uint32_t pointCount, const physx::PxVec3* points, int32_t interiorMaterialId) = 0; + virtual DamagePattern* generateVoronoiPattern(uint32_t pointCount, const NvcVec3* points, int32_t interiorMaterialId) = 0; virtual void release() = 0; }; diff --git a/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringTypes.h b/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringTypes.h index 729453b..ed5aa47 100644 --- a/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringTypes.h +++ b/sdk/extensions/authoringCommon/include/NvBlastExtAuthoringTypes.h @@ -29,263 +29,182 @@ #ifndef NVBLASTAUTHORINGTYPES_H #define NVBLASTAUTHORINGTYPES_H -#include <PxVec3.h> -#include <PxVec2.h> -#include <PxBounds3.h> #include "NvBlastTypes.h" - -#define NOT_VALID_VERTEX UINT32_MAX +#include "NvCTypes.h" namespace Nv { namespace Blast { +/** +Default material id assigned to interior faces (faces which created between 2 fractured chunks) +*/ +const uint32_t kMaterialInteriorId = 1000; + +/** +Default smoothing group id assigned to interior faces +*/ +const uint32_t kSmoothingGroupInteriorId = 1000; /** - Edge representation +Vertex index which considired by NvBlast as not valid. +*/ +const uint32_t kNotValidVertexIndex = UINT32_MAX; + +/** +Edge representation */ struct Edge { - uint32_t s, e; - Edge() : s(NOT_VALID_VERTEX), e(NOT_VALID_VERTEX){} - Edge(uint32_t s, uint32_t e) : s(s), e(e) {} - bool operator<(const Edge& b) const - { - if (s == b.s) - return e < b.e; - else - return s < b.s; - } - uint32_t operator[](uint32_t i) const - { - return *(reinterpret_cast<const uint32_t*>(this) + i); - } - + Edge(uint32_t s = kNotValidVertexIndex, uint32_t e = kNotValidVertexIndex) : s(s), e(e) {} + uint32_t s; + uint32_t e; }; /** - Mesh vertex representation + Mesh vertex representation */ struct Vertex { - physx::PxVec3 p; // Position - physx::PxVec3 n; // Normal - physx::PxVec2 uv[1]; // UV-coordinates array, currently supported only one UV coordinate. + Vertex() {}; + Vertex(const NvcVec3& p, const NvcVec3& n, const NvcVec2& _uv) : p(p), n(n) { uv[0] = _uv; } + NvcVec3 p; // Position + NvcVec3 n; // Normal + NvcVec2 uv[1]; // UV-coordinates array, currently supported only one UV coordinate. }; - -// Interior material ID -#define MATERIAL_INTERIOR 1000 -#define SMOOTHING_GROUP_INTERIOR 1000 - - - /** - Mesh triangle representation + Mesh triangle representation */ struct Triangle { Triangle() {}; - Triangle(Vertex a, Vertex b, Vertex c) : a(a), b(b), c(c) {}; + Triangle(const Vertex& a, const Vertex& b, const Vertex& c, int32_t ud = 0, int32_t mid = 0, int32_t sid = 0) + : a(a), b(b), c(c), userData(ud), materialId(mid), smoothingGroup(sid) {} Vertex a, b, c; int32_t userData; int32_t materialId; int32_t smoothingGroup; - physx::PxVec3 getNormal() const - { - return ((b.p - a.p).cross(c.p - a.p)); - } - inline Vertex& getVertex(uint32_t index) - { - return (&a)[index]; - } - inline const Vertex& getVertex(uint32_t index) const - { - return (&a)[index]; - } }; - /** - Index based triangle + Index based triangle */ struct TriangleIndexed { - TriangleIndexed() {}; - TriangleIndexed(uint32_t a, uint32_t b, uint32_t c) : ea(a), eb(b), ec(c) {}; - - uint32_t getOpposite(uint32_t a, uint32_t b) - { - if (ea != a && ea != b) - return ea; - if (eb != a && eb != b) - return eb; - if (ec != a && ec != b) - return ec; - return NOT_VALID_VERTEX; - } - - bool isContainEdge(uint32_t a, uint32_t b) - { - return (a == ea || a == eb || a == ec) && (b == ea || b == eb || b == ec); - } - - Triangle convertToTriangle(Vertex* vertices) - { - Triangle tr; - tr.a = vertices[ea]; - tr.b = vertices[eb]; - tr.c = vertices[ec]; - - tr.userData = userData; - tr.materialId = materialId; - tr.smoothingGroup = smoothingGroup; - return tr; - } - + TriangleIndexed(uint32_t ea, uint32_t eb, uint32_t ec, int32_t mid = 0, int32_t sid = 0, int32_t ud = 0) + : ea(ea), eb(eb), ec(ec), materialId(mid), smoothingGroup(sid), userData(ud) {} uint32_t ea, eb, ec; int32_t materialId; int32_t smoothingGroup; int32_t userData; }; - - - /** - Mesh facet representation + Mesh facet representation */ struct Facet { - int32_t firstEdgeNumber; - uint32_t edgesCount; - int64_t userData; - int32_t materialId; - int32_t smoothingGroup; - Facet(int32_t fEdge = 0, uint32_t eCount = 0, int32_t materialId = 0, int64_t userData = 0, int32_t smoothingGroup = 0) : firstEdgeNumber(fEdge), edgesCount(eCount), userData(userData), materialId(materialId), smoothingGroup(smoothingGroup) {} + Facet(int32_t fen = 0, uint32_t ec = 0, int64_t ud = 0, int32_t mid = 0, int32_t sid = 0) + : firstEdgeNumber(fen), edgesCount(ec), userData(ud), materialId(mid), smoothingGroup(sid) {} + int32_t firstEdgeNumber; + uint32_t edgesCount; + int64_t userData; + int32_t materialId; + int32_t smoothingGroup; }; /** - Abstract base class for user-defined random value generator. + Collision hull geometry format. */ -class RandomGeneratorBase +struct HullPolygon { -public: - // Generates uniformly distributed value in [0, 1] range. - virtual float getRandomValue() = 0; - // Seeds random value generator - virtual void seed(int32_t seed) = 0; - virtual ~RandomGeneratorBase() {}; + // Polygon base plane + float plane[4]; + // Number vertices in polygon + uint16_t vertexCount; + // First index in CollisionHull.indices array for this polygon + uint16_t indexBase; }; /** - Collision hull geometry format. +Collsion hull geometry. */ struct CollisionHull { - /** - Collision hull polygon format. - */ - struct HullPolygon - { - // Polygon base plane - float mPlane[4]; - // Number vertices in polygon - uint16_t mNbVerts; - // First index in CollisionHull.indices array for this polygon - uint16_t mIndexBase; - }; - ///** - - uint32_t pointsCount; - uint32_t indicesCount; - uint32_t polygonDataCount; - physx::PxVec3* points; - uint32_t* indices; - HullPolygon* polygonData; - - virtual ~CollisionHull() {} - - virtual void release() = 0; + uint32_t pointsCount; + uint32_t indicesCount; + uint32_t polygonDataCount; + NvcVec3* points; + uint32_t* indices; + HullPolygon* polygonData; }; /** - Authoring results. Which contains NvBlastAsset, render and collision meshes + Authoring results. Which contains NvBlastAsset, render and collision meshes. + If it was created by NvBlast it should be released with NvBlastExtAuthoringReleaseAuthoringResult + For releasing just collsion geometry call NvBlastExtAuthoringReleaseAuthoringResultCollision */ struct AuthoringResult { - uint32_t chunkCount; //Number of chunks in Blast asset + uint32_t chunkCount; // Number of chunks in Blast asset - uint32_t bondCount; //Number of bonds in Blast asset + uint32_t bondCount; // Number of bonds in Blast asset - NvBlastAsset* asset; //Blast asset + NvBlastAsset* asset; // Blast asset /** - assetToFractureChunkIdMap used for getting internal FractureChunkId with FractureTool::getChunkId. - FractureChunkId = FractureTool.getChunkId(aResult.assetToFractureChunkIdMap(AssetChunkId); + assetToFractureChunkIdMap used for getting internal FractureChunkId with FractureTool::getChunkId. + FractureChunkId = FractureTool.getChunkId(aResult.assetToFractureChunkIdMap(AssetChunkId); */ - uint32_t* assetToFractureChunkIdMap; + uint32_t* assetToFractureChunkIdMap; /** - Offsets for render mesh geometry. Contains chunkCount + 1 element. - First triangle for i-th chunk: aResult.geometry[aResult.geometryOffset[i]] - aResult.geometryOffset[chunkCount+1] is total number of triangles in geometry + Offsets for render mesh geometry. Contains chunkCount + 1 element. + First triangle for i-th chunk: aResult.geometry[aResult.geometryOffset[i]] + aResult.geometryOffset[chunkCount+1] is total number of triangles in geometry */ - uint32_t* geometryOffset; - - Triangle* geometry; //Raw array of Triangle for all chunks - - NvBlastChunkDesc* chunkDescs; //Array of chunk descriptors. Contains chunkCount elements + uint32_t* geometryOffset; - NvBlastBondDesc* bondDescs; //Array of bond descriptors. Contains bondCount elements + Triangle* geometry; // Raw array of Triangle for all chunks - /** - Collision hull offsets. Contains chunkCount + 1 element. - First collision hull for i-th chunk: aResult.collisionHull[aResult.collisionHullOffset[i]] - aResult.collisionHullOffset[chunkCount+1] is total number of collision hulls in collisionHull - */ - uint32_t* collisionHullOffset; + NvBlastChunkDesc* chunkDescs; // Array of chunk descriptors. Contains chunkCount elements - CollisionHull** collisionHull; //Raw array of pointers to collision hull for all chunks. + NvBlastBondDesc* bondDescs; // Array of bond descriptors. Contains bondCount elements /** - Array of chunk physics parameters. Contains chunkCount elements + Collision hull offsets. Contains chunkCount + 1 element. + First collision hull for i-th chunk: aResult.collisionHull[aResult.collisionHullOffset[i]] + aResult.collisionHullOffset[chunkCount+1] is total number of collision hulls in collisionHull */ - struct ExtPxChunk* physicsChunks; + uint32_t* collisionHullOffset; - /** - Array of phisics subchunks (convex mesh) descriptors. - Use collisionHullOffset for accessing elements. - */ - struct ExtPxSubchunk* physicsSubchunks; + CollisionHull** collisionHull; // Raw array of pointers to collision hull for all chunks. /** - Array of material names. + Array of material names. */ const char** materialNames; /** - Size of array of material names. + Size of array of material names. */ uint32_t materialCount; - - //// Member functions //// - virtual ~AuthoringResult() {} - - /** - Free collision hulls data - */ - virtual void releaseCollisionHulls() = 0; - - /** - Free all data and AuthoringResult - */ - virtual void release() = 0; }; +struct ConvexDecompositionParams +{ + uint32_t maximumNumberOfHulls = 8; // Maximum number of convex hull generated for one chunk. If equal to 1 convex + // decomposition is disabled. + uint32_t maximumNumberOfVerticesPerHull = 64; // Controls the maximum number of triangles per convex-hull + // (default=64, range=4-1024) + uint32_t voxelGridResolution = 1000000; // Voxel grid resolution used for chunk convex decomposition + // (default=1,000,000, range=10,000-16,000,000). + float concavity = 0.0025f; // Value between 0 and 1, controls how accurate hull generation is +}; -} // namespace Blast -} // namespace Nv +} // namespace Blast +} // namespace Nv -#endif // ifndef NVBLASTAUTHORINGTYPES_H +#endif // ifndef NVBLASTAUTHORINGTYPES_H diff --git a/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringAccelerator.cpp b/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringAccelerator.cpp index 20ff78b..5b3d4b6 100644 --- a/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringAccelerator.cpp +++ b/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringAccelerator.cpp @@ -30,88 +30,87 @@ #include "NvBlastExtAuthoringMesh.h" #include "NvBlastExtAuthoringInternalCommon.h" #include "NvBlastGlobals.h" - -using namespace physx; - +#include "NvBlastPxSharedHelpers.h" namespace Nv { namespace Blast { -DummyAccelerator::DummyAccelerator(int32_t count) :count(count) +DummyAccelerator::DummyAccelerator(int32_t count) : m_count(count) { - current = 0; + m_current = 0; } void DummyAccelerator::setState(const Vertex* pos, const Edge* ed, const Facet& fc) { - current = 0; + m_current = 0; NV_UNUSED(pos); NV_UNUSED(ed); NV_UNUSED(fc); } -void DummyAccelerator::setState(const physx::PxBounds3* bound) { - current = 0; +void DummyAccelerator::setState(const NvcBounds3* bound) { + m_current = 0; NV_UNUSED(bound); } -void DummyAccelerator::setState(const physx::PxVec3& point) { - current = 0; +void DummyAccelerator::setState(const NvcVec3& point) { + m_current = 0; NV_UNUSED(point); } int32_t DummyAccelerator::getNextFacet() { - if (current < count) + if (m_current < m_count) { - ++current; - return current - 1; + ++m_current; + return m_current - 1; } else return -1; } -Grid::Grid(int32_t resolution) : mResolution(resolution) +Grid::Grid(int32_t resolution) : m_resolution(resolution) { /** Set up 3d grid */ - r3 = resolution * resolution * resolution; - mSpatialMap.resize(resolution * resolution * resolution); + m_r3 = resolution * resolution * resolution; + m_spatialMap.resize(resolution * resolution * resolution); } void Grid::setMesh(const Mesh* m) { - physx::PxBounds3 bd = m->getBoundingBox(); - mappedFacetCount = m->getFacetCount(); + physx::PxBounds3 bd = toPxShared(m->getBoundingBox()); + m_mappedFacetCount = m->getFacetCount(); bd.fattenFast(0.001f); - spos = bd.minimum; - deltas = PxVec3(mResolution / bd.getDimensions().x, mResolution / bd.getDimensions().y, mResolution / bd.getDimensions().z); + m_spos = fromPxShared(bd.minimum); + m_deltas = { m_resolution / bd.getDimensions().x, m_resolution / bd.getDimensions().y, + m_resolution / bd.getDimensions().z }; - for (int32_t i = 0; i < r3; ++i) - mSpatialMap[i].clear(); + for (int32_t i = 0; i < m_r3; ++i) + m_spatialMap[i].clear(); const float ofs = 0.001f; for (uint32_t fc = 0; fc < m->getFacetCount(); ++fc) { - physx::PxBounds3 cfc = *m->getFacetBound(fc); + NvcBounds3 cfc = *m->getFacetBound(fc); - int32_t is = std::max(0.f, (cfc.minimum.x - spos.x - ofs) * deltas.x); - int32_t ie = std::max(0.f, (cfc.maximum.x - spos.x + ofs) * deltas.x); + int32_t is = std::max(0.f, (cfc.minimum.x - m_spos.x - ofs) * m_deltas.x); + int32_t ie = std::max(0.f, (cfc.maximum.x - m_spos.x + ofs) * m_deltas.x); - int32_t js = std::max(0.f, (cfc.minimum.y - spos.y - ofs) * deltas.y); - int32_t je = std::max(0.f, (cfc.maximum.y - spos.y + ofs) * deltas.y); + int32_t js = std::max(0.f, (cfc.minimum.y - m_spos.y - ofs) * m_deltas.y); + int32_t je = std::max(0.f, (cfc.maximum.y - m_spos.y + ofs) * m_deltas.y); - int32_t ks = std::max(0.f, (cfc.minimum.z - spos.z - ofs) * deltas.z); - int32_t ke = std::max(0.f, (cfc.maximum.z - spos.z + ofs) * deltas.z); + int32_t ks = std::max(0.f, (cfc.minimum.z - m_spos.z - ofs) * m_deltas.z); + int32_t ke = std::max(0.f, (cfc.maximum.z - m_spos.z + ofs) * m_deltas.z); - for (int32_t i = is; i < mResolution && i <= ie; ++i) + for (int32_t i = is; i < m_resolution && i <= ie; ++i) { - for (int32_t j = js; j < mResolution && j <= je; ++j) + for (int32_t j = js; j < m_resolution && j <= je; ++j) { - for (int32_t k = ks; k < mResolution && k <= ke; ++k) + for (int32_t k = ks; k < m_resolution && k <= ke; ++k) { - mSpatialMap[(i * mResolution + j) * mResolution + k].push_back(fc); + m_spatialMap[(i * m_resolution + j) * m_resolution + k].push_back(fc); } } } @@ -121,236 +120,234 @@ void Grid::setMesh(const Mesh* m) GridWalker::GridWalker(Grid* grd) { - mGrid = grd; - alreadyGotValue = 0; - alreadyGotFlag.resize(1 << 12); - cellList.resize(1 << 12); - pointCmdDir = 0; + m_grid = grd; + m_alreadyGotValue = 0; + m_alreadyGotFlag.resize(1 << 12); + m_cellList.resize(1 << 12); + m_pointCmdDir = 0; } void GridWalker::setState(const Vertex* pos, const Edge* ed, const Facet& fc) { - physx::PxBounds3 cfc(PxBounds3::empty()); + physx::PxBounds3 cfc(physx::PxBounds3::empty()); for (uint32_t v = 0; v < fc.edgesCount; ++v) { - cfc.include(pos[ed[fc.firstEdgeNumber + v].s].p); - cfc.include(pos[ed[fc.firstEdgeNumber + v].e].p); + cfc.include(toPxShared(pos[ed[fc.firstEdgeNumber + v].s].p)); + cfc.include(toPxShared(pos[ed[fc.firstEdgeNumber + v].e].p)); } - setState(&cfc); + setState(&fromPxShared(cfc)); } -void GridWalker::setState(const PxBounds3* facetBounding) +void GridWalker::setState(const NvcBounds3* facetBounding) { - alreadyGotValue++; - mIteratorCell = -1; - mIteratorFacet = -1; - gotCells = 0; - - physx::PxBounds3 cfc = *facetBounding; - + m_alreadyGotValue++; + m_iteratorCell = -1; + m_iteratorFacet = -1; + m_gotCells = 0; + NvcBounds3 cfc = *facetBounding; - int32_t is = std::max(0.f, (cfc.minimum.x - mGrid->spos.x - 0.001f) * mGrid->deltas.x); - int32_t ie = std::max(0.f, (cfc.maximum.x - mGrid->spos.x + 0.001f) * mGrid->deltas.x); + int32_t is = std::max(0.f, (cfc.minimum.x - m_grid->m_spos.x - 0.001f) * m_grid->m_deltas.x); + int32_t ie = std::max(0.f, (cfc.maximum.x - m_grid->m_spos.x + 0.001f) * m_grid->m_deltas.x); - int32_t js = std::max(0.f, (cfc.minimum.y - mGrid->spos.y - 0.001f) * mGrid->deltas.y); - int32_t je = std::max(0.f, (cfc.maximum.y - mGrid->spos.y + 0.001f) * mGrid->deltas.y); + int32_t js = std::max(0.f, (cfc.minimum.y - m_grid->m_spos.y - 0.001f) * m_grid->m_deltas.y); + int32_t je = std::max(0.f, (cfc.maximum.y - m_grid->m_spos.y + 0.001f) * m_grid->m_deltas.y); - int32_t ks = std::max(0.f, (cfc.minimum.z - mGrid->spos.z - 0.001f) * mGrid->deltas.z); - int32_t ke = std::max(0.f, (cfc.maximum.z - mGrid->spos.z + 0.001f) * mGrid->deltas.z); + int32_t ks = std::max(0.f, (cfc.minimum.z - m_grid->m_spos.z - 0.001f) * m_grid->m_deltas.z); + int32_t ke = std::max(0.f, (cfc.maximum.z - m_grid->m_spos.z + 0.001f) * m_grid->m_deltas.z); - for (int32_t i = is; i < mGrid->mResolution && i <= ie; ++i) + for (int32_t i = is; i < m_grid->m_resolution && i <= ie; ++i) { - for (int32_t j = js; j < mGrid->mResolution && j <= je; ++j) + for (int32_t j = js; j < m_grid->m_resolution && j <= je; ++j) { - for (int32_t k = ks; k < mGrid->mResolution && k <= ke; ++k) + for (int32_t k = ks; k < m_grid->m_resolution && k <= ke; ++k) { - int32_t id = (i * mGrid->mResolution + j) * mGrid->mResolution + k; - if (!mGrid->mSpatialMap[id].empty()) + int32_t id = (i * m_grid->m_resolution + j) * m_grid->m_resolution + k; + if (!m_grid->m_spatialMap[id].empty()) { - cellList[gotCells++] = id; + m_cellList[m_gotCells++] = id; } } } } - if (gotCells != 0) + if (m_gotCells != 0) { - mIteratorFacet = 0; - mIteratorCell = cellList[gotCells - 1]; - gotCells--; + m_iteratorFacet = 0; + m_iteratorCell = m_cellList[m_gotCells - 1]; + m_gotCells--; } } void GridWalker::setPointCmpDirection(int32_t d) { - pointCmdDir = d; + m_pointCmdDir = d; } -void GridWalker::setState(const physx::PxVec3& point) +void GridWalker::setState(const NvcVec3& point) { - alreadyGotValue++; - mIteratorCell = -1; - mIteratorFacet = -1; - gotCells = 0; + m_alreadyGotValue++; + m_iteratorCell = -1; + m_iteratorFacet = -1; + m_gotCells = 0; - int32_t is = std::max(0.f, (point.x - mGrid->spos.x - 0.001f) * mGrid->deltas.x); - int32_t ie = std::max(0.f, (point.x - mGrid->spos.x + 0.001f) * mGrid->deltas.x); + int32_t is = std::max(0.f, (point.x - m_grid->m_spos.x - 0.001f) * m_grid->m_deltas.x); + int32_t ie = std::max(0.f, (point.x - m_grid->m_spos.x + 0.001f) * m_grid->m_deltas.x); - int32_t js = std::max(0.f, (point.y - mGrid->spos.y - 0.001f) * mGrid->deltas.y); - int32_t je = std::max(0.f, (point.y - mGrid->spos.y + 0.001f) * mGrid->deltas.y); + int32_t js = std::max(0.f, (point.y - m_grid->m_spos.y - 0.001f) * m_grid->m_deltas.y); + int32_t je = std::max(0.f, (point.y - m_grid->m_spos.y + 0.001f) * m_grid->m_deltas.y); int32_t ks = 0; - int32_t ke = mGrid->mResolution; - switch (pointCmdDir) + int32_t ke = m_grid->m_resolution; + switch (m_pointCmdDir) { case 1: - ks = std::max(0.f, (point.z - mGrid->spos.z - 0.001f) * mGrid->deltas.z); + ks = std::max(0.f, (point.z - m_grid->m_spos.z - 0.001f) * m_grid->m_deltas.z); break; case -1: - ke = std::max(0.f, (point.z - mGrid->spos.z + 0.001f) * mGrid->deltas.z); + ke = std::max(0.f, (point.z - m_grid->m_spos.z + 0.001f) * m_grid->m_deltas.z); } - for (int32_t i = is; i < mGrid->mResolution && i <= ie; ++i) + for (int32_t i = is; i < m_grid->m_resolution && i <= ie; ++i) { - for (int32_t j = js; j < mGrid->mResolution && j <= je; ++j) + for (int32_t j = js; j < m_grid->m_resolution && j <= je; ++j) { - for (int32_t k = ks; k <= ke && k < mGrid->mResolution; ++k) + for (int32_t k = ks; k <= ke && k < m_grid->m_resolution; ++k) { - int32_t id = (i * mGrid->mResolution + j) * mGrid->mResolution + k; - if (!mGrid->mSpatialMap[id].empty()) + int32_t id = (i * m_grid->m_resolution + j) * m_grid->m_resolution + k; + if (!m_grid->m_spatialMap[id].empty()) { - cellList[gotCells++] = id; + m_cellList[m_gotCells++] = id; } } } } - if (gotCells != 0) + if (m_gotCells != 0) { - mIteratorFacet = 0; - mIteratorCell = cellList[gotCells - 1]; - gotCells--; + m_iteratorFacet = 0; + m_iteratorCell = m_cellList[m_gotCells - 1]; + m_gotCells--; } } int32_t GridWalker::getNextFacet() { int32_t facetId = -1; - while (mIteratorCell != -1) + while (m_iteratorCell != -1) { - if (mIteratorFacet >= (int32_t)mGrid->mSpatialMap[mIteratorCell].size()) + if (m_iteratorFacet >= (int32_t)m_grid->m_spatialMap[m_iteratorCell].size()) { - if (gotCells != 0) + if (m_gotCells != 0) { - mIteratorCell = cellList[gotCells - 1]; - gotCells--; - mIteratorFacet = 0; + m_iteratorCell = m_cellList[m_gotCells - 1]; + m_gotCells--; + m_iteratorFacet = 0; } else { - mIteratorCell = -1; + m_iteratorCell = -1; break; } } - if (alreadyGotFlag[mGrid->mSpatialMap[mIteratorCell][mIteratorFacet]] != alreadyGotValue) + if (m_alreadyGotFlag[m_grid->m_spatialMap[m_iteratorCell][m_iteratorFacet]] != m_alreadyGotValue) { - facetId = mGrid->mSpatialMap[mIteratorCell][mIteratorFacet]; - mIteratorFacet++; + facetId = m_grid->m_spatialMap[m_iteratorCell][m_iteratorFacet]; + m_iteratorFacet++; break; } else { - mIteratorFacet++; + m_iteratorFacet++; } } if (facetId != -1) { - alreadyGotFlag[facetId] = alreadyGotValue; + m_alreadyGotFlag[facetId] = m_alreadyGotValue; } return facetId; } -BBoxBasedAccelerator::BBoxBasedAccelerator(const Mesh* mesh, int32_t resolution) : mResolution(resolution), alreadyGotValue(1) +BBoxBasedAccelerator::BBoxBasedAccelerator(const Mesh* mesh, int32_t resolution) : m_resolution(resolution), m_alreadyGotValue(1) { - mBounds = mesh->getBoundingBox(); - mSpatialMap.resize(resolution * resolution * resolution); - mCells.resize(resolution * resolution * resolution); + m_bounds = mesh->getBoundingBox(); + m_spatialMap.resize(resolution * resolution * resolution); + m_cells.resize(resolution * resolution * resolution); int32_t currentCell = 0; - PxVec3 incr = (mBounds.maximum - mBounds.minimum) * (1.0f / mResolution); + NvcVec3 incr = (m_bounds.maximum - m_bounds.minimum) * (1.0f / m_resolution); for (int32_t z = 0; z < resolution; ++z) { for (int32_t y = 0; y < resolution; ++y) { for (int32_t x = 0; x < resolution; ++x) { - mCells[currentCell].minimum.x = mBounds.minimum.x + x * incr.x; - mCells[currentCell].minimum.y = mBounds.minimum.y + y * incr.y; - mCells[currentCell].minimum.z = mBounds.minimum.z + z * incr.z; + m_cells[currentCell].minimum.x = m_bounds.minimum.x + x * incr.x; + m_cells[currentCell].minimum.y = m_bounds.minimum.y + y * incr.y; + m_cells[currentCell].minimum.z = m_bounds.minimum.z + z * incr.z; - mCells[currentCell].maximum.x = mBounds.minimum.x + (x + 1) * incr.x; - mCells[currentCell].maximum.y = mBounds.minimum.y + (y + 1) * incr.y; - mCells[currentCell].maximum.z = mBounds.minimum.z + (z + 1) * incr.z; + m_cells[currentCell].maximum.x = m_bounds.minimum.x + (x + 1) * incr.x; + m_cells[currentCell].maximum.y = m_bounds.minimum.y + (y + 1) * incr.y; + m_cells[currentCell].maximum.z = m_bounds.minimum.z + (z + 1) * incr.z; ++currentCell; } } } - cellList.resize(1 << 16); - gotCells = 0; + m_cellList.resize(1 << 16); + m_gotCells = 0; buildAccelStructure(mesh->getVertices(), mesh->getEdges(), mesh->getFacetsBuffer(), mesh->getFacetCount()); } BBoxBasedAccelerator::~BBoxBasedAccelerator() { - mResolution = 0; - mBounds.setEmpty(); - mSpatialMap.clear(); - mCells.clear(); - cellList.clear(); + m_resolution = 0; + toPxShared(m_bounds).setEmpty(); + m_spatialMap.clear(); + m_cells.clear(); + m_cellList.clear(); } int32_t BBoxBasedAccelerator::getNextFacet() { int32_t facetId = -1; - while (mIteratorCell != -1) + while (m_iteratorCell != -1) { - if (mIteratorFacet >= (int32_t)mSpatialMap[mIteratorCell].size()) + if (m_iteratorFacet >= (int32_t)m_spatialMap[m_iteratorCell].size()) { - if (gotCells != 0) + if (m_gotCells != 0) { - mIteratorCell = cellList[gotCells - 1]; - gotCells--; - mIteratorFacet = 0; + m_iteratorCell = m_cellList[m_gotCells - 1]; + m_gotCells--; + m_iteratorFacet = 0; } else { - mIteratorCell = -1; + m_iteratorCell = -1; break; } } - if (alreadyGotFlag[mSpatialMap[mIteratorCell][mIteratorFacet]] != alreadyGotValue) + if (m_alreadyGotFlag[m_spatialMap[m_iteratorCell][m_iteratorFacet]] != m_alreadyGotValue) { - facetId = mSpatialMap[mIteratorCell][mIteratorFacet]; - mIteratorFacet++; + facetId = m_spatialMap[m_iteratorCell][m_iteratorFacet]; + m_iteratorFacet++; break; } else { - mIteratorFacet++; + m_iteratorFacet++; } } if (facetId != -1) { - alreadyGotFlag[facetId] = alreadyGotValue; + m_alreadyGotFlag[facetId] = m_alreadyGotValue; } return facetId; } @@ -359,65 +356,65 @@ int32_t BBoxBasedAccelerator::getNextFacet() void BBoxBasedAccelerator::setState(const Vertex* pos, const Edge* ed, const Facet& fc) { - physx::PxBounds3 cfc(PxBounds3::empty()); + physx::PxBounds3 cfc(physx::PxBounds3::empty()); for (uint32_t v = 0; v < fc.edgesCount; ++v) { - cfc.include(pos[ed[fc.firstEdgeNumber + v].s].p); - cfc.include(pos[ed[fc.firstEdgeNumber + v].e].p); + cfc.include(toPxShared(pos[ed[fc.firstEdgeNumber + v].s].p)); + cfc.include(toPxShared(pos[ed[fc.firstEdgeNumber + v].e].p)); } - setState(&cfc); + setState(&fromPxShared(cfc)); } -void BBoxBasedAccelerator::setState(const PxBounds3* facetBox) +void BBoxBasedAccelerator::setState(const NvcBounds3* facetBox) { - alreadyGotValue++; - mIteratorCell = -1; - mIteratorFacet = -1; - gotCells = 0; + m_alreadyGotValue++; + m_iteratorCell = -1; + m_iteratorFacet = -1; + m_gotCells = 0; - for (uint32_t i = 0; i < mCells.size(); ++i) + for (uint32_t i = 0; i < m_cells.size(); ++i) { - if (weakBoundingBoxIntersection(mCells[i], *facetBox)) + if (weakBoundingBoxIntersection(toPxShared(m_cells[i]), *toPxShared(facetBox))) { - if (!mSpatialMap[i].empty()) - cellList[gotCells++] = i; + if (!m_spatialMap[i].empty()) + m_cellList[m_gotCells++] = i; } } - if (gotCells != 0) + if (m_gotCells != 0) { - mIteratorFacet = 0; - mIteratorCell = cellList[gotCells - 1]; - gotCells--; + m_iteratorFacet = 0; + m_iteratorCell = m_cellList[m_gotCells - 1]; + m_gotCells--; } } -void BBoxBasedAccelerator::setState(const PxVec3& p) +void BBoxBasedAccelerator::setState(const NvcVec3& p) { - alreadyGotValue++; - mIteratorCell = -1; - mIteratorFacet = -1; - gotCells = 0; - int32_t perSlice = mResolution * mResolution; - for (uint32_t i = 0; i < mCells.size(); ++i) + m_alreadyGotValue++; + m_iteratorCell = -1; + m_iteratorFacet = -1; + m_gotCells = 0; + int32_t perSlice = m_resolution * m_resolution; + for (uint32_t i = 0; i < m_cells.size(); ++i) { - if (mCells[i].contains(p)) + if (toPxShared(m_cells[i]).contains(toPxShared(p))) { int32_t xyCellId = i % perSlice; - for (int32_t zCell = 0; zCell < mResolution; ++zCell) + for (int32_t zCell = 0; zCell < m_resolution; ++zCell) { int32_t cell = zCell * perSlice + xyCellId; - if (!mSpatialMap[cell].empty()) - cellList[gotCells++] = cell; + if (!m_spatialMap[cell].empty()) + m_cellList[m_gotCells++] = cell; } } } - if (gotCells != 0) + if (m_gotCells != 0) { - mIteratorFacet = 0; - mIteratorCell = cellList[gotCells - 1]; - gotCells--; + m_iteratorFacet = 0; + m_iteratorCell = m_cellList[m_gotCells - 1]; + m_gotCells--; } } @@ -426,27 +423,27 @@ void BBoxBasedAccelerator::buildAccelStructure(const Vertex* pos, const Edge* ed { for (int32_t facet = 0; facet < facetCount; ++facet) { - PxBounds3 bBox; + physx::PxBounds3 bBox; bBox.setEmpty(); const Edge* edge = &edges[0] + fc->firstEdgeNumber; int32_t count = fc->edgesCount; for (int32_t ec = 0; ec < count; ++ec) { - bBox.include(pos[edge->s].p); - bBox.include(pos[edge->e].p); + bBox.include(toPxShared(pos[edge->s].p)); + bBox.include(toPxShared(pos[edge->e].p)); edge++; } - for (uint32_t i = 0; i < mCells.size(); ++i) + for (uint32_t i = 0; i < m_cells.size(); ++i) { - if (weakBoundingBoxIntersection(mCells[i], bBox)) + if (weakBoundingBoxIntersection(toPxShared(m_cells[i]), bBox)) { - mSpatialMap[i].push_back(facet); + m_spatialMap[i].push_back(facet); } } fc++; } - alreadyGotFlag.resize(facetCount, 0); + m_alreadyGotFlag.resize(facetCount, 0); } #define SWEEP_RESOLUTION 2048 @@ -484,15 +481,15 @@ void buildIndex(std::vector<SegmentToIndex>& segm, float offset, float mlt, std: SweepingAccelerator::SweepingAccelerator(Nv::Blast::Mesh* in) { - PxBounds3 bnd; + physx::PxBounds3 bnd; const Vertex* verts = in->getVertices(); const Edge* edges = in->getEdges(); - facetCount = in->getFacetCount(); + m_facetCount = in->getFacetCount(); - foundx.resize(facetCount, 0); - foundy.resize(facetCount, 0); + m_foundx.resize(m_facetCount, 0); + m_foundy.resize(m_facetCount, 0); std::vector<SegmentToIndex> xevs; @@ -506,7 +503,7 @@ SweepingAccelerator::SweepingAccelerator(Nv::Blast::Mesh* in) bnd.setEmpty(); for (uint32_t v = 0; v < fc->edgesCount; ++v) { - bnd.include(verts[edges[v + fc->firstEdgeNumber].s].p); + bnd.include(toPxShared(verts[edges[v + fc->firstEdgeNumber].s].p)); } bnd.scaleFast(1.1f); xevs.push_back(SegmentToIndex(bnd.minimum.x, i, false)); @@ -525,126 +522,126 @@ SweepingAccelerator::SweepingAccelerator(Nv::Blast::Mesh* in) std::sort(zevs.begin(), zevs.end()); - minimal.x = xevs[0].coord; - minimal.y = yevs[0].coord; - minimal.z = zevs[0].coord; + m_minimal.x = xevs[0].coord; + m_minimal.y = yevs[0].coord; + m_minimal.z = zevs[0].coord; - maximal.x = xevs.back().coord; - maximal.y = yevs.back().coord; - maximal.z = zevs.back().coord; + m_maximal.x = xevs.back().coord; + m_maximal.y = yevs.back().coord; + m_maximal.z = zevs.back().coord; - rescale = (maximal - minimal) * 1.01f; - rescale.x = 1.0f / rescale.x * SWEEP_RESOLUTION; - rescale.y = 1.0f / rescale.y * SWEEP_RESOLUTION; - rescale.z = 1.0f / rescale.z * SWEEP_RESOLUTION; + m_rescale = (m_maximal - m_minimal) * 1.01f; + m_rescale.x = 1.0f / m_rescale.x * SWEEP_RESOLUTION; + m_rescale.y = 1.0f / m_rescale.y * SWEEP_RESOLUTION; + m_rescale.z = 1.0f / m_rescale.z * SWEEP_RESOLUTION; - xSegm.resize(SWEEP_RESOLUTION); - ySegm.resize(SWEEP_RESOLUTION); - zSegm.resize(SWEEP_RESOLUTION); + m_xSegm.resize(SWEEP_RESOLUTION); + m_ySegm.resize(SWEEP_RESOLUTION); + m_zSegm.resize(SWEEP_RESOLUTION); - buildIndex(xevs, minimal.x, rescale.x, xSegm); - buildIndex(yevs, minimal.y, rescale.y, ySegm); - buildIndex(zevs, minimal.z, rescale.z, zSegm); + buildIndex(xevs, m_minimal.x, m_rescale.x, m_xSegm); + buildIndex(yevs, m_minimal.y, m_rescale.y, m_ySegm); + buildIndex(zevs, m_minimal.z, m_rescale.z, m_zSegm); - iterId = 1; - current = 0; + m_iterId = 1; + m_current = 0; } -void SweepingAccelerator::setState(const PxBounds3* facetBounds) +void SweepingAccelerator::setState(const NvcBounds3* facetBounds) { - current = 0; - indices.clear(); + m_current = 0; + m_indices.clear(); - PxBounds3 bnd = *facetBounds; + physx::PxBounds3 bnd = *toPxShared(facetBounds); bnd.scaleFast(1.1); - uint32_t start = (std::max(0.0f, bnd.minimum.x - minimal.x)) * rescale.x; - uint32_t end = (std::max(0.0f, bnd.maximum.x - minimal.x)) * rescale.x; + uint32_t start = (std::max(0.0f, bnd.minimum.x - m_minimal.x)) * m_rescale.x; + uint32_t end = (std::max(0.0f, bnd.maximum.x - m_minimal.x)) * m_rescale.x; for (uint32_t i = start; i <= end && i < SWEEP_RESOLUTION; ++i) { - for (auto id : xSegm[i]) + for (auto id : m_xSegm[i]) { - foundx[id] = iterId; + m_foundx[id] = m_iterId; } } - start = (std::max(0.0f, bnd.minimum.y - minimal.y)) * rescale.y; - end = (std::max(0.0f, bnd.maximum.y - minimal.y)) * rescale.y; + start = (std::max(0.0f, bnd.minimum.y - m_minimal.y)) * m_rescale.y; + end = (std::max(0.0f, bnd.maximum.y - m_minimal.y)) * m_rescale.y; for (uint32_t i = start; i <= end && i < SWEEP_RESOLUTION; ++i) { - for (auto id : ySegm[i]) + for (auto id : m_ySegm[i]) { - foundy[id] = iterId; + m_foundy[id] = m_iterId; } } - start = (std::max(0.0f, bnd.minimum.z - minimal.z)) * rescale.z; - end = (std::max(0.0f, bnd.maximum.z - minimal.z)) * rescale.z; + start = (std::max(0.0f, bnd.minimum.z - m_minimal.z)) * m_rescale.z; + end = (std::max(0.0f, bnd.maximum.z - m_minimal.z)) * m_rescale.z; for (uint32_t i = start; i <= end && i < SWEEP_RESOLUTION; ++i) { - for (auto id : zSegm[i]) + for (auto id : m_zSegm[i]) { - if (foundy[id] == iterId && foundx[id] == iterId) + if (m_foundy[id] == m_iterId && m_foundx[id] == m_iterId) { - foundx[id] = iterId + 1; - foundy[id] = iterId + 1; - indices.push_back(id); + m_foundx[id] = m_iterId + 1; + m_foundy[id] = m_iterId + 1; + m_indices.push_back(id); } } } - iterId += 2; + m_iterId += 2; } void SweepingAccelerator::setState(const Vertex* pos, const Edge* ed, const Facet& fc) { - physx::PxBounds3 cfc(PxBounds3::empty()); + physx::PxBounds3 cfc(physx::PxBounds3::empty()); for (uint32_t v = 0; v < fc.edgesCount; ++v) { - cfc.include(pos[ed[fc.firstEdgeNumber + v].s].p); - cfc.include(pos[ed[fc.firstEdgeNumber + v].e].p); + cfc.include(toPxShared(pos[ed[fc.firstEdgeNumber + v].s].p)); + cfc.include(toPxShared(pos[ed[fc.firstEdgeNumber + v].e].p)); } - setState(&cfc); + setState(&fromPxShared(cfc)); } -void SweepingAccelerator::setState(const physx::PxVec3& point) { +void SweepingAccelerator::setState(const NvcVec3& point) { - indices.clear(); + m_indices.clear(); /*for (uint32_t i = 0; i < facetCount; ++i) { indices.push_back(i); }*/ - uint32_t xIndex = (point.x - minimal.x) * rescale.x; - uint32_t yIndex = (point.y- minimal.y) * rescale.y; + uint32_t xIndex = (point.x - m_minimal.x) * m_rescale.x; + uint32_t yIndex = (point.y - m_minimal.y) * m_rescale.y; - for (uint32_t i = 0; i < xSegm[xIndex].size(); ++i) + for (uint32_t i = 0; i < m_xSegm[xIndex].size(); ++i) { - foundx[xSegm[xIndex][i]] = iterId; + m_foundx[m_xSegm[xIndex][i]] = m_iterId; } - for (uint32_t i = 0; i < ySegm[yIndex].size(); ++i) + for (uint32_t i = 0; i < m_ySegm[yIndex].size(); ++i) { - if (foundx[ySegm[yIndex][i]] == iterId) + if (m_foundx[m_ySegm[yIndex][i]] == m_iterId) { - indices.push_back(ySegm[yIndex][i]); + m_indices.push_back(m_ySegm[yIndex][i]); } } - iterId++; - current = 0; + m_iterId++; + m_current = 0; NV_UNUSED(point); } int32_t SweepingAccelerator::getNextFacet() { - if (static_cast<uint32_t>(current) < indices.size()) + if (static_cast<uint32_t>(m_current) < m_indices.size()) { - ++current; - return indices[current - 1]; + ++m_current; + return m_indices[m_current - 1]; } else return -1; diff --git a/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringInternalCommon.h b/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringInternalCommon.h index 28d3349..4a0fbd0 100644 --- a/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringInternalCommon.h +++ b/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringInternalCommon.h @@ -29,10 +29,13 @@ #ifndef NVBLASTINTERNALCOMMON_H #define NVBLASTINTERNALCOMMON_H #include "NvBlastExtAuthoringTypes.h" +#include <PxVec2.h> +#include <PxVec3.h> +#include <PxPlane.h> +#include <PxBounds3.h> +#include <PxMath.h> #include <algorithm> -using namespace physx; - namespace Nv { namespace Blast @@ -75,6 +78,13 @@ struct EdgeComparator } }; +inline bool operator<(const Edge& a, const Edge& b) +{ + if (a.s == b.s) + return a.e < b.e; + else + return a.s < b.s; +} /** Vertex projection direction flag. @@ -129,6 +139,11 @@ NV_FORCE_INLINE physx::PxVec2 getProjectedPoint(const physx::PxVec3& point, Proj return physx::PxVec2(point.x, point.y); } +NV_FORCE_INLINE physx::PxVec2 getProjectedPoint(const NvcVec3& point, ProjectionDirections dir) +{ + return getProjectedPoint((const physx::PxVec3&)point, dir); +} + /** Computes point projected on given axis aligned plane, this method is polygon-winding aware. */ @@ -182,10 +197,11 @@ NV_INLINE bool weakBoundingBoxIntersection(const physx::PxBounds3& aBox, const /** Test segment vs plane intersection. If segment intersects the plane true is returned. Point of intersection is written into 'result'. */ -NV_INLINE bool getPlaneSegmentIntersection(const PxPlane& pl, const PxVec3& a, const PxVec3& b, PxVec3& result) +NV_INLINE bool getPlaneSegmentIntersection(const physx::PxPlane& pl, const physx::PxVec3& a, const physx::PxVec3& b, + physx::PxVec3& result) { float div = (b - a).dot(pl.n); - if (PxAbs(div) < 0.0001f) + if (physx::PxAbs(div) < 0.0001f) { if (pl.contains(a)) { @@ -243,7 +259,7 @@ Vertex comparator for vertex welding (not accounts normal and uv parameters of v */ struct VrtPositionComparator { - bool operator()(const physx::PxVec3& a, const physx::PxVec3& b) const + bool operator()(const NvcVec3& a, const NvcVec3& b) const { if (a.x + POS_COMPARISON_OFFSET < b.x) return true; if (a.x - POS_COMPARISON_OFFSET > b.x) return false; diff --git a/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringMeshImpl.cpp b/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringMeshImpl.cpp index f0c9a84..fad9184 100644 --- a/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringMeshImpl.cpp +++ b/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringMeshImpl.cpp @@ -31,22 +31,19 @@ #include "NvBlastExtAuthoringTypes.h" #include <NvBlastAssert.h> #include "PxMath.h" +#include <NvBlastPxSharedHelpers.h> #include <cmath> #include <string.h> #include <vector> #include <algorithm> -using physx::PxVec2; -using physx::PxVec3; -using physx::PxBounds3; - - namespace Nv { namespace Blast { -MeshImpl::MeshImpl(const PxVec3* position, const PxVec3* normals, const PxVec2* uv, uint32_t verticesCount, const uint32_t* indices, uint32_t indicesCount) +MeshImpl::MeshImpl(const NvcVec3* position, const NvcVec3* normals, const NvcVec2* uv, uint32_t verticesCount, + const uint32_t* indices, uint32_t indicesCount) { mVertices.resize(verticesCount); @@ -66,7 +63,7 @@ MeshImpl::MeshImpl(const PxVec3* position, const PxVec3* normals, const PxVec2* { for (uint32_t i = 0; i < mVertices.size(); ++i) { - mVertices[i].n = PxVec3(0, 0, 0); + mVertices[i].n = {0, 0, 0}; } } if (uv != 0) @@ -80,7 +77,7 @@ MeshImpl::MeshImpl(const PxVec3* position, const PxVec3* normals, const PxVec2* { for (uint32_t i = 0; i < mVertices.size(); ++i) { - mVertices[i].uv[0] = PxVec2(0, 0); + mVertices[i].uv[0] = {0, 0}; } } mEdges.resize(indicesCount); @@ -195,9 +192,9 @@ float MeshImpl::getMeshVolume() for (uint32_t i = 0; i < mFacets.size(); ++i) { int32_t offset = mFacets[i].firstEdgeNumber; - PxVec3& a = mVertices[mEdges[offset].s].p; - PxVec3& b = mVertices[mEdges[offset + 1].s].p; - PxVec3& c = mVertices[mEdges[offset + 2].s].p; + NvcVec3& a = mVertices[mEdges[offset].s].p; + NvcVec3& b = mVertices[mEdges[offset + 1].s].p; + NvcVec3& c = mVertices[mEdges[offset + 2].s].p; volume += (a.x * b.y * c.z - a.x * b.z * c.y - a.y * b.x * c.z + a.y * b.z * c.x + a.z * b.x * c.y - a.z * b.y * c.x); } @@ -264,14 +261,14 @@ void MeshImpl::release() delete this; } -const PxBounds3& MeshImpl::getBoundingBox() const +const NvcBounds3& MeshImpl::getBoundingBox() const { - return mBounds; + return fromPxShared(mBounds); } -PxBounds3& MeshImpl::getBoundingBoxWritable() +NvcBounds3& MeshImpl::getBoundingBoxWritable() { - return mBounds; + return fromPxShared(mBounds); } @@ -280,18 +277,18 @@ void MeshImpl::recalculateBoundingBox() mBounds.setEmpty(); for (uint32_t i = 0; i < mVertices.size(); ++i) { - mBounds.include(mVertices[i].p); + mBounds.include(toPxShared(mVertices[i].p)); } calcPerFacetBounds(); } -const physx::PxBounds3* MeshImpl::getFacetBound(uint32_t index) const +const NvcBounds3* MeshImpl::getFacetBound(uint32_t index) const { if (mPerFacetBounds.empty()) { return nullptr; } - return &mPerFacetBounds[index]; + return &fromPxShared(mPerFacetBounds[index]); } void MeshImpl::calcPerFacetBounds() @@ -305,8 +302,8 @@ void MeshImpl::calcPerFacetBounds() for (uint32_t v = 0; v < mFacets[i].edgesCount; ++v) { - fb.include(mVertices[mEdges[mFacets[i].firstEdgeNumber + v].s].p); - fb.include(mVertices[mEdges[mFacets[i].firstEdgeNumber + v].e].p); + fb.include(toPxShared(mVertices[mEdges[mFacets[i].firstEdgeNumber + v].s].p)); + fb.include(toPxShared(mVertices[mEdges[mFacets[i].firstEdgeNumber + v].e].p)); } } } diff --git a/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringMeshImpl.h b/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringMeshImpl.h index 0f4c339..75b8bf5 100644 --- a/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringMeshImpl.h +++ b/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringMeshImpl.h @@ -29,6 +29,7 @@ #define NVBLASTAUTHORINGMESHIMPL_H #include "NvBlastExtAuthoringMesh.h" +#include <PxBounds3.h> #include <vector> #include <map> #include <set> @@ -54,7 +55,7 @@ public: \param[in] indices Array of vertex indices. Indices contain vertex index triplets which form a mesh triangle. \param[in] indicesCount Indices count (should be equal to numberOfTriangles * 3) */ - MeshImpl(const physx::PxVec3* position, const physx::PxVec3* normals, const physx::PxVec2* uv, uint32_t verticesCount, const uint32_t* indices, uint32_t indicesCount); + MeshImpl(const NvcVec3* position, const NvcVec3* normals, const NvcVec2* uv, uint32_t verticesCount, const uint32_t* indices, uint32_t indicesCount); /** Constructs mesh object from array of facets. @@ -139,12 +140,12 @@ public: /** Return reference on mesh bounding box. */ - const physx::PxBounds3& getBoundingBox() const override; + const NvcBounds3& getBoundingBox() const override; /** Return writable reference on mesh bounding box. */ - physx::PxBounds3& getBoundingBoxWritable() override; + NvcBounds3& getBoundingBoxWritable() override; /** Recalculate bounding box @@ -181,18 +182,16 @@ public: /** Get pointer on facet bounding box, if not calculated return nullptr. */ - virtual const physx::PxBounds3* getFacetBound(uint32_t index) const override; + virtual const NvcBounds3* getFacetBound(uint32_t index) const override; private: std::vector<Vertex> mVertices; std::vector<Edge> mEdges; std::vector<Facet> mFacets; - physx::PxBounds3 mBounds; + physx::PxBounds3 mBounds; std::vector<physx::PxBounds3> mPerFacetBounds; }; - - } // namespace Blast } // namespace Nv |