00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
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 }
00439 }
00440
00441
00442 #endif // ifndef NVBLASTAUTHORINGFRACTURETOOLIMPL_H