RavEngine
Loading...
Searching...
No Matches
GuCookingConvexHullUtils.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 GU_COOKING_CONVEX_HULL_UTILS_H
30#define GU_COOKING_CONVEX_HULL_UTILS_H
31
32#include "foundation/PxMemory.h"
33#include "foundation/PxPlane.h"
34#include "cooking/PxConvexMeshDesc.h"
35
36#include "foundation/PxUserAllocated.h"
37#include "foundation/PxArray.h"
38
39namespace physx
40{
41
43 // helper class for hull construction, holds the vertices and planes together
44 // while cropping the hull with planes
46 {
47 public:
48
49 // Helper class for halfedge representation
51 {
52 public:
53 PxI16 ea; // the other half of the edge (index into edges list)
54 PxU8 v; // the vertex at the start of this edge (index into vertices list)
55 PxU8 p; // the facet on which this edge lies (index into facets list)
56 HalfEdge(){}
57 HalfEdge(PxI16 _ea, PxU8 _v, PxU8 _p) :ea(_ea), v(_v), p(_p){}
58 };
59
60 ConvexHull& operator = (const ConvexHull&);
61
62 // construct the base cube hull from given max/min AABB
63 ConvexHull(const PxVec3& bmin, const PxVec3& bmax, const PxArray<PxPlane>& inPlanes);
64
65 // construct the base cube hull from given OBB
66 ConvexHull(const PxVec3& extent, const PxTransform& transform, const PxArray<PxPlane>& inPlanes);
67
68 // copy constructor
69 ConvexHull(const ConvexHull& srcHull)
70 : mInputPlanes(srcHull.getInputPlanes())
71 {
72 copyHull(srcHull);
73 }
74
75 // construct plain hull
76 ConvexHull(const PxArray<PxPlane>& inPlanes)
77 : mInputPlanes(inPlanes)
78 {
79 }
80
81 // finds the candidate plane, returns -1 otherwise
82 PxI32 findCandidatePlane(float planetestepsilon, float epsilon) const;
83
84 // internal check of the hull integrity
85 bool assertIntact(float epsilon) const;
86
87 // return vertices
88 const PxArray<PxVec3>& getVertices() const
89 {
90 return mVertices;
91 }
92
93 // return edges
94 const PxArray<HalfEdge>& getEdges() const
95 {
96 return mEdges;
97 }
98
99 // return faces
100 const PxArray<PxPlane>& getFacets() const
101 {
102 return mFacets;
103 }
104
105 // return input planes
106 const PxArray<PxPlane>& getInputPlanes() const
107 {
108 return mInputPlanes;
109 }
110
111 // return vertices
112 PxArray<PxVec3>& getVertices()
113 {
114 return mVertices;
115 }
116
117 // return edges
118 PxArray<HalfEdge>& getEdges()
119 {
120 return mEdges;
121 }
122
123 // return faces
124 PxArray<PxPlane>& getFacets()
125 {
126 return mFacets;
127 }
128
129 // returns the maximum number of vertices on a face
130 PxU32 maxNumVertsPerFace() const;
131
132 // copy the hull from source
133 void copyHull(const ConvexHull& src)
134 {
135 mVertices.resize(src.getVertices().size());
136 mEdges.resize(src.getEdges().size());
137 mFacets.resize(src.getFacets().size());
138
139 PxMemCopy(mVertices.begin(), src.getVertices().begin(), src.getVertices().size()*sizeof(PxVec3));
140 PxMemCopy(mEdges.begin(), src.getEdges().begin(), src.getEdges().size()*sizeof(HalfEdge));
141 PxMemCopy(mFacets.begin(), src.getFacets().begin(), src.getFacets().size()*sizeof(PxPlane));
142 }
143
144 private:
145 PxArray<PxVec3> mVertices;
146 PxArray<HalfEdge> mEdges;
147 PxArray<PxPlane> mFacets;
148 const PxArray<PxPlane>& mInputPlanes;
149 };
150
152 // Crops the hull with a provided plane and with given epsilon
153 // returns new hull if succeeded
154 ConvexHull* convexHullCrop(const ConvexHull& convex, const PxPlane& slice, float planetestepsilon);
155
157 // three planes intersection
158 PX_FORCE_INLINE PxVec3 threePlaneIntersection(const PxPlane& p0, const PxPlane& p1, const PxPlane& p2)
159 {
160 PxMat33 mp = (PxMat33(p0.n, p1.n, p2.n)).getTranspose();
161 PxMat33 mi = (mp).getInverse();
162 PxVec3 b(p0.d, p1.d, p2.d);
163 return -mi.transform(b);
164 }
165
167 // Compute OBB around given convex hull
168 bool computeOBBFromConvex(const PxConvexMeshDesc& desc, PxVec3& sides, PxTransform& matrix);
169}
170
171#endif
Definition GuCookingConvexHullUtils.h:51
Definition GuCookingConvexHullUtils.h:46
Definition PxArray.h:53
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_FORCE_INLINE void * PxMemCopy(void *dest, const void *src, PxU32 count)
Copies the bytes of one memory block to another. The memory blocks must not overlap.
Definition PxMemory.h:83