// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of NVIDIA CORPORATION nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. #ifndef PVD_META_DATA_DEFINE_PROPERTIES_H #define PVD_META_DATA_DEFINE_PROPERTIES_H #if PX_SUPPORT_PVD #include "common/PxCoreUtilityTypes.h" #include "PvdMetaDataPropertyVisitor.h" #include "PxPvdDataStreamHelpers.h" #include "PxPvdDataStream.h" namespace physx { namespace Vd { using namespace physx::shdfnd; using namespace physx::pvdsdk; template struct PropertyDefinitionOp { void defineProperty( PvdPropertyDefinitionHelper& mHelper, NamespacedName mClassKey ) { mHelper.createProperty( mClassKey, "", getPvdNamespacedNameForType(), PropertyType::Scalar ); } }; template<> struct PropertyDefinitionOp { void defineProperty( PvdPropertyDefinitionHelper& mHelper, NamespacedName mClassKey ) { mHelper.createProperty( mClassKey, "", getPvdNamespacedNameForType(), PropertyType::Scalar ); } }; #define DEFINE_PROPERTY_DEFINITION_OP_NOP( type ) \ template<> struct PropertyDefinitionOp { void defineProperty( PvdPropertyDefinitionHelper&, NamespacedName ){} }; //NOP out these two types. DEFINE_PROPERTY_DEFINITION_OP_NOP( PxStridedData ) DEFINE_PROPERTY_DEFINITION_OP_NOP( PxBoundedData ) #define DEFINE_PROPERTY_DEFINITION_OBJECT_REF( type ) \ template<> struct PropertyDefinitionOp { \ void defineProperty( PvdPropertyDefinitionHelper& mHelper, NamespacedName mClassKey) \ { \ mHelper.createProperty( mClassKey, "", getPvdNamespacedNameForType(), PropertyType::Scalar ); \ } \ }; DEFINE_PROPERTY_DEFINITION_OBJECT_REF( PxTriangleMesh* ) DEFINE_PROPERTY_DEFINITION_OBJECT_REF( PxBVH33TriangleMesh* ) DEFINE_PROPERTY_DEFINITION_OBJECT_REF( PxBVH34TriangleMesh* ) DEFINE_PROPERTY_DEFINITION_OBJECT_REF( PxConvexMesh* ) DEFINE_PROPERTY_DEFINITION_OBJECT_REF( PxHeightField* ) struct PvdClassInfoDefine { PvdPropertyDefinitionHelper& mHelper; NamespacedName mClassKey; PvdClassInfoDefine( PvdPropertyDefinitionHelper& info, NamespacedName inClassName ) : mHelper( info ) , mClassKey( inClassName ) { } PvdClassInfoDefine( const PvdClassInfoDefine& other ) : mHelper( other.mHelper ) , mClassKey( other.mClassKey ) { } void defineProperty( NamespacedName inDtype, const char* semantic = "", PropertyType::Enum inPType = PropertyType::Scalar ) { mHelper.createProperty( mClassKey, semantic, inDtype, inPType ); } void pushName( const char* inName ) { mHelper.pushName( inName ); } void pushBracketedName( const char* inName) { mHelper.pushBracketedName( inName ); } void popName() { mHelper.popName(); } inline void defineNameValueDefs( const PxU32ToName* theConversions ) { while( theConversions->mName != NULL ) { mHelper.addNamedValue( theConversions->mName, theConversions->mValue ); ++theConversions; } } template void simpleProperty( PxU32, TAccessorType& /*inProp */) { typedef typename TAccessorType::prop_type TPropertyType; PropertyDefinitionOp().defineProperty( mHelper, mClassKey ); } template void extendedIndexedProperty( PxU32* key, const TAccessorType& inProp, TInfoType& ) { simpleProperty(*key, inProp); } template static NamespacedName getNameForEnumType() { size_t s = sizeof( TDataType ); switch(s) { case 1: return getPvdNamespacedNameForType(); case 2: return getPvdNamespacedNameForType(); case 4: return getPvdNamespacedNameForType(); default: return getPvdNamespacedNameForType(); } } template void enumProperty( PxU32 /*key*/, TAccessorType& /*inProp*/, const PxU32ToName* inConversions ) { typedef typename TAccessorType::prop_type TPropType; defineNameValueDefs( inConversions ); defineProperty( getNameForEnumType(), "Enumeration Value" ); } template void flagsProperty( PxU32 /*key*/, const TAccessorType& /*inAccessor*/, const PxU32ToName* inConversions ) { typedef typename TAccessorType::prop_type TPropType; defineNameValueDefs( inConversions ); defineProperty( getNameForEnumType(), "Bitflag" ); } template void complexProperty( PxU32* key, const TAccessorType& inAccessor, TInfoType& inInfo ) { PxU32 theOffset = inAccessor.mOffset; inInfo.visitBaseProperties( makePvdPropertyFilter( *this, key, &theOffset ) ); inInfo.visitInstanceProperties( makePvdPropertyFilter( *this, key, &theOffset ) ); } template void bufferCollectionProperty( PxU32* key, const TAccessorType& inAccessor, TInfoType& inInfo ) { complexProperty(key, inAccessor, inInfo); } template void handleBuffer( const PxBufferPropertyInfo&, TEnableFlag>& inProp ) { mHelper.pushName( inProp.mName ); defineProperty( getPvdNamespacedNameForType(), "", PropertyType::Array ); mHelper.popName(); } template void handleCollection( const PxReadOnlyCollectionPropertyInfo& inProp ) { mHelper.pushName( inProp.mName ); defineProperty( getPvdNamespacedNameForType(), "", PropertyType::Array ); mHelper.popName(); } template void handleCollection( const PxReadOnlyCollectionPropertyInfo& inProp, const PxU32ToName* inConversions ) { mHelper.pushName( inProp.mName ); defineNameValueDefs( inConversions ); defineProperty( getNameForEnumType(), "Enumeration Value", PropertyType::Array ); mHelper.popName(); } private: PvdClassInfoDefine& operator=(const PvdClassInfoDefine&); }; template struct SimplePropertyValueStructOp { void addPropertyMessageArg( PvdPropertyDefinitionHelper& mHelper, PxU32 inOffset ) { mHelper.addPropertyMessageArg( inOffset ); } }; #define DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_OP_NOP( type ) \ template<> struct SimplePropertyValueStructOp { void addPropertyMessageArg( PvdPropertyDefinitionHelper&, PxU32 ){}}; DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_OP_NOP( PxStridedData ) DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_OP_NOP( PxBoundedData ) #define DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_VOIDPTR_OP( type ) \ template<> struct SimplePropertyValueStructOp { \ void addPropertyMessageArg( PvdPropertyDefinitionHelper& mHelper, PxU32 inOffset ) \ { \ mHelper.addPropertyMessageArg( inOffset ); \ } \ }; DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_VOIDPTR_OP( PxTriangleMesh* ) DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_VOIDPTR_OP( PxBVH33TriangleMesh* ) DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_VOIDPTR_OP( PxBVH34TriangleMesh* ) DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_VOIDPTR_OP( PxConvexMesh* ) DEFINE_SIMPLE_PROPERTY_VALUE_STRUCT_VOIDPTR_OP( PxHeightField* ) struct PvdClassInfoValueStructDefine { private: PvdClassInfoValueStructDefine& operator=(const PvdClassInfoValueStructDefine&); public: PvdPropertyDefinitionHelper& mHelper; PvdClassInfoValueStructDefine( PvdPropertyDefinitionHelper& info ) : mHelper( info ) { } PvdClassInfoValueStructDefine( const PvdClassInfoValueStructDefine& other ) : mHelper( other.mHelper ) { } void defineValueStructOffset( const ValueStructOffsetRecord& inProp, PxU32 inPropSize ) { if( inProp.mHasValidOffset ) { switch( inPropSize ) { case 8: mHelper.addPropertyMessageArg( inProp.mOffset ); break; case 4: mHelper.addPropertyMessageArg( inProp.mOffset ); break; case 2: mHelper.addPropertyMessageArg( inProp.mOffset ); break; default: PX_ASSERT(1 == inPropSize); mHelper.addPropertyMessageArg( inProp.mOffset ); break; } } } void pushName( const char* inName ) { mHelper.pushName( inName ); } void pushBracketedName( const char* inName) { mHelper.pushBracketedName( inName ); } void popName() { mHelper.popName(); } template void bufferCollectionProperty( PxU32* /*key*/, const TAccessorType& /*inAccessor*/, TInfoType& /*inInfo*/ ) { //complexProperty(key, inAccessor, inInfo); } template void simpleProperty( PxU32 /*key*/, TAccessorType& inProp ) { typedef typename TAccessorType::prop_type TPropertyType; if ( inProp.mHasValidOffset ) { SimplePropertyValueStructOp().addPropertyMessageArg( mHelper, inProp.mOffset ); } } template void enumProperty( PxU32 /*key*/, TAccessorType& inAccessor, const PxU32ToName* /*inConversions */) { typedef typename TAccessorType::prop_type TPropType; defineValueStructOffset( inAccessor, sizeof( TPropType ) ); } template void flagsProperty( PxU32 /*key*/, const TAccessorType& inAccessor, const PxU32ToName* /*inConversions */) { typedef typename TAccessorType::prop_type TPropType; defineValueStructOffset( inAccessor, sizeof( TPropType ) ); } template void complexProperty( PxU32* key, const TAccessorType& inAccessor, TInfoType& inInfo ) { PxU32 theOffset = inAccessor.mOffset; inInfo.visitBaseProperties( makePvdPropertyFilter( *this, key, &theOffset ) ); inInfo.visitInstanceProperties( makePvdPropertyFilter( *this, key, &theOffset ) ); } template void handleCollection( const PxReadOnlyCollectionPropertyInfo& /*prop*/ ) { } template void handleCollection( const PxReadOnlyCollectionPropertyInfo& /*prop*/, const PxU32ToName* /*inConversions */) { } template void handleCollection( const PxBufferCollectionPropertyInfo& /*prop*/, const TInfoType& /*inInfo */) { } }; } } #endif #endif