RavEngine
Loading...
Searching...
No Matches
GuTetrahedronMesh.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_TETRAHEDRONMESH_H
30#define GU_TETRAHEDRONMESH_H
31
32#include "foundation/PxIO.h"
33#include "geometry/PxTetrahedronMeshGeometry.h"
34#include "geometry/PxTetrahedronMesh.h"
35#include "geometry/PxTetrahedron.h"
36#include "geometry/PxSimpleTriangleMesh.h"
37#include "CmRefCountable.h"
38#include "common/PxRenderOutput.h"
39#include "GuMeshData.h"
40#include "GuCenterExtents.h"
41#include "GuMeshFactory.h"
42
43namespace physx
44{
45 namespace Gu
46 {
47 class MeshFactory;
48#if PX_VC
49#pragma warning(push)
50#pragma warning(disable: 4324) // Padding was added at the end of a structure because of a __declspec(align) value.
51#endif
52
54 {
55 public:
57
58 virtual ~SoftBodyAuxData();
59
60 virtual const char* getConcreteTypeName() const { return "PxSoftBodyAuxData"; }
61
62 virtual void acquireReference() { Cm::RefCountable_incRefCount(*this); }
63 virtual PxU32 getReferenceCount() const { return Cm::RefCountable_getRefCount(*this); }
64 virtual void release() { Cm::RefCountable_decRefCount(*this); }
65 virtual void onRefCountZero() { PX_DELETE_THIS; }
66
67 PX_FORCE_INLINE PxU32 getNbTetRemapSizeFast() const { return mTetsRemapSize; }
68 PX_FORCE_INLINE PxReal* getGridModelInvMassFast() { return mGridModelInvMass; }
69 PX_FORCE_INLINE PxU32 getNbGMPartitionFast() const { return mGMNbPartitions; }
70
71 PX_FORCE_INLINE PxU32 getGMRemapOutputSizeFast() const { return mGMRemapOutputSize; }
72 PX_FORCE_INLINE PxU32 getGMMaxTetsPerPartitionsFast() const { return mGMMaxMaxTetsPerPartitions; }
73
74
75 PX_FORCE_INLINE PxU32* getCollisionAccumulatedTetrahedronRefs() const { return mCollisionAccumulatedTetrahedronsRef; }
76 PX_FORCE_INLINE PxU32* getCollisionTetrahedronRefs() const { return mCollisionTetrahedronsReferences; }
77 PX_FORCE_INLINE PxU32 getCollisionNbTetrahedronRefs() const { return mCollisionNbTetrahedronsReferences; }
78
79 PX_FORCE_INLINE PxU32* getCollisionSurfaceVertToTetRemap() const { return mCollisionSurfaceVertToTetRemap; }
80 PX_FORCE_INLINE PxMat33* getGridModelRestPosesFast() { return mGridModelTetraRestPoses; }
81 PX_FORCE_INLINE PxMat33* getRestPosesFast() { return mTetraRestPoses; }
82
83 float* mGridModelInvMass;
84
85 PxMat33* mGridModelTetraRestPoses;
86 PxU32* mGridModelOrderedTetrahedrons;
87
88
89 PxU32 mGMNbPartitions;
90 PxU32 mGMMaxMaxTetsPerPartitions;
91 PxU32 mGMRemapOutputSize;
92 PxU32* mGMRemapOutputCP;
93
94 PxU32* mGMAccumulatedPartitionsCP;
95 PxU32* mGMAccumulatedCopiesCP;
96
97 PxU32* mCollisionAccumulatedTetrahedronsRef;
98 PxU32* mCollisionTetrahedronsReferences;
99 PxU32 mCollisionNbTetrahedronsReferences;
100
101 PxU8* mCollisionSurfaceVertsHint;
102 PxU32* mCollisionSurfaceVertToTetRemap;
103
104 PxReal* mVertsBarycentricInGridModel;
105 PxU32* mVertsRemapInGridModel;
106
107
108 PxU32* mTetsRemapColToSim;
109 PxU32 mTetsRemapSize;
110 PxU32* mTetsAccumulatedRemapColToSim;
111
112 PxU32* mGMPullIndices;
113
114 PxMat33* mTetraRestPoses;
115
116 PxU32 mNumTetsPerElement;
117 };
118
120 {
121 public:
122 TetrahedronMesh(PxU32 nbVertices, PxVec3* vertices, PxU32 nbTetrahedrons, void* tetrahedrons, PxU8 flags, PxBounds3 aabb, PxReal geomEpsilon);
125 virtual ~TetrahedronMesh();
126
127 virtual const char* getConcreteTypeName() const { return "PxTetrahedronMesh"; }
128
129 virtual void acquireReference() { Cm::RefCountable_incRefCount(*this); }
130 virtual PxU32 getReferenceCount() const { return Cm::RefCountable_getRefCount(*this); }
131 virtual void release() { Cm::RefCountable_decRefCount(*this); }
132 virtual void onRefCountZero();
133
134 virtual PxU32 getNbVertices() const { return mNbVertices; }
135 virtual const PxVec3* getVertices() const { return mVertices; }
136 virtual PxU32 getNbTetrahedrons() const { return mNbTetrahedrons; }
137 virtual const void* getTetrahedrons() const { return mTetrahedrons; }
139 virtual const PxU32* getTetrahedraRemap() const { return NULL; }
140
141 PX_FORCE_INLINE PxU32 getNbVerticesFast() const { return mNbVertices; }
142 PX_FORCE_INLINE PxVec3* getVerticesFast() const { return mVertices; }
143 PX_FORCE_INLINE PxU32 getNbTetrahedronsFast() const { return mNbTetrahedrons; }
144 PX_FORCE_INLINE const void* getTetrahedronsFast() const { return mTetrahedrons; }
145 PX_FORCE_INLINE bool has16BitIndices() const { return (mFlags & PxMeshFlag::e16_BIT_INDICES) ? true : false; }
146 PX_FORCE_INLINE bool hasPerTriangleMaterials() const { return mMaterialIndices != NULL; }
147 PX_FORCE_INLINE const PxU16* getMaterials() const { return mMaterialIndices; }
148
149 PX_FORCE_INLINE const CenterExtents& getLocalBoundsFast() const { return mAABB; }
150
151 PX_FORCE_INLINE const CenterExtentsPadded& getPaddedBounds() const
152 {
153 // PT: see compile-time assert in cpp
154 return static_cast<const CenterExtentsPadded&>(mAABB);
155 }
156
157 virtual PxBounds3 getLocalBounds() const
158 {
159 PX_ASSERT(mAABB.isValid());
160 return PxBounds3::centerExtents(mAABB.mCenter, mAABB.mExtents);
161 }
162
163 PxU32 mNbVertices;
164 PxVec3* mVertices;
165 PxU32 mNbTetrahedrons;
166 void* mTetrahedrons;
167
168 PxU8 mFlags;
169
171
172 // PT: WARNING: bounds must be followed by at least 32bits of data for safe SIMD loading
173 CenterExtents mAABB;
174 PxReal mGeomEpsilon;
175
176 MeshFactory* mMeshFactory; // PT: changed to pointer for serialization
177 };
178
179 PX_FORCE_INLINE const Gu::TetrahedronMesh* _getTetraMeshData(const PxTetrahedronMeshGeometry& meshGeom)
180 {
181 return static_cast<const Gu::TetrahedronMesh*>(meshGeom.tetrahedronMesh);
182 }
183
185 {
186 public:
188
189 virtual ~BVTetrahedronMesh()
190 {
191 PX_FREE(mGRB_tetraIndices);
192 PX_FREE(mGRB_tetraSurfaceHint);
193 PX_FREE(mGRB_faceRemap);
194 PX_FREE(mGRB_faceRemapInverse);
195 PX_DELETE(mGRB_BV32Tree);
196 PX_FREE(mFaceRemap);
197 }
198
199 //virtual PxBounds3 refitBVH();
200
201 PX_FORCE_INLINE const Gu::BV4Tree& getBV4Tree() const { return mBV4Tree; }
202
203 PX_FORCE_INLINE Gu::BV4Tree& getBV4Tree() { return mBV4Tree; }
204
205 PX_FORCE_INLINE void* getGRBTetraFaceRemap() { return mGRB_faceRemap; }
206
207 PX_FORCE_INLINE void* getGRBTetraFaceRemapInverse() { return mGRB_faceRemapInverse; }
208
209 virtual const PxU32* getTetrahedraRemap() const { return mFaceRemap; }
210
211 PX_FORCE_INLINE bool isTetMeshGPUCompatible() const
212 {
213 return mGRB_BV32Tree != NULL;
214 }
215
216 PxU32* mFaceRemap;
217
218 // GRB data -------------------------
220 PxU8* mGRB_tetraSurfaceHint;
221 PxU32* mGRB_faceRemap;
222 PxU32* mGRB_faceRemapInverse;
224
225 private:
226 Gu::TetrahedronSourceMesh mMeshInterface4;
227 Gu::BV4Tree mBV4Tree;
228 Gu::TetrahedronSourceMesh mMeshInterface32;
229 };
230
231 // Possible optimization: align the whole struct to cache line
233 {
234 //= ATTENTION! =====================================================================================
235 // Changing the data layout of this class breaks the binary serialization format. See comments for
236 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
237 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
238 // accordingly.
239 //==================================================================================================
240 public:
241
242 virtual const char* getConcreteTypeName() const { return "PxSoftBodyMesh"; }
243
244 // PX_SERIALIZATION
245 virtual void exportExtraData(PxSerializationContext& ctx);
246 void importExtraData(PxDeserializationContext&);
247 //PX_PHYSX_COMMON_API static void getBinaryMetaData(PxOutputStream& stream);
248 virtual void release();
249
250 void resolveReferences(PxDeserializationContext&) {}
251 virtual void requiresObjects(PxProcessPxBaseCallback&) {}
252 //~PX_SERIALIZATION
253
254 virtual void acquireReference() { Cm::RefCountable_incRefCount(*this); }
255 virtual PxU32 getReferenceCount() const { return Cm::RefCountable_getRefCount(*this); }
256 virtual void onRefCountZero();
257
258 //virtual PxMeshMidPhase::Enum getMidphaseID() const { return PxMeshMidPhase::eBVH34; }
259
261
262 virtual ~SoftBodyMesh();
263
264 void setMeshFactory(MeshFactory* factory) { mMeshFactory = factory; }
265
266 virtual const PxTetrahedronMesh* getCollisionMesh() const { return mCollisionMesh; }
267 virtual PxTetrahedronMesh* getCollisionMesh() { return mCollisionMesh; }
268
269 PX_FORCE_INLINE const BVTetrahedronMesh* getCollisionMeshFast() const { return mCollisionMesh; }
270 PX_FORCE_INLINE BVTetrahedronMesh* getCollisionMeshFast() { return mCollisionMesh; }
271
272 virtual const PxTetrahedronMesh* getSimulationMesh() const { return mSimulationMesh; }
273 virtual PxTetrahedronMesh* getSimulationMesh() { return mSimulationMesh; }
274
275 PX_FORCE_INLINE const TetrahedronMesh* getSimulationMeshFast() const { return mSimulationMesh; }
276 PX_FORCE_INLINE TetrahedronMesh* getSimulationMeshFast() { return mSimulationMesh; }
277
278 virtual const PxSoftBodyAuxData* getSoftBodyAuxData() const { return mSoftBodyAuxData; }
279 virtual PxSoftBodyAuxData* getSoftBodyAuxData() { return mSoftBodyAuxData; }
280
281 PX_FORCE_INLINE const SoftBodyAuxData* getSoftBodyAuxDataFast() const { return mSoftBodyAuxData; }
282 PX_FORCE_INLINE SoftBodyAuxData* getSoftBodyAuxDataFast() { return mSoftBodyAuxData; }
283
284 protected:
285 TetrahedronMesh* mSimulationMesh;
286 BVTetrahedronMesh* mCollisionMesh;
287 SoftBodyAuxData* mSoftBodyAuxData;
288
289 MeshFactory* mMeshFactory; // PT: changed to pointer for serialization
290 };
291
292#if PX_VC
293#pragma warning(pop)
294#endif
295
296 } // namespace Gu
297}
298
299#endif
Definition GuBV32.h:121
Definition GuBV4.h:341
Definition GuTetrahedronMesh.h:185
PxU32 * mFaceRemap
new faces to old faces mapping (after cleaning, etc). Usage: old = faceRemap[new]
Definition GuTetrahedronMesh.h:216
virtual const PxU32 * getTetrahedraRemap() const
Returns the tetrahedra remapping table.
Definition GuTetrahedronMesh.h:209
Gu::BV32Tree * mGRB_BV32Tree
GRB: BV32 tree.
Definition GuTetrahedronMesh.h:223
void * mGRB_tetraIndices
GRB: GPU-friendly tri indices [uint4].
Definition GuTetrahedronMesh.h:219
Definition GuCenterExtents.h:44
Definition GuMeshData.h:425
Definition GuMeshFactory.h:83
Definition GuTetrahedronMesh.h:54
virtual void release()
Decrements the reference count of a tetrahedron mesh and releases it if the new reference count is ze...
Definition GuTetrahedronMesh.h:64
virtual const char * getConcreteTypeName() const
Returns string name of dynamic type.
Definition GuTetrahedronMesh.h:60
virtual void acquireReference()
Acquires a counted reference to this object.
Definition GuTetrahedronMesh.h:62
virtual PxU32 getReferenceCount() const
Returns the reference count of the object.
Definition GuTetrahedronMesh.h:63
Definition GuMeshData.h:365
Definition GuMeshData.h:616
Definition GuTetrahedronMesh.h:233
virtual const char * getConcreteTypeName() const
Returns string name of dynamic type.
Definition GuTetrahedronMesh.h:242
virtual const PxTetrahedronMesh * getCollisionMesh() const
Const accecssor to the softbody's collision mesh.
Definition GuTetrahedronMesh.h:266
virtual void acquireReference()
Acquires a counted reference to this object.
Definition GuTetrahedronMesh.h:254
virtual PxTetrahedronMesh * getSimulationMesh()
Accecssor to the softbody's simulation mesh.
Definition GuTetrahedronMesh.h:273
virtual PxTetrahedronMesh * getCollisionMesh()
Accecssor to the softbody's collision mesh.
Definition GuTetrahedronMesh.h:267
virtual const PxTetrahedronMesh * getSimulationMesh() const
Const accessor to the softbody's simulation mesh.
Definition GuTetrahedronMesh.h:272
virtual PxSoftBodyAuxData * getSoftBodyAuxData()
Accessor to the softbody's auxilary data like mass and rest pose information.
Definition GuTetrahedronMesh.h:279
virtual PxU32 getReferenceCount() const
Returns the reference count of the object.
Definition GuTetrahedronMesh.h:255
virtual const PxSoftBodyAuxData * getSoftBodyAuxData() const
Const accessor to the softbodies simulation state.
Definition GuTetrahedronMesh.h:278
virtual void release()
Decrements the reference count of a tetrahedron mesh and releases it if the new reference count is ze...
Definition GuTetrahedronMesh.cpp:307
Definition GuMeshData.h:502
Definition GuMeshData.h:285
Definition GuTetrahedronMesh.h:120
virtual PxBounds3 getLocalBounds() const
Returns the local-space (vertex space) AABB from the tetrahedron mesh.
Definition GuTetrahedronMesh.h:157
PxU16 * mMaterialIndices
the size of the array is mNbTetrahedrons.
Definition GuTetrahedronMesh.h:170
PxU8 mFlags
Flag whether indices are 16 or 32 bits wide.
Definition GuTetrahedronMesh.h:168
virtual PxTetrahedronMeshFlags getTetrahedronMeshFlags() const
Reads the PxTetrahedronMesh flags.
Definition GuTetrahedronMesh.h:138
virtual const char * getConcreteTypeName() const
Returns string name of dynamic type.
Definition GuTetrahedronMesh.h:127
virtual const PxVec3 * getVertices() const
Returns the vertices.
Definition GuTetrahedronMesh.h:135
virtual const void * getTetrahedrons() const
Returns the tetrahedron indices.
Definition GuTetrahedronMesh.h:137
virtual void release()
Decrements the reference count of a tetrahedron mesh and releases it if the new reference count is ze...
Definition GuTetrahedronMesh.h:131
virtual PxU32 getNbVertices() const
Returns the number of vertices.
Definition GuTetrahedronMesh.h:134
virtual const PxU32 * getTetrahedraRemap() const
Returns the tetrahedra remapping table.
Definition GuTetrahedronMesh.h:139
virtual void acquireReference()
Acquires a counted reference to this object.
Definition GuTetrahedronMesh.h:129
virtual PxU32 getNbTetrahedrons() const
Returns the number of tetrahedrons.
Definition GuTetrahedronMesh.h:136
virtual PxU32 getReferenceCount() const
Returns the reference count of the object.
Definition GuTetrahedronMesh.h:130
Definition GuBV4.h:230
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 centerExtents(const PxVec3 &center, const PxVec3 &extent)
returns the AABB from center and extents vectors.
Definition PxBounds3.h:299
Binary deserialization context class.
Definition PxSerialFramework.h:174
Container for bitfield flag variables associated with a specific enum type.
Definition PxFlags.h:73
Callback class used to process PxBase objects.
Definition PxSerialFramework.h:81
Binary serialization context class.
Definition PxSerialFramework.h:99
A data container providing mass, rest pose and other information required for softbody simulation.
Definition PxTetrahedronMesh.h:70
A softbody mesh, containing structures to store collision shape, simulation shape and deformation sta...
Definition PxTetrahedronMesh.h:214
Tetrahedron mesh geometry class.
Definition PxTetrahedronMeshGeometry.h:50
PxTetrahedronMesh * tetrahedronMesh
A reference to the mesh object.
Definition PxTetrahedronMeshGeometry.h:92
A tetramedron mesh, also called a 'tetrahedron soup'.
Definition PxTetrahedronMesh.h:115
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxFlags< PxTetrahedronMeshFlag::Enum, PxU8 > PxTetrahedronMeshFlags
collection of set bits defined in PxTetrahedronMeshFlag.
Definition PxTetrahedronMesh.h:58
@ e16_BIT_INDICES
Denotes the use of 16-bit vertex indices.
Definition PxSimpleTriangleMesh.h:66