00001 // This code contains NVIDIA Confidential Information and is disclosed to you 00002 // under a form of NVIDIA software license agreement provided separately to you. 00003 // 00004 // Notice 00005 // NVIDIA Corporation and its licensors retain all intellectual property and 00006 // proprietary rights in and to this software and related documentation and 00007 // any modifications thereto. Any use, reproduction, disclosure, or 00008 // distribution of this software and related documentation without an express 00009 // license agreement from NVIDIA Corporation is strictly prohibited. 00010 // 00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES 00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO 00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, 00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. 00015 // 00016 // Information and code furnished is believed to be accurate and reliable. 00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such 00018 // information or for any infringement of patents or other rights of third parties that may 00019 // result from its use. No license is granted by implication or otherwise under any patent 00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice. 00021 // This code supersedes and replaces all information previously supplied. 00022 // NVIDIA Corporation products are not authorized for use as critical 00023 // components in life support devices or systems without express written approval of 00024 // NVIDIA Corporation. 00025 // 00026 // Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. 00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. 00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. 00029 00030 00031 #ifndef NV_CLOTH_EXTENSIONS_CLOTHMESHDESC 00032 #define NV_CLOTH_EXTENSIONS_CLOTHMESHDESC 00033 00037 #include "foundation/PxVec3.h" 00038 00039 namespace nv 00040 { 00041 namespace cloth 00042 { 00043 00044 struct StridedData 00045 { 00051 physx::PxU32 stride; 00052 const void* data; 00053 00054 StridedData() : stride( 0 ), data( NULL ) {} 00055 00056 template<typename TDataType> 00057 PX_INLINE const TDataType& at( physx::PxU32 idx ) const 00058 { 00059 physx::PxU32 theStride( stride ); 00060 if ( theStride == 0 ) 00061 theStride = sizeof( TDataType ); 00062 physx::PxU32 offset( theStride * idx ); 00063 return *(reinterpret_cast<const TDataType*>( reinterpret_cast< const physx::PxU8* >( data ) + offset )); 00064 } 00065 }; 00066 00067 struct BoundedData : public StridedData 00068 { 00069 physx::PxU32 count; 00070 BoundedData() : count( 0 ) {} 00071 }; 00072 00076 struct MeshFlag 00077 { 00078 enum Enum 00079 { 00080 e16_BIT_INDICES = (1<<1) 00081 }; 00082 }; 00083 00087 class ClothMeshDesc 00088 { 00089 public: 00090 00094 BoundedData points; 00095 00099 BoundedData pointsStiffness; 00100 00108 BoundedData invMasses; 00109 00124 BoundedData triangles; 00125 00140 BoundedData quads; 00141 00145 unsigned int flags; 00146 00150 PX_INLINE ClothMeshDesc(); 00154 PX_INLINE void setToDefault(); 00159 PX_INLINE bool isValid() const; 00160 }; 00161 00162 PX_INLINE ClothMeshDesc::ClothMeshDesc() 00163 { 00164 flags = 0; 00165 } 00166 00167 PX_INLINE void ClothMeshDesc::setToDefault() 00168 { 00169 *this = ClothMeshDesc(); 00170 } 00171 00172 PX_INLINE bool ClothMeshDesc::isValid() const 00173 { 00174 if (points.count < 3) // at least 1 triangle 00175 return false; 00176 if ((pointsStiffness.count != points.count) && pointsStiffness.count != 0) 00177 return false; // either all or none of the points can have stiffness information 00178 if (points.count > 0xffff && flags & MeshFlag::e16_BIT_INDICES) 00179 return false; 00180 if (!points.data) 00181 return false; 00182 if (points.stride < sizeof(physx::PxVec3)) // should be at least one point 00183 return false; 00184 00185 if (invMasses.data && invMasses.stride < sizeof(float)) 00186 return false; 00187 if (invMasses.data && invMasses.count != points.count) 00188 return false; 00189 00190 if (!triangles.count && !quads.count) // no support for non-indexed mesh 00191 return false; 00192 if (triangles.count && !triangles.data) 00193 return false; 00194 if (quads.count && !quads.data) 00195 return false; 00196 00197 physx::PxU32 indexSize = (flags & MeshFlag::e16_BIT_INDICES) ? sizeof(physx::PxU16) : sizeof(physx::PxU32); 00198 if (triangles.count && triangles.stride < indexSize*3) 00199 return false; 00200 if (quads.count && quads.stride < indexSize*4) 00201 return false; 00202 00203 return true; 00204 } 00205 00206 } // namespace cloth 00207 } // namespace nv 00208 00209 00211 #endif