1 | // |
2 | // Redistribution and use in source and binary forms, with or without |
3 | // modification, are permitted provided that the following conditions |
4 | // are met: |
5 | // * Redistributions of source code must retain the above copyright |
6 | // notice, this list of conditions and the following disclaimer. |
7 | // * Redistributions in binary form must reproduce the above copyright |
8 | // notice, this list of conditions and the following disclaimer in the |
9 | // documentation and/or other materials provided with the distribution. |
10 | // * Neither the name of NVIDIA CORPORATION nor the names of its |
11 | // contributors may be used to endorse or promote products derived |
12 | // from this software without specific prior written permission. |
13 | // |
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | // |
26 | // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. |
27 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
28 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
29 | |
30 | |
31 | #ifndef PX_PHYSICS_NP_SHAPE |
32 | #define PX_PHYSICS_NP_SHAPE |
33 | |
34 | #include "common/PxMetaData.h" |
35 | #include "PxShape.h" |
36 | #include "buffering/ScbShape.h" |
37 | |
38 | namespace physx |
39 | { |
40 | |
41 | struct NpInternalShapeFlag |
42 | { |
43 | enum Enum |
44 | { |
45 | eEXCLUSIVE = (1<<0) |
46 | }; |
47 | }; |
48 | |
49 | /** |
50 | \brief collection of set bits defined in PxShapeFlag. |
51 | |
52 | @see PxShapeFlag |
53 | */ |
54 | typedef PxFlags<NpInternalShapeFlag::Enum,PxU8> NpInternalShapeFlags; |
55 | PX_FLAGS_OPERATORS(NpInternalShapeFlag::Enum,PxU8) |
56 | |
57 | |
58 | class NpScene; |
59 | class NpShapeManager; |
60 | |
61 | namespace Scb |
62 | { |
63 | class Scene; |
64 | class RigidObject; |
65 | } |
66 | |
67 | namespace Sc |
68 | { |
69 | class MaterialCore; |
70 | } |
71 | |
72 | class NpShape : public PxShape, public Ps::UserAllocated, public Cm::RefCountable |
73 | { |
74 | //= ATTENTION! ===================================================================================== |
75 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
76 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
77 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
78 | // accordingly. |
79 | //================================================================================================== |
80 | public: |
81 | // PX_SERIALIZATION |
82 | NpShape(PxBaseFlags baseFlags); |
83 | void preExportDataReset(); |
84 | virtual void (PxSerializationContext& context); |
85 | void (PxDeserializationContext& context); |
86 | virtual void requiresObjects(PxProcessPxBaseCallback& c); |
87 | void resolveReferences(PxDeserializationContext& context); |
88 | static NpShape* createObject(PxU8*& address, PxDeserializationContext& context); |
89 | static void getBinaryMetaData(PxOutputStream& stream); |
90 | //~PX_SERIALIZATION |
91 | NpShape(const PxGeometry& geometry, |
92 | PxShapeFlags shapeFlags, |
93 | const PxU16* materialIndices, |
94 | PxU16 materialCount, |
95 | bool isExclusive); |
96 | |
97 | virtual ~NpShape(); |
98 | |
99 | //--------------------------------------------------------------------------------- |
100 | // PxShape implementation |
101 | //--------------------------------------------------------------------------------- |
102 | virtual void release(); //!< call to release from actor |
103 | virtual PxU32 getReferenceCount() const; |
104 | virtual void acquireReference(); |
105 | |
106 | virtual PxGeometryType::Enum getGeometryType() const; |
107 | |
108 | virtual void setGeometry(const PxGeometry&); |
109 | virtual PxGeometryHolder getGeometry() const; |
110 | virtual bool getBoxGeometry(PxBoxGeometry&) const; |
111 | virtual bool getSphereGeometry(PxSphereGeometry&) const; |
112 | virtual bool getCapsuleGeometry(PxCapsuleGeometry&) const; |
113 | virtual bool getPlaneGeometry(PxPlaneGeometry&) const; |
114 | virtual bool getConvexMeshGeometry(PxConvexMeshGeometry& g) const; |
115 | virtual bool getTriangleMeshGeometry(PxTriangleMeshGeometry& g) const; |
116 | virtual bool getHeightFieldGeometry(PxHeightFieldGeometry& g) const; |
117 | |
118 | virtual PxRigidActor* getActor() const; |
119 | |
120 | virtual void setLocalPose(const PxTransform& pose); |
121 | virtual PxTransform getLocalPose() const; |
122 | |
123 | virtual void setSimulationFilterData(const PxFilterData& data); |
124 | virtual PxFilterData getSimulationFilterData() const; |
125 | virtual void setQueryFilterData(const PxFilterData& data); |
126 | virtual PxFilterData getQueryFilterData() const; |
127 | |
128 | virtual void setMaterials(PxMaterial*const* materials, PxU16 materialCount); |
129 | virtual PxU16 getNbMaterials() const; |
130 | virtual PxU32 getMaterials(PxMaterial** userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const; |
131 | virtual PxMaterial* getMaterialFromInternalFaceIndex(PxU32 faceIndex) const; |
132 | |
133 | virtual void setContactOffset(PxReal); |
134 | virtual PxReal getContactOffset() const; |
135 | |
136 | virtual void setRestOffset(PxReal); |
137 | virtual PxReal getRestOffset() const; |
138 | |
139 | virtual void setTorsionalPatchRadius(PxReal); |
140 | virtual PxReal getTorsionalPatchRadius() const; |
141 | |
142 | virtual void setMinTorsionalPatchRadius(PxReal); |
143 | virtual PxReal getMinTorsionalPatchRadius() const; |
144 | |
145 | virtual void setFlag(PxShapeFlag::Enum flag, bool value); |
146 | virtual void setFlags( PxShapeFlags inFlags ); |
147 | virtual PxShapeFlags getFlags() const; |
148 | |
149 | virtual bool isExclusive() const; |
150 | |
151 | virtual void setName(const char* debugName); |
152 | virtual const char* getName() const; |
153 | |
154 | //--------------------------------------------------------------------------------- |
155 | // RefCountable implementation |
156 | //--------------------------------------------------------------------------------- |
157 | |
158 | // Ref counting for shapes works like this: |
159 | // * for exclusive shapes the actor has a counted reference |
160 | // * for shared shapes, each actor has a counted reference, and the user has a counted reference |
161 | // * for either kind, each instance of the shape in a scene (i.e. each shapeSim) causes the reference count to be incremented by 1. |
162 | // Because these semantics aren't clear to users, this reference count should not be exposed in the API |
163 | |
164 | virtual void onRefCountZero(); |
165 | |
166 | //--------------------------------------------------------------------------------- |
167 | // Miscellaneous |
168 | //--------------------------------------------------------------------------------- |
169 | |
170 | void setFlagsInternal( PxShapeFlags inFlags ); |
171 | |
172 | PX_FORCE_INLINE PxShapeFlags getFlagsFast() const { return mShape.getFlags(); } |
173 | PX_FORCE_INLINE PxShapeFlags getFlagsUnbuffered() const { return mShape.getScShape().getFlags(); } |
174 | PX_FORCE_INLINE PxGeometryType::Enum getGeometryTypeFast() const { return mShape.getGeometryType(); } |
175 | PX_FORCE_INLINE const Gu::GeometryUnion& getGeometryFast() const { return mShape.getGeometryUnion(); } |
176 | PX_FORCE_INLINE const PxTransform& getLocalPoseFast() const { return mShape.getShape2Actor(); } |
177 | PX_FORCE_INLINE PxU32 getActorCount() const { return PxU32(mExclusiveAndActorCount & ACTOR_COUNT_MASK); } |
178 | PX_FORCE_INLINE PxI32 isExclusiveFast() const { return mExclusiveAndActorCount & EXCLUSIVE_MASK; } |
179 | |
180 | PX_FORCE_INLINE const PxFilterData& getQueryFilterDataFast() const |
181 | { |
182 | return mShape.getScShape().getQueryFilterData(); // PT: this one doesn't need double-buffering |
183 | } |
184 | |
185 | PX_FORCE_INLINE const Scb::Shape& getScbShape() const { return mShape; } |
186 | PX_FORCE_INLINE Scb::Shape& getScbShape() { return mShape; } |
187 | static PX_FORCE_INLINE size_t getScbShapeOffset() { return PX_OFFSET_OF_RT(NpShape, mShape); } |
188 | |
189 | PX_INLINE PxMaterial* getMaterial(PxU32 index) const { return mShape.getMaterial(index); } |
190 | static bool checkMaterialSetup(const PxGeometry& geom, const char* errorMsgPrefix, PxMaterial*const* materials, PxU16 materialCount); |
191 | |
192 | void onActorAttach(PxRigidActor& actor); |
193 | void onActorDetach(); |
194 | |
195 | // These methods are used only for sync'ing, and may only be called on exclusive shapes since only exclusive shapes have buffering |
196 | Sc::RigidCore& getScRigidObjectExclusive() const; |
197 | void releaseInternal(); |
198 | |
199 | NpScene* getOwnerScene() const; // same distinctions as for NpActor |
200 | private: |
201 | NpScene* getAPIScene() const; |
202 | |
203 | void incMeshRefCount(); |
204 | void decMeshRefCount(); |
205 | Cm::RefCountable* getMeshRefCountable(); |
206 | bool isWritable(); |
207 | void updateSQ(const char* errorMessage); |
208 | |
209 | PxRigidActor* mActor; // Auto-resolving refs breaks DLL loading for some reason |
210 | Scb::Shape mShape; |
211 | const char* mName; |
212 | |
213 | static const PxI32 EXCLUSIVE_MASK = 0x80000000; |
214 | static const PxI32 ACTOR_COUNT_MASK = 0x7fffffff; |
215 | |
216 | volatile PxI32 mExclusiveAndActorCount; |
217 | }; |
218 | |
219 | } |
220 | |
221 | #endif |
222 | |