NvBlastExtAuthoringFractureToolImpl.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
27 
28 #ifndef NVBLASTAUTHORINGFRACTURETOOLIMPL_H
29 #define NVBLASTAUTHORINGFRACTURETOOLIMPL_H
30 
33 #include <vector>
34 #include <set>
35 
36 namespace Nv
37 {
38 namespace Blast
39 {
40 
41 class SpatialAccelerator;
42 class Triangulator;
43 
44 
49 {
50 public:
51 
61 
62  void release() override;
63 
67  void setBaseMesh(const Mesh* m) override;
68 
75  uint32_t getVoronoiSites(const NvcVec3*& sites) override;
76 
81  void addSite(const NvcVec3& site) override;
86  void uniformlyGenerateSitesInMesh(uint32_t numberOfSites) override;
87 
94  void clusteredSitesGeneration(uint32_t numberOfClusters, uint32_t sitesPerCluster, float clusterRadius) override;
95 
106  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;
107 
114  void generateInSphere(const uint32_t count, const float radius, const NvcVec3& center) override;
119  void setStencil(const Mesh* stencil) override;
123  void clearStencil() override;
124 
131  void deleteInSphere(const float radius, const NvcVec3& center, const float eraserProbability = 1) override;
132 
133 private:
134  std::vector <NvcVec3> mGeneratedSites;
135  const Mesh* mMesh;
136  const Mesh* mStencil;
137  RandomGeneratorBase* mRnd;
138  SpatialAccelerator* mAccelerator;
139 };
140 
141 
142 
147 {
148 
149 public:
150 
155  {
156  mPlaneIndexerOffset = 1;
157  mChunkIdCounter = 0;
158  mRemoveIslands = false;
159  mInteriorMaterialId = kMaterialInteriorId;
160  }
161 
163  {
164  reset();
165  }
166 
167  void release() override;
168 
172  void reset() override;
173 
177  void setInteriorMaterialId(int32_t materialId) override;
178 
182  int32_t getInteriorMaterialId() const override;
183 
187  void replaceMaterialId(int32_t oldMaterialId, int32_t newMaterialId) override;
188 
192  void setSourceMesh(const Mesh* mesh) override;
193 
197  int32_t setChunkMesh(const Mesh* mesh, int32_t parentId) override;
198 
202  Mesh* createChunkMesh(int32_t chunkId) override;
203 
208  void getTransformation(NvcVec3& offset, float& scale) override;
209 
210 
219  int32_t voronoiFracturing(uint32_t chunkId, uint32_t cellCount, const NvcVec3* cellPoints, bool replaceChunk) override;
220 
232  int32_t voronoiFracturing(uint32_t chunkId, uint32_t cellCount, const NvcVec3* cellPoints, const NvcVec3& scale, const NvcQuat& rotation, bool replaceChunk) override;
233 
234 
245  int32_t slicing(uint32_t chunkId, const SlicingConfiguration& conf, bool replaceChunk, RandomGeneratorBase* rnd) override;
246 
247 
260  int32_t cut(uint32_t chunkId, const NvcVec3& normal, const NvcVec3& position, const NoiseConfiguration& noise, bool replaceChunk, RandomGeneratorBase* rnd) override;
261 
272  int32_t cutout(uint32_t chunkId, CutoutConfiguration conf, bool replaceChunk, RandomGeneratorBase* rnd) override;
273 
274 
278  void finalizeFracturing() override;
279 
280  uint32_t getChunkCount() const override;
281 
285  const ChunkInfo& getChunkInfo(int32_t chunkIndex) override;
286 
294  float getMeshOverlap(const Mesh& meshA, const Mesh& meshB) override;
295 
303  uint32_t getBaseMesh(int32_t chunkIndex, Triangle*& output) override;
304 
312  uint32_t updateBaseMesh(int32_t chunkIndex, Triangle* output) override;
313 
319  int32_t getChunkIndex(int32_t chunkId) override;
320 
326  int32_t getChunkId(int32_t chunkIndex) override;
327 
333  int32_t getChunkDepth(int32_t chunkId) override;
334 
342  uint32_t getChunksIdAtDepth(uint32_t depth, int32_t*& chunkIds) override;
343 
344 
355  uint32_t getBufferedBaseMeshes(Vertex*& vertexBuffer, uint32_t*& indexBuffer, uint32_t*& indexBufferOffsets) override;
356 
361  void setRemoveIslands(bool isRemoveIslands) override;
362 
368  int32_t islandDetectionAndRemoving(int32_t chunkId, bool createAtNewDepth = false) override;
369 
374  bool isMeshContainOpenEdges(const Mesh* input) override;
375 
376  bool deleteChunkSubhierarchy(int32_t chunkId, bool deleteRoot = false) override;
377 
378  void uniteChunks(uint32_t threshold, uint32_t targetClusterSize,
379  const uint32_t* chunksToMerge, uint32_t mergeChunkCount,
380  const NvcVec2i* adjChunks, uint32_t adjChunksSize,
381  bool removeOriginalChunks = false) override;
382 
383  bool setApproximateBonding(uint32_t chunkId, bool useApproximateBonding) override;
384 
390  void fitUvToRect(float side, uint32_t chunkId) override;
391 
396  void fitAllUvToRect(float side) override;
397 
398 
399 
400 private:
401  bool isAncestorForChunk(int32_t ancestorId, int32_t chunkId);
402  int32_t slicingNoisy(uint32_t chunkId, const SlicingConfiguration& conf, bool replaceChunk, RandomGeneratorBase* rnd);
403  uint32_t stretchGroup(const std::vector<uint32_t>& group, std::vector<std::vector<uint32_t>>& graph);
404  void rebuildAdjGraph(const std::vector<uint32_t>& chunksToRebuild, const NvcVec2i* adjChunks, uint32_t adjChunksSize,
405  std::vector<std::vector<uint32_t> >& chunkGraph);
406  void fitAllUvToRect(float side, std::set<uint32_t>& mask);
407  void markLeaves();
408 
412  uint32_t createNewChunk(uint32_t parentId);
413 
414 
415 protected:
421 
422  /* Chunk mesh wrappers */
423  std::vector<Triangulator*> mChunkPostprocessors;
424 
425 
426 
429  std::vector<ChunkInfo> mChunkData;
430 
433 };
434 
435 void findCellBasePlanes(const std::vector<NvcVec3>& sites, std::vector<std::vector<int32_t> >& neighboors);
436 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);
437 
438 } // namespace Blast
439 } // namespace Nv
440 
441 
442 #endif // ifndef NVBLASTAUTHORINGFRACTURETOOLIMPL_H
Definition: NvBlastExtAuthoringFractureTool.h:107
void generateInSphere(const uint32_t count, const float radius, const NvcVec3 &center) override
Definition: NvBlastExtAuthoringFractureTool.h:47
uint32_t getVoronoiSites(const NvcVec3 *&sites) override
void addSite(const NvcVec3 &site) override
~FractureToolImpl()
Definition: NvBlastExtAuthoringFractureToolImpl.h:162
void deleteInSphere(const float radius, const NvcVec3 &center, const float eraserProbability=1) override
Definition: NvBlastExtAuthoringFractureTool.h:179
Definition: NvBlastExtAuthoringBooleanTool.h:108
NV_INLINE float normal(const float a[3], float r[3])
Definition: NvBlastMath.h:93
void setBaseMesh(const Mesh *m) override
float mScaleFactor
Definition: NvBlastExtAuthoringFractureToolImpl.h:419
Definition: NvBlastExtAuthoringAccelerator.h:47
Definition: NvBlastExtAuthoringFractureTool.h:79
Definition: NvBlastExtAuthoringMesh.h:42
Definition: NvBlastExtAuthoringFractureTool.h:264
void findCellBasePlanes(const std::vector< NvcVec3 > &sites, std::vector< std::vector< int32_t > > &neighboors)
Definition: NvBlastExtAuthoringFractureTool.h:66
void uniformlyGenerateSitesInMesh(uint32_t numberOfSites) override
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)
int32_t mChunkIdCounter
Definition: NvBlastExtAuthoringFractureToolImpl.h:428
Definition: NvCTypes.h:106
const uint32_t kMaterialInteriorId
Definition: NvBlastExtAuthoringTypes.h:42
std::vector< ChunkInfo > mChunkData
Definition: NvBlastExtAuthoringFractureToolImpl.h:429
std::vector< Triangulator * > mChunkPostprocessors
Definition: NvBlastExtAuthoringFractureToolImpl.h:423
NvcVec3 mOffset
Definition: NvBlastExtAuthoringFractureToolImpl.h:420
Definition: NvBlastExtAuthoringFractureTool.h:133
Definition: NvBlastExtAuthoringTypes.h:79
int32_t mInteriorMaterialId
Definition: NvBlastExtAuthoringFractureToolImpl.h:432
Definition: NvBlastExtAuthoringFractureToolImpl.h:48
Definition: NvBlastExtAuthoringFractureToolImpl.h:146
FractureToolImpl()
Definition: NvBlastExtAuthoringFractureToolImpl.h:154
VoronoiSitesGeneratorImpl(const Mesh *mesh, RandomGeneratorBase *rnd)
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
Definition: NvBlastExtAuthoringTypes.h:67
void setStencil(const Mesh *stencil) override
Definition: NvBlastArray.h:37
Definition: NvCTypes.h:49
void clusteredSitesGeneration(uint32_t numberOfClusters, uint32_t sitesPerCluster, float clusterRadius) override
int64_t mPlaneIndexerOffset
Definition: NvBlastExtAuthoringFractureToolImpl.h:427
Definition: NvCTypes.h:61
bool mRemoveIslands
Definition: NvBlastExtAuthoringFractureToolImpl.h:431