RavEngine
Loading...
Searching...
No Matches
GuBV4Build.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_BV4_BUILD_H
30#define GU_BV4_BUILD_H
31
32#include "foundation/PxSimpleTypes.h"
33#include "foundation/PxUserAllocated.h"
34#include "foundation/PxBounds3.h"
35#include "GuBV4Settings.h"
36
37namespace physx
38{
39namespace Gu
40{
41 class BV4Tree;
42 class SourceMeshBase;
43
44 // PT: TODO: refactor with SQ version (TA34704)
46 {
47 public:
49#ifdef GU_BV4_FILL_GAPS
50 , mNextSplit(0)
51#endif
52 {
53 }
55 {
56 mPos = 0;
57 mNodePrimitives = NULL; // This was just a shortcut to the global list => no release
58 mNbPrimitives = 0;
59 }
60 // Data access
61 PX_FORCE_INLINE const PxBounds3& getAABB() const { return mBV; }
62
63 PX_FORCE_INLINE const AABBTreeNode* getPos() const { return reinterpret_cast<const AABBTreeNode*>(mPos); }
64 PX_FORCE_INLINE const AABBTreeNode* getNeg() const { const AABBTreeNode* P = getPos(); return P ? P+1 : NULL; }
65
66 PX_FORCE_INLINE bool isLeaf() const { return !getPos(); }
67
68 PxBounds3 mBV; // Global bounding-volume enclosing all the node-related primitives
69 size_t mPos; // "Positive" & "Negative" children
70
71 // Data access
72 PX_FORCE_INLINE const PxU32* getPrimitives() const { return mNodePrimitives; }
73 PX_FORCE_INLINE PxU32 getNbPrimitives() const { return mNbPrimitives; }
74
77#ifdef GU_BV4_FILL_GAPS
78 PxU32 mNextSplit;
79#endif
80 };
81
82 typedef bool (*WalkingCallback) (const AABBTreeNode* current, PxU32 depth, void* userData);
83 typedef bool (*WalkingDistanceCallback) (const AABBTreeNode* current, void* userData);
84
85 enum BV4_BuildStrategy
86 {
87 BV4_SPLATTER_POINTS,
88 BV4_SPLATTER_POINTS_SPLIT_GEOM_CENTER,
89 BV4_SAH
90 };
91
92 // PT: TODO: refactor with SQ version (TA34704)
94 {
95 public:
98
99 bool buildFromMesh(SourceMeshBase& mesh, PxU32 limit, BV4_BuildStrategy strategy=BV4_SPLATTER_POINTS);
100 void release();
101
102 PX_FORCE_INLINE const PxU32* getIndices() const { return mIndices; }
103 PX_FORCE_INLINE PxU32 getNbNodes() const { return mTotalNbNodes; }
104
105 PX_FORCE_INLINE const PxU32* getPrimitives() const { return mPool->mNodePrimitives; }
106 PX_FORCE_INLINE PxU32 getNbPrimitives() const { return mPool->mNbPrimitives; }
107 PX_FORCE_INLINE const AABBTreeNode* getNodes() const { return mPool; }
108 PX_FORCE_INLINE const PxBounds3& getBV() const { return mPool->mBV; }
109
110 PxU32 walk(WalkingCallback callback, void* userData) const;
111 PxU32 walkDistance(WalkingCallback callback, WalkingDistanceCallback distancCallback, void* userData) const;
112 private:
113 PxU32* mIndices;
114 AABBTreeNode* mPool;
115 PxU32 mTotalNbNodes;
116 };
117
118 bool BuildBV4Ex(BV4Tree& tree, SourceMeshBase& mesh, float epsilon, PxU32 nbPrimitivePerLeaf, bool quantized, BV4_BuildStrategy strategy=BV4_SPLATTER_POINTS);
119
120} // namespace Gu
121}
122
123#endif // GU_BV4_BUILD_H
Definition GuBV4Build.h:46
PxU32 * mNodePrimitives
Node-related primitives (shortcut to a position in mIndices below)
Definition GuBV4Build.h:75
PxU32 mNbPrimitives
Number of primitives for this node.
Definition GuBV4Build.h:76
Definition GuBV4Build.h:94
PX_FORCE_INLINE const PxU32 * getIndices() const
Catch the indices.
Definition GuBV4Build.h:102
PX_FORCE_INLINE PxU32 getNbNodes() const
Catch the number of nodes.
Definition GuBV4Build.h:103
Definition GuBV4.h:141
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
Definition PxUserAllocated.h:43
#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