RavEngine
Loading...
Searching...
No Matches
NpShapeManager.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 NP_SHAPE_MANAGER_H
30#define NP_SHAPE_MANAGER_H
31
32#include "NpShape.h"
33#include "CmPtrTable.h"
34#include "GuBVH.h"
35
36#if PX_ENABLE_DEBUG_VISUALIZATION
37 #include "common/PxRenderOutput.h"
38#else
39 PX_CATCH_UNDEFINED_ENABLE_DEBUG_VISUALIZATION
40#endif
41
42#include "SqTypedef.h"
43
44namespace physx
45{
46
47namespace Sq
48{
49 class PruningStructure;
50 class PrunerManager;
51}
52
53class NpScene;
54
55 // PT: if we go through an SQ virtual interface then the implementation can be different from our internal version,
56 // and nothing says it uses the same types as what we have internally in SQ. So we need a separate set of types.
57 typedef PxSQCompoundHandle NpCompoundId;
58 static const NpCompoundId NP_INVALID_COMPOUND_ID = NpCompoundId(Sq::INVALID_COMPOUND_ID);
59
61{
62//= ATTENTION! =====================================================================================
63// Changing the data layout of this class breaks the binary serialization format. See comments for
64// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
65// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
66// accordingly.
67//==================================================================================================
68public:
69// PX_SERIALIZATION
70 static void getBinaryMetaData(PxOutputStream& stream);
72 void preExportDataReset();
73 void exportExtraData(PxSerializationContext& stream);
74 void importExtraData(PxDeserializationContext& context);
75//~PX_SERIALIZATION
78
79 PX_FORCE_INLINE PxU32 getNbShapes() const { return mShapes.getCount(); }
80 PX_FORCE_INLINE NpShape* const* getShapes() const { return reinterpret_cast<NpShape*const*>(mShapes.getPtrs()); }
81 PxU32 getShapes(PxShape** buffer, PxU32 bufferSize, PxU32 startIndex=0) const;
82
83 void attachShape(NpShape& shape, PxRigidActor& actor);
84 bool detachShape(NpShape& s, PxRigidActor& actor, bool wakeOnLostTouch);
85 void detachAll(PxSceneQuerySystem* pxsq, const PxRigidActor& actor);
86
87 void setupSQShape(PxSceneQuerySystem& pxsq, const NpShape& shape, const NpActor& npActor, const PxRigidActor& actor, bool dynamic, const PxBounds3* bounds, const Sq::PruningStructure* ps);
88 void setupSceneQuery(PxSceneQuerySystem& pxsq, const NpActor& npActor, const PxRigidActor& actor, const NpShape& shape);
89 void setupAllSceneQuery(PxSceneQuerySystem& pxsq, const NpActor& npActor, const PxRigidActor& actor, const Sq::PruningStructure* ps, const PxBounds3* bounds, bool isDynamic);
90 void setupAllSceneQuery(PxSceneQuerySystem& pxsq, const PxRigidActor& actor, const Sq::PruningStructure* ps, const PxBounds3* bounds=NULL, const Gu::BVH* bvh = NULL);
91 void teardownAllSceneQuery(PxSceneQuerySystem& pxsq, const PxRigidActor& actor);
92 void teardownSceneQuery(PxSceneQuerySystem& pxsq, const PxRigidActor& actor, const NpShape& shape);
93 void markShapeForSQUpdate(PxSceneQuerySystem& pxsq, const PxShape& shape, const PxRigidActor& actor);
94 void markActorForSQUpdate(PxSceneQuerySystem& pxsq, const PxRigidActor& actor);
95
96 PxBounds3 getWorldBounds_(const PxRigidActor&) const;
97
98 PX_FORCE_INLINE void setPruningStructure(Sq::PruningStructure* ps) { mPruningStructure = ps; }
99 PX_FORCE_INLINE Sq::PruningStructure* getPruningStructure() const { return mPruningStructure; }
100
101// PX_FORCE_INLINE bool isSqCompound() const { return mSqCompoundId != NP_INVALID_COMPOUND_ID; }
102// PX_FORCE_INLINE NpCompoundId getCompoundID() const { return mSqCompoundId; }
103// PX_FORCE_INLINE void setCompoundID(NpCompoundId id) { mSqCompoundId = id; }
104
105 // PT: TODO: we don't really need to store the compound id anymore
106 PX_FORCE_INLINE bool isSqCompound() const { return mShapes.mFreeSlot != NP_INVALID_COMPOUND_ID; }
107 PX_FORCE_INLINE NpCompoundId getCompoundID() const { return mShapes.mFreeSlot; }
108 PX_FORCE_INLINE void setCompoundID(NpCompoundId id) { mShapes.mFreeSlot = id; }
109
110 void clearShapesOnRelease(NpScene& s, PxRigidActor&);
111
112#if PX_ENABLE_DEBUG_VISUALIZATION
113 void visualize(PxRenderOutput& out, NpScene& scene, const PxRigidActor& actor, float scale) const;
114#else
115 PX_CATCH_UNDEFINED_ENABLE_DEBUG_VISUALIZATION
116#endif
117 // for batching
118 PX_FORCE_INLINE const Cm::PtrTable& getShapeTable() const { return mShapes; }
119 static PX_FORCE_INLINE size_t getShapeTableOffset() { return PX_OFFSET_OF_RT(NpShapeManager, mShapes); }
120private:
121 Cm::PtrTable mShapes;
122 Sq::PruningStructure* mPruningStructure; // Shape scene query data are pre-build in pruning structure
123// NpCompoundId mSqCompoundId;
124
125 void releaseExclusiveUserReferences();
126 void setupSceneQuery_(PxSceneQuerySystem& pxsq, const NpActor& npActor, const PxRigidActor& actor, const NpShape& shape);
127 void addBVHShapes(PxSceneQuerySystem& pxsq, const PxRigidActor& actor, const Gu::BVH& bvh);
128};
129
130}
131
132#endif
Definition base.h:1940
Represents a BVH.
Definition GuBVH.h:93
Definition NpActor.h:45
Definition NpScene.h:130
Definition NpShapeManager.h:61
Definition NpShape.h:44
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
Binary deserialization context class.
Definition PxSerialFramework.h:174
Output stream class for I/O.
Definition PxIO.h:114
Definition PxRenderOutput.h:50
PxRigidActor represents a base class shared between dynamic and static rigid bodies in the physics SD...
Definition PxRigidActor.h:53
Scene-queries external sub-system for PxScene-based objects.
Definition PxSceneQuerySystem.h:421
Binary serialization context class.
Definition PxSerialFramework.h:99
Abstract class for collision shapes.
Definition PxShape.h:146
Definition PxUserAllocated.h:43
Definition NpPruningStructure.h:44
#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
PxEMPTY
Definition Px.h:87
Definition CmPtrTable.h:72