1//
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions
4// are met:
5// * Redistributions of source code must retain the above copyright
6// notice, this list of conditions and the following disclaimer.
7// * Redistributions in binary form must reproduce the above copyright
8// notice, this list of conditions and the following disclaimer in the
9// documentation and/or other materials provided with the distribution.
10// * Neither the name of NVIDIA CORPORATION nor the names of its
11// contributors may be used to endorse or promote products derived
12// from this software without specific prior written permission.
13//
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25//
26// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29
30
31#ifndef PX_PHYSICS_GEOMUTILS_NX_SIMPLETRIANGLEMESH
32#define PX_PHYSICS_GEOMUTILS_NX_SIMPLETRIANGLEMESH
33/** \addtogroup geomutils
34@{
35*/
36
37#include "foundation/PxVec3.h"
38#include "foundation/PxFlags.h"
39#include "common/PxCoreUtilityTypes.h"
40#include "common/PxPhysXCommonConfig.h"
41
42#if !PX_DOXYGEN
43namespace physx
44{
45#endif
46
47/**
48\brief Enum with flag values to be used in PxSimpleTriangleMesh::flags.
49*/
50struct PxMeshFlag
51{
52 enum Enum
53 {
54 /**
55 \brief Specifies if the SDK should flip normals.
56
57 The PhysX libraries assume that the face normal of a triangle with vertices [a,b,c] can be computed as:
58 edge1 = b-a
59 edge2 = c-a
60 face_normal = edge1 x edge2.
61
62 Note: This is the same as a counterclockwise winding in a right handed coordinate system or
63 alternatively a clockwise winding order in a left handed coordinate system.
64
65 If this does not match the winding order for your triangles, raise the below flag.
66 */
67 eFLIPNORMALS = (1<<0),
68 e16_BIT_INDICES = (1<<1) //!< Denotes the use of 16-bit vertex indices
69 };
70};
71
72/**
73\brief collection of set bits defined in PxMeshFlag.
74
75@see PxMeshFlag
76*/
77typedef PxFlags<PxMeshFlag::Enum,PxU16> PxMeshFlags;
78PX_FLAGS_OPERATORS(PxMeshFlag::Enum,PxU16)
79
80
81/**
82\brief A structure describing a triangle mesh.
83*/
84class PxSimpleTriangleMesh
85{
86public:
87
88 /**
89 \brief Pointer to first vertex point.
90 */
91 PxBoundedData points;
92
93 /**
94 \brief Pointer to first triangle.
95
96 Caller may add triangleStrideBytes bytes to the pointer to access the next triangle.
97
98 These are triplets of 0 based indices:
99 vert0 vert1 vert2
100 vert0 vert1 vert2
101 vert0 vert1 vert2
102 ...
103
104 where vertex is either a 32 or 16 bit unsigned integer. There are numTriangles*3 indices.
105
106 This is declared as a void pointer because it is actually either an PxU16 or a PxU32 pointer.
107 */
108 PxBoundedData triangles;
109
110 /**
111 \brief Flags bits, combined from values of the enum ::PxMeshFlag
112 */
113 PxMeshFlags flags;
114
115 /**
116 \brief constructor sets to default.
117 */
118 PX_INLINE PxSimpleTriangleMesh();
119 /**
120 \brief (re)sets the structure to the default.
121 */
122 PX_INLINE void setToDefault();
123 /**
124 \brief returns true if the current settings are valid
125 */
126 PX_INLINE bool isValid() const;
127};
128
129
130PX_INLINE PxSimpleTriangleMesh::PxSimpleTriangleMesh()
131{
132}
133
134PX_INLINE void PxSimpleTriangleMesh::setToDefault()
135{
136 *this = PxSimpleTriangleMesh();
137}
138
139PX_INLINE bool PxSimpleTriangleMesh::isValid() const
140{
141 // Check geometry
142 if(points.count > 0xffff && flags & PxMeshFlag::e16_BIT_INDICES)
143 return false;
144 if(!points.data)
145 return false;
146 if(points.stride < sizeof(PxVec3)) //should be at least one point's worth of data
147 return false;
148
149 // Check topology
150 // The triangles pointer is not mandatory
151 if(triangles.data)
152 {
153 // Indexed mesh
154 PxU32 limit = (flags & PxMeshFlag::e16_BIT_INDICES) ? sizeof(PxU16)*3 : sizeof(PxU32)*3;
155 if(triangles.stride < limit)
156 return false;
157 }
158 return true;
159}
160
161#if !PX_DOXYGEN
162} // namespace physx
163#endif
164
165/** @} */
166#endif
167

source code of qtquick3dphysics/src/3rdparty/PhysX/include/geometry/PxSimpleTriangleMesh.h