RavEngine
Loading...
Searching...
No Matches
ExtUtilities.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
27#ifndef EXT_TET_CPU_BVH_H
28#define EXT_TET_CPU_BVH_H
29
30#include "foundation/PxArray.h"
31
32#include "foundation/PxBounds3.h"
33
34#include "GuBVH.h"
35#include "GuAABBTree.h"
36#include "GuAABBTreeNode.h"
37#include "GuAABBTreeBounds.h"
38#include "GuAABBTreeQuery.h"
39#include "GuTriangle.h"
40#include "ExtVec3.h"
41
42namespace physx
43{
44namespace Ext
45{
46 using Triangle = Gu::IndexedTriangleT<PxI32>;
47
48 //Creates an unique 64bit bit key out of two 32bit values, the key is order independent, useful as hash key for edges
49 //Use this functions to compute the edge keys used in the edgesToSplit parameter of the split function below.
50 PX_FORCE_INLINE PxU64 key(PxI32 a, PxI32 b)
51 {
52 if (a < b)
53 return ((PxU64(a)) << 32) | (PxU64(b));
54 else
55 return ((PxU64(b)) << 32) | (PxU64(a));
56 }
57
58 void buildTree(const PxU32* triangles, const PxU32 numTriangles, const Vec3* points, PxArray<Gu::BVHNode>& tree, PxF32 enlargement = 1e-4f);
59
60 //Builds a BVH from a set of triangles
61 PX_FORCE_INLINE void buildTree(const PxArray<Triangle>& triangles, const PxArray<Vec3>& points, PxArray<Gu::BVHNode>& tree, PxF32 enlargement = 1e-4f)
62 {
63 buildTree(reinterpret_cast<const PxU32*>(triangles.begin()), triangles.size(), points.begin(), tree, enlargement);
64 }
65
66 template<typename T>
67 void traverseBVH(const PxArray<Gu::BVHNode>& nodes, T& traversalController, PxI32 rootNodeIndex = 0)
68 {
69 traverseBVH(nodes.begin(), traversalController, rootNodeIndex);
70 }
71
73 {
74 PxBounds3 box;
75 PxArray<PxI32>& candidateTriangleIndices;
76
77 public:
79 box(PxBounds3::empty()), candidateTriangleIndices(candidateTriangleIndices_)
80 { }
81
82 IntersectionCollectingTraversalController(const PxBounds3& box_, PxArray<PxI32>& candidateTriangleIndices_) :
83 box(box_), candidateTriangleIndices(candidateTriangleIndices_)
84 { }
85
86 void reset(const PxBounds3& box_)
87 {
88 box = box_;
89 candidateTriangleIndices.clear();
90 }
91
92 Gu::TraversalControl::Enum analyze(const Gu::BVHNode& node, PxI32)
93 {
94 if (node.isLeaf())
95 {
96 candidateTriangleIndices.pushBack(node.getPrimitiveIndex());
97 return Gu::TraversalControl::eDontGoDeeper;
98 }
99
100 if (node.mBV.intersects(box))
101 return Gu::TraversalControl::eGoDeeper;
102 return Gu::TraversalControl::eDontGoDeeper;
103 }
104 private:
106 };
107}
108}
109#endif
Definition PxArray.h:53
PX_INLINE void clear()
Definition PxArray.h:250
PX_FORCE_INLINE T & pushBack(const T &a)
Definition PxArray.h:296
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
PX_CUDA_CALLABLE PX_FORCE_INLINE bool intersects(const PxBounds3 &b) const
indicates whether the intersection of this and b is empty or not.
Definition PxBounds3.h:357
static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 empty()
Return empty bounds.
Definition PxBounds3.h:284
#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
Definition SnippetImmediateMode.cpp:303
Definition GuAABBTreeNode.h:44