RavEngine
Loading...
Searching...
No Matches
GuMeshFactory.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_MESH_FACTORY_H
30#define GU_MESH_FACTORY_H
31
32#include "foundation/PxIO.h"
33#include "foundation/PxHashSet.h"
34#include "foundation/PxUserAllocated.h"
35#include "geometry/PxTriangleMesh.h"
36#include "geometry/PxTetrahedronMesh.h"
37#include "geometry/PxConvexMesh.h"
38#include "geometry/PxHeightField.h"
39#include "geometry/PxBVH.h"
40#include "PxPhysXConfig.h"
41
42#include "foundation/PxMutex.h"
43#include "foundation/PxArray.h"
44
45// PT: added for platforms that compile the onRefCountZero template immediately
46#include "CmUtils.h"
47#include "foundation/PxFoundation.h"
48
49namespace physx
50{
51namespace Gu
52{
53 class ConvexMesh;
54 class HeightField;
55 class TriangleMesh;
56 class TriangleMeshData;
57 class SoftBodyMesh;
58 class SoftBodyMeshData;
59 class TetrahedronMesh;
60 class TetrahedronMeshData;
61 class BVH;
62 struct ConvexHullInitData;
63 class BVHData;
64
66 {
67 protected:
68 virtual ~MeshFactoryListener(){}
69 public:
70 virtual void onMeshFactoryBufferRelease(const PxBase* object, PxType type) = 0;
71#if PX_SUPPORT_OMNI_PVD
72 virtual void onObjectAdd(const PxBase*) {}
73 virtual void onObjectRemove(const PxBase*) {}
74#endif
75 };
76
77 #if PX_VC
78 #pragma warning(push)
79 #pragma warning( disable : 4251 ) // class needs to have dll-interface to be used by clients of class
80 #endif
81
82 class PX_PHYSX_COMMON_API MeshFactory : public PxUserAllocated
83 {
84 PX_NOCOPY(MeshFactory)
85 public:
87 protected:
88 virtual ~MeshFactory();
89
90 public:
91 void release();
92
93 // Triangle meshes
94 void addTriangleMesh(Gu::TriangleMesh* np, bool lock=true);
95 PxTriangleMesh* createTriangleMesh(PxInputStream& stream);
96 PxTriangleMesh* createTriangleMesh(void* triangleMeshData);
97 bool removeTriangleMesh(PxTriangleMesh&);
98 PxU32 getNbTriangleMeshes() const;
99 PxU32 getTriangleMeshes(PxTriangleMesh** userBuffer, PxU32 bufferSize, PxU32 startIndex) const;
100
101 // Tetrahedron meshes
102 void addTetrahedronMesh(Gu::TetrahedronMesh* np, bool lock = true);
103 PxTetrahedronMesh* createTetrahedronMesh(PxInputStream& stream);
104 PxTetrahedronMesh* createTetrahedronMesh(void* tetrahedronMeshData);
105 bool removeTetrahedronMesh(PxTetrahedronMesh&);
106 PxU32 getNbTetrahedronMeshes() const;
107 PxU32 getTetrahedronMeshes(PxTetrahedronMesh** userBuffer, PxU32 bufferSize, PxU32 startIndex) const;
108
109 // SoftBody meshes
110 void addSoftBodyMesh(Gu::SoftBodyMesh* np, bool lock = true);
111 PxSoftBodyMesh* createSoftBodyMesh(PxInputStream& stream);
112 PxSoftBodyMesh* createSoftBodyMesh(void* tetrahedronMeshData);
113 bool removeSoftBodyMesh(PxSoftBodyMesh&);
114 PxU32 getNbSoftBodyMeshes() const;
115 PxU32 getSoftBodyMeshes(PxSoftBodyMesh** userBuffer, PxU32 bufferSize, PxU32 startIndex) const;
116
117 // Convexes
118 void addConvexMesh(Gu::ConvexMesh* np, bool lock=true);
119 PxConvexMesh* createConvexMesh(PxInputStream&);
120 PxConvexMesh* createConvexMesh(void* convexMeshData);
121 bool removeConvexMesh(PxConvexMesh&);
122 PxU32 getNbConvexMeshes() const;
123 PxU32 getConvexMeshes(PxConvexMesh** userBuffer, PxU32 bufferSize, PxU32 startIndex) const;
124
125 // Heightfields
126 void addHeightField(Gu::HeightField* np, bool lock=true);
127 PxHeightField* createHeightField(void* heightFieldMeshData);
128 PxHeightField* createHeightField(PxInputStream&);
129 bool removeHeightField(PxHeightField&);
130 PxU32 getNbHeightFields() const;
131 PxU32 getHeightFields(PxHeightField** userBuffer, PxU32 bufferSize, PxU32 startIndex) const;
132
133 // BVH
134 void addBVH(Gu::BVH* np, bool lock=true);
135 PxBVH* createBVH(PxInputStream&);
136 PxBVH* createBVH(void* bvhData);
137 bool removeBVH(PxBVH&);
138 PxU32 getNbBVHs() const;
139 PxU32 getBVHs(PxBVH** userBuffer, PxU32 bufferSize, PxU32 startIndex) const;
140
141 void addFactoryListener(MeshFactoryListener& listener);
142 void removeFactoryListener(MeshFactoryListener& listener);
143 void notifyFactoryListener(const PxBase*, PxType typeID);
144
145 bool remove(PxBase&);
146
147 protected:
148
149 PxTriangleMesh* createTriangleMesh(Gu::TriangleMeshData& data);
150 PxTetrahedronMesh* createTetrahedronMesh(Gu::TetrahedronMeshData& data);
151 PxSoftBodyMesh* createSoftBodyMesh(Gu::SoftBodyMeshData& data);
152 PxConvexMesh* createConvexMesh(Gu::ConvexHullInitData& data);
153 PxBVH* createBVH(Gu::BVHData& data);
154
155 mutable PxMutex mTrackingMutex;
156 private:
163
164 PxArray<MeshFactoryListener*> mFactoryListeners;
165
166#if PX_SUPPORT_OMNI_PVD
167 protected:
168 void notifyListenersAdd(const PxBase*);
169 void notifyListenersRemove(const PxBase*);
170#endif
171 };
172 #if PX_VC
173 #pragma warning(pop)
174 #endif
175
176 template<typename T>
177 PX_INLINE void onRefCountZero(T* object, Gu::MeshFactory* mf, bool cndt, const char* errorMsg)
178 {
179 if(mf)
180 {
181 if(cndt || mf->remove(*object))
182 {
183 const PxType type = object->getConcreteType();
184 Cm::deletePxBase(object);
185 mf->notifyFactoryListener(object, type);
186 return;
187 }
188
189 // PT: if we reach this point, we didn't find the mesh in the Physics object => don't delete!
190 // This prevents deleting the object twice.
191 PxGetFoundation().error(PxErrorCode::eINVALID_OPERATION, PX_FL, errorMsg);
192 }
193 else
194 Cm::deletePxBase(object);
195 }
196 }
197
198}
199#endif
Definition GuBVH.h:55
Represents a BVH.
Definition GuBVH.h:93
Definition GuConvexMesh.h:94
Definition GuHeightField.h:54
Definition GuMeshFactory.h:66
Definition GuMeshFactory.h:83
Definition GuMeshData.h:616
Definition GuTetrahedronMesh.h:233
Definition GuMeshData.h:285
Definition GuTetrahedronMesh.h:120
Definition GuMeshData.h:171
Definition GuTriangleMesh.h:78
Definition PxArray.h:53
Class representing a bounding volume hierarchy.
Definition PxBVH.h:63
Base class for objects that can be members of a PxCollection.
Definition PxBase.h:73
Definition PxHashSet.h:100
A convex mesh.
Definition PxConvexMesh.h:83
A height field class.
Definition PxHeightField.h:84
Input stream class for I/O.
Definition PxIO.h:50
Definition PxMutex.h:89
A softbody mesh, containing structures to store collision shape, simulation shape and deformation sta...
Definition PxTetrahedronMesh.h:214
A tetramedron mesh, also called a 'tetrahedron soup'.
Definition PxTetrahedronMesh.h:115
A triangle mesh, also called a 'polygon soup'.
Definition PxTriangleMesh.h:118
Definition PxUserAllocated.h:43
PX_C_EXPORT PX_FOUNDATION_API physx::PxFoundation &PX_CALL_CONV PxGetFoundation()
Retrieves the Foundation SDK after it has been created.
Definition FdFoundation.cpp:279
#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 GuConvexMesh.h:67
@ eINVALID_OPERATION
method was called at a time when an operation is not possible
Definition PxErrors.h:65