RavEngine
Loading...
Searching...
No Matches
PvdMetaDataDefineProperties.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 PVD_META_DATA_DEFINE_PROPERTIES_H
30#define PVD_META_DATA_DEFINE_PROPERTIES_H
31
32#if PX_SUPPORT_PVD
33
34#include "common/PxCoreUtilityTypes.h"
35
36#include "PvdMetaDataPropertyVisitor.h"
37#include "PxPvdDataStreamHelpers.h"
38#include "PxPvdDataStream.h"
39
40namespace physx
41{
42namespace Vd
43{
44 using namespace physx::pvdsdk;
45
46 template<typename TPropType>
47 struct PropertyDefinitionOp
48 {
49 void defineProperty( PvdPropertyDefinitionHelper& mHelper, NamespacedName mClassKey )
50 {
51 mHelper.createProperty( mClassKey, "", getPvdNamespacedNameForType<TPropType>(), PropertyType::Scalar );
52 }
53 };
54 template<>
55 struct PropertyDefinitionOp<const char*>
56 {
57 void defineProperty( PvdPropertyDefinitionHelper& mHelper, NamespacedName mClassKey )
58 {
59 mHelper.createProperty( mClassKey, "", getPvdNamespacedNameForType<StringHandle>(), PropertyType::Scalar );
60 }
61 };
62#define DEFINE_PROPERTY_DEFINITION_OP_NOP( type ) \
63 template<> struct PropertyDefinitionOp<type> { void defineProperty( PvdPropertyDefinitionHelper&, NamespacedName ){} };
64
65 //NOP out these two types.
66 DEFINE_PROPERTY_DEFINITION_OP_NOP( PxStridedData )
67 DEFINE_PROPERTY_DEFINITION_OP_NOP( PxBoundedData )
68
69#define DEFINE_PROPERTY_DEFINITION_OBJECT_REF( type ) \
70 template<> struct PropertyDefinitionOp<type> { \
71 void defineProperty( PvdPropertyDefinitionHelper& mHelper, NamespacedName mClassKey) \
72 { \
73 mHelper.createProperty( mClassKey, "", getPvdNamespacedNameForType<ObjectRef>(), PropertyType::Scalar ); \
74 } \
75 };
76
77 DEFINE_PROPERTY_DEFINITION_OBJECT_REF( PxTetrahedronMesh* )
78 DEFINE_PROPERTY_DEFINITION_OBJECT_REF( PxTriangleMesh* )
79 DEFINE_PROPERTY_DEFINITION_OBJECT_REF( PxBVH33TriangleMesh* )
80 DEFINE_PROPERTY_DEFINITION_OBJECT_REF( PxBVH34TriangleMesh* )
81 DEFINE_PROPERTY_DEFINITION_OBJECT_REF( PxConvexMesh* )
82 DEFINE_PROPERTY_DEFINITION_OBJECT_REF( PxHeightField* )
83
84
85struct PvdClassInfoDefine
86{
88 NamespacedName mClassKey;
89
90 PvdClassInfoDefine( PvdPropertyDefinitionHelper& info, NamespacedName inClassName )
91 : mHelper( info )
92 , mClassKey( inClassName ) { }
93
94 PvdClassInfoDefine( const PvdClassInfoDefine& other )
95 : mHelper( other.mHelper )
96 , mClassKey( other.mClassKey )
97 {
98 }
99
100 void defineProperty( NamespacedName inDtype, const char* semantic = "", PropertyType::Enum inPType = PropertyType::Scalar )
101 {
102 mHelper.createProperty( mClassKey, semantic, inDtype, inPType );
103 }
104
105 void pushName( const char* inName )
106 {
107 mHelper.pushName( inName );
108 }
109
110 void pushBracketedName( const char* inName)
111 {
112 mHelper.pushBracketedName( inName );
113 }
114
115 void popName()
116 {
117 mHelper.popName();
118 }
119
120 inline void defineNameValueDefs( const PxU32ToName* theConversions )
121 {
122 while( theConversions->mName != NULL )
123 {
124 mHelper.addNamedValue( theConversions->mName, theConversions->mValue );
125 ++theConversions;
126 }
127 }
128
129 template<typename TAccessorType>
130 void simpleProperty( PxU32, TAccessorType& /*inProp */)
131 {
132 typedef typename TAccessorType::prop_type TPropertyType;
133 PropertyDefinitionOp<TPropertyType>().defineProperty( mHelper, mClassKey );
134 }
135
136 template<typename TAccessorType, typename TInfoType>
137 void extendedIndexedProperty( PxU32* key, const TAccessorType& inProp, TInfoType& )
138 {
139 simpleProperty(*key, inProp);
140 }
141
142 template<typename TDataType>
143 static NamespacedName getNameForEnumType()
144 {
145 size_t s = sizeof( TDataType );
146 switch(s)
147 {
148 case 1: return getPvdNamespacedNameForType<PxU8>();
149 case 2: return getPvdNamespacedNameForType<PxU16>();
150 case 4: return getPvdNamespacedNameForType<PxU32>();
151 default: return getPvdNamespacedNameForType<PxU64>();
152 }
153 }
154
155 template<typename TAccessorType>
156 void enumProperty( PxU32 /*key*/, TAccessorType& /*inProp*/, const PxU32ToName* inConversions )
157 {
158 typedef typename TAccessorType::prop_type TPropType;
159 defineNameValueDefs( inConversions );
160 defineProperty( getNameForEnumType<TPropType>(), "Enumeration Value" );
161 }
162
163 template<typename TAccessorType>
164 void flagsProperty( PxU32 /*key*/, const TAccessorType& /*inAccessor*/, const PxU32ToName* inConversions )
165 {
166 typedef typename TAccessorType::prop_type TPropType;
167 defineNameValueDefs( inConversions );
168 defineProperty( getNameForEnumType<TPropType>(), "Bitflag" );
169 }
170
171 template<typename TAccessorType, typename TInfoType>
172 void complexProperty( PxU32* key, const TAccessorType& inAccessor, TInfoType& inInfo )
173 {
174 PxU32 theOffset = inAccessor.mOffset;
175 inInfo.visitBaseProperties( makePvdPropertyFilter( *this, key, &theOffset ) );
176 inInfo.visitInstanceProperties( makePvdPropertyFilter( *this, key, &theOffset ) );
177 }
178
179 template<typename TAccessorType, typename TInfoType>
180 void bufferCollectionProperty( PxU32* key, const TAccessorType& inAccessor, TInfoType& inInfo )
181 {
182 complexProperty(key, inAccessor, inInfo);
183 }
184
185 template<PxU32 TKey, typename TObjectType, typename TPropertyType, PxU32 TEnableFlag>
186 void handleBuffer( const PxBufferPropertyInfo<TKey, TObjectType, const PxArray< TPropertyType >&, TEnableFlag>& inProp )
187 {
188 mHelper.pushName( inProp.mName );
189 defineProperty( getPvdNamespacedNameForType<TPropertyType>(), "", PropertyType::Array );
190 mHelper.popName();
191 }
192
193 template<PxU32 TKey, typename TObjectType, typename TCollectionType>
195 {
196 mHelper.pushName( inProp.mName );
197 defineProperty( getPvdNamespacedNameForType<TCollectionType>(), "", PropertyType::Array );
198 mHelper.popName();
199 }
200
201 template<PxU32 TKey, typename TObjectType, typename TEnumType>
202 void handleCollection( const PxReadOnlyCollectionPropertyInfo<TKey, TObjectType, TEnumType>& inProp, const PxU32ToName* inConversions )
203 {
204 mHelper.pushName( inProp.mName );
205 defineNameValueDefs( inConversions );
206 defineProperty( getNameForEnumType<TEnumType>(), "Enumeration Value", PropertyType::Array );
207 mHelper.popName();
208 }
209
210private:
211 PvdClassInfoDefine& operator=(const PvdClassInfoDefine&);
212};
213
214template<typename TPropType>
215struct SimplePropertyValueStructOp
216{
217 void addPropertyMessageArg( PvdPropertyDefinitionHelper& mHelper, PxU32 inOffset )
218 {
219 mHelper.addPropertyMessageArg<TPropType>( inOffset );
220 }
221};
222
223#define DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_OP_NOP( type ) \
224template<> struct SimplePropertyValueStructOp<type> { void addPropertyMessageArg( PvdPropertyDefinitionHelper&, PxU32 ){}};
225
226DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_OP_NOP( PxStridedData )
227DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_OP_NOP( PxBoundedData )
228
229#define DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_VOIDPTR_OP( type ) \
230template<> struct SimplePropertyValueStructOp<type> { \
231void addPropertyMessageArg( PvdPropertyDefinitionHelper& mHelper, PxU32 inOffset ) \
232{ \
233 mHelper.addPropertyMessageArg<VoidPtr>( inOffset ); \
234} \
235};
236
237DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_VOIDPTR_OP( PxTetrahedronMesh* )
238DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_VOIDPTR_OP( PxTriangleMesh* )
239DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_VOIDPTR_OP( PxBVH33TriangleMesh* )
240DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_VOIDPTR_OP( PxBVH34TriangleMesh* )
241DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_VOIDPTR_OP( PxConvexMesh* )
242DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_VOIDPTR_OP( PxHeightField* )
243
244
245struct PvdClassInfoValueStructDefine
246{
247private:
248 PvdClassInfoValueStructDefine& operator=(const PvdClassInfoValueStructDefine&);
249public:
250
252
253 PvdClassInfoValueStructDefine( PvdPropertyDefinitionHelper& info )
254 : mHelper( info )
255 { }
256
257 PvdClassInfoValueStructDefine( const PvdClassInfoValueStructDefine& other )
258 : mHelper( other.mHelper )
259 {
260 }
261
262 void defineValueStructOffset( const ValueStructOffsetRecord& inProp, PxU32 inPropSize )
263 {
264 if( inProp.mHasValidOffset )
265 {
266 switch( inPropSize )
267 {
268 case 8: mHelper.addPropertyMessageArg<PxU64>( inProp.mOffset ); break;
269 case 4: mHelper.addPropertyMessageArg<PxU32>( inProp.mOffset ); break;
270 case 2: mHelper.addPropertyMessageArg<PxU16>( inProp.mOffset ); break;
271 default:
272 PX_ASSERT(1 == inPropSize);
273 mHelper.addPropertyMessageArg<PxU8>( inProp.mOffset ); break;
274 }
275 }
276 }
277
278 void pushName( const char* inName )
279 {
280 mHelper.pushName( inName );
281 }
282
283 void pushBracketedName( const char* inName)
284 {
285 mHelper.pushBracketedName( inName );
286 }
287
288 void popName()
289 {
290 mHelper.popName();
291 }
292
293 template<typename TAccessorType, typename TInfoType>
294 void bufferCollectionProperty( PxU32* /*key*/, const TAccessorType& /*inAccessor*/, TInfoType& /*inInfo*/ )
295 {
296 //complexProperty(key, inAccessor, inInfo);
297 }
298
299 template<typename TAccessorType>
300 void simpleProperty( PxU32 /*key*/, TAccessorType& inProp )
301 {
302 typedef typename TAccessorType::prop_type TPropertyType;
303 if ( inProp.mHasValidOffset )
304 {
305 SimplePropertyValueStructOp<TPropertyType>().addPropertyMessageArg( mHelper, inProp.mOffset );
306 }
307 }
308
309 template<typename TAccessorType>
310 void enumProperty( PxU32 /*key*/, TAccessorType& inAccessor, const PxU32ToName* /*inConversions */)
311 {
312 typedef typename TAccessorType::prop_type TPropType;
313 defineValueStructOffset( inAccessor, sizeof( TPropType ) );
314 }
315
316 template<typename TAccessorType>
317 void flagsProperty( PxU32 /*key*/, const TAccessorType& inAccessor, const PxU32ToName* /*inConversions */)
318 {
319 typedef typename TAccessorType::prop_type TPropType;
320 defineValueStructOffset( inAccessor, sizeof( TPropType ) );
321 }
322
323 template<typename TAccessorType, typename TInfoType>
324 void complexProperty( PxU32* key, const TAccessorType& inAccessor, TInfoType& inInfo )
325 {
326 PxU32 theOffset = inAccessor.mOffset;
327 inInfo.visitBaseProperties( makePvdPropertyFilter( *this, key, &theOffset ) );
328 inInfo.visitInstanceProperties( makePvdPropertyFilter( *this, key, &theOffset ) );
329 }
330
331 template<PxU32 TKey, typename TObjectType, typename TCollectionType>
332 void handleCollection( const PxReadOnlyCollectionPropertyInfo<TKey, TObjectType, TCollectionType>& /*prop*/ )
333 {
334 }
335
336 template<PxU32 TKey, typename TObjectType, typename TEnumType>
337 void handleCollection( const PxReadOnlyCollectionPropertyInfo<TKey, TObjectType, TEnumType>& /*prop*/, const PxU32ToName* /*inConversions */)
338 {
339 }
340
341 template<PxU32 TKey, typename TObjectType, typename TInfoType>
342 void handleCollection( const PxBufferCollectionPropertyInfo<TKey, TObjectType, TInfoType>& /*prop*/, const TInfoType& /*inInfo */)
343 {
344 }
345};
346
347}
348
349}
350
351#endif
352#endif
Definition PxArray.h:53
A triangle mesh containing the PxMeshMidPhase::eBVH33 structure.
Definition PxTriangleMesh.h:308
A triangle mesh containing the PxMeshMidPhase::eBVH34 structure.
Definition PxTriangleMesh.h:324
A convex mesh.
Definition PxConvexMesh.h:83
A height field class.
Definition PxHeightField.h:84
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 PxPvdDataStreamHelpers.h:43
virtual void pushBracketedName(const char *inName, const char *leftBracket="[", const char *rightBracket="]")=0
virtual void createProperty(const NamespacedName &clsName, const char *inSemantic, const NamespacedName &dtypeName, PropertyType::Enum propType=PropertyType::Scalar)=0
virtual void pushName(const char *inName, const char *inAppendStr=".")=0
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition PxCoreUtilityTypes.h:96
Definition PxMetaDataObjects.h:298
Definition PxMetaDataObjects.h:353
Definition PxCoreUtilityTypes.h:45
Definition PxMetaDataObjects.h:124
Definition PxPvdObjectModelBaseTypes.h:188