aboutsummaryrefslogtreecommitdiff
path: root/PhysX_3.4/Source/PhysX/src/NpShape.h
blob: baace112c0610a3f2308fe207cd4b2f2a05e8e60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  


#ifndef PX_PHYSICS_NP_SHAPE
#define PX_PHYSICS_NP_SHAPE

#include "PxShape.h"
#include "buffering/ScbShape.h"
#include "PxMetaData.h"

namespace physx
{

struct NpInternalShapeFlag
{
	enum Enum
	{
		eEXCLUSIVE				= (1<<0)
	};
};

/**
\brief collection of set bits defined in PxShapeFlag.

@see PxShapeFlag
*/
typedef PxFlags<NpInternalShapeFlag::Enum,PxU8> NpInternalShapeFlags;
PX_FLAGS_OPERATORS(NpInternalShapeFlag::Enum,PxU8)


class NpScene;
class NpShapeManager;

namespace Scb
{
	class Scene;
	class RigidObject;
}

namespace Sc
{
	class MaterialCore;
}

class NpShape : public PxShape, public Ps::UserAllocated, public Cm::RefCountable
{
//= ATTENTION! =====================================================================================
// Changing the data layout of this class breaks the binary serialization format.  See comments for 
// PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
// function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
// accordingly.
//==================================================================================================
public:
// PX_SERIALIZATION
												NpShape(PxBaseFlags baseFlags);
	virtual			void						exportExtraData(PxSerializationContext& stream);
					void						importExtraData(PxDeserializationContext& context);
	virtual			void						requiresObjects(PxProcessPxBaseCallback& c);
					void						resolveReferences(PxDeserializationContext& context);
	static			NpShape*					createObject(PxU8*& address, PxDeserializationContext& context);
	static			void						getBinaryMetaData(PxOutputStream& stream);
//~PX_SERIALIZATION
												NpShape(const PxGeometry& geometry,
													PxShapeFlags shapeFlags,
													const PxU16* materialIndices,
													PxU16 materialCount, 
													bool isExclusive);

	virtual										~NpShape();
	
	//---------------------------------------------------------------------------------
	// PxShape implementation
	//---------------------------------------------------------------------------------
	virtual			void						release(); //!< call to release from actor
	virtual			void						acquireReference();

	virtual			PxGeometryType::Enum		getGeometryType() const;

	virtual			void						setGeometry(const PxGeometry&);
	virtual			PxGeometryHolder			getGeometry() const;
	virtual			bool						getBoxGeometry(PxBoxGeometry&) const;
	virtual			bool						getSphereGeometry(PxSphereGeometry&) const;
	virtual			bool						getCapsuleGeometry(PxCapsuleGeometry&) const;
	virtual			bool						getPlaneGeometry(PxPlaneGeometry&) const;
	virtual			bool						getConvexMeshGeometry(PxConvexMeshGeometry& g) const;
	virtual			bool						getTriangleMeshGeometry(PxTriangleMeshGeometry& g) const;
	virtual			bool						getHeightFieldGeometry(PxHeightFieldGeometry& g) const;

	virtual			PxRigidActor*				getActor() const;

	virtual			void						setLocalPose(const PxTransform& pose);
	virtual			PxTransform					getLocalPose() const;

	virtual			void						setSimulationFilterData(const PxFilterData& data);
	virtual			PxFilterData				getSimulationFilterData() const;
	virtual			void						setQueryFilterData(const PxFilterData& data);
	virtual			PxFilterData				getQueryFilterData() const;

	virtual			void						setMaterials(PxMaterial*const* materials, PxU16 materialCount);
	virtual			PxU16						getNbMaterials()															const;
	virtual			PxU32						getMaterials(PxMaterial** userBuffer, PxU32 bufferSize, PxU32 startIndex=0)	const;
	virtual			PxMaterial*					getMaterialFromInternalFaceIndex(PxU32 faceIndex)							const;

	virtual			void						setContactOffset(PxReal);
	virtual			PxReal						getContactOffset() const;

	virtual			void						setRestOffset(PxReal);
	virtual			PxReal						getRestOffset() const;

	virtual			void						setFlag(PxShapeFlag::Enum flag, bool value);
	virtual			void						setFlags( PxShapeFlags inFlags );
	virtual			PxShapeFlags				getFlags() const;

	virtual			bool						isExclusive() const;

	virtual			void					    setName(const char* debugName);
	virtual			const char*					getName() const;

	//---------------------------------------------------------------------------------
	// RefCountable implementation
	//---------------------------------------------------------------------------------

	// Ref counting for shapes works like this: 
	// * for exclusive shapes the actor has a counted reference
	// * for shared shapes, each actor has a counted reference, and the user has a counted reference
	// * for either kind, each instance of the shape in a scene (i.e. each shapeSim) causes the reference count to be incremented by 1.
	// Because these semantics aren't clear to users, this reference count should not be exposed in the API

	virtual			void						onRefCountZero();

	//---------------------------------------------------------------------------------
	// Miscellaneous
	//---------------------------------------------------------------------------------

					void						setFlagsInternal( PxShapeFlags inFlags );

	PX_FORCE_INLINE	PxShapeFlags				getFlagsFast()			const	{ return mShape.getFlags();									}
	PX_FORCE_INLINE	PxShapeFlags				getFlagsUnbuffered()	const	{ return mShape.getScShape().getFlags();					}
	PX_FORCE_INLINE	PxGeometryType::Enum		getGeometryTypeFast()	const	{ return mShape.getGeometryType();							}
	PX_FORCE_INLINE	const Gu::GeometryUnion&	getGeometryFast()		const	{ return mShape.getGeometryUnion();							}
	PX_FORCE_INLINE const PxTransform&			getLocalPoseFast()		const	{ return mShape.getShape2Actor();							}
	PX_FORCE_INLINE PxU32						getActorCount()			const	{ return PxU32(mExclusiveAndActorCount & ACTOR_COUNT_MASK);	}
	PX_FORCE_INLINE PxI32						isExclusiveFast()		const	{ return mExclusiveAndActorCount & EXCLUSIVE_MASK;			}

	PX_FORCE_INLINE	const PxFilterData&			getQueryFilterDataFast() const
												{
													return mShape.getScShape().getQueryFilterData();	// PT: this one doesn't need double-buffering
												}

	PX_FORCE_INLINE	const Scb::Shape&			getScbShape()			const	{ return mShape;	}
	PX_FORCE_INLINE	Scb::Shape&					getScbShape()					{ return mShape;	}

	PX_INLINE		PxMaterial*					getMaterial(PxU32 index) const { return mShape.getMaterial(index); }
	static			bool						checkMaterialSetup(const PxGeometry& geom, const char* errorMsgPrefix, PxMaterial*const* materials, PxU16 materialCount);

					void						onActorAttach(PxRigidActor& actor);
					void						onActorDetach();

					// These methods are used only for sync'ing, and may only be called on exclusive shapes since only exclusive shapes have buffering
					Sc::RigidCore&				getScRigidObjectExclusive() const;
					void						releaseInternal();

					NpScene*					getOwnerScene()				const;	// same distinctions as for NpActor
private:
					NpScene*					getAPIScene()				const;

					void						incMeshRefCount();
					void						decMeshRefCount();
					Cm::RefCountable*			getMeshRefCountable();
					bool						isWritable();
					void						updateSQ(const char* errorMessage);

					PxRigidActor*				mActor;							// Auto-resolving refs breaks DLL loading for some reason
					Scb::Shape					mShape;
					const char*					mName;

					static const PxI32 EXCLUSIVE_MASK = 0x80000000;
					static const PxI32 ACTOR_COUNT_MASK = 0x7fffffff;
					
					volatile PxI32				mExclusiveAndActorCount;
};

}

#endif