RavEngine
Loading...
Searching...
No Matches
GuConvexMesh.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_H
30#define GU_CONVEX_MESH_H
31
32#include "foundation/PxBitAndData.h"
33#include "common/PxMetaData.h"
34#include "geometry/PxConvexMesh.h"
35#include "geometry/PxConvexMeshGeometry.h"
36#include "foundation/PxUserAllocated.h"
37#include "CmRefCountable.h"
38#include "common/PxRenderOutput.h"
39#include "GuConvexMeshData.h"
40
41namespace physx
42{
43class BigConvexData;
44
45namespace Gu
46{
47 class MeshFactory;
48 struct HullPolygonData;
49
50 PX_INLINE PxU32 computeBufferSize(const Gu::ConvexHullData& data, PxU32 nb)
51 {
52 PxU32 bytesNeeded = sizeof(Gu::HullPolygonData) * data.mNbPolygons;
53 bytesNeeded += sizeof(PxVec3) * data.mNbHullVertices;
54 bytesNeeded += sizeof(PxU8) * data.mNbEdges * 2; // mFacesByEdges8
55 bytesNeeded += sizeof(PxU8) * data.mNbHullVertices * 3; // mFacesByVertices8;
56 bytesNeeded += data.mNbEdges.isBitSet() ? (sizeof(PxU16) * data.mNbEdges * 2) : 0; // mEdges;
57 bytesNeeded += sizeof(PxU8) * nb; // mVertexData8
58
59 //4 align the whole thing!
60 const PxU32 mod = bytesNeeded % sizeof(PxReal);
61 if (mod)
62 bytesNeeded += sizeof(PxReal) - mod;
63 return bytesNeeded;
64 }
65
67 {
68 ConvexHullData mHullData;
69 PxU32 mNb;
70 PxReal mMass;
71 PxMat33 mInertia;
72 BigConvexData* mBigConvexData;
73 SDF* mSdfData;
74 };
75
76 // 0: includes raycast map
77 // 1: discarded raycast map
78 // 2: support map not always there
79 // 3: support stackless trees for non-recursive collision queries
80 // 4: no more opcode model
81 // 5: valencies table and gauss map combined, only exported over a vertex count treshold that depends on the platform cooked for.
82 // 6: removed support for edgeData16.
83 // 7: removed support for edge8Data.
84 // 8: removed support for triangles.
85 // 9: removed local sphere.
86 //10: removed geometric center.
87 //11: removed mFlags, and mERef16 from Poly; nbVerts is just a byte.
88 //12: removed explicit minimum, maximum from Poly
89 //13: internal objects
90 //14: SDF
91 #define PX_CONVEX_VERSION 14
92
94 {
95 //= ATTENTION! =====================================================================================
96 // Changing the data layout of this class breaks the binary serialization format. See comments for
97 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
98 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
99 // accordingly.
100 //==================================================================================================
101 public:
102 // PX_SERIALIZATION
103 ConvexMesh(PxBaseFlags baseFlags) : PxConvexMesh(baseFlags), mHullData(PxEmpty), mNb(PxEmpty)
104 {
105 mNb.setBit();
106 }
107
108 void preExportDataReset() { Cm::RefCountable_preExportDataReset(*this); }
109 virtual void exportExtraData(PxSerializationContext& stream);
110 void importExtraData(PxDeserializationContext& context);
111 PX_PHYSX_COMMON_API static ConvexMesh* createObject(PxU8*& address, PxDeserializationContext& context);
112 PX_PHYSX_COMMON_API static void getBinaryMetaData(PxOutputStream& stream);
113 void resolveReferences(PxDeserializationContext&) {}
114 virtual void requiresObjects(PxProcessPxBaseCallback&){}
115 //~PX_SERIALIZATION
116 ConvexMesh(MeshFactory* factory);
117
119
120 bool load(PxInputStream& stream);
121
122 // PxBase
123 virtual void onRefCountZero();
124 //~PxBase
125
126 // PxRefCounted
127 virtual PxU32 getReferenceCount() const;
128 virtual void acquireReference();
129 //~PxRefCounted
130
131 // PxConvexMesh
132 virtual void release();
133 virtual PxU32 getNbVertices() const { return mHullData.mNbHullVertices; }
134 virtual const PxVec3* getVertices() const { return mHullData.getHullVertices(); }
135 virtual const PxU8* getIndexBuffer() const { return mHullData.getVertexData8(); }
136 virtual PxU32 getNbPolygons() const { return mHullData.mNbPolygons; }
137 virtual bool getPolygonData(PxU32 i, PxHullPolygon& data) const;
138 virtual bool isGpuCompatible() const;
139
140 virtual void getMassInformation(PxReal& mass, PxMat33& localInertia, PxVec3& localCenterOfMass) const;
141 virtual PxBounds3 getLocalBounds() const;
142 virtual const PxReal* getSDF() const;
143
144 //~PxConvexMesh
145
146 PX_FORCE_INLINE PxU32 getNbVerts() const { return mHullData.mNbHullVertices; }
147 PX_FORCE_INLINE const PxVec3* getVerts() const { return mHullData.getHullVertices(); }
148 PX_FORCE_INLINE PxU32 getNbPolygonsFast() const { return mHullData.mNbPolygons; }
149 PX_FORCE_INLINE const HullPolygonData& getPolygon(PxU32 i) const { return mHullData.mPolygons[i]; }
150 PX_FORCE_INLINE const HullPolygonData* getPolygons() const { return mHullData.mPolygons; }
151 PX_FORCE_INLINE PxU32 getNbEdges() const { return mHullData.mNbEdges; }
152
153 PX_FORCE_INLINE const ConvexHullData& getHull() const { return mHullData; }
154 PX_FORCE_INLINE ConvexHullData& getHull() { return mHullData; }
155 PX_FORCE_INLINE const CenterExtents& getLocalBoundsFast() const { return mHullData.mAABB; }
156 PX_FORCE_INLINE PxReal getMass() const { return mMass; }
157 PX_FORCE_INLINE void setMass(PxReal mass) { mMass = mass; }
158 PX_FORCE_INLINE const PxMat33& getInertia() const { return mInertia; }
159 PX_FORCE_INLINE void setInertia(const PxMat33& inertia) { mInertia = inertia; }
160
161 PX_FORCE_INLINE BigConvexData* getBigConvexData() const { return mBigConvexData; }
162 PX_FORCE_INLINE void setBigConvexData(BigConvexData* bcd) { mBigConvexData = bcd; }
163
164 PX_FORCE_INLINE PxU32 getBufferSize() const { return computeBufferSize(mHullData, getNb()); }
165
166 virtual ~ConvexMesh();
167
168 PX_FORCE_INLINE void setMeshFactory(MeshFactory* f) { mMeshFactory = f; }
169 PX_FORCE_INLINE void setNb(PxU32 nb) { mNb = nb; }
170
171 protected:
172 ConvexHullData mHullData;
173 PxBitAndDword mNb; // ### PT: added for serialization. Try to remove later?
174
175 SDF* mSdfData;
177 PxReal mMass; //this is mass assuming a unit density that can be scaled by instances!
178 PxMat33 mInertia; //in local space of mesh!
179 private:
180 MeshFactory* mMeshFactory; // PT: changed to pointer for serialization
181
182 PX_FORCE_INLINE PxU32 getNb() const { return mNb; }
183 PX_FORCE_INLINE PxU32 ownsMemory() const { return PxU32(!mNb.isBitSet()); }
184 };
185
186 PX_FORCE_INLINE const Gu::ConvexHullData* _getHullData(const PxConvexMeshGeometry& convexGeom)
187 {
188 return &static_cast<const Gu::ConvexMesh*>(convexGeom.convexMesh)->getHull();
189 }
190
191} // namespace Gu
192
193}
194
195#endif
Definition base.h:1940
Definition GuBigConvexData2.h:42
Definition GuConvexMesh.h:94
virtual PxBounds3 getLocalBounds() const
Returns the local-space (vertex space) AABB from the convex mesh.
Definition GuConvexMesh.cpp:438
virtual PxU32 getNbVertices() const
Returns the number of vertices.
Definition GuConvexMesh.h:133
virtual void acquireReference()
Acquires a counted reference to this object.
Definition GuConvexMesh.cpp:421
virtual const PxU8 * getIndexBuffer() const
Returns the index buffer.
Definition GuConvexMesh.h:135
BigConvexData * mBigConvexData
optional, only for large meshes! PT: redundant with ptr in chull data? Could also be end of other buf...
Definition GuConvexMesh.h:176
virtual const PxReal * getSDF() const
Returns the local-space Signed Distance Field for this mesh if it has one.
Definition GuConvexMesh.cpp:444
virtual const PxVec3 * getVertices() const
Returns the vertices.
Definition GuConvexMesh.h:134
virtual bool isGpuCompatible() const
This method decides whether a convex mesh is gpu compatible. If the total number of vertices are more...
Definition GuConvexMesh.cpp:100
virtual void getMassInformation(PxReal &mass, PxMat33 &localInertia, PxVec3 &localCenterOfMass) const
Returns the mass properties of the mesh assuming unit density.
Definition GuConvexMesh.cpp:431
virtual PxU32 getNbPolygons() const
Returns the number of polygons.
Definition GuConvexMesh.h:136
virtual PxU32 getReferenceCount() const
Returns the reference count of the object.
Definition GuConvexMesh.cpp:426
virtual bool getPolygonData(PxU32 i, PxHullPolygon &data) const
Returns the polygon data.
Definition GuConvexMesh.cpp:38
virtual void release()
Decrements the reference count of a convex mesh and releases it if the new reference count is zero.
Definition GuConvexMesh.cpp:410
Definition GuMeshFactory.h:83
Represents a signed distance field.
Definition GuSDF.h:88
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
A convex mesh.
Definition PxConvexMesh.h:83
Binary deserialization context class.
Definition PxSerialFramework.h:174
Input stream class for I/O.
Definition PxIO.h:50
3x3 matrix class
Definition PxMat33.h:91
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
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
#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
Definition GuConvexMeshData.h:109
HullPolygonData * mPolygons
Array of mNbPolygons structures.
Definition GuConvexMeshData.h:128
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
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
PxU8 mNbHullVertices
Number of vertices in the convex hull.
Definition GuConvexMeshData.h:125
Definition GuConvexMesh.h:67
Polygon data.
Definition PxConvexMesh.h:50