RavEngine
Loading...
Searching...
No Matches
OmniPvdPxSampler.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 OMNI_PVD_PX_SAMPLER_H
30#define OMNI_PVD_PX_SAMPLER_H
31
32/*
33The below helper macros are to be used in SDK code to send information to PVD as unintrusively as possible.
34
35Principles:
36* Data created or changed by the user should be sent as soon as it has been written to an SDK class, ideally right at the end of the API create() or set() call.
37* Objects should ideally be destroyed from their destructors (since release() calls might just decrement).
38* Data written by the SDK should be sent at the end of the simulate frame.
39* Ideally use Px-pointers as object handles. Beware that multiple inheritance can result in different pointer values so its best to cast to the Px-type pointer / reference explicitly.
40 Even if the code works by passing in different equivalent pointer types, this will generate unnecessary duplicate template code.
41*/
42#if PX_SUPPORT_OMNI_PVD
43// You can use this in conditional statements to check for a connection
44 #define OMNI_PVD_ACTIVE (::OmniPvdPxSampler::getInstance() != NULL)
45// Create object reference o of PVD type c. Example: OMNI_PVD_CREATE(scene, static_cast<PxScene &>(*npScene));
46 #define OMNI_PVD_CREATE(c, o) if (::OmniPvdPxSampler::getInstance() != NULL) {::OmniPvdPxSampler::getInstance()->createObject(OmniPvdPxSampler::classHandle_##c, o); }
47// Destroy object reference o of PVD type c. Example: OMNI_PVD_DESTROY(scene, static_cast<PxScene &>(*npScene));
48 #define OMNI_PVD_DESTROY(c, o) if (::OmniPvdPxSampler::getInstance() != NULL) {::OmniPvdPxSampler::getInstance()->destroyObject(o); }
49// Set PVD attribute a of object reference o of PVD type c to value v. v is passed as reference to value; PVD object handles are passed as reference to POINTER here!
50// Example: OMNI_PVD_SET(actor, isdynamic, a, false)
51 #define OMNI_PVD_SET(c, a, o, v) if (::OmniPvdPxSampler::getInstance() != NULL) {::OmniPvdPxSampler::getInstance()->setAttribute(OmniPvdPxSampler::attributeHandle_##c##_##a, o, v); }
52// Same as set, but for variable length attributes like vertex buffers. pv is the address of the data, and n is the size in bytes.
53 #define OMNI_PVD_SETB(c, a, o, pv, n)if (::OmniPvdPxSampler::getInstance() != NULL) {::OmniPvdPxSampler::getInstance()->setAttributeBytes(OmniPvdPxSampler::attributeHandle_##c##_##a, o, pv, n); }
54// Same as set, but for attribute sets of unique things like an array of references. v is passed as a REFERENCE.
55 #define OMNI_PVD_ADD(c, a, o, v) if (::OmniPvdPxSampler::getInstance() != NULL) {::OmniPvdPxSampler::getInstance()->addToSet(OmniPvdPxSampler::attributeHandle_##c##_##a, o, v); }
56// TO remove a member handle from the set.
57 #define OMNI_PVD_REMOVE(c, a, o, v) if (::OmniPvdPxSampler::getInstance() != NULL) {::OmniPvdPxSampler::getInstance()->removeFromSet(OmniPvdPxSampler::attributeHandle_##c##_##a, o, v); }
58
59#else
60 #define OMNI_PVD_ACTIVE (false)
61 #define OMNI_PVD_CREATE(c, p)
62 #define OMNI_PVD_DESTROY(c, p)
63 #define OMNI_PVD_SET(c, a, p, v)
64 #define OMNI_PVD_SETB(c, a, p, v, n)
65 #define OMNI_PVD_ADD(c, a, p, v)
66 #define OMNI_PVD_REMOVE(c, a, p, v)
67#endif
68
69
70#if PX_SUPPORT_OMNI_PVD
71#include "omnipvd/PxOmniPvd.h"
72
73#include "foundation/PxSimpleTypes.h"
74#include "foundation/PxHashMap.h"
75#include "foundation/PxMutex.h"
76#include "OmniPvdChunkAlloc.h"
77#include "foundation/PxUserAllocated.h"
78
79#include "../../../pvdruntime/include/OmniPvdDefines.h"
80
81namespace physx
82{
83 class PxScene;
84 class PxBase;
85 class NpActor;
86 class NpScene;
87 class NpShape;
88 class NpShapeManager;
89 class PxActor;
90 class PxGeometryHolder;
91 class NpOmniPvd;
92 class PxGeometry;
93 class PxJoint;
94 class PxShape;
95 class PxMaterial;
96}
97
98extern void streamActorName(physx::PxActor & a, const char* name);
99extern void streamShapeMaterials(physx::PxShape* shapePtr, physx::PxMaterial** mats, physx::PxU32 nbrMaterials);
100
101enum OmniPvdSharedMeshEnum {
102 eOmniPvdTriMesh = 0,
103 eOmniPvdConvexMesh = 1,
104 eOmniPvdHeightField = 2,
105};
106
107class OmniPvdLoader;
108class OmniPvdWriter;
109class OmniPvdPxSampler;
111class OmniPvdActorMod;
112class OmniPvdShapeMod;
113class OmniPvdPxScene;
114
115class OmniPvdPxSampler : public physx::PxUserAllocated
116{
117public:
118 OmniPvdPxSampler();
119 ~OmniPvdPxSampler();
120 //enables sampling:
121 void startSampling();
122 bool isSampling();
123 //sets destination:
124 void setOmniPvdWriter(OmniPvdWriter* omniPvdWriter);
125
126 // writes all contacts to the stream
127 void streamSceneContacts(physx::NpScene* scene);
128
129 // call at the end of a simulation step:
130 void sampleScene(physx::NpScene* scene);
132 //void createGeometry(const physx::PxGeometry & g);
133 //void destroyGeometry(const physx::PxGeometry & g);
134
135 //simplified generic API to be used via simple macros above:
136 template <typename ClassType> void createObject(OmniPvdClassHandle, ClassType const & objectId);
137 template <typename ClassType> void destroyObject(ClassType const & objectId);
138 template <typename ClassType, typename AttributeType> void setAttribute(OmniPvdAttributeHandle, ClassType const & objectId, AttributeType const & value);
139 template <typename ClassType, typename AttributeType> void setAttributeBytes(OmniPvdAttributeHandle, ClassType const & objectId, AttributeType const * value, unsigned nBytes);
140 template <typename ClassType, typename AttributeType> void addToSet(OmniPvdAttributeHandle, ClassType const & objectId, AttributeType const & value);
141 template <typename ClassType, typename AttributeType> void removeFromSet(OmniPvdAttributeHandle, ClassType const & objectId, AttributeType const & value);
142
143 //handles for all SDK classes and attributes
144
145#define OMNI_PVD_FAKE_CLASS(c, classT, classStr) static OmniPvdClassHandle classHandle_##c;
146#define OMNI_PVD_CLASS(c, classT) static OmniPvdClassHandle classHandle_##c;
147#define OMNI_PVD_CLASS_DERIVED(c, classT, baseClass) OMNI_PVD_CLASS(c, classT)
148#define OMNI_PVD_ENUM(c, classT) OMNI_PVD_CLASS(c, classT)
149#define OMNI_PVD_ENUM_VALUE(c, a, v)
150#define OMNI_PVD_ATTRIBUTE(c, a, classT, attrT, t, n) static OmniPvdAttributeHandle attributeHandle_##c##_##a;
151#define OMNI_PVD_ATTRIBUTE_SET(c, a, classT, attrT) static OmniPvdAttributeHandle attributeHandle_##c##_##a;
152#define OMNI_PVD_ATTRIBUTE_FLAG(c, a, classT, attrT, enumClass) static OmniPvdAttributeHandle attributeHandle_##c##_##a;
153
154
155#include "OmniPvdTypes.h" //SDK classes and attributes declared here
156#undef OMNI_PVD_ENUM
157#undef OMNI_PVD_ENUM_VALUE
158#undef OMNI_PVD_FAKE_CLASS
159#undef OMNI_PVD_CLASS
160#undef OMNI_PVD_CLASS_DERIVED
161#undef OMNI_PVD_ATTRIBUTE
162#undef OMNI_PVD_ATTRIBUTE_SET
163#undef OMNI_PVD_ATTRIBUTE_FLAG
164
165 static OmniPvdPxSampler* getInstance();
166
167 void onObjectAdd(const physx::PxBase* object);
168 void onObjectRemove(const physx::PxBase* object);
169
170
171private:
172 OmniPvdPxScene* getSampledScene(physx::NpScene* scene);
173};
174
175#endif
176
177#endif
Definition OmniPvdLoader.h:43
Used to abstract a memory write stream.
Definition OmniPvdWriteStream.h:40
Used to write debug information to an OmniPvdWriteStream.
Definition OmniPvdWriter.h:47
Definition NpScene.h:130
PxActor is the base class for the main simulation objects in the physics SDK.
Definition PxActor.h:201
Base class for objects that can be members of a PxCollection.
Definition PxBase.h:73
Material class to represent a set of surface properties.
Definition PxMaterial.h:149
Abstract class for collision shapes.
Definition PxShape.h:146
Definition PxUserAllocated.h:43
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39