RavEngine
Loading...
Searching...
No Matches
GuSDF.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef GU_SDF_H
30#define GU_SDF_H
35#include "common/PxPhysXCommonConfig.h"
36#include "foundation/PxVec3.h"
37#include "foundation/PxUserAllocated.h"
38#include "foundation/PxArray.h"
39
40namespace physx
41{
42 namespace Gu
43 {
47 class Dim3
48 {
49 public:
54 {
55 }
56
60 Dim3(PxZERO d) : x(0), y(0), z(0)
61 {
62 PX_UNUSED(d);
63 }
64
68 Dim3(PxU32 _x, PxU32 _y, PxU32 _z) : x(_x), y(_y), z(_z)
69 {
70 }
71
75 Dim3(const Dim3& d) : x(d.x), y(d.y), z(d.z)
76 {
77 }
78
79 PxU32 x;
80 PxU32 y;
81 PxU32 z;
82 };
83
87 class SDF : public PxUserAllocated
88 {
89 public:
90
91// PX_SERIALIZATION
92 SDF(const PxEMPTY) {}
93 static void getBinaryMetaData(PxOutputStream& stream);
94//~PX_SERIALIZATION
98 SDF() : mSdf(NULL), mSubgridStartSlots(NULL), mSubgridSdf(NULL)
99 {
100 }
101
106 : mMeshLower(PxZero), mSpacing(0.0f), mDims(PxZero), mNumSdfs(0), mSdf(NULL),
109 {
110 PX_UNUSED(s);
111 }
112
122
126 ~SDF();
127
128
129 PxReal* allocateSdfs(const PxVec3& meshLower, const PxReal& spacing, const PxU32 dimX, const PxU32 dimY, const PxU32 dimZ,
130 const PxU32 subgridSize, const PxU32 sdfSubgrids3DTexBlockDimX, const PxU32 sdfSubgrids3DTexBlockDimY, const PxU32 sdfSubgrids3DTexBlockDimZ,
131 PxReal subgridsMinSdfValue, PxReal subgridsMaxSdfValue, PxU32 bytesPerSparsePixel);
132
134 PxReal mSpacing;
136 PxU32 mNumSdfs;
137 PxReal* mSdf;
138
139 // Additional data to support sparse grid SDFs
149 };
150
166 PX_PHYSX_COMMON_API void windingNumbers(const PxVec3* vertices, const PxU32* indices, PxU32 numTriangleIndices, PxU32 width, PxU32 height, PxU32 depth,
167 PxReal* windingNumbers, PxVec3 minExtents, PxVec3 maxExtents, PxVec3* sampleLocations = NULL);
168
183 PX_PHYSX_COMMON_API void windingNumbersInsideCheck(const PxVec3* vertices, const PxU32* indices, PxU32 numTriangleIndices, PxU32 width, PxU32 height, PxU32 depth,
184 bool* insideResult, PxVec3 minExtents, PxVec3 maxExtents, PxVec3* sampleLocations = NULL);
185
203 PX_PHYSX_COMMON_API void SDFUsingWindingNumbers(const PxVec3* vertices, const PxU32* indices, PxU32 numTriangleIndices, PxU32 width, PxU32 height, PxU32 depth,
204 PxReal* sdf, PxVec3 minExtents, PxVec3 maxExtents, PxVec3* sampleLocations = NULL, bool cellCenteredSamples = true, PxU32 numThreads = 1);
205
230 PX_PHYSX_COMMON_API void SDFUsingWindingNumbersSparse(const PxVec3* vertices, const PxU32* indices, PxU32 numTriangleIndices, PxU32 width, PxU32 height, PxU32 depth,
231 const PxVec3& minExtents, const PxVec3& maxExtents, PxReal narrowBandThicknessRelativeToExtentDiagonal, PxU32 cellsPerSubgrid,
232 PxArray<PxReal>& sdfCoarse, PxArray<PxU32>& sdfFineStartSlots, PxArray<PxReal>& subgridData, PxArray<PxReal>& denseSdf,
233 PxReal& subgridsMinSdfValue, PxReal& subgridsMaxSdfValue, PxU32 numThreads = 1);
234
235
252 PX_PHYSX_COMMON_API void convertSparseSDFTo3DTextureLayout(PxU32 width, PxU32 height, PxU32 depth, PxU32 cellsPerSubgrid,
253 PxU32* sdfFineStartSlots, const PxReal* sdfFineSubgridsIn, PxU32 sdfFineSubgridsSize, PxArray<PxReal>& subgrids3DTexFormat,
254 PxU32& numSubgridsX, PxU32& numSubgridsY, PxU32& numSubgridsZ);
255
263 PX_PHYSX_COMMON_API void extractIsosurfaceFromSDF(const Gu::SDF& sdf, PxArray<PxVec3>& isosurfaceVertices, PxArray<PxU32>& isosurfaceTriangleIndices);
264 }
265}
266
268#endif
269
270
Represents dimensions of signed distance field.
Definition GuSDF.h:48
PxU32 y
Size of Y dimension.
Definition GuSDF.h:80
PxU32 z
Size of Z dimension.
Definition GuSDF.h:81
Dim3(const Dim3 &d)
Copy constructor.
Definition GuSDF.h:75
Dim3(PxU32 _x, PxU32 _y, PxU32 _z)
Constructor.
Definition GuSDF.h:68
PxU32 x
Size of X dimension.
Definition GuSDF.h:79
Dim3(PxZERO d)
Constructor.
Definition GuSDF.h:60
Dim3()
Constructor.
Definition GuSDF.h:53
Represents a signed distance field.
Definition GuSDF.h:88
PxReal mSpacing
Spacing of each sdf voxel.
Definition GuSDF.h:134
PxU32 mSubgridSize
The number of cells in a sparse subgrid block (full block has mSubgridSize^3 cells and (mSubgridSize+...
Definition GuSDF.h:140
PxU32 * mSubgridStartSlots
Array with start indices into the subgrid texture for every subgrid block. 10bits for z coordinate,...
Definition GuSDF.h:142
PxReal mSubgridsMinSdfValue
The minimum value over all subgrid blocks. Used if normalized textures are used which is the case for...
Definition GuSDF.h:146
PxU32 mNumSubgridSdfs
Array length of mSubgridSdf. Only used for serialization.
Definition GuSDF.h:143
SDF(PxZERO s)
Constructor.
Definition GuSDF.h:105
SDF()
Constructor.
Definition GuSDF.h:98
PxReal * mSdf
Array of sdf.
Definition GuSDF.h:137
Dim3 mDims
Dimension of the sdf.
Definition GuSDF.h:135
PxU32 mNumStartSlots
Array length of mSubgridStartSlots. Only used for serialization.
Definition GuSDF.h:141
SDF(const SDF &sdf)
Copy constructor.
Definition GuSDF.h:116
PxVec3 mMeshLower
Lower bound of the original mesh.
Definition GuSDF.h:133
PxReal mSubgridsMaxSdfValue
The maximum value over all subgrid blocks. Used if normalized textures are used which is the case for...
Definition GuSDF.h:147
Dim3 mSdfSubgrids3DTexBlockDim
Subgrid sdf is layed out as a 3d texture including packed blocks of size (mSubgridSize+1)^3.
Definition GuSDF.h:145
~SDF()
Destructor.
Definition GuSDF.cpp:52
PxU8 * mSubgridSdf
The data to create the 3d texture containg the packed subgrid blocks. Stored as PxU8 to support multi...
Definition GuSDF.h:144
PxU32 mBytesPerSparsePixel
The number of bytes per subgrid pixel.
Definition GuSDF.h:148
PxU32 mNumSdfs
Number of sdf values.
Definition GuSDF.h:136
Definition PxArray.h:53
Output stream class for I/O.
Definition PxIO.h:114
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
void windingNumbersInsideCheck(const PxVec3 *vertices, const PxU32 *indices, PxU32 numTriangleIndices, PxU32 width, PxU32 height, PxU32 depth, bool *insideResult, PxVec3 min, PxVec3 max, PxVec3 *sampleLocations)
Returns if a point is enclosed by a triangle mesh.
Definition GuSDF.cpp:399
void windingNumbers(const PxVec3 *vertices, const PxU32 *indices, PxU32 numTriangleIndices, PxU32 width, PxU32 height, PxU32 depth, PxReal *windingNumbers, PxVec3 min, PxVec3 max, PxVec3 *sampleLocations)
Returns the number of times a point is enclosed by a triangle mesh. Therefore points with a winding n...
Definition GuSDF.cpp:298
void convertSparseSDFTo3DTextureLayout(PxU32 width, PxU32 height, PxU32 depth, PxU32 cellsPerSubgrid, PxU32 *sdfFineStartSlots, const PxReal *sdfFineSubgridsIn, PxU32 sdfFineSubgridsSize, PxArray< PxReal > &subgrids3DTexFormat, PxU32 &numSubgridsX, PxU32 &numSubgridsY, PxU32 &numSubgridsZ)
Converts a sparse grid sdf to a format that can be used to create a 3d texture. 3d textures support v...
Definition GuSDF.cpp:1034
void SDFUsingWindingNumbersSparse(const PxVec3 *vertices, const PxU32 *indices, PxU32 numTriangleIndices, PxU32 width, PxU32 height, PxU32 depth, const PxVec3 &minExtents, const PxVec3 &maxExtents, PxReal narrowBandThickness, PxU32 cellsPerSubgrid, PxArray< PxReal > &sdfCoarse, PxArray< PxU32 > &sdfFineStartSlots, PxArray< PxReal > &subgridData, PxArray< PxReal > &denseSdf, PxReal &subgridsMinSdfValue, PxReal &subgridsMaxSdfValue, PxU32 numThreads)
Returns the distance to the mesh's surface for all samples in a grid. The sign is dependent on the tr...
Definition GuSDF.cpp:1189
void extractIsosurfaceFromSDF(const Gu::SDF &sdf, PxArray< PxVec3 > &isosurfaceVertices, PxArray< PxU32 > &isosurfaceTriangleIndices)
Extracts an isosurface as a triangular mesh from a signed distance function.
Definition GuSDF.cpp:1718
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxZERO
Definition Px.h:93
PxEMPTY
Definition Px.h:87