RavEngine
Loading...
Searching...
No Matches
GuConvexMeshData.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_CONVEX_MESH_DATA_H
30#define GU_CONVEX_MESH_DATA_H
31
32#include "foundation/PxPlane.h"
33#include "foundation/PxBitAndData.h"
34
35#include "foundation/PxIntrinsics.h"
36#include "GuCenterExtents.h"
37#include "CmSerialize.h"
38#include "GuSDF.h"
39
40// Data definition
41
42namespace physx
43{
44namespace Gu
45{
46 struct BigConvexRawData;
47
49 {
50 //= ATTENTION! =====================================================================================
51 // Changing the data layout of this class breaks the binary serialization format. See comments for
52 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
53 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
54 // accordingly.
55 //==================================================================================================
56
57 // PT: this structure won't be allocated with PX_NEW because polygons aren't allocated alone (with a dedicated alloc).
58 // Instead they are part of a unique allocation/buffer containing all data for the ConvexHullData class (polygons, followed by
59 // hull vertices, edge data, etc). As a result, ctors for embedded classes like PxPlane won't be called.
60
62 PxU16 mVRef8;
63 PxU8 mNbVerts;
64 PxU8 mMinIndex;
65
66 PX_FORCE_INLINE PxReal getMin(const PxVec3* PX_RESTRICT hullVertices) const //minimum of projection of the hull along this plane normal
67 {
68 return mPlane.n.dot(hullVertices[mMinIndex]);
69 }
70
71 PX_FORCE_INLINE PxReal getMax() const { return -mPlane.d; } //maximum of projection of the hull along this plane normal
72 };
73
74 PX_FORCE_INLINE void flipData(Gu::HullPolygonData& data)
75 {
76 flip(data.mPlane.n.x);
77 flip(data.mPlane.n.y);
78 flip(data.mPlane.n.z);
79 flip(data.mPlane.d);
80 flip(data.mVRef8);
81 }
82 // PT: if this one breaks, please make sure the 'flipData' function is properly updated.
83 PX_COMPILE_TIME_ASSERT(sizeof(Gu::HullPolygonData) == 20);
84
85// TEST_INTERNAL_OBJECTS
87 {
88 //= ATTENTION! =====================================================================================
89 // Changing the data layout of this class breaks the binary serialization format. See comments for
90 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
91 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
92 // accordingly.
93 //==================================================================================================
94 PxReal mRadius;
95 PxReal mExtents[3];
96
97 PX_FORCE_INLINE void reset()
98 {
99 mRadius = 0.0f;
100 mExtents[0] = 0.0f;
101 mExtents[1] = 0.0f;
102 mExtents[2] = 0.0f;
103 }
104 };
106//~TEST_INTERNAL_OBJECTS
107
109 {
110 //= ATTENTION! =====================================================================================
111 // Changing the data layout of this class breaks the binary serialization format. See comments for
112 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
113 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
114 // accordingly.
115 //==================================================================================================
116
117 // PT: WARNING: bounds must be followed by at least 32bits of data for safe SIMD loading
119 PxVec3 mCenterOfMass; //in local space of mesh!
120
121 // PT: WARNING: mNbHullVertices *must* appear before mBigConvexRawData for ConvX to be able to do "big raw data" surgery
122
124
127
130
131 // SDF data
132 SDF* mSdfData;
133
134// TEST_INTERNAL_OBJECTS
135 InternalObjectsData mInternal;
136//~TEST_INTERNAL_OBJECTS
137
139 {
140 }
141
143 {
144 }
145
146 PX_FORCE_INLINE const CenterExtentsPadded& getPaddedBounds() const
147 {
148 // PT: see compile-time assert at the end of file
149 return static_cast<const CenterExtentsPadded&>(mAABB);
150 }
151
153 {
154 const char* tmp = reinterpret_cast<const char*>(mPolygons);
155 tmp += sizeof(Gu::HullPolygonData) * mNbPolygons;
156 return reinterpret_cast<const PxVec3*>(tmp);
157 }
158
160 {
161 const char* tmp = reinterpret_cast<const char*>(mPolygons);
162 tmp += sizeof(Gu::HullPolygonData) * mNbPolygons;
163 tmp += sizeof(PxVec3) * mNbHullVertices;
164 return reinterpret_cast<const PxU8*>(tmp);
165 }
166
168 {
169 const char* tmp = reinterpret_cast<const char*>(mPolygons);
170 tmp += sizeof(Gu::HullPolygonData) * mNbPolygons;
171 tmp += sizeof(PxVec3) * mNbHullVertices;
172 tmp += sizeof(PxU8) * mNbEdges * 2;
173 return reinterpret_cast<const PxU8*>(tmp);
174 }
175
176 //If we don't build the convex hull with grb data, we will return NULL pointer
178 {
179 if (mNbEdges.isBitSet())
180 {
181 const char* tmp = reinterpret_cast<const char*>(mPolygons);
182 tmp += sizeof(Gu::HullPolygonData) * mNbPolygons;
183 tmp += sizeof(PxVec3) * mNbHullVertices;
184 tmp += sizeof(PxU8) * mNbEdges * 2;
185 tmp += sizeof(PxU8) * mNbHullVertices * 3;
186 return reinterpret_cast<const PxU16*>(tmp);
187 }
188 return NULL;
189 }
190
191 PX_FORCE_INLINE const PxU8* getVertexData8() const
192 {
193 const char* tmp = reinterpret_cast<const char*>(mPolygons);
194 tmp += sizeof(Gu::HullPolygonData) * mNbPolygons;
195 tmp += sizeof(PxVec3) * mNbHullVertices;
196 tmp += sizeof(PxU8) * mNbEdges * 2;
197 tmp += sizeof(PxU8) * mNbHullVertices * 3;
198 if (mNbEdges.isBitSet())
199 tmp += sizeof(PxU16) * mNbEdges * 2;
200 return reinterpret_cast<const PxU8*>(tmp);
201 }
202
203 };
204 #if PX_P64_FAMILY
206 #else
208 #endif
209
210 // PT: 'getPaddedBounds()' is only safe if we make sure the bounds member is followed by at least 32bits of data
211 PX_COMPILE_TIME_ASSERT(PX_OFFSET_OF(Gu::ConvexHullData, mCenterOfMass)>=PX_OFFSET_OF(Gu::ConvexHullData, mAABB)+4);
212
213} // namespace Gu
214
215}
216
217//#pragma PX_POP_PACK
218
219#endif
A padded version of CenterExtents, to safely load its data using SIMD.
Definition GuCenterExtents.h:114
Definition GuCenterExtents.h:44
Represents a signed distance field.
Definition GuSDF.h:88
Representation of a plane.
Definition PxPlane.h:49
PxVec3 n
The normal to the plane.
Definition PxPlane.h:152
float d
The distance from the origin.
Definition PxPlane.h:153
3 Element vector class.
Definition PxVec3.h:50
PX_CUDA_CALLABLE PX_FORCE_INLINE float dot(const PxVec3 &v) const
returns the scalar product of this and other.
Definition PxVec3.h:276
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxEMPTY
Definition Px.h:87
Definition GuBigConvexData.h:61
Definition GuConvexMeshData.h:109
HullPolygonData * mPolygons
Array of mNbPolygons structures.
Definition GuConvexMeshData.h:128
PX_FORCE_INLINE const PxU8 * getFacesByVertices8() const
< for each edge, gives 2 adjacent polygons; used by convex-convex code to come up with all the convex...
Definition GuConvexMeshData.h:167
BigConvexRawData * mBigConvexRawData
Hill climbing data, only for large convexes! else NULL.
Definition GuConvexMeshData.h:129
CenterExtents mAABB
bounds TODO: compute this on the fly from first 6 vertices in the vertex array. We'll of course need ...
Definition GuConvexMeshData.h:118
PX_FORCE_INLINE const PxU8 * getVertexData8() const
< Vertex indices indexed by hull polygons
Definition GuConvexMeshData.h:191
PX_FORCE_INLINE const PxU16 * getVerticesByEdges16() const
< Vertex indices indexed by unique edges
Definition GuConvexMeshData.h:177
PxBitAndWord mNbEdges
the highest bit indicate whether we have grb data, the other 15 bits indicate the number of edges in ...
Definition GuConvexMeshData.h:123
PX_FORCE_INLINE const PxVec3 * getHullVertices() const
< Convex hull vertices
Definition GuConvexMeshData.h:152
PxU8 mNbPolygons
Number of planar polygons composing the hull.
Definition GuConvexMeshData.h:126
PX_FORCE_INLINE const PxU8 * getFacesByEdges8() const
< for each edge, gives 2 adjacent polygons; used by convex-convex code to come up with all the convex...
Definition GuConvexMeshData.h:159
PxU8 mNbHullVertices
Number of vertices in the convex hull.
Definition GuConvexMeshData.h:125
Definition GuConvexMeshData.h:49
PxPlane mPlane
Plane equation for this polygon //Could drop 4th elem as it can be computed from any vertex as: d = -...
Definition GuConvexMeshData.h:61
PxU8 mMinIndex
Index of the polygon vertex that has minimal projection along this plane's normal.
Definition GuConvexMeshData.h:64
PxU8 mNbVerts
Number of vertices/edges in the polygon.
Definition GuConvexMeshData.h:63
PxU16 mVRef8
Offset of vertex references in hull vertex data (CS: can we assume indices are tightly packed and off...
Definition GuConvexMeshData.h:62
Definition GuConvexMeshData.h:87