NvBlastExtAuthoringMeshNoiser.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 
29 #ifndef NVBLASTEXTAUTHORINGMESHNOISER_H
30 #define NVBLASTEXTAUTHORINGMESHNOISER_H
31 #include <vector>
32 #include <map>
34 
35 namespace Nv
36 {
37  namespace Blast
38  {
39  class SimplexNoise;
40 
45  {
46  int32_t tr[2];
47  int32_t c;
49  {
50  c = 0;
51  }
55  void add(int32_t t)
56  {
57  tr[c] = t;
58  ++c;
59  }
63  void replace(int32_t from, int32_t to)
64  {
65  if (tr[0] == from)
66  {
67  tr[0] = to;
68  }
69  else
70  {
71  if (c == 2 && tr[1] == from)
72  {
73  tr[1] = to;
74  }
75  }
76  }
80  int32_t getNot(int32_t id)
81  {
82  if (tr[0] != id)
83  {
84  return tr[0];
85  }
86  if (c == 2 && tr[1] != id)
87  {
88  return tr[1];
89  }
90  return -1;
91  }
92 
93  };
94 
99  class MeshNoiser
100  {
101  public:
103  {
104  reset();
105  }
106 
107  void reset();
108 
112  enum EdgeFlag { INTERNAL_EDGE, EXTERNAL_BORDER_EDGE, INTERNAL_BORDER_EDGE, EXTERNAL_EDGE, NONE };
113 
114 
118  void setMesh(const std::vector<Triangle>& mesh);
119 
124  void tesselateInternalSurface(float maxLen);
125 
133  void applyNoise(SimplexNoise& noise, float falloff, int32_t relaxIterations, float relaxFactor);
134 
135  std::vector<Triangle> getMesh();
136 
137  private:
138  physx::PxVec3 mOffset;
139  float mScale;
140  bool isTesselated;
144  std::vector<Vertex> mVertices;
145  std::vector<TriangleIndexed> mTriangles;
146  std::vector<Edge> mEdges;
147  std::map<Vertex, int32_t, VrtComp> mVertMap;
148  std::map<Edge, int32_t> mEdgeMap;
149 
150 
154  std::vector<Triangle> mResultTriangles;
155 
156 
157  int32_t addVerticeIfNotExist(const Vertex& p);
158  int32_t addEdge(const Edge& e);
159  int32_t findEdge(const Edge& e);
160 
161 
162 
163  void collapseEdge(int32_t id);
164  void divideEdge(int32_t id);
165  void updateVertEdgeInfo();
166  void updateEdgeTriangleInfo();
167  void relax(int32_t iterations, float factor, std::vector<Vertex>& vertices);
168  void recalcNoiseDirs();
169 
170 
171  std::vector<bool> mRestrictionFlag;
172  std::vector<EdgeFlag> mEdgeFlag;
173  std::vector<EdgeToTriangles> mTrMeshEdToTr;
174  std::vector<int32_t> mVertexValence;
175  std::vector<std::vector<int32_t> > mVertexToTriangleMap;
176 
177 
178 
179  std::vector<float> mVerticesDistances;
180  std::vector<physx::PxVec3> mVerticesNormalsSmoothed;
181  std::vector<uint32_t> mPositionMappedVrt;
182  std::vector<std::vector<int32_t> > mGeometryGraph;
183 
184  void prebuildEdgeFlagArray();
185  void computePositionedMapping();
186  void computeFalloffAndNormals();
187 
188  void prebuildTesselatedTriangles();
189  };
190 
191  } // namespace Blast
192 } // namespace Nv
193 #endif // ! NVBLASTEXTAUTHORINGMESHNOISER_H
MeshNoiser()
Definition: NvBlastExtAuthoringMeshNoiser.h:102
EdgeToTriangles()
Definition: NvBlastExtAuthoringMeshNoiser.h:48
void add(int32_t t)
Definition: NvBlastExtAuthoringMeshNoiser.h:55
int32_t c
Definition: NvBlastExtAuthoringMeshNoiser.h:47
EdgeFlag
Definition: NvBlastExtAuthoringMeshNoiser.h:112
Definition: NvBlastExtAuthoringMeshNoiser.h:44
Definition: NvBlastExtAuthoringMeshNoiser.h:99
int32_t tr[2]
Definition: NvBlastExtAuthoringMeshNoiser.h:46
int32_t getNot(int32_t id)
Definition: NvBlastExtAuthoringMeshNoiser.h:80
Definition: NvBlastExtAuthoringPerlinNoise.h:235
Definition: NvBlastExtAuthoringTypes.h:57
Definition: NvBlastExtAuthoringTypes.h:67
void replace(int32_t from, int32_t to)
Definition: NvBlastExtAuthoringMeshNoiser.h:63
Definition: NvBlastArray.h:37