32#include "foundation/PxSimpleTypes.h"
33#include "foundation/PxVec4.h"
34#include "foundation/PxBounds3.h"
35#include "geometry/PxTriangleMesh.h"
36#include "geometry/PxTetrahedronMesh.h"
38#include "foundation/PxUserAllocated.h"
39#include "foundation/PxAllocator.h"
66#define PX_MESH_VERSION 16
67#define PX_TET_MESH_VERSION 1
68#define PX_SOFTBODY_MESH_VERSION 2
87#pragma warning(disable: 4324)
100 PxVec3 mLocalCenterOfMass;
110 PxU32* mGRB_faceRemapInverse;
117 PxU32* mAccumulatedTrianglesRef;
118 PxU32* mTrianglesReferences;
119 PxU32 mNbTrianglesReferences;
127 mLocalCenterOfMass (0.f),
133 mGRB_faceRemapInverse (NULL),
135 mAccumulatedTrianglesRef(NULL),
136 mTrianglesReferences (NULL),
137 mNbTrianglesReferences (0)
147 PX_FREE(mGRB_faceRemapInverse);
149 PX_FREE(mAccumulatedTrianglesRef);
151 PX_FREE(mTrianglesReferences);
156 PX_ASSERT(!mVertices);
158 const PxU32 nbAllocatedVerts = nbVertices + 1;
159 mVertices = PX_ALLOCATE(
PxVec3, nbAllocatedVerts,
"PxVec3");
160 mNbVertices = nbVertices;
178 PxU8* mExtraTrigData;
179 PxU16* mMaterialIndices;
190 mExtraTrigData (NULL),
191 mMaterialIndices (NULL),
200 PX_FREE(mAdjacencies);
201 PX_FREE(mMaterialIndices);
202 PX_FREE(mExtraTrigData);
204 PX_DELETE(mGRB_BV32Tree);
209 PX_ASSERT(mNbTriangles);
210 PX_ASSERT(!mAdjacencies);
211 mAdjacencies = PX_ALLOCATE(PxU32, mNbTriangles * 3,
"mAdjacencies");
218 PX_ASSERT(mNbTriangles);
219 PX_ASSERT(!mFaceRemap);
220 mFaceRemap = PX_ALLOCATE(PxU32, mNbTriangles,
"mFaceRemap");
224 PX_NOINLINE void* allocateTriangles(PxU32 nbTriangles,
bool force32Bit, PxU32 allocateGPUData = 0)
226 PX_ASSERT(mNbVertices);
227 PX_ASSERT(!mTriangles);
229 bool index16 = mNbVertices <= 0xffff && !force32Bit;
233 mTriangles = PX_ALLOC(nbTriangles * (index16 ?
sizeof(PxU16) : sizeof(PxU32)) * 3,
"mTriangles");
235 mGRB_primIndices = PX_ALLOC(nbTriangles * (index16 ?
sizeof(PxU16) : sizeof(PxU32)) * 3,
"mGRB_triIndices");
236 mNbTriangles = nbTriangles;
242 PX_ASSERT(mNbTriangles);
243 PX_ASSERT(!mMaterialIndices);
244 mMaterialIndices = PX_ALLOCATE(PxU16, mNbTriangles,
"mMaterialIndices");
245 return mMaterialIndices;
250 PX_ASSERT(mNbTriangles);
251 PX_ASSERT(!mExtraTrigData);
252 mExtraTrigData = PX_ALLOCATE(PxU8, mNbTriangles,
"mExtraTrigData");
253 return mExtraTrigData;
256 PX_FORCE_INLINE void setTriangleAdjacency(PxU32 triangleIndex, PxU32 adjacency, PxU32 offset)
258 PX_ASSERT(mAdjacencies);
259 mAdjacencies[triangleIndex*3 + offset] = adjacency;
289 PxU16* mMaterialIndices;
291 PxU32 mNbTetrahedrons;
302 mMaterialIndices(NULL),
311 mNbVertices(nbVertices),
313 mNbTetrahedrons(nbTetrahedrons),
314 mTetrahedrons(tetrahedrons),
316 mGeomEpsilon(geomEpsilon),
320 void allocateTetrahedrons(
const PxU32 nbGridTetrahedrons,
const PxU32 allocateGPUData = 0)
324 mTetrahedrons = PX_ALLOC(nbGridTetrahedrons *
sizeof(PxU32) * 4,
"mGridModelTetrahedrons");
327 mNbTetrahedrons = nbGridTetrahedrons;
330 PxVec3* allocateVertices(PxU32 nbVertices,
const PxU32 allocateGPUData = 1)
332 PX_ASSERT(!mVertices);
336 const PxU32 nbAllocatedVerts = nbVertices + 1;
337 mVertices = PX_ALLOCATE(
PxVec3, nbAllocatedVerts,
"PxVec3");
339 mNbVertices = nbVertices;
343 PxU16* allocateMaterials()
345 PX_ASSERT(mNbTetrahedrons);
346 PX_ASSERT(!mMaterialIndices);
347 mMaterialIndices = PX_ALLOCATE(PxU16, mNbTetrahedrons,
"mMaterialIndices");
348 return mMaterialIndices;
358 PX_FREE(mTetrahedrons);
360 PX_FREE(mMaterialIndices)
372 PxU32* mGRB_faceRemapInverse;
374 PxU8* mGRB_tetraSurfaceHint;
388 mGRB_faceRemapInverse(NULL),
390 mGRB_tetraSurfaceHint(NULL),
391 mTetraRestPoses(NULL)
396 PX_FREE(mGRB_tetraSurfaceHint);
397 PX_DELETE(mGRB_BV32Tree);
401 PX_FREE(mGRB_faceRemapInverse);
402 PX_FREE(mTetraRestPoses);
405 PxU32* allocateFaceRemap(PxU32 nbTetrahedrons)
407 PX_ASSERT(nbTetrahedrons);
408 PX_ASSERT(!mFaceRemap);
409 mFaceRemap = PX_ALLOCATE(PxU32, nbTetrahedrons,
"mFaceRemap");
413 void allocateCollisionData(PxU32 nbTetrahedrons)
415 mGRB_primIndices = PX_ALLOC(nbTetrahedrons * 4 *
sizeof(PxU32),
"mGRB_primIndices");
416 mGRB_tetraSurfaceHint = PX_ALLOCATE(PxU8, nbTetrahedrons,
"mGRB_tetraSurfaceHint");
418 mTetraRestPoses = PX_ALLOCATE(PxMat33, nbTetrahedrons,
"mTetraRestPoses");
427 PxReal* mVertsBarycentricInGridModel;
428 PxU32* mVertsRemapInGridModel;
430 PxU32* mTetsRemapColToSim;
431 PxU32 mTetsRemapSize;
432 PxU32* mTetsAccumulatedRemapColToSim;
435 PxU32* mCollisionAccumulatedTetrahedronsRef;
436 PxU32* mCollisionTetrahedronsReferences;
437 PxU32 mCollisionNbTetrahedronsReferences;
439 PxU32* mCollisionSurfaceVertToTetRemap;
440 PxU8* mCollisionSurfaceVertsHint;
443 mVertsBarycentricInGridModel(NULL),
444 mVertsRemapInGridModel(NULL),
445 mTetsRemapColToSim(NULL),
447 mTetsAccumulatedRemapColToSim(NULL),
448 mCollisionAccumulatedTetrahedronsRef(NULL),
449 mCollisionTetrahedronsReferences(NULL),
450 mCollisionNbTetrahedronsReferences(0),
451 mCollisionSurfaceVertToTetRemap(NULL),
452 mCollisionSurfaceVertsHint(NULL)
459 PX_FREE(mVertsBarycentricInGridModel);
460 PX_FREE(mVertsRemapInGridModel);
461 PX_FREE(mTetsRemapColToSim);
462 PX_FREE(mTetsAccumulatedRemapColToSim);
463 PX_FREE(mCollisionAccumulatedTetrahedronsRef);
464 PX_FREE(mCollisionTetrahedronsReferences);
465 PX_FREE(mCollisionSurfaceVertsHint);
466 PX_FREE(mCollisionSurfaceVertToTetRemap);
469 void allocatemappingData(
const PxU32 nbVerts,
const PxU32 tetRemapSize,
const PxU32 nbColTetrahedrons,
const PxU32 allocateGPUData = 0)
473 mVertsBarycentricInGridModel =
reinterpret_cast<PxReal*
>(PX_ALLOC(nbVerts *
sizeof(PxReal) * 4,
"mVertsBarycentricInGridModel"));
474 mVertsRemapInGridModel =
reinterpret_cast<PxU32*
>(PX_ALLOC(nbVerts *
sizeof(PxU32),
"mVertsRemapInGridModel"));
475 mTetsRemapColToSim =
reinterpret_cast<PxU32*
>(PX_ALLOC(tetRemapSize *
sizeof(PxU32),
"mTetsRemapInSimModel"));
476 mTetsAccumulatedRemapColToSim =
reinterpret_cast<PxU32*
>(PX_ALLOC(nbColTetrahedrons *
sizeof(PxU32),
"mTetsAccumulatedRemapInSimModel"));
477 mCollisionSurfaceVertsHint =
reinterpret_cast<PxU8*
>(PX_ALLOC(nbVerts *
sizeof(PxU8),
"mCollisionSurfaceVertsHint"));
478 mCollisionSurfaceVertToTetRemap =
reinterpret_cast<PxU32*
>(PX_ALLOC(nbVerts *
sizeof(PxU32),
"mCollisionSurfaceVertToTetRemap"));
480 mTetsRemapSize = tetRemapSize;
483 void allocateTetRefData(
const PxU32 totalTetReference,
const PxU32 nbCollisionVerts,
const PxU32 allocateGPUData )
487 mCollisionAccumulatedTetrahedronsRef =
reinterpret_cast<PxU32*
>(PX_ALLOC(nbCollisionVerts *
sizeof(PxU32),
"mGMAccumulatedTetrahedronsRef"));
488 mCollisionTetrahedronsReferences =
reinterpret_cast<PxU32*
>(PX_ALLOC(totalTetReference *
sizeof(PxU32),
"mGMTetrahedronsReferences"));
492 mCollisionNbTetrahedronsReferences = totalTetReference;
495 virtual void release()
504 PxReal* mGridModelInvMass;
506 PxMat33* mGridModelTetraRestPoses;
508 PxU32 mGridModelNbPartitions;
509 PxU32 mGridModelMaxTetsPerPartitions;
511 PxU32* mGridModelOrderedTetrahedrons;
513 PxU32* mGMRemapOutputCP;
514 PxU32* mGMAccumulatedPartitionsCP;
515 PxU32* mGMAccumulatedCopiesCP;
517 PxU32 mGMRemapOutputSize;
519 PxU32* mGMPullIndices;
521 PxU32 mNumTetsPerElement;
524 mGridModelInvMass(NULL),
525 mGridModelTetraRestPoses(NULL),
526 mGridModelNbPartitions(0),
527 mGridModelOrderedTetrahedrons(NULL),
528 mGMRemapOutputCP(NULL),
529 mGMAccumulatedPartitionsCP(NULL),
530 mGMAccumulatedCopiesCP(NULL),
531 mGMRemapOutputSize(0),
537 PX_FREE(mGridModelInvMass);
538 PX_FREE(mGridModelTetraRestPoses);
539 PX_FREE(mGridModelOrderedTetrahedrons);
540 PX_FREE(mGMRemapOutputCP);
541 PX_FREE(mGMAccumulatedPartitionsCP);
542 PX_FREE(mGMAccumulatedCopiesCP);
543 PX_FREE(mGMPullIndices);
546 void allocateGridModelData(
const PxU32 nbGridTetrahedrons,
const PxU32 nbGridVerts,
547 const PxU32 nbVerts,
const PxU32 nbPartitions,
const PxU32 remapOutputSize,
const PxU32 numTetsPerElement,
const PxU32 allocateGPUData = 0)
553 const PxU32 numElements = nbGridTetrahedrons / numTetsPerElement;
554 const PxU32 numVertsPerElement = numTetsPerElement == 6 ? 8 : 4;
556 mGridModelInvMass =
reinterpret_cast<float*
>(PX_ALLOC(nbGridVerts *
sizeof(
float),
"mGridModelInvMass"));
557 mGridModelTetraRestPoses =
reinterpret_cast<PxMat33*
>(PX_ALLOC(nbGridTetrahedrons *
sizeof(
PxMat33),
"mGridModelTetraRestPoses"));
559 mGridModelOrderedTetrahedrons =
reinterpret_cast<PxU32*
>(PX_ALLOC(numElements *
sizeof(PxU32),
"mGridModelOrderedTetrahedrons"));
560 mGMRemapOutputCP =
reinterpret_cast<PxU32*
>(PX_ALLOC(remapOutputSize *
sizeof(PxU32),
"mGMRemapOutputCP"));
561 mGMAccumulatedPartitionsCP =
reinterpret_cast<PxU32*
>(PX_ALLOC(nbPartitions *
sizeof(PxU32),
"mGMAccumulatedPartitionsCP"));
562 mGMAccumulatedCopiesCP =
reinterpret_cast<PxU32*
>(PX_ALLOC(nbGridVerts *
sizeof(PxU32),
"mGMAccumulatedCopiesCP"));
563 mGMPullIndices =
reinterpret_cast<PxU32*
>(PX_ALLOC(numElements * numVertsPerElement *
sizeof(PxU32) ,
"mGMPullIndices"));
566 mGridModelNbPartitions = nbPartitions;
567 mGMRemapOutputSize = remapOutputSize;
585 PX_FREE(mCollisionData);
588 virtual void release()
606 PX_FREE(mSimulationData);
609 virtual void release()
627 mSimulationMesh(simulationMesh),
628 mSimulationData(simulationData),
629 mCollisionMesh(collisionMesh),
630 mCollisionData(collisionData),
631 mMappingData(mappingData)
Definition GuMeshData.h:273
Definition GuMeshData.h:425
Definition GuMeshData.h:572
Definition GuMeshData.h:91
void * mGRB_primIndices
GRB: GPU-friendly primitive indices(either triangle or tetrahedron)
Definition GuMeshData.h:108
PxU32 * mGRB_faceRemap
GRB: this remap the GPU triangle indices to CPU triangle indices.
Definition GuMeshData.h:109
Definition GuMeshData.h:264
Represents a signed distance field.
Definition GuSDF.h:88
Definition GuMeshData.h:595
Definition GuMeshData.h:365
void * mGRB_primIndices
GRB: GPU-friendly primitive indices(either triangle or tetrahedron)
Definition GuMeshData.h:370
PxU32 * mGRB_faceRemap
GRB: this remap the GPU triangle indices to CPU triangle indices.
Definition GuMeshData.h:371
Definition GuMeshData.h:616
Definition GuMeshData.h:502
Definition GuMeshData.h:285
Definition GuMeshData.h:171
void * mGRB_primAdjacencies
GRB: adjacency data, with BOUNDARY and NONCONVEX flags (flags replace adj indices where applicable) [...
Definition GuMeshData.h:182
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 empty()
Return empty bounds.
Definition PxBounds3.h:284
Contains information about how to update the collision mesh's vertices given a deformed simulation te...
Definition PxTetrahedronMesh.h:283
Conbines PxTetrahedronMeshData and PxSoftBodyCollisionData.
Definition PxTetrahedronMesh.h:330
3x3 matrix class
Definition PxMat33.h:91
Conbines PxTetrahedronMeshData and PxSoftBodyCollisionData.
Definition PxTetrahedronMesh.h:348
Stores data to accelerate collision detection of a tetrahedral mesh.
Definition PxTetrahedronMesh.h:297
Stores data to compute and store the state of a deformed tetrahedral mesh.
Definition PxTetrahedronMesh.h:319
Contains raw geometry information describing the tetmesh's vertices and its elements (tetrahedra)
Definition PxTetrahedronMesh.h:308
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
#define PX_NOINLINE
Definition PxPreprocessor.h:346
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
InternalMeshSerialFlag
Definition GuMeshData.h:72
@ IMSF_VERT_MAPPING
if set, the cooked mesh file contains vertex mapping information
Definition GuMeshData.h:80
@ IMSF_INERTIA
if set, the cooked mesh file contains inertia tensor for the mesh
Definition GuMeshData.h:82
@ IMSF_8BIT_INDICES
if set, the cooked mesh file contains 8bit indices (topology)
Definition GuMeshData.h:75
@ IMSF_FACE_REMAP
if set, the cooked mesh file contains a remap table
Definition GuMeshData.h:74
@ IMSF_SDF
if set, the cooked mesh file contains SDF data structures
Definition GuMeshData.h:79
@ IMSF_ADJACENCIES
if set, the cooked mesh file contains adjacency structures
Definition GuMeshData.h:77
@ IMSF_MATERIALS
if set, the cooked mesh file contains per-triangle material indices
Definition GuMeshData.h:73
@ IMSF_16BIT_INDICES
if set, the cooked mesh file contains 16bit indices (topology)
Definition GuMeshData.h:76
@ IMSF_GRB_DATA
if set, the cooked mesh file contains GRB data structures
Definition GuMeshData.h:78
@ IMSF_GRB_INV_REMAP
if set, the cooked mesh file contains vertex inv mapping information. Required for cloth
Definition GuMeshData.h:81
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Enum
Definition PxTriangleMesh.h:58
@ eBVH33
Default midphase mesh structure, as used up to PhysX 3.3 (deprecated)
Definition PxTriangleMesh.h:59
@ eBVH34
New midphase mesh structure, introduced in PhysX 3.4.
Definition PxTriangleMesh.h:60
@ eADJACENCY_INFO
The triangle mesh has adjacency information build.
Definition PxTriangleMesh.h:76
@ e16_BIT_INDICES
The triangle mesh has 16bits vertex indices.
Definition PxTriangleMesh.h:75