Main Page   Class List   Class Members  

  • Main Page
  • User's Guide
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

sdk/extensions/authoring/source/NvBlastExtAuthoringFractureToolImpl.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 #ifndef NVBLASTAUTHORINGFRACTURETOOLIMPL_H
00029 #define NVBLASTAUTHORINGFRACTURETOOLIMPL_H
00030 
00031 #include "NvBlastExtAuthoringFractureTool.h"
00032 #include "NvBlastExtAuthoringMesh.h"
00033 #include <vector>
00034 #include <set>
00035 
00036 namespace Nv
00037 {
00038 namespace Blast
00039 {
00040 
00041 class SpatialAccelerator;
00042 class Triangulator;
00043 
00044 
00048 class VoronoiSitesGeneratorImpl : public VoronoiSitesGenerator
00049 {
00050 public:
00051     
00059     VoronoiSitesGeneratorImpl(const Mesh* mesh, RandomGeneratorBase* rnd);
00060     ~VoronoiSitesGeneratorImpl();
00061 
00062     void                        release() override;
00063 
00067     void                        setBaseMesh(const Mesh* m) override;
00068 
00075      uint32_t                   getVoronoiSites(const NvcVec3*& sites) override;
00076     
00081     void                        addSite(const NvcVec3& site) override;
00086     void                        uniformlyGenerateSitesInMesh(uint32_t numberOfSites) override;
00087 
00094     void                        clusteredSitesGeneration(uint32_t numberOfClusters, uint32_t sitesPerCluster, float clusterRadius) override;
00095 
00106     void                        radialPattern(const NvcVec3& center, const NvcVec3& normal, float radius, int32_t angularSteps, int32_t radialSteps, float angleOffset = 0.0f, float variability = 0.0f) override;
00107 
00114     void                        generateInSphere(const uint32_t count, const float radius, const NvcVec3& center) override;
00119     void                        setStencil(const Mesh* stencil) override;
00123     void                        clearStencil() override;
00124 
00131     void                        deleteInSphere(const float radius, const NvcVec3& center, const float eraserProbability = 1) override;
00132 
00133 private:
00134     std::vector <NvcVec3>   mGeneratedSites;
00135     const Mesh*                 mMesh;
00136     const Mesh*                 mStencil;
00137     RandomGeneratorBase*        mRnd;
00138     SpatialAccelerator*         mAccelerator;
00139 };
00140 
00141 
00142 
00146 class FractureToolImpl : public FractureTool
00147 {
00148 
00149 public:
00150 
00154     FractureToolImpl()
00155     {
00156         mPlaneIndexerOffset = 1;
00157         mChunkIdCounter = 0;
00158         mRemoveIslands = false;
00159         mInteriorMaterialId = kMaterialInteriorId;
00160     }
00161 
00162     ~FractureToolImpl()
00163     {
00164         reset();
00165     }
00166 
00167     void                                    release() override;
00168 
00172     void                                    reset() override;
00173     
00177     void                                    setInteriorMaterialId(int32_t materialId) override;
00178 
00182     int32_t                                 getInteriorMaterialId() const override;
00183     
00187     void                                    replaceMaterialId(int32_t oldMaterialId, int32_t newMaterialId) override;
00188 
00192     void                                    setSourceMesh(const Mesh* mesh) override;
00193 
00197     int32_t                                 setChunkMesh(const Mesh* mesh, int32_t parentId) override;
00198 
00202     Mesh*                                   createChunkMesh(int32_t chunkId) override;
00203 
00208     void                                    getTransformation(NvcVec3& offset, float& scale) override;
00209 
00210 
00219     int32_t                                 voronoiFracturing(uint32_t chunkId, uint32_t cellCount, const NvcVec3* cellPoints, bool replaceChunk) override;
00220 
00232     int32_t                                 voronoiFracturing(uint32_t chunkId, uint32_t cellCount, const NvcVec3* cellPoints, const NvcVec3& scale, const NvcQuat& rotation, bool replaceChunk) override;
00233 
00234 
00245     int32_t                                 slicing(uint32_t chunkId, const SlicingConfiguration& conf, bool replaceChunk, RandomGeneratorBase* rnd) override;
00246 
00247 
00260     int32_t                                 cut(uint32_t chunkId, const NvcVec3& normal, const NvcVec3& position, const NoiseConfiguration& noise, bool replaceChunk, RandomGeneratorBase* rnd) override;
00261 
00272     int32_t                                 cutout(uint32_t chunkId, CutoutConfiguration conf, bool replaceChunk, RandomGeneratorBase* rnd) override;
00273 
00274 
00278     void                                    finalizeFracturing() override;
00279     
00280     uint32_t                                getChunkCount() const override;
00281 
00285     const ChunkInfo&                        getChunkInfo(int32_t chunkIndex) override;
00286 
00294     float                                   getMeshOverlap(const Mesh& meshA, const Mesh& meshB) override;
00295 
00303     uint32_t                                getBaseMesh(int32_t chunkIndex, Triangle*& output) override;
00304 
00312     uint32_t                                updateBaseMesh(int32_t chunkIndex, Triangle* output) override;
00313 
00319     int32_t                                 getChunkIndex(int32_t chunkId) override;
00320 
00326     int32_t                                 getChunkId(int32_t chunkIndex) override;
00327 
00333     int32_t                                 getChunkDepth(int32_t chunkId) override;
00334 
00342     uint32_t                                getChunksIdAtDepth(uint32_t depth, int32_t*& chunkIds) override;
00343 
00344 
00355     uint32_t                                getBufferedBaseMeshes(Vertex*& vertexBuffer, uint32_t*& indexBuffer, uint32_t*& indexBufferOffsets) override;
00356 
00361     void                                    setRemoveIslands(bool isRemoveIslands) override;
00362 
00368     int32_t                                 islandDetectionAndRemoving(int32_t chunkId, bool createAtNewDepth = false) override;
00369 
00374     bool                                    isMeshContainOpenEdges(const Mesh* input) override;
00375 
00376     bool                                    deleteChunkSubhierarchy(int32_t chunkId, bool deleteRoot = false) override;
00377 
00378     void                                    uniteChunks(uint32_t threshold, uint32_t targetClusterSize,
00379                                                         const uint32_t* chunksToMerge, uint32_t mergeChunkCount,
00380                                                         const NvcVec2i* adjChunks, uint32_t adjChunksSize,
00381                                                         bool removeOriginalChunks = false) override;
00382     
00383     bool                                    setApproximateBonding(uint32_t chunkId, bool useApproximateBonding) override;
00384 
00390     void                                    fitUvToRect(float side, uint32_t chunkId) override;
00391 
00396     void                                    fitAllUvToRect(float side) override;
00397 
00398 
00399 
00400 private:    
00401     bool                                    isAncestorForChunk(int32_t ancestorId, int32_t chunkId);
00402     int32_t                                 slicingNoisy(uint32_t chunkId, const SlicingConfiguration& conf, bool replaceChunk, RandomGeneratorBase* rnd);
00403     uint32_t                                stretchGroup(const std::vector<uint32_t>& group, std::vector<std::vector<uint32_t>>& graph);
00404     void                                    rebuildAdjGraph(const std::vector<uint32_t>& chunksToRebuild, const NvcVec2i* adjChunks, uint32_t adjChunksSize,
00405                                                             std::vector<std::vector<uint32_t> >& chunkGraph);
00406     void                                    fitAllUvToRect(float side, std::set<uint32_t>& mask);
00407     void                                    markLeaves();
00408 
00412     uint32_t                                createNewChunk(uint32_t parentId);
00413 
00414 
00415 protected:
00419     float                               mScaleFactor;
00420     NvcVec3                             mOffset;
00421 
00422     /* Chunk mesh wrappers */
00423     std::vector<Triangulator*>          mChunkPostprocessors;
00424 
00425 
00426     
00427     int64_t                             mPlaneIndexerOffset;
00428     int32_t                             mChunkIdCounter;
00429     std::vector<ChunkInfo>              mChunkData;
00430 
00431     bool                                mRemoveIslands;
00432     int32_t                             mInteriorMaterialId;
00433 };
00434 
00435 void findCellBasePlanes(const std::vector<NvcVec3>& sites, std::vector<std::vector<int32_t> >& neighboors);
00436 Mesh* getCellMesh(class BooleanEvaluator& eval, int32_t planeIndexerOffset, int32_t cellId, const std::vector<NvcVec3>& sites, std::vector < std::vector<int32_t> >& neighboors, int32_t interiorMaterialId, NvcVec3 origin);
00437 
00438 } // namespace Blast
00439 } // namespace Nv
00440 
00441 
00442 #endif // ifndef NVBLASTAUTHORINGFRACTURETOOLIMPL_H
Copyright © 2015-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com