87 INVALID_BROAD_PHASE_ALGORITHM = -1,
110 bool setBroadPhaseAlgorithm(BroadPhaseAlgorithm algorithm);
115 BroadPhaseAlgorithm getBroadPhaseAlgorithm()
const;
185 void updateBroadPhase();
196 void updateNarrowPhase();
276 bool testBoundingVolumeOverlap(
295 bool testGeometryOverlap(
342 void setEnableContactReduction(
bool flag );
354 void setContactReductionBinResolution(
agx::UInt binResolution);
357 bool getEnableContactReduction()
const;
360 agx::UInt getContactReductionBinResolution()
const;
367 void setContactReductionThreshold(
agx::UInt threshold);
372 agx::UInt getContactReductionThreshold()
const;
417 template<
typename F >
422 for (
agx::UInt i = 0, numGeometries = m_geometries.size(); !m_geometries.empty() && i < numGeometries - 1; ++i ) {
423 for (
agx::UInt j = i + 1; j < numGeometries; ++j ) {
429 if ( relevantCollision(m_geometries[ i ], m_geometries[ j ] ) &&
431 canCollide( m_geometries[ i ], m_geometries[ j ] ) &&
432 m_geometries[ i ]->getBoundingVolume()->hasOverlap( *m_geometries[ j ]->getBoundingVolume() ) ) {
433 reportOverlap( m_geometries[ i ], m_geometries[ j ] );
447 template<
typename F >
457 for (
agx::UInt i = 0, numBroadPhasePairs = broadPhasePairs.
size(); i < numBroadPhasePairs; ++i ) {
463 while ( !pairsToRemove.
empty() ) {
465 m_sweepAndPrune->removePair( pairsToRemove.
back().first, pairsToRemove.
back().second );
515 void setEnableGeometry(
Geometry* geometry,
bool flag);
520 agx::Real getOrientedBoundsThreshold()
const;
526 void setOrientedBoundsThreshold(
agx::Real threshold );
538 void commitRemovedContacts();
594 void resetParticleCellAssignments();
624 void synchronizeTransforms();
629 void synchronizeBounds();
634 void printContacts(const agx::
String& title);
639 agxData::EntityStorage* getShapeStorage(agxData::EntityModel* shapeModel);
641 agxData::EntityStorage *getGeometryStorage();
643 agxData::EntityStorage* getGeometryContactStorage();
644 agxData::EntityStorage* getContactPointStorage();
645 agxData::EntityStorage* getOrientedGeometryBoundStorage();
647 void setEnableParticleGridTasks(
bool flag);
648 void optimizeGridCellFitting();
651 agx::TaskGroup* getUpdateTask();
660 static agx::Model* ClassModel();
664 typedef agx::SymmetricPair<
unsigned> GeometryIDPair;
667 class SpaceSerializer : public agxStream::Serializable
681 DisablePairVector m_disabledGeometryIDPairs;
685 SpaceSerializer( ) : m_space(nullptr) {}
686 const Space* m_space;
690 friend class SpaceSerializer;
707 void restore( const SpaceSerializer& ss );
709 void commitNewOverlaps();
711 friend class Geometry;
718 template <typename T1, typename T2>
719 void calculateNarrowPhase(BroadPhasePair* pair, T1& contactContainer, T2& separationContainer);
721 void createGeometryContacts();
722 void startUpdateTimer(agx::Task* task);
723 void stopUpdateTimerAndReport(agx::Task* task);
724 void createShapeStorage(const agx::Path& entityPath);
725 void updateContactState();
726 void createMissingContactMaterials();
727 void updateSweepAndPrune();
729 void loadTasks(BroadPhaseAlgorithm algorithm);
730 agx::Task* createSynchronizeTransformsTask();
731 agx::Task* createSynchronizeBoundsTask();
732 agx::Task* createUpdateBroadPhaseTask(BroadPhaseAlgorithm algorithm);
733 agx::Task* createUpdateNarrowPhaseTask( const agx::
String& implementation = "");
734 agx::Task* createUpdateContactStateTask();
736 void createParticlePairContacts();
737 void createParticleGeometryContacts();
745 bool removeSweepAndPrune();
748 BroadPhaseAlgorithm m_broadPhaseAlgorithm;
754 agx::
TaskRef m_synchronizeTransformsTask;
755 agx::
TaskRef m_synchronizeBoundsTask;
756 agx::
TaskRef m_updateBroadPhaseTask;
757 agx::
TaskRef m_updateNarrowPhaseTask;
758 agx::
TaskRef m_updateContactStateTask;
759 agx::
TaskRef m_createMissingMaterialsTask;
761 agx::
TaskRef m_synchronizeTransformsTask2;
762 agx::
TaskRef m_synchronizeBoundsTask2;
763 agx::
TaskRef m_updateBroadPhaseTask2;
764 agx::
TaskRef m_updateNarrowPhaseTask2;
765 agx::
TaskRef m_updateContactStateTask2;
766 agx::
TaskRef m_createMissingMaterialsTask2;
777 agxData::
BufferRef m_materialLessGeometryContacts;
778 agxData::
BufferRef m_sortedGeometryContacts;
779 agxData::
BufferRef m_sortedSeparationPairs;
780 agxData::
BufferRef m_filteredBroadPhasePairs;
785 GeometryPairHash m_disabledGeometryPairs;
787 friend class agxIO::SceneExporter;
790 agxCollide::SweepAndPrune::ExternallyReportedPairsContainer m_externallyReportedPairs;
793 GeometryRemoveTable m_geometriesToRemove;
795 agx::Timer m_updateTimer;
796 agx::Task::ExecutionEvent::CallbackType m_startUpdateTimerCallback;
797 agx::Task::ExecutionEvent::CallbackType m_stopUpdateTimerAndReportCallback;
799 agxData::ValueRefT<agx::
Bool> m_contactReductionEnable;
800 agxData::ValueRefT<agx::
UInt> m_contactReductionBinResolution;
801 agxData::ValueRefT<agx::
UInt> m_contactReductionThreshold;
802 agxData::ValueRefT<agx::
UInt> m_narrowPhaseMinJobSize;
804 agxData::ValueRefT<agx::
Real> m_orientedBoundsThreshold;
810 agxData::
BufferRef m_geometryContactInstanceBuffer;
811 agxData::
BufferRef m_contactPointInstanceBuffer;
817 ShapeStorageTable m_shapeStorageTable;
820 SpaceListenerRefVector m_listeners;
821 agxData::Buffer::
Event::CallbackType m_shapeTransformReallocationCallback;
825 agxData::
BufferRef m_collisionObjectBuffer_sourceIndex;
826 agxData::
BufferRef m_collisionObjectBuffer_subsystem;
827 agxData::
BufferRef m_collisionObjectBuffer_position;
828 agxData::
BufferRef m_collisionObjectBuffer_radius;
829 agxData::
BufferRef m_collisionObjectBuffer_obbIndex;
831 agxData::
BufferRef m_gridOvelapBuffer_collisionObject1;
832 agxData::
BufferRef m_gridOvelapBuffer_collisionObject2;
834 agx::
TaskRef m_overlapTestTask;
836 agx::HashSet<Geometry*> m_skipTable;
838 typedef agx::HashTableComponent<agxData::
GeometryPair, agx::Physics::GeometryContactPtr> GridContactTableComponent;
839 typedef agx::QuadraticProbingHashTable<agxData::GeometryPair, agx::Physics::GeometryContactPtr, agx::HashFn<agxData::GeometryPair>, agxData::BufferProxyAllocator>
GridContactTable;
844 agxData::Value::
Event::CallbackType m_gridCellSizeAlignmentCallback;
845 void gridCellSizeAlignmentCallback(agxData::Value* sizeAlignment);
847 GridContactTable* m_gridContactTable;
861 if (!(g1->isEnabled() && g2->isEnabled()))
864 if (!(g1->getEnableCollisions() && g2->getEnableCollisions()))
875 if (rb1 && (rb1 == rb2))
879 if (m_disabledGeometryPairs.contains( GeometryPair(const_cast<Geometry*>(g1), const_cast<Geometry*>(g2)) ))
885 if (groupSet1 && groupSet2 && g1->getSpace() ==
this && g2->getSpace() ==
this && !m_collisionGroupManager->canSetsCollide(groupSet1, groupSet2))
895 return m_orientedGeometryBoundStorage;
900 return m_geometryContactStorage;
905 return m_contactPointStorage;
911 return m_collisionGroupManager;
914 AGX_FORCE_INLINE const CollisionGroupManager* Space::getCollisionGroupManager()
const
916 return m_collisionGroupManager;
930 return this->getEnablePair(
931 m_collisionGroupManager->getGroupId(group1),
932 m_collisionGroupManager->getGroupId(group2));
937 return m_collisionGroupManager->canGroupsCollide(group1, group2);
943 return m_broadPhasePairVector;
949 return m_separationPairVector;
960 if ( geometry1 == 0L || geometry2 == 0L || !geometry1->
isEnabled() || !geometry2->
isEnabled() )
968 if ( m_sweepAndPrune == 0L || geometry1 == 0L || geometry2 == 0L )
972 if ( it != m_externallyReportedPairs.end() )
973 m_externallyReportedPairs.erase( it );
975 m_sweepAndPrune->removePair( geometry1, geometry2 );
980 return m_contactReductionEnable->get();
985 return m_contactReductionBinResolution->get();
990 return m_orientedBoundsThreshold->get();
agx::ref_ptr< Task > TaskRef
HierarchicalGrid * getHierarchicalGrid()
void enableForContacts(F relevantCollision)
If for some reason a geometry or several geometries collides with more geometries now than previously...
void AGXPHYSICS_EXPORT init()
Initialize agx.
agx::ref_ptr< EntityStorage > EntityStorageRef
bool getEnablePair(agx::UInt32 group1, agx::UInt32 group2) const
Get information if group1 and group2 are allowed to collide.
Class for listening for add/remove geometry events for an associated Space.
std::pair< agx::Physics::ParticlePtr, agx::Physics::GeometryPtr > ParticleGeometryPair
Data storage for a collection of entity instances of a specified EntityModel.
void garbageCollect()
Use with caution!
agx::SymmetricPair< agx::Physics::GeometryPtr > GeometryPair
bool restore(const agx::String &filename, agx::UInt selection=READ_DEFAULT)
Restore state from a serialized scene file.
A component is an object containing other objects, enabling hierarchical structuring.
Pointer to a entity instance of type Physics.BroadPhasePair.
const GeometryContact ** const_iterator
void removeOverlap(agxCollide::Geometry *geometry1, agxCollide::Geometry *geometry2)
Remove a (Sweep and Prune) bounding overlap, if it exists, between geometry1 and geoemtry2.
Inheritance with partial specialization due to bug with ref_ptr containers.
#define AGXPHYSICS_EXPORT
AgXString< std::string > String
GLenum GLuint GLenum GLsizei length
agx::ref_ptr< Buffer > BufferRef
GeometryContactPtrVector::const_iterator removeContact(GeometryContactPtrVector::const_iterator contact)
Remove a specified GeometryContact from the list of contacts.
Representation of a name string.
agx::Vector< agx::Physics::BroadPhasePairPtr, agxData::BufferProxyAllocator > BroadPhasePairVector
Pointer to a entity instance of type Physics.CollisionGroupSet.
void reserve(size_t size)
Reserve capacity in the vector.
The geometry representation used by the collision detection engine.
bool getEnableContactReduction() const
const SeparationPairVector & getSeparationPairs() const
agx::ref_ptr< TaskGroup > TaskGroupRef
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
void disableForContacts(F relevantCollision)
If for some reason a geometry or several geometries collides with less geometries now than previously...
const agxCollide::GeometryRefVector & getGeometries() const
bool getEnable() const
Access the state enable flag.
agx::ref_ptr< SweepAndPrune > SweepAndPruneRef
agx::Vector< agx::Physics::GeometryPairPtr > LocalSeparationPairVector
AGXPHYSICS_EXPORT agx::Physics::GeometryPtr & geometry1()
agx::UInt getContactReductionBinResolution() const
agx::Vector< agx::Physics::GeometryPairPtr, agxData::BufferProxyAllocator > SeparationPairVector
agx::Vector< ParticleGeometryPair > ParticleGeometryPairVector
typedef void(GLAD_API_PTR *GLDEBUGPROC)(GLenum source
The rigid body class, combining a geometric model and a frame of reference.
AGXPHYSICS_EXPORT bool setEnableCollisions(agx::RigidBody *rb1, agx::RigidBody *rb2, bool enable)
Enable or disable the collision between all geometries in RigidBody rb1 and RigidBody rb2...
BroadPhaseAlgorithm
Enum for specifying which BroadPhase algorithm space should use.
void clearContactData()
Clears contact data in the simulation.
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
AGXPHYSICS_EXPORT agxCollide::Geometry *& model()
agx::Real getOrientedBoundsThreshold() const
Returns the current threshold for where oriented bounds are created for Geometries.
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
AGXPHYSICS_EXPORT agx::Physics::GeometryPtr & geometry2()
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
bool isEnabled() const
Alias for getEnable Return whether the geometry should be used in intersection tests.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Complete disabled collisions state in a simulation including disabled given name, group id (integer) ...
void reportOverlap(agxCollide::Geometry *geometry1, agxCollide::Geometry *geometry2)
Add an explicit bounding volume overlap between the two specified geometries.
agx::Vector< agx::ref_ptr< Geometry > > GeometryRefVector
agx::Vector< agx::Physics::ParticlePairContactPtr > ParticlePairContactVector
SAP good for scenes which are semi stationary.
Inheritance with partial specialization due to bug with ref_ptr containers.
agx::SetVector< GeometryPair > GeometryPairHash
An agx::Device is an abstract representation of a device on which data can be stored and processed...
LinearProbingHashTable< KeyT, DataT, HashT, AllocatorT > HashTable
const BroadPhasePairVector & getBroadPhasePairs() const
void push_back(const T2 &value)
#define DOXYGEN_END_INTERNAL_BLOCK()
#define DOXYGEN_START_INTERNAL_BLOCK()
agx::observer_ptr< Geometry > GeometryObserver
AGX_DECLARE_POINTER_TYPES(SpaceListener)
agx::ref_ptr< HierarchicalGrid > HierarchicalGridRef
agx::Vector< agx::Physics::ParticleGeometryContactPtr > ParticleGeometryContactVector