RavEngine
Loading...
Searching...
No Matches
PxvGeometry.h
Go to the documentation of this file.
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 PXV_GEOMETRY_H
30#define PXV_GEOMETRY_H
31
32#include "foundation/PxTransform.h"
33#include "PxvConfig.h"
34
40/************************************************************************/
41/* Shapes */
42/************************************************************************/
43
44#include "GuGeometryChecks.h"
45#include "CmUtils.h"
46
47namespace physx
48{
49
50//
51// Summary of our material approach:
52//
53// On the API level, materials are accessed via pointer. Internally we store indices into the material table.
54// The material table is stored in the SDK and the materials are shared among scenes. To make this threadsafe,
55// we have the following approach:
56//
57// - Every scene has a copy of the SDK master material table
58// - At the beginning of a simulation step, the scene material table gets synced to the master material table.
59// - While the simulation is running, the scene table does not get touched.
60// - Each shape stores the indices of its material(s). When the simulation is not running and a user requests the
61// materials of the shape, the indices are used to fetch the material from the master material table. When the
62// the simulation is running then the same indices are used internally to fetch the materials from the scene
63// material table.
64// - This whole scheme only works as long as the position of a material in the material table does not change
65// when other materials get deleted/inserted. The data structure of the material table makes sure that is the case.
66//
67
69{
70//= ATTENTION! =====================================================================================
71// Changing the data layout of this class breaks the binary serialization format. See comments for
72// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
73// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
74// accordingly.
75//==================================================================================================
76// PX_SERIALIZATION
78 static void getBinaryMetaData(PxOutputStream& stream);
79//~PX_SERIALIZATION
80
82 : indices(NULL)
83 , numIndices(0)
84 , pad(PX_PADDING_16)
85 {
86 }
87
89 {
90 }
91
92 void allocate(PxU16 size)
93 {
94 indices = PX_ALLOCATE(PxU16, size, "MaterialIndicesStruct::allocate");
95 numIndices = size;
96 }
97
98 void deallocate()
99 {
100 PX_FREE(indices);
101 numIndices = 0;
102 }
103 PxU16* indices; // the remap table for material index
104 PxU16 numIndices; // the size of the remap table
105 PxU16 pad; // pad for serialization
106 PxU32 gpuRemapId; // PT: using padding bytes on x64
107};
108
110{
111 bool gpuCompatible; // PT: TODO: remove?
112};
113
118
123
128
130{
131 MaterialIndicesStruct materialsLL;
132};
133
135{
136 PxU32 gpuRemapId;
137};
138
139template <> struct PxcGeometryTraits<PxParticleSystemGeometryLL> { enum { TypeID = PxGeometryType::ePARTICLESYSTEM}; };
140template <> struct PxcGeometryTraits<PxConvexMeshGeometryLL> { enum { TypeID = PxGeometryType::eCONVEXMESH }; };
141template <> struct PxcGeometryTraits<PxTriangleMeshGeometryLL> { enum { TypeID = PxGeometryType::eTRIANGLEMESH }; };
142template <> struct PxcGeometryTraits<PxTetrahedronMeshGeometryLL> { enum { TypeID = PxGeometryType::eTETRAHEDRONMESH }; };
143template <> struct PxcGeometryTraits<PxHeightFieldGeometryLL> { enum { TypeID = PxGeometryType::eHEIGHTFIELD }; };
144template <> struct PxcGeometryTraits<PxHairSystemGeometryLL> { enum { TypeID = PxGeometryType::eHAIRSYSTEM }; };
145
147{
148public:
150};
151
153{
154//= ATTENTION! =====================================================================================
155// Changing the data layout of this class breaks the binary serialization format. See comments for
156// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
157// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
158// accordingly.
159//==================================================================================================
160public:
161// PX_SERIALIZATION
162 GeometryUnion(const PxEMPTY) {}
163 static void getBinaryMetaData(PxOutputStream& stream);
164//~PX_SERIALIZATION
165
166 PX_CUDA_CALLABLE PX_FORCE_INLINE GeometryUnion() { reinterpret_cast<InvalidGeometry&>(mGeometry) = InvalidGeometry(); }
167 PX_CUDA_CALLABLE PX_FORCE_INLINE GeometryUnion(const PxGeometry& g) { set(g); }
168
169 PX_CUDA_CALLABLE PX_FORCE_INLINE const PxGeometry& getGeometry() const { return reinterpret_cast<const PxGeometry&>(mGeometry); }
170 PX_CUDA_CALLABLE PX_FORCE_INLINE PxGeometryType::Enum getType() const { return reinterpret_cast<const PxGeometry&>(mGeometry).getType(); }
171
172 PX_CUDA_CALLABLE void set(const PxGeometry& g);
173
174 template<class Geom> PX_CUDA_CALLABLE PX_FORCE_INLINE Geom& get()
175 {
176 checkType<Geom>(getGeometry());
177 return reinterpret_cast<Geom&>(mGeometry);
178 }
179
180 template<class Geom> PX_CUDA_CALLABLE PX_FORCE_INLINE const Geom& get() const
181 {
182 checkType<Geom>(getGeometry());
183 return reinterpret_cast<const Geom&>(mGeometry);
184 }
185
186private:
187
188 union {
189 void* alignment; // PT: Makes sure the class is at least aligned to pointer size. See DE6803.
190 PxU8 box[sizeof(PxBoxGeometry)];
191 PxU8 sphere[sizeof(PxSphereGeometry)];
192 PxU8 capsule[sizeof(PxCapsuleGeometry)];
193 PxU8 plane[sizeof(PxPlaneGeometry)];
194 PxU8 convex[sizeof(PxConvexMeshGeometryLL)];
195 PxU8 particleSystem[sizeof(PxParticleSystemGeometryLL)];
196 PxU8 mesh[sizeof(PxTriangleMeshGeometryLL)];
197 PxU8 tetMesh[sizeof(PxTetrahedronMeshGeometryLL)];
198 PxU8 heightfield[sizeof(PxHeightFieldGeometryLL)];
199 PxU8 hairsystem[sizeof(PxHairSystemGeometryLL)];
200 PxU8 custom[sizeof(PxCustomGeometry)];
201 PxU8 invalid[sizeof(InvalidGeometry)];
202 } mGeometry;
203};
204
206 {
207 enum Enum
208 {
209 eOWNS_MATERIAL_IDX_MEMORY = (1<<0), // PT: for de-serialization to avoid deallocating material index list. Moved there from Sc::ShapeCore (since one byte was free).
210 eIS_EXCLUSIVE = (1<<1), // PT: shape's exclusive flag
211 eIDT_TRANSFORM = (1<<2), // PT: true if PxsShapeCore::transform is identity
212 eSOFT_BODY_SHAPE = (1<<3), // True if this shape is a soft body shape
213 eCLOTH_SHAPE = (1<<4) // True if this shape is a cloth shape
214 };
215 };
216
218 PX_FLAGS_OPERATORS(PxShapeCoreFlag::Enum,PxU8)
219
221{
222//= ATTENTION! =====================================================================================
223// Changing the data layout of this class breaks the binary serialization format. See comments for
224// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
225// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
226// accordingly.
227//==================================================================================================
228
229// PX_SERIALIZATION
231 {
232 setDensityForFluid(800.0f);
233 }
234 PxsShapeCore(const PxEMPTY) : mGeometry(PxEmpty) {}
235//~PX_SERIALIZATION
236
237#if PX_WINDOWS_FAMILY // PT: to avoid "error: offset of on non-standard-layout type" on Linux
238 protected:
239#endif
240 PX_ALIGN_PREFIX(16)
241 PxTransform mTransform PX_ALIGN_SUFFIX(16); // PT: Offset 0
242#if PX_WINDOWS_FAMILY // PT: to avoid "error: offset of on non-standard-layout type" on Linux
243 public:
244#endif
245 PX_FORCE_INLINE const PxTransform& getTransform() const
246 {
247 return mTransform;
248 }
249
250 PX_FORCE_INLINE void setTransform(const PxTransform& t)
251 {
252 mTransform = t;
253 if(t.p.isZero() && t.q.isIdentity())
254 mShapeCoreFlags.raise(PxShapeCoreFlag::eIDT_TRANSFORM);
255 else
256 mShapeCoreFlags.clear(PxShapeCoreFlag::eIDT_TRANSFORM);
257 }
258
259 PxReal mContactOffset; // PT: Offset 28
260 PxU8 mShapeFlags; // PT: Offset 32 !< API shape flags // PT: TODO: use PxShapeFlags here. Needs to move flags to separate file.
261 PxShapeCoreFlags mShapeCoreFlags; // PT: Offset 33
262 PxU16 mMaterialIndex; // PT: Offset 34
263 PxReal mRestOffset; // PT: Offset 36 - same as the API property of the same name - PT: moved from Sc::ShapeCore to fill padding bytes
264 GeometryUnion mGeometry; // PT: Offset 40
265 PxReal mTorsionalRadius; // PT: Offset 104 - PT: moved from Sc::ShapeCore to fill padding bytes
266 PxReal mMinTorsionalPatchRadius; // PT: Offset 108 - PT: moved from Sc::ShapeCore to fill padding bytes
267
268 PX_FORCE_INLINE float getDensityForFluid() const
269 {
270 return mGeometry.getGeometry().mTypePadding;
271 }
272
273 PX_FORCE_INLINE void setDensityForFluid(float density)
274 {
275 const_cast<PxGeometry&>(mGeometry.getGeometry()).mTypePadding = density;
276 }
277};
278
279PX_COMPILE_TIME_ASSERT( sizeof(GeometryUnion) <= 64); // PT: if you break this one I will not be happy
280
281PX_COMPILE_TIME_ASSERT( (sizeof(PxsShapeCore)&0xf) == 0);
282
283}
284
285#endif
Definition PxvGeometry.h:153
Definition PxvGeometry.h:147
Class representing the geometry of a box.
Definition PxBoxGeometry.h:49
Class representing the geometry of a capsule.
Definition PxCapsuleGeometry.h:54
Convex mesh geometry class.
Definition PxConvexMeshGeometry.h:79
Custom geometry class. This class allows user to create custom geometries by providing a set of virtu...
Definition PxCustomGeometry.h:52
Container for bitfield flag variables associated with a specific enum type.
Definition PxFlags.h:73
A geometry object.
Definition PxGeometry.h:79
Hair system geometry class.
Definition PxHairSystemGeometry.h:45
Height field geometry class.
Definition PxHeightFieldGeometry.h:55
Output stream class for I/O.
Definition PxIO.h:114
Particle system geometry class.
Definition PxParticleSystemGeometry.h:51
Class describing a plane geometry.
Definition PxPlaneGeometry.h:56
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isIdentity() const
returns true if quat is identity
Definition PxQuat.h:116
A class representing the geometry of a sphere.
Definition PxSphereGeometry.h:48
Tetrahedron mesh geometry class.
Definition PxTetrahedronMeshGeometry.h:50
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
Triangle mesh geometry class.
Definition PxTriangleMeshGeometry.h:81
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isZero() const
tests for exact zero vector
Definition PxVec3.h:148
#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 PxvGeometry.h:69
Definition PxvGeometry.h:110
Enum
Definition PxGeometry.h:52
@ eINVALID
internal use only!
Definition PxGeometry.h:66
Definition PxvGeometry.h:135
Definition PxvGeometry.h:130
Definition PxvGeometry.h:120
Definition PxvGeometry.h:206
Definition PxvGeometry.h:125
Definition PxvGeometry.h:115
Definition GuGeometryChecks.h:55
Definition PxvGeometry.h:221