| 1 | /* |
| 2 | * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
| 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property |
| 5 | * and proprietary rights in and to this software, related documentation |
| 6 | * and any modifications thereto. Any use, reproduction, disclosure or |
| 7 | * distribution of this software and related documentation without an express |
| 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. |
| 9 | */ |
| 10 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
| 11 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
| 12 | |
| 13 | |
| 14 | #ifndef PX_PHYSICS_NX_SCENEDESC |
| 15 | #define PX_PHYSICS_NX_SCENEDESC |
| 16 | /** \addtogroup physics |
| 17 | @{ |
| 18 | */ |
| 19 | |
| 20 | #include "PxPhysXConfig.h" |
| 21 | #include "foundation/PxFlags.h" |
| 22 | #include "foundation/PxBounds3.h" |
| 23 | #include "PxFiltering.h" |
| 24 | #include "PxBroadPhase.h" |
| 25 | #include "common/PxTolerancesScale.h" |
| 26 | |
| 27 | #ifndef PX_DOXYGEN |
| 28 | namespace physx |
| 29 | { |
| 30 | #endif |
| 31 | |
| 32 | class PxCpuDispatcher; |
| 33 | class PxGpuDispatcher; |
| 34 | class PxSpuDispatcher; |
| 35 | |
| 36 | /** |
| 37 | \brief Pruning structure used to accelerate scene queries. |
| 38 | |
| 39 | eNONE uses a simple data structure that consumes less memory than the alternatives, |
| 40 | but generally has slower query performance. |
| 41 | |
| 42 | eDYNAMIC_AABB_TREE usually provides the fastest queries. However there is a |
| 43 | constant per-frame management cost associated with this structure. How much work should |
| 44 | be done per frame can be tuned via the #PxSceneDesc::dynamicTreeRebuildRateHint |
| 45 | parameter. |
| 46 | |
| 47 | eSTATIC_AABB_TREE is typically used for static objects. It is the same as the |
| 48 | dynamic AABB tree, without the per-frame overhead. This can be a good choice for static |
| 49 | objects, if no static objects are added, moved or removed after the scene has been |
| 50 | created. If there is no such guarantee (e.g. when streaming parts of the world in and out), |
| 51 | then the dynamic version is a better choice even for static objects. |
| 52 | */ |
| 53 | struct PxPruningStructure |
| 54 | { |
| 55 | enum Enum |
| 56 | { |
| 57 | eNONE, //!< Using a simple data structure |
| 58 | eDYNAMIC_AABB_TREE, //!< Using a dynamic AABB tree |
| 59 | eSTATIC_AABB_TREE, //!< Using a static AABB tree |
| 60 | |
| 61 | eLAST |
| 62 | }; |
| 63 | }; |
| 64 | |
| 65 | |
| 66 | /** |
| 67 | \brief The order in which collide and solve are run in a normal simulation time-step |
| 68 | |
| 69 | eCOLLIDE_SOLVE Indicates that collide is performed before solve |
| 70 | eSOLVE_COLLIDE Indicates that solve is performed before collide <b>(This feature is currently disabled)</b> |
| 71 | |
| 72 | */ |
| 73 | |
| 74 | struct PxSimulationOrder |
| 75 | { |
| 76 | enum Enum |
| 77 | { |
| 78 | eCOLLIDE_SOLVE, //!< Perform collide before solve |
| 79 | eSOLVE_COLLIDE //!< Perform solve before collide |
| 80 | }; |
| 81 | }; |
| 82 | |
| 83 | |
| 84 | |
| 85 | /** |
| 86 | \brief Enum for selecting the friction algorithm used for simulation. |
| 87 | |
| 88 | #PxFrictionType::ePATCH selects the patch friction model which typically leads to the most stable results at low solver iteration counts and is also quite inexpensive, as it uses only |
| 89 | up to four scalar solver constraints per pair of touching objects. The patch friction model is the same basic strong friction algorithm as PhysX 3.2 and before. |
| 90 | |
| 91 | #PxFrictionType::eONE_DIRECTIONAL is a simplification of the Coulomb friction model, in which the friction for a given point of contact is applied in the alternating tangent directions of |
| 92 | the contact's normal. This simplification allows us to reduce the number of iterations required for convergence but is not as accurate as the two directional model. |
| 93 | |
| 94 | #PxFrictionType::eTWO_DIRECTIONAL is identical to the one directional model, but it applies friction in both tangent directions simultaneously. This hurts convergence a bit so it |
| 95 | requires more solver iterations, but is more accurate. Like the one directional model, it is applied at every contact point, which makes it potentially more expensive |
| 96 | than patch friction for scenarios with many contact points. |
| 97 | */ |
| 98 | struct PxFrictionType |
| 99 | { |
| 100 | enum Enum |
| 101 | { |
| 102 | ePATCH, //!< Select default patch-friction model. |
| 103 | eONE_DIRECTIONAL, //!< Select one directional per-contact friction model. |
| 104 | eTWO_DIRECTIONAL //!< Select two directional per-contact friction model. |
| 105 | }; |
| 106 | }; |
| 107 | |
| 108 | /** |
| 109 | \brief flags for configuring properties of the scene |
| 110 | |
| 111 | @see PxScene |
| 112 | */ |
| 113 | |
| 114 | struct PxSceneFlag |
| 115 | { |
| 116 | enum Enum |
| 117 | { |
| 118 | /** |
| 119 | \brief Enable Active Transform Notification. |
| 120 | |
| 121 | This flag enables the the Active Transform Notification feature for a scene. This |
| 122 | feature defaults to disabled. When disabled, the function |
| 123 | PxScene::getActiveTransforms() will always return a NULL list. |
| 124 | |
| 125 | \note There may be a performance penalty for enabling the Active Transform Notification, hence this flag should |
| 126 | only be enabled if the application intends to use the feature. |
| 127 | |
| 128 | <b>Default:</b> False |
| 129 | */ |
| 130 | eENABLE_ACTIVETRANSFORMS =(1<<1), |
| 131 | |
| 132 | /** |
| 133 | \brief Enables a second broad phase check after integration that makes it possible to prevent objects from tunneling through eachother. |
| 134 | |
| 135 | PxPairFlag::eDETECT_CCD_CONTACT requires this flag to be specified. |
| 136 | |
| 137 | \note For this feature to be effective for bodies that can move at a significant velocity, the user should raise the flag PxRigidBodyFlag::eENABLE_CCD for them. |
| 138 | \note This flag is not mutable, and must be set in PxSceneDesc at scene creation. |
| 139 | |
| 140 | <b>Default:</b> False |
| 141 | |
| 142 | @see PxRigidBodyFlag::eENABLE_CCD, PxPairFlag::eDETECT_CCD_CONTACT, eDISABLE_CCD_RESWEEP |
| 143 | */ |
| 144 | eENABLE_CCD =(1<<2), |
| 145 | |
| 146 | /** |
| 147 | \brief Enables a simplified swept integration strategy, which sacrifices some accuracy for improved performance. |
| 148 | |
| 149 | This simplified swept integration approach makes certain assumptions about the motion of objects that are not made when using a full swept integration. |
| 150 | These assumptions usually hold but there are cases where they could result in incorrect behavior between a set of fast-moving rigid bodies. A key issue is that |
| 151 | fast-moving dynamic objects may tunnel through each-other after a rebound. This will not happen if this mode is disabled. However, this approach will be potentially |
| 152 | faster than a full swept integration because it will perform significantly fewer sweeps in non-trivial scenes involving many fast-moving objects. This approach |
| 153 | should successfully resist objects passing through the static environment. |
| 154 | |
| 155 | PxPairFlag::eDETECT_CCD_CONTACT requires this flag to be specified. |
| 156 | |
| 157 | \note This scene flag requires eENABLE_CCD to be enabled as well. If it is not, this scene flag will do nothing. |
| 158 | \note For this feature to be effective for bodies that can move at a significant velocity, the user should raise the flag PxRigidBodyFlag::eENABLE_CCD for them. |
| 159 | \note This flag is not mutable, and must be set in PxSceneDesc at scene creation. |
| 160 | |
| 161 | <b>Default:</b> False |
| 162 | |
| 163 | @see PxRigidBodyFlag::eENABLE_CCD, PxPairFlag::eDETECT_CCD_CONTACT, eENABLE_CCD |
| 164 | */ |
| 165 | eDISABLE_CCD_RESWEEP =(1<<3), |
| 166 | |
| 167 | |
| 168 | /** |
| 169 | \brief Enable adaptive forces to accelerate convergence of the solver. |
| 170 | |
| 171 | \note This flag is not mutable, and must be set in PxSceneDesc at scene creation. |
| 172 | |
| 173 | <b>Default:</b> false |
| 174 | */ |
| 175 | eADAPTIVE_FORCE =(1<<4), |
| 176 | |
| 177 | |
| 178 | /** |
| 179 | \brief Enable contact pair filtering between kinematic and static rigid bodies. |
| 180 | |
| 181 | By default contacts between kinematic and static rigid bodies are suppressed (see #PxFilterFlag::eSUPPRESS) and don't get reported to the filter mechanism. |
| 182 | Raise this flag if these pairs should go through the filtering pipeline nonetheless. |
| 183 | |
| 184 | \note This flag is not mutable, and must be set in PxSceneDesc at scene creation. |
| 185 | |
| 186 | <b>Default:</b> false |
| 187 | */ |
| 188 | eENABLE_KINEMATIC_STATIC_PAIRS =(1<<5), |
| 189 | |
| 190 | |
| 191 | /** |
| 192 | \brief Enable contact pair filtering between kinematic rigid bodies. |
| 193 | |
| 194 | By default contacts between kinematic bodies are suppressed (see #PxFilterFlag::eSUPPRESS) and don't get reported to the filter mechanism. |
| 195 | Raise this flag if these pairs should go through the filtering pipeline nonetheless. |
| 196 | |
| 197 | \note This flag is not mutable, and must be set in PxSceneDesc at scene creation. |
| 198 | |
| 199 | <b>Default:</b> false |
| 200 | */ |
| 201 | eENABLE_KINEMATIC_PAIRS =(1<<6), |
| 202 | |
| 203 | |
| 204 | /** |
| 205 | \brief Enable GJK-based distance collision detection system. |
| 206 | |
| 207 | \note This flag is not mutable, and must be set in PxSceneDesc at scene creation. |
| 208 | |
| 209 | <b>Default:</b> false |
| 210 | */ |
| 211 | eENABLE_PCM = (1 << 9), |
| 212 | |
| 213 | /** |
| 214 | \brief Disable contact report buffer resize. Once the contact buffer is full, the rest of the contact reports will |
| 215 | not be buffered and sent. |
| 216 | |
| 217 | \note This flag is not mutable, and must be set in PxSceneDesc at scene creation. |
| 218 | |
| 219 | <b>Default:</b> false |
| 220 | */ |
| 221 | eDISABLE_CONTACT_REPORT_BUFFER_RESIZE = (1 << 10), |
| 222 | |
| 223 | /** |
| 224 | \brief Disable contact cache. |
| 225 | |
| 226 | Contact caches are used internally to provide faster contact generation. You can disable all contact caches |
| 227 | if memory usage for this feature becomes too high. |
| 228 | |
| 229 | <b>Default:</b> false |
| 230 | */ |
| 231 | eDISABLE_CONTACT_CACHE = (1 << 11), |
| 232 | |
| 233 | |
| 234 | /** |
| 235 | \brief Require scene-level locking |
| 236 | |
| 237 | When set to true this requires that threads accessing the PxScene use the |
| 238 | multi-threaded lock methods. |
| 239 | |
| 240 | \note This flag is not mutable, and must be set in PxSceneDesc at scene creation. |
| 241 | |
| 242 | @see PxScene::lockRead |
| 243 | @see PxScene::unlockRead |
| 244 | @see PxScene::lockWrite |
| 245 | @see PxScene::unlockWrite |
| 246 | |
| 247 | <b>Default:</b> false |
| 248 | */ |
| 249 | eREQUIRE_RW_LOCK = (1 << 12), |
| 250 | |
| 251 | /** |
| 252 | \brief Enables additional stabilization pass in solver |
| 253 | |
| 254 | When set to true, this enables additional stabilization processing to improve that stability of complex interactions between large numbers of bodies. |
| 255 | |
| 256 | Note that this flag is not mutable and must be set in PxSceneDesc at scene creation. Also, this is an experimental feature which does result in some loss of momentum. |
| 257 | */ |
| 258 | eENABLE_STABILIZATION = (1 << 14), |
| 259 | |
| 260 | /** |
| 261 | \brief Enables average points in contact manifolds |
| 262 | |
| 263 | When set to true, this enables additional contacts to be generated per manifold to represent the average point in a manifold. This can stabilize stacking when only a small |
| 264 | number of solver iterations is used. |
| 265 | |
| 266 | Note that this flag is not mutable and must be set in PxSceneDesc at scene creation. |
| 267 | */ |
| 268 | eENABLE_AVERAGE_POINT = (1 << 15) |
| 269 | |
| 270 | }; |
| 271 | }; |
| 272 | |
| 273 | /** |
| 274 | \brief collection of set bits defined in PxSceneFlag. |
| 275 | |
| 276 | @see PxSceneFlag |
| 277 | */ |
| 278 | typedef PxFlags<PxSceneFlag::Enum,PxU16> PxSceneFlags; |
| 279 | PX_FLAGS_OPERATORS(PxSceneFlag::Enum,PxU16) |
| 280 | |
| 281 | |
| 282 | class PxSimulationEventCallback; |
| 283 | class PxContactModifyCallback; |
| 284 | class PxCCDContactModifyCallback; |
| 285 | class PxSimulationFilterCallback; |
| 286 | |
| 287 | /** |
| 288 | \brief Class used to retrieve limits(e.g. maximum number of bodies) for a scene. The limits |
| 289 | are used as a hint to the size of the scene, not as a hard limit (i.e. it will be possible |
| 290 | to create more objects than specified in the scene limits). |
| 291 | |
| 292 | 0 indicates no limit. |
| 293 | */ |
| 294 | class PxSceneLimits |
| 295 | { |
| 296 | public: |
| 297 | PxU32 maxNbActors; //!< Expected maximum number of actors |
| 298 | PxU32 maxNbBodies; //!< Expected maximum number of dynamic rigid bodies |
| 299 | PxU32 maxNbStaticShapes; //!< Expected maximum number of static shapes |
| 300 | PxU32 maxNbDynamicShapes; //!< Expected maximum number of dynamic shapes |
| 301 | PxU32 maxNbAggregates; //!< Expected maximum number of aggregates |
| 302 | PxU32 maxNbConstraints; //!< Expected maximum number of constraint shaders |
| 303 | PxU32 maxNbRegions; //!< Expected maximum number of broad-phase regions |
| 304 | PxU32 maxNbObjectsPerRegion; //!< Expected maximum number of objects in one broad-phase region |
| 305 | |
| 306 | /** |
| 307 | \brief constructor sets to default |
| 308 | */ |
| 309 | PX_INLINE PxSceneLimits(); |
| 310 | |
| 311 | /** |
| 312 | \brief (re)sets the structure to the default |
| 313 | */ |
| 314 | PX_INLINE void setToDefault(); |
| 315 | |
| 316 | /** |
| 317 | \brief Returns true if the descriptor is valid. |
| 318 | \return true if the current settings are valid. |
| 319 | */ |
| 320 | PX_INLINE bool isValid() const; |
| 321 | }; |
| 322 | |
| 323 | PX_INLINE PxSceneLimits::PxSceneLimits() //constructor sets to default |
| 324 | { |
| 325 | maxNbActors = 0; |
| 326 | maxNbBodies = 0; |
| 327 | maxNbStaticShapes = 0; |
| 328 | maxNbDynamicShapes = 0; |
| 329 | maxNbAggregates = 0; |
| 330 | maxNbConstraints = 0; |
| 331 | maxNbRegions = 0; |
| 332 | maxNbObjectsPerRegion = 0; |
| 333 | } |
| 334 | |
| 335 | PX_INLINE void PxSceneLimits::setToDefault() |
| 336 | { |
| 337 | *this = PxSceneLimits(); |
| 338 | } |
| 339 | |
| 340 | PX_INLINE bool PxSceneLimits::isValid() const |
| 341 | { |
| 342 | if(maxNbRegions>256) // max number of regions is currently limited |
| 343 | return false; |
| 344 | |
| 345 | return true; |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | \brief Descriptor class for scenes. See #PxScene. |
| 350 | |
| 351 | This struct must be initialized with the same PxTolerancesScale values used to initialize PxPhysics. |
| 352 | |
| 353 | @see PxScene PxPhysics.createScene PxTolerancesScale |
| 354 | */ |
| 355 | class PxSceneDesc |
| 356 | { |
| 357 | public: |
| 358 | |
| 359 | /** |
| 360 | \brief Gravity vector. |
| 361 | |
| 362 | <b>Range:</b> force vector<br> |
| 363 | <b>Default:</b> Zero |
| 364 | |
| 365 | @see PxScene.setGravity() |
| 366 | |
| 367 | When setting gravity, you should probably also set bounce threshold. |
| 368 | */ |
| 369 | PxVec3 gravity; |
| 370 | |
| 371 | /** |
| 372 | \brief Possible notification callback. |
| 373 | |
| 374 | This callback will be associated with the client PX_DEFAULT_CLIENT. |
| 375 | Please use PxScene::setSimulationEventCallback() to register callbacks for other clients. |
| 376 | |
| 377 | <b>Default:</b> NULL |
| 378 | |
| 379 | @see PxSimulationEventCallback PxScene.setSimulationEventCallback() PxScene.getSimulationEventCallback() |
| 380 | */ |
| 381 | PxSimulationEventCallback* simulationEventCallback; |
| 382 | |
| 383 | /** |
| 384 | \brief Possible asynchronous callback for contact modification. |
| 385 | |
| 386 | <b>Default:</b> NULL |
| 387 | |
| 388 | @see PxContactModifyCallback PxScene.setContactModifyCallback() PxScene.getContactModifyCallback() |
| 389 | */ |
| 390 | PxContactModifyCallback* contactModifyCallback; |
| 391 | |
| 392 | /** |
| 393 | \brief Possible asynchronous callback for contact modification. |
| 394 | |
| 395 | <b>Default:</b> NULL |
| 396 | |
| 397 | @see PxContactModifyCallback PxScene.setContactModifyCallback() PxScene.getContactModifyCallback() |
| 398 | */ |
| 399 | PxCCDContactModifyCallback* ccdContactModifyCallback; |
| 400 | |
| 401 | /** |
| 402 | \brief Shared global filter data which will get passed into the filter shader. |
| 403 | |
| 404 | \note The provided data will get copied to internal buffers and this copy will be used for filtering calls. |
| 405 | |
| 406 | <b>Default:</b> NULL |
| 407 | |
| 408 | @see PxSimulationFilterShader |
| 409 | */ |
| 410 | const void* filterShaderData; |
| 411 | |
| 412 | /** |
| 413 | \brief Size (in bytes) of the shared global filter data #filterShaderData. |
| 414 | |
| 415 | <b>Default:</b> 0 |
| 416 | |
| 417 | @see PxSimulationFilterShader filterShaderData |
| 418 | */ |
| 419 | PxU32 filterShaderDataSize; |
| 420 | |
| 421 | /** |
| 422 | \brief The custom filter shader to use for collision filtering. |
| 423 | |
| 424 | \note This parameter is compulsory. If you don't want to define your own filter shader you can |
| 425 | use the default shader #PxDefaultSimulationFilterShader which can be found in the PhysX extensions |
| 426 | library. |
| 427 | |
| 428 | @see PxSimulationFilterShader |
| 429 | */ |
| 430 | PxSimulationFilterShader filterShader; |
| 431 | |
| 432 | /** |
| 433 | \brief A custom collision filter callback which can be used to implement more complex filtering operations which need |
| 434 | access to the simulation state, for example. |
| 435 | |
| 436 | <b>Default:</b> NULL |
| 437 | |
| 438 | @see PxSimulationFilterCallback |
| 439 | */ |
| 440 | PxSimulationFilterCallback* filterCallback; |
| 441 | |
| 442 | /** |
| 443 | \brief Selects the broad-phase algorithm to use. |
| 444 | |
| 445 | <b>Default:</b> PxBroadPhaseType::eSAP |
| 446 | |
| 447 | @see PxBroadPhaseType |
| 448 | */ |
| 449 | PxBroadPhaseType::Enum broadPhaseType; |
| 450 | |
| 451 | /** |
| 452 | \brief Broad-phase callback |
| 453 | |
| 454 | This callback will be associated with the client PX_DEFAULT_CLIENT. |
| 455 | Please use PxScene::setBroadPhaseCallback() to register callbacks for other clients. |
| 456 | |
| 457 | <b>Default:</b> NULL |
| 458 | |
| 459 | @see PxBroadPhaseCallback |
| 460 | */ |
| 461 | PxBroadPhaseCallback* broadPhaseCallback; |
| 462 | |
| 463 | /** |
| 464 | \brief Expected scene limits. |
| 465 | |
| 466 | @see PxSceneLimits |
| 467 | */ |
| 468 | PxSceneLimits limits; |
| 469 | |
| 470 | /** |
| 471 | \deprecated |
| 472 | \brief A small margin value used for mesh collision detection. |
| 473 | (convex/box vs height field or convex/box vs triangle mesh) |
| 474 | |
| 475 | \note If interested in distance-based collision, please see |
| 476 | the PxSceneFlag::eENABLE_PCM to enable the GJK/EPA path. |
| 477 | |
| 478 | \note Will be removed in future releases. |
| 479 | |
| 480 | @see PxTolerancesScale |
| 481 | <b>Default:</b> 0.01 * PxTolerancesScale::length |
| 482 | */ |
| 483 | PX_DEPRECATED PxReal meshContactMargin; |
| 484 | |
| 485 | |
| 486 | /** |
| 487 | \brief Selects the friction algorithm to use for simulation. |
| 488 | |
| 489 | \note frictionType cannot be modified after the first call to any of PxScene::simulate, PxScene::solve and PxScene::collide |
| 490 | |
| 491 | @see PxFrictionType |
| 492 | <b>Default:</b> PxFrictionType::ePATCH |
| 493 | |
| 494 | @see PxScene::setFrictionType, PxScene::getFrictionType |
| 495 | */ |
| 496 | PxFrictionType::Enum frictionType; |
| 497 | |
| 498 | /** |
| 499 | \deprecated |
| 500 | \brief The patch friction model uses this coefficient to determine if a friction anchor can persist between frames. |
| 501 | |
| 502 | A friction anchor is a point on a body where friction gets applied, similar to a contact point. The simulation determines |
| 503 | new potential friction anchors every time step, and deletes them if over time the bodies that they are attached to slide apart |
| 504 | by more than this distance. We believe the user does not need to modify this parameter from its default. For this reason we are |
| 505 | planning to remove it in future releases. If you have an application that is relying on modifying this parameter, please let us know. |
| 506 | |
| 507 | The alternative Coulomb friction model does not use this coefficient. |
| 508 | |
| 509 | <b>Range:</b> [0, PX_MAX_F32)<br> |
| 510 | <b>Default:</b> 0.025 * PxTolerancesScale::length |
| 511 | */ |
| 512 | PX_DEPRECATED PxReal contactCorrelationDistance; |
| 513 | |
| 514 | /** |
| 515 | \brief A contact with a relative velocity below this will not bounce. A typical value for simulation. |
| 516 | stability is about 0.2 * gravity. |
| 517 | |
| 518 | <b>Range:</b> [0, PX_MAX_F32)<br> |
| 519 | <b>Default:</b> 0.2 * PxTolerancesScale::speed |
| 520 | |
| 521 | @see PxMaterial |
| 522 | */ |
| 523 | PxReal bounceThresholdVelocity; |
| 524 | |
| 525 | /** |
| 526 | \brief A threshold of contact separation distance used to decide if a contact point will experience friction forces. |
| 527 | |
| 528 | \note If the separation distance of a contact point is greater than the threshold then the contact point will not experience friction forces. |
| 529 | |
| 530 | \note If the aggregated contact offset of a pair of shapes is large it might be desirable to neglect friction |
| 531 | for contact points whose separation distance is sufficiently large that the shape surfaces are clearly separated. |
| 532 | |
| 533 | \note This parameter can be used to tune the separation distance of contact points at which friction starts to have an effect. |
| 534 | |
| 535 | <b>Range:</b> [0, PX_MAX_F32)<br> |
| 536 | <b>Default:</b> 0.04 * PxTolerancesScale::length |
| 537 | */ |
| 538 | PxReal frictionOffsetThreshold; |
| 539 | |
| 540 | /** |
| 541 | \brief Flags used to select scene options. |
| 542 | |
| 543 | @see PxSceneFlag PxSceneFlags |
| 544 | */ |
| 545 | PxSceneFlags flags; |
| 546 | |
| 547 | /** |
| 548 | \brief The CPU task dispatcher for the scene. |
| 549 | |
| 550 | See PxCpuDispatcher, PxScene::getCpuDispatcher |
| 551 | */ |
| 552 | PxCpuDispatcher* cpuDispatcher; |
| 553 | |
| 554 | /** |
| 555 | \brief The GPU task dispatcher for the scene. |
| 556 | |
| 557 | <b>Platform specific:</b> Applies to PC GPU only. |
| 558 | |
| 559 | See PxGpuDispatcher, PxScene::getGpuDispatcher |
| 560 | */ |
| 561 | PxGpuDispatcher* gpuDispatcher; |
| 562 | |
| 563 | /** |
| 564 | \brief The SPU task dispatcher for the scene. |
| 565 | |
| 566 | <b>Platform specific:</b> Applies to PS3 only. |
| 567 | |
| 568 | See PxSpuDispatcher, PxScene::getSpuDispatcher |
| 569 | */ |
| 570 | PxSpuDispatcher* spuDispatcher; |
| 571 | |
| 572 | /** |
| 573 | \brief Defines the structure used to store static objects. |
| 574 | |
| 575 | \note Only PxPruningStructure::eSTATIC_AABB_TREE and PxPruningStructure::eDYNAMIC_AABB_TREE are allowed here. |
| 576 | */ |
| 577 | PxPruningStructure::Enum staticStructure; |
| 578 | |
| 579 | /** |
| 580 | \brief Defines the structure used to store dynamic objects. |
| 581 | */ |
| 582 | PxPruningStructure::Enum dynamicStructure; |
| 583 | |
| 584 | /** |
| 585 | \brief Hint for how much work should be done per simulation frame to rebuild the pruning structure. |
| 586 | |
| 587 | This parameter gives a hint on the distribution of the workload for rebuilding the dynamic AABB tree |
| 588 | pruning structure #PxPruningStructure::eDYNAMIC_AABB_TREE. It specifies the desired number of simulation frames |
| 589 | the rebuild process should take. Higher values will decrease the workload per frame but the pruning |
| 590 | structure will get more and more outdated the longer the rebuild takes (which can make |
| 591 | scene queries less efficient). |
| 592 | |
| 593 | \note Only used for #PxPruningStructure::eDYNAMIC_AABB_TREE pruning structure. |
| 594 | |
| 595 | \note This parameter gives only a hint. The rebuild process might still take more or less time depending on the |
| 596 | number of objects involved. |
| 597 | |
| 598 | <b>Range:</b> [4, PX_MAX_U32)<br> |
| 599 | <b>Default:</b> 100 |
| 600 | */ |
| 601 | PxU32 dynamicTreeRebuildRateHint; |
| 602 | |
| 603 | /** |
| 604 | \brief Will be copied to PxScene::userData. |
| 605 | |
| 606 | <b>Default:</b> NULL |
| 607 | */ |
| 608 | void* userData; |
| 609 | |
| 610 | /** |
| 611 | \brief Defines the number of actors required to spawn a separate rigid body solver island task chain. |
| 612 | |
| 613 | This parameter defines the minimum number of actors required to spawn a separate rigid body solver task chain. Setting a low value |
| 614 | will potentially cause more task chains to be generated. This may result in the overhead of spawning tasks can become a limiting performance factor. |
| 615 | Setting a high value will potentially cause fewer islands to be generated. This may reduce thread scaling (fewer task chains spawned) and may |
| 616 | detrimentally affect performance if some bodies in the scene have large solver iteration counts because all constraints in a given island are solved by the |
| 617 | maximum number of solver iterations requested by any body in the island. |
| 618 | |
| 619 | <b>Default:</b> 32 |
| 620 | |
| 621 | <b>Platform specific:</b> Not applicable on PS3. All bodies are batched into one island. |
| 622 | |
| 623 | @see PxScene.setSolverBatchSize() PxScene.getSolverBatchSize() |
| 624 | */ |
| 625 | PxU32 solverBatchSize; |
| 626 | |
| 627 | /** |
| 628 | \brief Setting to define the number of 16K blocks that will be initially reserved to store contact, friction, and contact cache data. |
| 629 | This is the number of 16K memory blocks that will be automatically allocated from the user allocator when the scene is instantiated. Further 16k |
| 630 | memory blocks may be allocated during the simulation up to maxNbContactDataBlocks. |
| 631 | |
| 632 | \note This value cannot be larger than maxNbContactDataBlocks because that defines the maximum number of 16k blocks that can be allocated by the SDK. |
| 633 | |
| 634 | <b>Default:</b> 0, or 256 on PS3 |
| 635 | |
| 636 | <b>Range:</b> [0, PX_MAX_U32]<br> |
| 637 | |
| 638 | @see PxPhysics::createScene PxScene::setNbContactDataBlocks |
| 639 | */ |
| 640 | PxU32 nbContactDataBlocks; |
| 641 | |
| 642 | /** |
| 643 | \brief Setting to define the maximum number of 16K blocks that can be allocated to store contact, friction, and contact cache data. |
| 644 | As the complexity of a scene increases, the SDK may require to allocate new 16k blocks in addition to the blocks it has already |
| 645 | allocated. This variable controls the maximum number of blocks that the SDK can allocate. |
| 646 | |
| 647 | In the case that the scene is sufficiently complex that all the permitted 16K blocks are used, contacts will be dropped and |
| 648 | a warning passed to the error stream. |
| 649 | |
| 650 | If a warning is reported to the error stream to indicate the number of 16K blocks is insufficient for the scene complexity |
| 651 | then the choices are either (i) re-tune the number of 16K data blocks until a number is found that is sufficient for the scene complexity, |
| 652 | (ii) to simplify the scene or (iii) to opt to not increase the memory requirements of physx and accept some dropped contacts. |
| 653 | |
| 654 | <b>Default:</b> 65536, or 256 on PS3 |
| 655 | |
| 656 | <b>Range:</b> [0, PX_MAX_U32]<br> |
| 657 | |
| 658 | @see nbContactDataBlocks PxScene::setNbContactDataBlocks |
| 659 | */ |
| 660 | PxU32 maxNbContactDataBlocks; |
| 661 | |
| 662 | /** |
| 663 | \brief Size of the contact report stream (in bytes). |
| 664 | |
| 665 | The contact report stream buffer is used during the simulation to store all the contact reports. |
| 666 | If the size is not sufficient, the buffer will grow by a factor of two. |
| 667 | It is possible to disable the buffer growth by setting the flag PxSceneFlag::eDISABLE_CONTACT_REPORT_BUFFER_RESIZE. |
| 668 | In that case the buffer will not grow but contact reports not stored in the buffer will not get sent in the contact report callbacks. |
| 669 | |
| 670 | <b>Default:</b> 8192 |
| 671 | |
| 672 | <b>Range:</b> (0, PX_MAX_U32]<br> |
| 673 | |
| 674 | */ |
| 675 | PxU32 contactReportStreamBufferSize; |
| 676 | |
| 677 | /** |
| 678 | \brief Maximum number of CCD passes |
| 679 | |
| 680 | The CCD performs multiple passes, where each pass every object advances to its time of first impact. This value defines how many passes the CCD system should perform. |
| 681 | |
| 682 | \note The CCD system is a multi-pass best-effort conservative advancement approach. After the defined number of passes has been completed, any remaining time is dropped. |
| 683 | \note This defines the maximum number of passes the CCD can perform. It may perform fewer if additional passes are not necessary. |
| 684 | |
| 685 | <b>Default:</b> 1 |
| 686 | <b>Range:</b> [1, PX_MAX_U32]<br> |
| 687 | */ |
| 688 | PxU32 ccdMaxPasses; |
| 689 | |
| 690 | /** |
| 691 | \brief The simulation order |
| 692 | PhysX supports 2 simulation update approaches. The default model - eCOLLIDE_SOLVE - performs collision detection before solver. The alternative model, |
| 693 | eSOLVE_COLLIDE <b>(This feature is currently disabled)</b>, performs solve before collision. This has the performance benefit of allowing the game to defer collision detection for the subsequent frame |
| 694 | so that it can overlap with things like game logic, rendering etc. However, it has the disadvantage that it requires insertions, removals and teleports to be deferred |
| 695 | between dispatching collision detection and solve, which can potentially cause 1 frame's delay in these operations. |
| 696 | |
| 697 | <b>Default:</b> eCOLLIDE_SOLVE |
| 698 | */ |
| 699 | PxSimulationOrder::Enum simulationOrder; |
| 700 | |
| 701 | /** |
| 702 | \brief The wake counter reset value |
| 703 | |
| 704 | Calling wakeUp() on objects which support sleeping will set their wake counter value to the specified reset value. |
| 705 | |
| 706 | <b>Range:</b> (0, PX_MAX_F32)<br> |
| 707 | <b>Default:</b> 0.4 (which corresponds to 20 frames for a time step of 0.02) |
| 708 | |
| 709 | @see PxRigidDynamic::wakeUp() PxArticulation::wakeUp() PxCloth::wakeUp() |
| 710 | */ |
| 711 | PxReal wakeCounterResetValue; |
| 712 | |
| 713 | |
| 714 | /** |
| 715 | \brief The bounds used to sanity check user-set positions of actors and articulation links |
| 716 | |
| 717 | These bounds are used to check the position values of rigid actors inserted into the scene, and positions set for rigid actors |
| 718 | already within the scene. |
| 719 | |
| 720 | <b>Range:</b> any valid PxBounds3 <br> |
| 721 | <b>Default:</b> (-PX_MAX_BOUNDS_EXTENTS, PX_MAX_BOUNDS_EXTENTS) on each axis |
| 722 | */ |
| 723 | PxBounds3 sanityBounds; |
| 724 | |
| 725 | private: |
| 726 | /** |
| 727 | \cond |
| 728 | */ |
| 729 | // For internal use only |
| 730 | PxTolerancesScale tolerancesScale; |
| 731 | /** |
| 732 | \endcond |
| 733 | */ |
| 734 | |
| 735 | |
| 736 | public: |
| 737 | /** |
| 738 | \brief constructor sets to default. |
| 739 | |
| 740 | \param[in] scale scale values for the tolerances in the scene, these must be the same values passed into |
| 741 | PxCreatePhysics(). The affected tolerances are meshContactMargin, contactCorrelationDistance, bounceThresholdVelocity |
| 742 | and frictionOffsetThreshold. |
| 743 | |
| 744 | @see PxCreatePhysics() PxTolerancesScale meshContactMargin contactCorrelationDistance bounceThresholdVelocity frictionOffsetThreshold |
| 745 | */ |
| 746 | PX_INLINE PxSceneDesc(const PxTolerancesScale& scale); |
| 747 | |
| 748 | /** |
| 749 | \brief (re)sets the structure to the default. |
| 750 | |
| 751 | \param[in] scale scale values for the tolerances in the scene, these must be the same values passed into |
| 752 | PxCreatePhysics(). The affected tolerances are meshContactMargin, contactCorrelationDistance, bounceThresholdVelocity |
| 753 | and frictionOffsetThreshold. |
| 754 | |
| 755 | @see PxCreatePhysics() PxTolerancesScale meshContactMargin contactCorrelationDistance bounceThresholdVelocity frictionOffsetThreshold |
| 756 | */ |
| 757 | PX_INLINE void setToDefault(const PxTolerancesScale& scale); |
| 758 | |
| 759 | /** |
| 760 | \brief Returns true if the descriptor is valid. |
| 761 | \return true if the current settings are valid. |
| 762 | */ |
| 763 | PX_INLINE bool isValid() const; |
| 764 | |
| 765 | /** |
| 766 | \cond |
| 767 | */ |
| 768 | // For internal use only |
| 769 | PX_INLINE const PxTolerancesScale& getTolerancesScale() const { return tolerancesScale; } |
| 770 | /** |
| 771 | \endcond |
| 772 | */ |
| 773 | }; |
| 774 | |
| 775 | PX_INLINE PxSceneDesc::PxSceneDesc(const PxTolerancesScale& scale): |
| 776 | gravity (PxVec3(0.0f)), |
| 777 | simulationEventCallback (NULL), |
| 778 | contactModifyCallback (NULL), |
| 779 | ccdContactModifyCallback (NULL), |
| 780 | |
| 781 | filterShaderData (NULL), |
| 782 | filterShaderDataSize (0), |
| 783 | filterShader (NULL), |
| 784 | filterCallback (NULL), |
| 785 | broadPhaseType (PxBroadPhaseType::eSAP), |
| 786 | broadPhaseCallback (NULL), |
| 787 | |
| 788 | meshContactMargin (0.01f * scale.length), |
| 789 | frictionType (PxFrictionType::ePATCH), |
| 790 | contactCorrelationDistance (0.025f * scale.length), |
| 791 | bounceThresholdVelocity (0.2f * scale.speed), |
| 792 | frictionOffsetThreshold (0.04f * scale.length), |
| 793 | |
| 794 | flags (0), |
| 795 | |
| 796 | cpuDispatcher (NULL), |
| 797 | gpuDispatcher (NULL), |
| 798 | spuDispatcher (NULL), |
| 799 | |
| 800 | staticStructure (PxPruningStructure::eDYNAMIC_AABB_TREE), |
| 801 | dynamicStructure (PxPruningStructure::eDYNAMIC_AABB_TREE), |
| 802 | dynamicTreeRebuildRateHint (100), |
| 803 | |
| 804 | userData (NULL), |
| 805 | |
| 806 | solverBatchSize (32), |
| 807 | |
| 808 | #ifdef PX_PS3 |
| 809 | nbContactDataBlocks (256), |
| 810 | #else |
| 811 | nbContactDataBlocks (0), |
| 812 | #endif |
| 813 | |
| 814 | maxNbContactDataBlocks (1<<16), |
| 815 | contactReportStreamBufferSize (8192), |
| 816 | ccdMaxPasses (1), |
| 817 | simulationOrder (PxSimulationOrder::eCOLLIDE_SOLVE), |
| 818 | wakeCounterResetValue (20.0f*0.02f), |
| 819 | sanityBounds (PxBounds3(PxVec3(-PX_MAX_BOUNDS_EXTENTS, -PX_MAX_BOUNDS_EXTENTS, -PX_MAX_BOUNDS_EXTENTS), |
| 820 | PxVec3(PX_MAX_BOUNDS_EXTENTS, PX_MAX_BOUNDS_EXTENTS, PX_MAX_BOUNDS_EXTENTS))), |
| 821 | tolerancesScale (scale) |
| 822 | { |
| 823 | } |
| 824 | |
| 825 | PX_INLINE void PxSceneDesc::setToDefault(const PxTolerancesScale& scale) |
| 826 | { |
| 827 | *this = PxSceneDesc(scale); |
| 828 | } |
| 829 | |
| 830 | PX_INLINE bool PxSceneDesc::isValid() const |
| 831 | { |
| 832 | if(filterShader == NULL) |
| 833 | return false; |
| 834 | |
| 835 | if( ((filterShaderDataSize == 0) && (filterShaderData != NULL)) || |
| 836 | ((filterShaderDataSize > 0) && (filterShaderData == NULL)) ) |
| 837 | return false; |
| 838 | |
| 839 | if(!limits.isValid()) |
| 840 | return false; |
| 841 | |
| 842 | if(staticStructure!=PxPruningStructure::eSTATIC_AABB_TREE && staticStructure!=PxPruningStructure::eDYNAMIC_AABB_TREE) |
| 843 | return false; |
| 844 | |
| 845 | if(dynamicTreeRebuildRateHint < 4) |
| 846 | return false; |
| 847 | |
| 848 | if(meshContactMargin < 0.0f) |
| 849 | return false; |
| 850 | if(contactCorrelationDistance < 0.0f) |
| 851 | return false; |
| 852 | if(bounceThresholdVelocity < 0.0f) |
| 853 | return false; |
| 854 | if(frictionOffsetThreshold < 0.f) |
| 855 | return false; |
| 856 | |
| 857 | if(cpuDispatcher == NULL) |
| 858 | return false; |
| 859 | |
| 860 | if(contactReportStreamBufferSize == 0) |
| 861 | return false; |
| 862 | |
| 863 | if(maxNbContactDataBlocks < nbContactDataBlocks) |
| 864 | return false; |
| 865 | |
| 866 | if (wakeCounterResetValue <= 0.0f) |
| 867 | return false; |
| 868 | |
| 869 | #if !PX_ENABLE_INVERTED_STEPPER_FEATURE |
| 870 | if (simulationOrder == PxSimulationOrder::eSOLVE_COLLIDE) |
| 871 | return false; |
| 872 | #endif |
| 873 | |
| 874 | //Adaptive force and stabilization are incompatible. You can only have one or the other |
| 875 | if((flags & (PxSceneFlag::eADAPTIVE_FORCE | PxSceneFlag::eENABLE_STABILIZATION)) == (PxSceneFlag::eADAPTIVE_FORCE | PxSceneFlag::eENABLE_STABILIZATION)) |
| 876 | return false; |
| 877 | |
| 878 | if(!sanityBounds.isValid()) |
| 879 | return false; |
| 880 | |
| 881 | return true; |
| 882 | } |
| 883 | |
| 884 | |
| 885 | #ifndef PX_DOXYGEN |
| 886 | } // namespace physx |
| 887 | #endif |
| 888 | |
| 889 | /** @} */ |
| 890 | #endif |
| 891 | |