PxConvexMeshDesc.h

Go to the documentation of this file.
00001 //
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions
00004 // are met:
00005 //  * Redistributions of source code must retain the above copyright
00006 //    notice, this list of conditions and the following disclaimer.
00007 //  * Redistributions in binary form must reproduce the above copyright
00008 //    notice, this list of conditions and the following disclaimer in the
00009 //    documentation and/or other materials provided with the distribution.
00010 //  * Neither the name of NVIDIA CORPORATION nor the names of its
00011 //    contributors may be used to endorse or promote products derived
00012 //    from this software without specific prior written permission.
00013 //
00014 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
00015 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017 // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00018 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 //
00026 // Copyright (c) 2008-2018 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 PX_COLLISION_NXCONVEXMESHDESC
00032 #define PX_COLLISION_NXCONVEXMESHDESC
00033 
00037 #include "foundation/PxVec3.h"
00038 #include "foundation/PxFlags.h"
00039 #include "common/PxCoreUtilityTypes.h"
00040 #include "geometry/PxConvexMesh.h"
00041 
00042 #if !PX_DOXYGEN
00043 namespace physx
00044 {
00045 #endif
00046 
00050 struct PxConvexFlag
00051 {
00052     enum Enum
00053     {
00059         e16_BIT_INDICES     =   (1<<0),
00060 
00068         eCOMPUTE_CONVEX     =   (1<<1), 
00069 
00081         eCHECK_ZERO_AREA_TRIANGLES      =   (1<<2),
00082 
00092         PX_DEPRECATED eINFLATE_CONVEX       =   (1<<3),
00093 
00101         eQUANTIZE_INPUT = (1 << 4),
00102 
00110         eDISABLE_MESH_VALIDATION = (1 << 5),
00111 
00129         ePLANE_SHIFTING = (1 << 6),
00130 
00135         eFAST_INERTIA_COMPUTATION = (1 << 7),
00136 
00142         eGPU_COMPATIBLE = (1 << 8),
00143 
00150         eSHIFT_VERTICES = (1 << 9)
00151     };
00152 };
00153 
00159 typedef PxFlags<PxConvexFlag::Enum,PxU16> PxConvexFlags;
00160 PX_FLAGS_OPERATORS(PxConvexFlag::Enum,PxU16)
00161 
00162 
00169 class PxConvexMeshDesc
00170 {
00171 public:
00172 
00178     PxBoundedData points;
00179 
00188     PxBoundedData polygons;
00189 
00200     PxBoundedData indices;
00201 
00207     PxConvexFlags flags;
00208 
00222     PxU16 vertexLimit;  
00223 
00233     PxU16 quantizedCount;
00234 
00238     PX_INLINE PxConvexMeshDesc();
00242     PX_INLINE void setToDefault();
00248     PX_INLINE bool isValid() const;
00249 };
00250 
00251 PX_INLINE PxConvexMeshDesc::PxConvexMeshDesc()  //constructor sets to default
00252 : vertexLimit(255), quantizedCount(255)
00253 {
00254 }
00255 
00256 PX_INLINE void PxConvexMeshDesc::setToDefault()
00257 {
00258     *this = PxConvexMeshDesc();
00259 }
00260 
00261 PX_INLINE bool PxConvexMeshDesc::isValid() const
00262 {
00263     // Check geometry
00264     if(points.count < 3 ||  //at least 1 trig's worth of points
00265         (points.count > 0xffff && flags & PxConvexFlag::e16_BIT_INDICES))
00266         return false;
00267     if(!points.data)
00268         return false;
00269     if(points.stride < sizeof(PxVec3))  //should be at least one point's worth of data
00270         return false;
00271     if (quantizedCount < 4)
00272         return false;
00273 
00274     // Check topology
00275     if(polygons.data)
00276     {
00277         if(polygons.count < 4) // we require 2 neighbors for each vertex - 4 polygons at least
00278             return false;
00279 
00280         if(!indices.data) // indices must be provided together with polygons
00281             return false;
00282 
00283         PxU32 limit = (flags & PxConvexFlag::e16_BIT_INDICES) ? sizeof(PxU16) : sizeof(PxU32);
00284         if(indices.stride < limit) 
00285             return false;
00286 
00287         limit = sizeof(PxHullPolygon);
00288         if(polygons.stride < limit) 
00289             return false;
00290     }
00291     else
00292     {
00293         // We can compute the hull from the vertices
00294         if(!(flags & PxConvexFlag::eCOMPUTE_CONVEX))
00295             return false;   // If the mesh is convex and we're not allowed to compute the hull,
00296                             // you have to provide it completely (geometry & topology).
00297     }
00298 
00299     if((flags & PxConvexFlag::ePLANE_SHIFTING) &&  vertexLimit < 4)
00300     {
00301         return false;
00302     }
00303 
00304     if (!(flags & PxConvexFlag::ePLANE_SHIFTING) && vertexLimit < 8)
00305     {
00306         return false;
00307     }
00308 
00309     if(vertexLimit > 256)
00310     {
00311         return false;
00312     }
00313     return true;
00314 }
00315 
00316 #if !PX_DOXYGEN
00317 } // namespace physx
00318 #endif
00319 
00321 #endif


Copyright © 2008-2018 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com