17 #ifndef AGX_MERGEDBODY_H
18 #define AGX_MERGEDBODY_H
30 #define MERGED_BODY_SERIALIZATION_VERSION_1 49
31 #define MERGED_BODY_SERIALIZATION_VERSION_2 75
36 class MergeSplitHandler;
70 INTERACTION_GRAPH_DIRTY = 1 << 0,
72 READY_FOR_SOLVER = 1 << 2,
73 AUTO_CLEAN_WHEN_EMPTY = 1 << 3
92 : index( rb ? rb.calculateIndex() : agx::
InvalidIndex ), originalIndex( orgRb ? orgRb.calculateIndex() : agx::
InvalidIndex ) {}
192 static BinaryConstraintEdgeInteraction* getEdge(
const agx::Constraint* constraint );
259 agx::Bool remove( EdgeInteraction* edge );
288 agx::MergedBodyRefVector splitIslands();
330 void setEnableAutomaticCleanupWhenEmpty(
agx::Bool enable );
335 agx::Bool getEnableAutomaticCleanupWhenEmpty()
const;
390 void getDebugRenderColor(
agx::Vec3& color )
const;
399 virtual
void updateVelocities();
405 virtual
void storeRelativeTransforms();
410 void postIntegrate();
417 void clearGeneratedInteractions();
424 virtual ~MergedBody() throw();
426 friend class agxSDK::Simulation;
427 friend class agxCollide::Space;
433 virtual
void setSimulation( agxSDK::Simulation* simulation );
438 virtual
void onRemove( agx::RigidBody* rb );
443 virtual
void onRemove( agx::
Constraint* constraint );
448 virtual
void onRemove( agxCollide::Geometry* geometry );
453 virtual
void preCollide();
458 virtual
void preStep();
464 virtual
void postStep();
469 virtual
void onCleanup();
475 agxSDK::Simulation* getSimulation();
480 const agxSDK::Simulation* getSimulation() const;
486 agx::
Bool updateProperties();
494 virtual ~PairData() {}
501 typedef PairInteractionsContainer::iterator PairInteractionsIterator;
502 typedef PairInteractionsContainer::const_iterator PairInteractionsConstIterator;
528 INTEGRATE_POSITIONS = 1 << 0
532 using Flags = agx::BitState<Flag, agx::UInt16>;
538 : otherBodies(), relativeTransform(), mergedBody( nullptr ),
id( agx::
InvalidIndex ),
539 mergedWithWorldCounter( 0 ), rootBodyData( nullptr ), flags( agx::
UInt16( 0 ) )
545 MergedBody* mergedBody;
548 RootBodyDataRef rootBodyData;
552 virtual ~MergedData() {}
561 ConstraintMergedData()
562 : mergedBody( nullptr ), edge( nullptr ) {}
564 MergedBody* mergedBody;
565 EdgeInteraction* edge;
568 virtual ~ConstraintMergedData() {}
576 void writeConnectivityGraph( std::ostream& stream )
const;
582 template<
typename DataT,
typename ObjT>
583 static DataT* getMergedData(
const ObjT& obj );
588 template<
typename DataT,
typename ObjT>
589 static DataT* getOrCreateMergedData( ObjT obj );
599 static agx::Bool isMerged(
const MergedData* data );
605 Key createKey( EdgeInteraction* edge )
const;
649 void remove( PairInteractionsIterator it );
664 void handleOnAdd( EdgeInteraction* edge );
669 void handleOnRemove(
const EdgeInteractionRefContainer& edges );
674 void handleOnMovedTo(
const EdgeInteractionRefContainer& edges, MergedBody* newMergedBody );
687 void commitGeneratedInteractions();
691 PairInteractionsContainer m_pairInteractions;
692 EdgeInteractionRefContainer m_removedEdges;
693 ListenerContainer m_listeners;
694 RigidBodyContainer m_bodies;
696 mutable InternalState m_state;
711 virtual ListenerRef clone() = 0;
756 CONTACT_GENERATOR = 1 << 1,
759 PARTICLE_GENERATOR = 1 << 4
835 virtual ~EdgeInteraction();
879 EmptyEdgeInteraction();
884 virtual ~EmptyEdgeInteraction();
921 ContactGeneratorEdgeInteraction();
926 virtual ~ContactGeneratorEdgeInteraction();
1015 typedef std::function<agxCollide::Geometry*( agxCollide::Geometry*, agx::RigidBody* )> GeometryUpdateFunction;
1025 void updateGeometries( GeometryUpdateFunction geometryUpdateFunction );
1033 GeometryContactEdgeInteraction();
1038 virtual ~GeometryContactEdgeInteraction();
1043 virtual
void generateInteraction( agxSDK::Simulation* simulation, agxCollide::
LocalGeometryContactVector& newContacts ) override;
1060 explicit BinaryConstraintEdgeInteraction(
agx::Constraint* constraint );
1095 BinaryConstraintEdgeInteraction();
1100 virtual ~BinaryConstraintEdgeInteraction();
1139 ParticleParticleInteraction();
1144 virtual ~ParticleParticleInteraction();
1152 template<
typename DataT,
typename ObjT>
1158 template<
typename DataT,
typename ObjT>
1167 const MergedData* data = getMergedData<MergedData>( rb );
1168 return data !=
nullptr ? data->mergedBody :
nullptr;
1173 MergedData* data = getMergedData<MergedData>( rb );
1174 return data !=
nullptr ? data->mergedBody :
nullptr;
1180 return mb !=
nullptr && mb->
isActive() ? mb :
nullptr;
1186 return mb !=
nullptr && mb->
isActive() ? mb :
nullptr;
1191 return rb !=
nullptr &&
1217 return data !=
nullptr && data->mergedBody !=
nullptr;
1222 return m_simulation !=
nullptr && m_state.Is( READY_FOR_SOLVER );
1227 MergedData* data = getMergedData<MergedData>( rb );
1228 return data !=
nullptr ? data->rootBodyData :
nullptr;
1232 inline
Bool MergedBody::EdgeInteraction::isTagged(InteractionTag tag)
const
1234 return ( m_tag & (
Int32)tag ) != 0;
AGXPHYSICS_EXPORT agx::RigidBody *& model()
static agx::Bool isRoot(const agx::RigidBody *rb)
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Merged states, neighbors etc.
Object with index of merged body and the original index of a merged object.
agx::BitState< State > InternalState
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive...
MergedBodyIndex(agx::Physics::RigidBodyPtr rb, agx::Physics::RigidBodyPtr orgRb)
Construct given object associated to index, and an original object associated to originalIndex.
virtual void onMovedFromTo(const MergedBody::EdgeInteractionRefContainer &, const agx::MergedBody *, const agx::MergedBody *) const
Called when the edges between two bodies are moved from one merged body to another.
GeometryContactEdgeInteraction()
Default constructor used by serialization.
Contact point data store in first rigid body local frame.
Base class for a merge split algorithm handling a set of merged bodies.
static const agx::MergedBody * getActive(const agx::RigidBody *rb)
This method returns an agx::MergedBody that is active and in a simulation.
Base class for a strong interaction concept where there interaction is defined in the mass matrix par...
virtual void onAdd(agx::RigidBody *, const agx::MergedBody *) const
Called when a body is added to the merged body.
agx::VectorPOD< Point > PointContainer
ParticleParticleInteraction()
Default constructor used by serialization.
virtual void onRemove(agx::RigidBody *, const agx::MergedBody *) const
Called when a body is removed from the merged body.
#define AGXPHYSICS_EXPORT
agx::Vector< EdgeInteractionRef > EdgeInteractionRefContainer
The base class for a constraint.
virtual void generateInteraction(agxSDK::Simulation *, agxCollide::LocalGeometryContactVector &) override
Does nothing.
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
#define AGX_DECLARE_POINTER_TYPES(type)
agx::Bool isActive() const
virtual void onRemoved(const MergedBody::EdgeInteractionRefContainer &, const agx::MergedBody *) const
Called when an edge is removed from the merged body.
agx::RigidBody * getRigidBody() const
agx::Bool isMerged() const
AGXPHYSICS_EXPORT agx::RigidBodyState & state()
Base class providing referencing counted objects.
EmptyEdgeInteraction()
Default constructor used by serialization.
The geometry representation used by the collision detection engine.
Structure holding several "normal" rigid bodies.
The body fixed node is attached to a body at a given offset.
Pointer to a entity instance of type Physics.RigidBody.
static MergedBodyIndex findMergedBodyIndex(agx::Physics::RigidBodyPtr rb)
Similar to filter( const agx::RigidBody* rb ).
agx::Vector< LocalGeometryContact > LocalGeometryContactVector
BinaryConstraintEdgeInteraction()
Default constructor used by serialization.
State
Internal state of this merged body.
The rigid body class, combining a geometric model and a frame of reference.
virtual void onAdded(EdgeInteraction *, const agx::MergedBody *) const
Called when an edge is added to the merged body.
agx::VectorPOD< RigidBodyPtr > RigidBodyPtrVector
agx::ref_ptr< RigidBody > RigidBodyRef
Abstract base class for storing/restoring a line/drums with version control.
std::function< void(EdgeInteraction *) > EdgeInteractionVisitor
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
static const agx::MergedBody * get(const agx::RigidBody *rb)
This method returns an agx::MergedBody if rb has been added to one.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Class for writing serialized data in binary format to a stream.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
ContactGeneratorEdgeInteraction()
Default constructor used by serialization.
MergedBodyIndex()
Default constructor initializes both indices to Invalid Index.
MotionControl
The MotionControl enumeration indicates what makes a RigidBody move.
AGXCORE_EXPORT Component * root()
static const agx::RigidBody * filter(const agx::RigidBody *rb)
Filters rb and returns the merged rigid body if rb is part of one.
agx::Physics::RigidBodyPtr getEntity() const
Internal method.
std::function< void(agx::RigidBody *) > RigidBodyVisitor
#define DOXYGEN_END_INTERNAL_BLOCK()
#define DOXYGEN_START_INTERNAL_BLOCK()
agx::observer_ptr< Geometry > GeometryObserver
AGX_DECLARE_VECTOR_TYPES(Clock)
EdgeInteraction(agx::RigidBody *rb1, agx::RigidBody *rb2, InteractionTag tag, agx::Bool valid=true)
Construct given two rigid bodies and a valid flag.
Flags
Flags for specifying what is enabled in the debug rendering system.