29#ifndef GU_TRIANGLEMESH_H
30#define GU_TRIANGLEMESH_H
32#include "foundation/PxIO.h"
33#include "geometry/PxTriangle.h"
34#include "geometry/PxTriangleMeshGeometry.h"
35#include "geometry/PxSimpleTriangleMesh.h"
36#include "geometry/PxTriangleMesh.h"
38#include "GuMeshData.h"
39#include "GuCenterExtents.h"
41#include "CmRefCountable.h"
42#include "common/PxRenderOutput.h"
47struct PxTriangleMeshInternalData;
51 PX_FORCE_INLINE void getVertexRefs(PxU32 triangleIndex, PxU32& vref0, PxU32& vref1, PxU32& vref2,
const void* indices,
bool has16BitIndices)
55 const PxU16* inds =
reinterpret_cast<const PxU16*
>(indices) + triangleIndex*3;
62 const PxU32* inds =
reinterpret_cast<const PxU32*
>(indices) + triangleIndex*3;
72#pragma warning(disable: 4324)
90 void preExportDataReset() { Cm::RefCountable_preExportDataReset(*
this); }
93 PX_PHYSX_COMMON_API
static void getBinaryMetaData(
PxOutputStream& stream);
102 virtual void onRefCountZero();
122 if (preferProjection)
132 return hasPerTriangleMaterials() ? getMaterials()[triangleIndex] : PxMaterialTableIndex(0xffff);
137 PX_ASSERT(mAABB.isValid());
143 return mSdfData.
mSdf;
155 numX = numY = numZ = 0;
160 mass = mMass; localInertia = mInertia; localCenterOfMass = mLocalCenterOfMass;
174 PX_FORCE_INLINE PxU32 getNbVerticesFast()
const {
return mNbVertices; }
175 PX_FORCE_INLINE PxU32 getNbTrianglesFast()
const {
return mNbTriangles; }
177 PX_FORCE_INLINE const PxVec3* getVerticesFast()
const {
return mVertices; }
180 PX_FORCE_INLINE const CenterExtents& getLocalBoundsFast()
const {
return mAABB; }
182 PX_FORCE_INLINE const PxU8* getExtraTrigData()
const {
return mExtraTrigData; }
184 PX_FORCE_INLINE const PxU32* getAccumulatedTriangleRef()
const {
return mAccumulatedTrianglesRef; }
185 PX_FORCE_INLINE const PxU32* getTriangleReferences()
const {
return mTrianglesReferences; }
186 PX_FORCE_INLINE PxU32 getNbTriangleReferences()
const {
return mNbTrianglesReferences; }
191 return static_cast<const CenterExtentsPadded&
>(mAABB);
195 PxTriangle& worldTri, PxTriangleID triangleIndex,
const PxMat34& worldMatrix,
bool flipNormal =
false,
197 PX_FORCE_INLINE void getLocalTriangle(PxTriangle& localTri, PxTriangleID triangleIndex,
bool flipNormal =
false)
const;
199 void setMeshFactory(MeshFactory* factory) { mMeshFactory = factory; }
208 PX_PHYSX_COMMON_API
const Gu::EdgeList* requestEdgeList()
const;
219 PxU8* mExtraTrigData;
241 PxVec3 mLocalCenterOfMass;
251 PxU32* mGRB_faceRemapInverse;
259 void setAllEdgesActive();
261 PxU32* mAccumulatedTrianglesRef;
262 PxU32* mTrianglesReferences;
263 PxU32 mNbTrianglesReferences;
276 PxU32 vref0, vref1, vref2;
277 getVertexRefs(triangleIndex, vref0, vref1, vref2,
mTriangles, has16BitIndices());
280 PxSwap<PxU32>(vref1, vref2);
289 vertexIndices[0] = vref0;
290 vertexIndices[1] = vref1;
291 vertexIndices[2] = vref2;
300 adjacencyIndices[1] =
mAdjacencies[triangleIndex*3 + 1];
305 adjacencyIndices[0] = 0xffffffff;
306 adjacencyIndices[1] = 0xffffffff;
307 adjacencyIndices[2] = 0xffffffff;
312PX_FORCE_INLINE void Gu::TriangleMesh::getLocalTriangle(PxTriangle& localTri, PxTriangleID triangleIndex,
bool flipNormal)
const
314 PxU32 vref0, vref1, vref2;
315 getVertexRefs(triangleIndex, vref0, vref1, vref2, mTriangles, has16BitIndices());
318 PxSwap<PxU32>(vref1, vref2);
320 const PxVec3*
PX_RESTRICT vertices = getVerticesFast();
321 localTri.verts[0] = vertices[vref0];
322 localTri.verts[1] = vertices[vref1];
323 localTri.verts[2] = vertices[vref2];
326PX_INLINE float computeSweepData(
const PxTriangleMeshGeometry& triMeshGeom, PxVec3& sweepOrigin, PxVec3& sweepExtents, PxVec3& sweepDir,
float distance)
328 PX_ASSERT(!Cm::isEmpty(sweepOrigin, sweepExtents));
330 const PxVec3 endPt = sweepOrigin + sweepDir*distance;
331 PX_ASSERT(!Cm::isEmpty(endPt, sweepExtents));
333 const Cm::FastVertex2ShapeScaling meshScaling(triMeshGeom.scale.getInverse());
335 const PxMat33& vertex2ShapeSkew = meshScaling.getVertex2ShapeSkew();
337 const PxVec3 originBoundsCenter = vertex2ShapeSkew * sweepOrigin;
338 const PxVec3 originBoundsExtents = Cm::basisExtent(vertex2ShapeSkew.column0, vertex2ShapeSkew.column1, vertex2ShapeSkew.column2, sweepExtents);
340 sweepOrigin = originBoundsCenter;
341 sweepExtents = originBoundsExtents;
342 sweepDir = (vertex2ShapeSkew * endPt) - originBoundsCenter;
343 return sweepDir.normalizeSafe();
346PX_FORCE_INLINE const Gu::TriangleMesh* _getMeshData(
const PxTriangleMeshGeometry& meshGeom)
348 return static_cast<const Gu::TriangleMesh*
>(meshGeom.triangleMesh);
Definition GuCenterExtents.h:44
PxU32 y
Size of Y dimension.
Definition GuSDF.h:80
PxU32 z
Size of Z dimension.
Definition GuSDF.h:81
PxU32 x
Size of X dimension.
Definition GuSDF.h:79
Definition GuEdgeList.h:135
Definition GuMeshFactory.h:83
Represents a signed distance field.
Definition GuSDF.h:88
PxReal * mSdf
Array of sdf.
Definition GuSDF.h:137
Dim3 mDims
Dimension of the sdf.
Definition GuSDF.h:135
Definition GuMeshData.h:171
Definition GuTriangleMesh.h:78
Gu::BV32Tree * mGRB_BV32Tree
GRB: BV32 tree.
Definition GuTriangleMesh.h:252
virtual void getSDFDimensions(PxU32 &numX, PxU32 &numY, PxU32 &numZ) const
Returns the resolution of the local-space dense SDF.
Definition GuTriangleMesh.h:146
virtual void setPreferSDFProjection(bool preferProjection)
Sets whether this mesh should be preferred for SDF projection.
Definition GuTriangleMesh.h:120
PxU32 * mFaceRemap
new faces to old faces mapping (after cleaning, etc). Usage: old = faceRemap[new]
Definition GuTriangleMesh.h:231
virtual const PxReal * getSDF() const
Returns the local-space Signed Distance Field for this mesh if it has one.
Definition GuTriangleMesh.h:141
virtual PxBounds3 getLocalBounds() const
Returns the local-space (vertex space) AABB from the triangle mesh.
Definition GuTriangleMesh.h:135
void * mTriangles
16 (<= 0xffff #vertices) or 32 bit trig indices (mNbTriangles * 3)
Definition GuTriangleMesh.h:214
virtual bool getPreferSDFProjection() const
Returns whether this mesh prefers SDF projection.
Definition GuTriangleMesh.h:128
virtual const PxU32 * getTrianglesRemap() const
Returns the triangle remapping table.
Definition GuTriangleMesh.h:119
virtual PxVec3 * getVerticesForModification()
Returns all mesh vertices for modification.
Definition GuTriangleMesh.cpp:271
void * mGRB_triAdjacencies
GRB: adjacency data, with BOUNDARY and NONCONVEX flags (flags replace adj indices where applicable)
Definition GuTriangleMesh.h:248
PxReal mGeomEpsilon
see comments in cooking code referencing this variable
Definition GuTriangleMesh.h:220
virtual void acquireReference()
Acquires a counted reference to this object.
Definition GuTriangleMesh.h:106
PxU32 * mAdjacencies
Definition GuTriangleMesh.h:232
PxU8 mFlags
Definition GuTriangleMesh.h:228
virtual const PxVec3 * getVertices() const
Returns the vertices.
Definition GuTriangleMesh.h:112
PxU16 * mMaterialIndices
the size of the array is numTriangles.
Definition GuTriangleMesh.h:230
virtual PxU32 getNbTriangles() const
Returns the number of triangles.
Definition GuTriangleMesh.h:116
virtual const void * getTriangles() const
Returns the triangle indices.
Definition GuTriangleMesh.h:117
void * mGRB_triIndices
GRB: GPU-friendly tri indices.
Definition GuTriangleMesh.h:245
virtual void release()
Decrements the reference count of a triangle mesh and releases it if the new reference count is zero.
Definition GuTriangleMesh.cpp:266
virtual PxBounds3 refitBVH()
Refits BVH for mesh vertices.
Definition GuTriangleMesh.cpp:278
virtual PxU32 getNbVertices() const
Returns the number of vertices.
Definition GuTriangleMesh.h:111
virtual PxMaterialTableIndex getTriangleMaterialIndex(PxTriangleID triangleIndex) const
Returns material table index of given triangle.
Definition GuTriangleMesh.h:130
PxU32 * mGRB_faceRemap
GRB : gpu to cpu triangle indice remap.
Definition GuTriangleMesh.h:250
virtual PxU32 getReferenceCount() const
Returns the reference count of the object.
Definition GuTriangleMesh.h:107
virtual PxTriangleMeshFlags getTriangleMeshFlags() const
Reads the PxTriangleMesh flags.
Definition GuTriangleMesh.h:118
virtual void getMassInformation(PxReal &mass, PxMat33 &localInertia, PxVec3 &localCenterOfMass) const
Returns the mass properties of the mesh assuming unit density.
Definition GuTriangleMesh.h:158
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 centerExtents(const PxVec3 ¢er, const PxVec3 &extent)
returns the AABB from center and extents vectors.
Definition PxBounds3.h:299
Binary deserialization context class.
Definition PxSerialFramework.h:174
3x3 matrix class
Definition PxMat33.h:91
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T< Type > transform(const PxVec3T< Type > &other) const
Transform point by matrix.
Definition PxMat34.h:216
Output stream class for I/O.
Definition PxIO.h:114
Callback class used to process PxBase objects.
Definition PxSerialFramework.h:81
Binary serialization context class.
Definition PxSerialFramework.h:99
A triangle mesh, also called a 'polygon soup'.
Definition PxTriangleMesh.h:118
Triangle class.
Definition PxTriangle.h:47
PxVec3 verts[3]
Array of Vertices.
Definition PxTriangle.h:140
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxFlags< PxTriangleMeshFlag::Enum, PxU8 > PxTriangleMeshFlags
collection of set bits defined in PxTriangleMeshFlag.
Definition PxTriangleMesh.h:86
@ e16_BIT_INDICES
Denotes the use of 16-bit vertex indices.
Definition PxSimpleTriangleMesh.h:66
Enum
Definition PxTriangleMesh.h:58
@ ePREFER_NO_SDF_PROJ
Indicates that this mesh would preferably not be the mesh projected for mesh-mesh collision....
Definition PxTriangleMesh.h:77
Definition PxGeometryInternal.h:46