29#ifndef NP_RIGID_ACTOR_TEMPLATE_H
30#define NP_RIGID_ACTOR_TEMPLATE_H
32#include "NpActorTemplate.h"
33#include "NpShapeManager.h"
34#include "NpConstraint.h"
39#include "foundation/PxErrors.h"
41#include "omnipvd/OmniPvdPxSampler.h"
45template<
class APIClass>
55 NpBase::mFreeSlot = 0xFFFFFFFF;
58 void preExportDataReset();
76 virtual PxU32 getInternalActorIndex()
const PX_OVERRIDE;
80 virtual PxU32 getShapes(
PxShape** buffer, PxU32 bufferSize, PxU32 startIndex=0)
const PX_OVERRIDE;
82 virtual PxU32 getConstraints(
PxConstraint** userBuffer, PxU32 bufferSize, PxU32 startIndex=0)
const PX_OVERRIDE;
87 virtual void switchToNoSim() { PX_ASSERT(
false); }
88 virtual void switchFromNoSim() { PX_ASSERT(
false); }
93 void updateShaderComs();
98 PX_FORCE_INLINE PxU32 getRigidActorArrayIndex()
const {
return NpBase::mFreeSlot; }
99 PX_FORCE_INLINE void setRigidActorArrayIndex(PxU32 index) { NpBase::mFreeSlot = index; }
103 PX_FORCE_INLINE PxU32 getRigidActorSceneIndex()
const {
return NpBase::getBaseIndex(); }
104 PX_FORCE_INLINE void setRigidActorSceneIndex(PxU32 index) { NpBase::setBaseIndex(index); }
108#if PX_ENABLE_DEBUG_VISUALIZATION
112 PX_CATCH_UNDEFINED_ENABLE_DEBUG_VISUALIZATION
126template<
class APIClass>
130 PxU32 nbShapes = mShapeManager.getNbShapes();
131 for(PxU32 i=0;i<nbShapes;i++)
133 NpShape* np = mShapeManager.getShapes()[i];
138template<
class APIClass>
139void NpRigidActorTemplate<APIClass>::preExportDataReset()
144 Sc::ActorCore& actorCore = NpActor::getActorCore();
145 actorCore.setAggregateID(PX_INVALID_U32);
146 mShapeManager.preExportDataReset();
148 NpBase::mFreeSlot = 0xFFFFFFFF;
149 NpBase::setBaseIndex(NP_UNUSED_BASE_INDEX);
152template<
class APIClass>
153void NpRigidActorTemplate<APIClass>::exportExtraData(PxSerializationContext&
context)
155 mShapeManager.exportExtraData(
context);
156 ActorTemplateClass::exportExtraData(
context);
159template<
class APIClass>
160void NpRigidActorTemplate<APIClass>::importExtraData(PxDeserializationContext&
context)
162 mShapeManager.importExtraData(
context);
163 ActorTemplateClass::importExtraData(
context);
166template<
class APIClass>
167void NpRigidActorTemplate<APIClass>::resolveReferences(PxDeserializationContext&
context)
169 const PxU32 nbShapes = mShapeManager.getNbShapes();
170 NpShape** shapes =
const_cast<NpShape**
>(mShapeManager.getShapes());
171 for(PxU32 j=0;j<nbShapes;j++)
173 context.translatePxBase(shapes[j]);
174 shapes[j]->onActorAttach(*
this);
177 ActorTemplateClass::resolveReferences(
context);
182template<
class APIClass>
183NpRigidActorTemplate<APIClass>::NpRigidActorTemplate(PxType concreteType, PxBaseFlags baseFlags, NpType::Enum type) :
184 ActorTemplateClass (concreteType, baseFlags, type)
187 NpBase::mFreeSlot = 0xFFFFFFFF;
190template<
class APIClass>
191NpRigidActorTemplate<APIClass>::~NpRigidActorTemplate()
196template<
class APIClass>
197PxU32 NpRigidActorTemplate<APIClass>::getInternalActorIndex()
const
199 NP_READ_CHECK(ActorTemplateClass::getNpScene());
201 const PxU32 index = NpBase::getBaseIndex();
202 return index!=NP_UNUSED_BASE_INDEX ? index : 0xffffffff;
205template<
class APIClass>
206void NpRigidActorTemplate<APIClass>::removeShapes(PxSceneQuerySystem* sqManager)
208 if(mShapeManager.getPruningStructure())
211 mShapeManager.getPruningStructure()->invalidate(
this);
214 mShapeManager.detachAll(sqManager, *
this);
217template<
class APIClass>
218bool NpRigidActorTemplate<APIClass>::attachShape(PxShape& shape)
220 NpScene* npScene = ActorTemplateClass::getNpScene();
221 NP_WRITE_CHECK(npScene);
222 NpShape& npShape =
static_cast<NpShape&
>(shape);
223 PX_CHECK_AND_RETURN_VAL(!
static_cast<NpShape&
>(shape).isExclusive() || shape.
getActor()==NULL,
"PxRigidActor::attachShape: shape must be shared or unowned",
false);
224 PX_CHECK_AND_RETURN_VAL(!(npShape.getCore().getCore().mShapeCoreFlags & PxShapeCoreFlag::eSOFT_BODY_SHAPE),
"PxRigidActor::attachShape() not allowed to attach a soft body shape to a rigid actor",
false);
225 PX_CHECK_AND_RETURN_VAL(!(npShape.getCore().getCore().mShapeCoreFlags & PxShapeCoreFlag::eCLOTH_SHAPE),
"PxRigidActor::attachShape() not allowed to attach a cloth shape to a rigid actor",
false);
227 PX_CHECK_SCENE_API_WRITE_FORBIDDEN_AND_RETURN_VAL(npScene,
"PxRigidActor::attachShape() not allowed while simulation is running. Call will be ignored.",
false);
231 if (mShapeManager.getPruningStructure())
234 mShapeManager.getPruningStructure()->invalidate(
this);
237 mShapeManager.attachShape(npShape, *
this);
239 OMNI_PVD_ADD(actor, shapes,
static_cast<PxActor&
>(*
this), shape)
244template<
class APIClass>
245void NpRigidActorTemplate<APIClass>::detachShape(PxShape& shape,
bool wakeOnLostTouch)
247 NpScene* npScene = ActorTemplateClass::getNpScene();
248 NP_WRITE_CHECK(npScene);
250 PX_CHECK_SCENE_API_WRITE_FORBIDDEN(npScene,
"PxRigidActor::detachShape() not allowed while simulation is running. Call will be ignored.")
252 OMNI_PVD_REMOVE(actor, shapes, static_cast<PxActor&>(*this), shape)
254 if (mShapeManager.getPruningStructure())
257 mShapeManager.getPruningStructure()->invalidate(
this);
260 if(!mShapeManager.detachShape(
static_cast<NpShape&
>(shape), *
this, wakeOnLostTouch))
266template<
class APIClass>
267PxU32 NpRigidActorTemplate<APIClass>::getNbShapes()
const
269 NP_READ_CHECK(ActorTemplateClass::getNpScene());
270 return mShapeManager.getNbShapes();
273template<
class APIClass>
274PxU32 NpRigidActorTemplate<APIClass>::getShapes(PxShape** buffer, PxU32 bufferSize, PxU32 startIndex)
const
276 NP_READ_CHECK(ActorTemplateClass::getNpScene());
277 return mShapeManager.getShapes(buffer, bufferSize, startIndex);
280template<
class APIClass>
281PxU32 NpRigidActorTemplate<APIClass>::getNbConstraints()
const
283 NP_READ_CHECK(ActorTemplateClass::getNpScene());
284 return ActorTemplateClass::getNbConnectors(NpConnectorType::eConstraint);
287template<
class APIClass>
288PxU32 NpRigidActorTemplate<APIClass>::getConstraints(PxConstraint** buffer, PxU32 bufferSize, PxU32 startIndex)
const
290 NP_READ_CHECK(ActorTemplateClass::getNpScene());
291 return ActorTemplateClass::template getConnectors<PxConstraint>(NpConnectorType::eConstraint, buffer, bufferSize, startIndex);
296template<
class APIClass>
297PxBounds3 NpRigidActorTemplate<APIClass>::getWorldBounds(
float inflation)
const
299 NP_READ_CHECK(ActorTemplateClass::getNpScene());
301 PX_CHECK_SCENE_API_READ_FORBIDDEN_EXCEPT_COLLIDE_AND_RETURN_VAL(ActorTemplateClass::getNpScene(),
"PxRigidActor::getWorldBounds() not allowed while simulation is running (except during PxScene::collide()).",
PxBounds3::empty());
304 const PxBounds3 bounds = mShapeManager.getWorldBounds_(*
this);
305 PX_ASSERT(bounds.isValid());
308 const PxVec3 center = bounds.getCenter();
309 const PxVec3 inflatedExtents = bounds.getExtents() * inflation;
313template<
class APIClass>
314PX_FORCE_INLINE void NpRigidActorTemplate<APIClass>::setActorSimFlag(
bool value)
316 NpScene* scene = ActorTemplateClass::getNpScene();
318 PxActorFlags oldFlags = ActorTemplateClass::getActorFlags();
321 PX_CHECK_AND_RETURN((getType() !=
PxActorType::eARTICULATION_LINK) || (!value && !hadNoSimFlag),
"PxActor::setActorFlag: PxActorFlag::eDISABLE_SIMULATION is only supported by PxRigidDynamic and PxRigidStatic objects.");
323 if (hadNoSimFlag && (!value))
328 NpActor::addConstraintsToScene();
330 else if ((!hadNoSimFlag) && value)
333 NpActor::removeConstraintsFromScene();
339template<
class APIClass>
340void NpRigidActorTemplate<APIClass>::setActorFlag(
PxActorFlag::Enum flag,
bool value)
342 NpScene* npScene = ActorTemplateClass::getNpScene();
343 NP_WRITE_CHECK(npScene);
345 PX_CHECK_SCENE_API_WRITE_FORBIDDEN(npScene,
"PxRigidActor::setActorFlag() not allowed while simulation is running. Call will be ignored.")
347 if (flag == PxActorFlag::eDISABLE_SIMULATION)
348 setActorSimFlag(value);
350 ActorTemplateClass::setActorFlagInternal(flag, value);
353template<class APIClass>
354void NpRigidActorTemplate<APIClass>::setActorFlags(
PxActorFlags inFlags)
356 NpScene* npScene = ActorTemplateClass::getNpScene();
357 NP_WRITE_CHECK(npScene);
359 PX_CHECK_SCENE_API_WRITE_FORBIDDEN(npScene,
"PxRigidActor::setActorFlags() not allowed while simulation is running. Call will be ignored.")
361 bool noSim = inFlags.isSet(PxActorFlag::eDISABLE_SIMULATION);
362 setActorSimFlag(noSim);
364 ActorTemplateClass::setActorFlagsInternal(inFlags);
367template<class APIClass>
368void NpRigidActorTemplate<APIClass>::updateShaderComs()
370 NpConnectorIterator iter = ActorTemplateClass::getConnectorIterator(NpConnectorType::eConstraint);
371 while (PxBase* ser = iter.getNext())
373 NpConstraint* c =
static_cast<NpConstraint*
>(ser);
378template<
class APIClass>
379bool NpRigidActorTemplate<APIClass>::resetFiltering_(NpActor& ro, Sc::RigidCore& core, PxShape*
const* shapes, PxU32 shapeCount)
382 PX_CHECK_AND_RETURN_VAL(!(ro.getActorFlags().isSet(
PxActorFlag::eDISABLE_SIMULATION)),
"PxScene::resetFiltering(): Not allowed if PxActorFlag::eDISABLE_SIMULATION is set!",
false);
383 for(PxU32 i=0; i < shapeCount; i++)
385 PxRigidActor* ra = shapes[i]->getActor();
391 NpShape*
const* sh = mShapeManager.getShapes();
392 for(PxU32 j=0; j < mShapeManager.getNbShapes(); j++)
394 if (sh[j] == shapes[i])
402 PX_CHECK_AND_RETURN_VAL(found,
"PxScene::resetFiltering(): specified shape not in actor!",
false);
412 sCount = mShapeManager.getNbShapes();
414 PX_ALLOCA(scShapes, NpShape*, sCount);
420 for(PxU32 i=0; i < sCount; i++)
421 scShapes[sAccepted++] =
static_cast<NpShape*
>(shapes[i]);
427 NpShape*
const* sh = mShapeManager.getShapes();
429 for(PxU32 i=0; i < sCount; i++)
432 scShapes[sAccepted++] = sh[i];
440 PX_ASSERT(!ro.isAPIWriteForbidden());
444 for(PxU32 i=0; i < sCount; i++)
445 core.onShapeChange(scShapes[i]->getCore(), Sc::ShapeChangeNotifyFlag::eRESET_FILTERING);
452#if PX_ENABLE_DEBUG_VISUALIZATION
453template<
class APIClass>
454void NpRigidActorTemplate<APIClass>::visualize(PxRenderOutput& out, NpScene& scene,
float scale)
const
456 mShapeManager.visualize(out, scene, *
this, scale);
459 PX_CATCH_UNDEFINED_ENABLE_DEBUG_VISUALIZATION
Definition NpActorTemplate.h:54
Definition NpRigidActorTemplate.h:47
Definition NpShapeManager.h:61
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 empty()
Return empty bounds.
Definition PxBounds3.h:284
static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 centerExtents(const PxVec3 ¢er, const PxVec3 &extent)
returns the AABB from center and extents vectors.
Definition PxBounds3.h:299
A plugin class for implementing constraints.
Definition PxConstraint.h:100
Binary deserialization context class.
Definition PxSerialFramework.h:174
Callback class used to process PxBase objects.
Definition PxSerialFramework.h:81
Definition PxRenderOutput.h:50
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
virtual PxRigidActor * getActor() const =0
Retrieves the actor which this shape is associated with.
Definition ScRigidCore.h:61
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_OVERRIDE
Definition PxPreprocessor.h:375
PX_C_EXPORT PX_FOUNDATION_API physx::PxFoundation &PX_CALL_CONV PxGetFoundation()
Retrieves the Foundation SDK after it has been created.
Definition FdFoundation.cpp:279
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxFlags< PxActorFlag::Enum, PxU8 > PxActorFlags
collection of set bits defined in PxActorFlag.
Definition PxActor.h:111
Enum
Definition PxActor.h:66
@ eDISABLE_SIMULATION
Disables simulation for the actor.
Definition PxActor.h:102
Enum
Definition PxActor.h:121
@ eARTICULATION_LINK
An articulation link.
Definition PxActor.h:138
@ eINVALID_OPERATION
method was called at a time when an operation is not possible
Definition PxErrors.h:65
@ 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