RavEngine
Loading...
Searching...
No Matches
ScShapeSimBase.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 SC_SHAPESIM_BASE_H
28#define SC_SHAPESIM_BASE_H
29
30#include "ScElementSim.h"
31#include "ScShapeCore.h"
32#include "ScRigidSim.h"
33#include "PxsShapeSim.h"
34
35namespace physx
36{
37 namespace Sc
38 {
39
40 PX_FORCE_INLINE PxU32 isBroadPhase(PxShapeFlags flags) { return PxU32(flags) & PxU32(PxShapeFlag::eTRIGGER_SHAPE | PxShapeFlag::eSIMULATION_SHAPE); }
41 class ShapeCore;
42
43 // PT: TODO: ShapeSimBase is bonkers:
44 // PxU32 ElementSim::mElementID
45 // PxU32 ElementSim::mShapeArrayIndex;
46 // IG::NodeIndex mLLShape::mBodySimIndex; *** GPU only
47 // PxU32 mLLShape::mElementIndex; *** GPU only, looks like a copy of ElementSim::mElementID
48 // PxU32 mLLShape::mShapeIndex; *** GPU only, looks like a copy of ElementSim::mElementID
49 // PxU32 ShapeSimBase::mId;
50 // PxU32 ShapeSimBase::mSqBoundsId;
51 // => do we really need 7 different IDs per shape?
52
53 class ShapeSimBase : public ElementSim
54 {
55 ShapeSimBase &operator=(const ShapeSimBase &);
56 public:
57
58 // passing in a pointer for the shape to output its bounds allows us not to have to compute them twice.
59 // A neater way to do this would be to ask the AABB Manager for the bounds after the shape has been
60 // constructed, but there is currently no spec for what the AABBMgr is allowed to do with the bounds,
61 // hence better not to assume anything.
62
63 ShapeSimBase(ActorSim& owner, const ShapeCore* core) :
64 ElementSim (owner),
65 mSqBoundsId (PX_INVALID_U32),
66 mPrunerIndex(PX_INVALID_U32)
67 { setCore(core); }
68 ~ShapeSimBase() { }
69
70 PX_FORCE_INLINE void setCore(const ShapeCore* core);
71 PX_FORCE_INLINE const ShapeCore& getCore() const;
72
73 PX_INLINE PxGeometryType::Enum getGeometryType() const { return getCore().getGeometryType(); }
74
75 // This is just for getting a reference for the user, so we cast away const-ness
76
77 PX_INLINE PxShape* getPxShape() const { return const_cast<PxShape*>(getCore().getPxShape()); }
78
79 PX_FORCE_INLINE PxReal getRestOffset() const { return getCore().getRestOffset(); }
80 PX_FORCE_INLINE PxReal getTorsionalPatchRadius() const { return getCore().getTorsionalPatchRadius(); }
81 PX_FORCE_INLINE PxReal getMinTorsionalPatchRadius() const { return getCore().getMinTorsionalPatchRadius(); }
82 PX_FORCE_INLINE PxU32 getFlags() const { return getCore().getFlags(); }
83 PX_FORCE_INLINE PxReal getContactOffset() const { return getCore().getContactOffset(); }
84
85 PX_FORCE_INLINE PxU32 getTransformCacheID() const { return getElementID(); }
86
87 PX_FORCE_INLINE PxU32 getSqBoundsId() const { return mSqBoundsId; }
88 PX_FORCE_INLINE void setSqBoundsId(PxU32 id) { mSqBoundsId = id; }
89
90 PX_FORCE_INLINE PxU32 getSqPrunerIndex() const { return mPrunerIndex; }
91 PX_FORCE_INLINE void setSqPrunerIndex(PxU32 index) { mPrunerIndex = index; }
92
93 PX_FORCE_INLINE PxsShapeSim& getLLShapeSim() { return mLLShape; }
94
95 void onFilterDataChange();
96 void onRestOffsetChange();
97 void onFlagChange(PxShapeFlags oldFlags);
98 void onResetFiltering();
99 void onVolumeOrTransformChange();
100 void onMaterialChange(); // remove when material properties are gone from PxcNpWorkUnit
101 void onContactOffsetChange();
102 void markBoundsForUpdate();
103 void reinsertBroadPhase();
104 void removeFromBroadPhase(bool wakeOnLostTouch);
105 void getAbsPoseAligned(PxTransform* PX_RESTRICT globalPose) const;
106
107 PX_FORCE_INLINE RigidSim& getRbSim() const { return static_cast<RigidSim&>(getActor()); }
108 BodySim* getBodySim() const;
109
110 PxsRigidCore& getPxsRigidCore() const;
111
112 void createSqBounds();
113 void destroySqBounds();
114
115 void updateCached(PxU32 transformCacheFlags, PxBitMapPinned* shapeChangedMap);
116 void updateCached(PxsTransformCache& transformCache, Bp::BoundsArray& boundsArray);
117 void updateBPGroup();
118 protected:
119
120 PX_FORCE_INLINE void internalAddToBroadPhase();
121 PX_FORCE_INLINE bool internalRemoveFromBroadPhase(bool wakeOnLostTouch = true);
122 void initSubsystemsDependingOnElementID();
123
124 PxsShapeSim mLLShape;
125 PxU32 mSqBoundsId;
126 PxU32 mPrunerIndex;
127 };
128
129#if PX_P64_FAMILY
130 // PT: to compensate for the padding I removed in PxsShapeSim
131 PX_COMPILE_TIME_ASSERT((sizeof(ShapeSimBase) - sizeof(PxsShapeSim))>=12);
132#else
133 // PX_COMPILE_TIME_ASSERT(32==sizeof(Sc::ShapeSim)); // after removing bounds from shapes
134 // PX_COMPILE_TIME_ASSERT((sizeof(Sc::ShapeSim) % 16) == 0); // aligned mem bounds are better for prefetching
135#endif
136
137 PX_FORCE_INLINE void ShapeSimBase::setCore(const ShapeCore* core)
138 {
139 mLLShape.mShapeCore = const_cast<PxsShapeCore*>(&core->getCore());
140 }
141 PX_FORCE_INLINE const ShapeCore& ShapeSimBase::getCore() const
142 {
143 return Sc::ShapeCore::getCore(*mLLShape.mShapeCore);
144 }
145
146 } // namespace Sc
147}
148
149#endif
Definition BpAABBManagerBase.h:101
Abstract class for collision shapes.
Definition PxShape.h:146
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
Definition PxsTransformCache.h:60
Definition ScActorSim.h:83
Definition ScBodySim.h:60
Definition ScElementSim.h:50
Definition ScRigidSim.h:42
Definition ScShapeCore.h:46
Definition ScShapeSimBase.h:54
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxFlags< PxShapeFlag::Enum, PxU8 > PxShapeFlags
collection of set bits defined in PxShapeFlag.
Definition PxShape.h:126
Enum
Definition PxGeometry.h:52
@ eSIMULATION_SHAPE
The shape will partake in collision in the physical simulation.
Definition PxShape.h:83
@ eTRIGGER_SHAPE
The shape is a trigger which can send reports whenever other shapes enter/leave its volume.
Definition PxShape.h:110
Definition PxvDynamics.h:48
Definition PxvGeometry.h:221
Definition PxsShapeSim.h:40