sdk/extensions/RT/include/NvBlastExtRT.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
00027 
00028 
00029 #ifndef NVBLASTEXTRT_H
00030 #define NVBLASTEXTRT_H
00031 
00032 #include <cinttypes>
00033 #include <NvBlastTypes.h>
00034 #include <NvCTypes.h>
00035 
00036 
00037 //#define USE_MERGED_MESH
00038 
00039 
00040 #define BLASTRT_MAX_VERTICES 262144
00041 #define BLASTRT_MAX_EDGES_PER_CHUNK 16384
00042 #define BLASTRT_MAX_CHUNKS 256
00043 
00044 namespace Nv
00045 {
00046     namespace Blast
00047     {
00048         struct Vertex;
00049         class  Mesh;
00050         class  SpatialAccelerator;
00051         class  VertexWelding;
00052         struct DamagePattern;
00053 
00054         struct FacetFacetResult
00055         {
00056             uint32_t parentFacet;
00057             uint32_t adjacentFacet;
00058             uint32_t parentEdge;
00059             int32_t status;
00060             uint32_t pIdx;
00061 
00062             bool operator<(const FacetFacetResult& in) const
00063             {
00064                 return parentFacet < in.parentFacet;
00065             }
00066         };
00067 
00068         struct BooleanResultEdge
00069         {
00070             uint32_t start;
00071             uint32_t end;
00072             int32_t parentFacet;
00073             int32_t adjacentFacet = -1;
00074 
00075             BooleanResultEdge getInversed()
00076             {
00077                 BooleanResultEdge ret;
00078                 ret.start = end;
00079                 ret.end = start;
00080                 ret.parentFacet = parentFacet;
00081                 ret.adjacentFacet = adjacentFacet;
00082                 return ret;
00083             }
00084         };
00085 
00086         struct BooleanToolOutputData
00087         {
00088             virtual void release() = 0;
00089 
00090             //set edges, vertices and ffResult counters to 0
00091             virtual void reset() = 0;
00092             virtual void resetEdges() = 0;
00093 
00094             virtual void copyVerticesAndResults(const BooleanToolOutputData* other) = 0;
00095 
00096             virtual uint32_t edgesCount() const = 0;
00097             virtual uint32_t verticesCount() const = 0;
00098             virtual uint32_t ffResultCount() const = 0;
00099 
00100             //Thread safe add, return index in buffer
00101             virtual uint32_t addEdge(const BooleanResultEdge&) = 0;
00102             virtual uint32_t addVertex(const Vertex&) = 0;
00103             virtual uint32_t addFfResult(const FacetFacetResult&) = 0;
00104 
00105             //Thread safe, increment counter and return reference to last element
00106             virtual BooleanResultEdge& getNewEdge() = 0;
00107             virtual Vertex& getNewVertex() = 0;
00108             virtual FacetFacetResult& getNewFfResult() = 0;
00109 
00110             //User allocated buffers should have size more than return values of above function 
00111             BooleanResultEdge* edges = nullptr;
00112             Vertex* vertices = nullptr;
00113             FacetFacetResult* ffResult = nullptr;
00114         };
00115         
00120         class Fracturer
00121         {
00122         public:
00123             virtual void release() = 0;
00124         };
00125 
00126         class MeshGenerator
00127         {
00128         public:
00129             virtual void release() = 0;
00130         };
00131 
00132         struct FractureDesc
00133         {
00134             Fracturer* fr = nullptr;
00135             const Mesh* model = nullptr;
00136             const Mesh* cell = nullptr;
00137             SpatialAccelerator* modelAccel = nullptr;
00138             SpatialAccelerator* cellAccel = nullptr;
00139             DamagePattern* pattern = nullptr;
00140             BooleanToolOutputData* outputData = nullptr;
00141             uint32_t chunkId;
00142         };
00143 
00144         struct PerTriangleAdditionalData
00145         {
00146             int32_t materialIndex;
00147             int32_t smoothingGroup;
00148         };
00149 
00150         struct MeshDesc
00151         {
00152             MeshGenerator* tr = nullptr;
00153             const BooleanResultEdge* bEdges = nullptr;
00154             uint32_t edesCount = 0;
00155             const Vertex* inVertices = nullptr;
00156             const Mesh* meshA = nullptr; // used to gather additional data from source mesh, for example material ID 
00157             const Mesh* meshB = nullptr;
00158         };
00159 
00160         class FractureRT
00161         {
00162         public:
00163 
00164             struct Stage
00165             {
00166                 enum
00167                 {
00168                     FACET_FACET_TEST = 1,
00169                     RETAIN_FROM_FRACTURED_MESH = 2,
00170                     RETAIN_FROM_PATTERN = 4,
00171 
00172                     ALL = 0xFFFFFFFF
00173                 };
00174             };
00175 
00176             virtual void release() = 0;
00177             virtual void processMesh(DamagePattern* pattern, const Mesh* msh) = 0;
00178             virtual uint32_t getResultChunkCount() = 0;
00179             virtual Vertex* getVertexBuffer() = 0;
00180             virtual uint32_t* getIndexBuffer() = 0;
00181             virtual uint32_t* getVertexOffset() = 0;
00182             virtual uint32_t* getIndexOffset() = 0;
00183             virtual PerTriangleAdditionalData* getPerTriangleData() = 0;
00184             virtual void dumpChunksToObj(const char* path) = 0;
00185         };
00186 
00187         enum PatternFacetType { GOOD_FACET = 0, INFINITE_FACET = 0xffffff };
00188 
00189 
00193         struct ChunkGraphLink
00194         {
00195             ChunkGraphLink() = default;
00196             ChunkGraphLink(uint32_t i, uint32_t j) : l1(i), l2(j) {};
00197             uint32_t l1;
00198             uint32_t l2;
00199 
00200             bool operator<(const ChunkGraphLink& lk) const;
00201             bool operator<(const uint32_t in) const;
00202         };
00203 
00204         struct ChunkGraph
00205         {
00206             virtual void eraseNode(uint32_t index) = 0;
00207             virtual void release() = 0;
00208 
00209             ChunkGraphLink* links = nullptr;
00210             uint32_t* dirtyChunks = nullptr;
00211             uint32_t linksCount = 0;
00212             uint32_t dirtyChunksCount = 0;
00213             uint32_t newlyAddedCount = 0;
00214             uint32_t maxLinksCount = 0;
00215         };
00216 
00217     }
00218 }
00219 
00220 
00224 NVBLAST_API Nv::Blast::FractureRT* NvBlastExtRTCreateFractureRT(uint32_t threads = 1);
00225 
00229 NVBLAST_API Nv::Blast::Fracturer* NvBlastExtRTCreateFracturer();
00230 
00234 NVBLAST_API uint32_t NvBlastExtRTDoFracture(const Nv::Blast::FractureDesc& desc, int32_t stage = Nv::Blast::FractureRT::Stage::ALL, int32_t threadId = 0, int32_t threadCount = 1);
00235 
00239 NVBLAST_API Nv::Blast::MeshGenerator* NvBlastExtRTCreateMeshGenerator();
00240 
00244 NVBLAST_API uint32_t NvBlastExtRTBuildMesh(Nv::Blast::MeshDesc dsc, Nv::Blast::Vertex* outVertices, uint32_t& vCount, uint32_t* indices, Nv::Blast::PerTriangleAdditionalData* adata, uint32_t maxICount, uint32_t maxVCount);
00245 
00249 NVBLAST_API uint32_t NvBlastExtRTGetChunksToUnite(Nv::Blast::DamagePattern* pattern, const Nv::Blast::Vertex* vertices, const uint32_t* voffsets, uint32_t chunksCount, uint32_t* chunksToUnite);
00250 
00254 NVBLAST_API uint32_t NvBlastExtRTDetectIslands(Nv::Blast::Vertex* vertices, uint32_t* offsets, NvcBounds3* bounds, uint32_t chunkCount, Nv::Blast::ChunkGraph* graph, uint32_t* islandChunks, uint32_t* islandOffsets);
00255 
00259 NVBLAST_API Nv::Blast::ChunkGraph* NvBlastExtRTCreateChunkGraph(uint32_t maxLinksCount = 4096);
00260 
00264 NVBLAST_API void NvBlastExtRTCookMergedMesh(Nv::Blast::DamagePattern* pattern);
00265 
00266 
00267 
00268 #endif // ifndef NVBLASTEXTRT_H