AGX Dynamics  2.37.2.0
MaterialManager.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #include <agxSDK/agxSDK.h>
20 
21 #include <agx/Material.h>
23 
24 #include <agxCollide/Contacts.h>
25 
26 #include <agxData/EntityStorage.h>
27 
28 namespace agx
29 {
32 }
33 
34 namespace agxSDK
35 {
37  typedef agx::ContactMaterial* (*ContactMaterialFunction)(const agx::Material* m1, const agx::Material* m2);
38 
42 
44 
50  {
51  public:
55  static agx::Model* ClassModel();
56 
62  static void calculateContactMaterial( agx::ContactMaterial* contactMaterial );
63 
64  public:
69 
76  bool add( agx::Material* material );
77 
90  bool add( agx::ContactMaterial* contactMaterial );
91 
97  bool remove( agx::Material* material );
98 
104  bool remove( agx::ContactMaterial* contactMaterial );
105 
113  agx::ContactMaterial* getOrCreateContactMaterial( const agx::Material* material1, const agx::Material* material2 );
114 
122  const agx::ContactMaterial* getContactMaterial( const agx::Material* material1, const agx::Material* material2 ) const;
123 
131  const agx::ContactMaterial* getContactMaterial( agx::Physics::MaterialPtr material1, agx::Physics::MaterialPtr material2 ) const;
132 
136  agx::Material* getMaterial( const agx::String& name );
137 
141  const agx::Material* getMaterial( const agx::String& name ) const;
142 
146  agx::Material* getMaterial(const agx::Uuid& uuid);
147 
151  const agx::Material* getDefaultMaterial() const;
152 
156  const StringMaterialRefTable& getMaterials() const;
157 
165 
169  const MaterialSPairContactMaterialRefTable& getContactMaterials() const;
170 
178 
182  bool hasMaterialsWithContactReduction() const;
183 
191  bool setContactMaterial( agxCollide::LocalGeometryContact* localGeometryContact );
192 
196  agx::ContactMaterial* getOrCreateContactMaterial( const agxCollide::GeometryContact* geometryContact );
197 
201  agxData::EntityStorage* getContactMaterialStorage();
202 
208  agx::ContactMaterial* getContactMaterialOrCreateImplicit(const agx::Material* material1, const agx::Material* material2);
209 
214  agx::ContactMaterial* getContactMaterialOrCreateImplicit(const agxCollide::Geometry* geometry1, const agxCollide::Geometry* geometry2);
216 
217  public:
222  {
223  public:
225  : m_mgr( mgr ) {}
227 
228  const MaterialManager* get() const { return m_mgr; }
229  void set( MaterialManager* mgr ) { m_mgr = mgr; }
230 
232  ContactMaterialVector m_contactMaterials;
233 
234  protected:
235  MaterialManagerSerializer() : m_mgr( nullptr ) {}
237  };
238 
242  void store( agxStream::OutputArchive& out ) const;
243 
247  void restore( const MaterialManagerSerializer& mgr );
248 
249  protected:
253  virtual ~MaterialManager();
254 
258  SymmetricMaterialPair getSymmetricPair( const agx::ContactMaterial* contactMaterial ) const;
259 
263  SymmetricMaterialPair getSymmetricPair( const agx::Material* material1, const agx::Material* material2 ) const;
264 
265  friend class Simulation;
266  friend class SimulationController;
267 
271  void clear();
272 
276  void resetDirtyMaterials() const;
277 
283  void initializeNewGeometryContacts( const agxCollide::GeometryContactPtrVector& geometryContacts );
284 
288  void updateContactMaterials( const agxCollide::GeometryContactPtrVector& geometryContacts );
289 
295  bool loadLibraryContactMaterial( const agx::Material* material1, const agx::Material* material2, agx::ContactMaterial* contactMaterial );
296 
297  private:
298  StringMaterialRefTable m_materials;
299  MaterialSPairContactMaterialRefTable m_contactMaterials;
300 
301  bool m_hasMaterialsWithContactReduction;
302  agxData::EntityStorageRef m_contactMaterialStorage;
303 
304  agx::Mutex m_mutex;
305  };
306 
307  inline const agx::Material* MaterialManager::getDefaultMaterial() const
308  {
310  }
311 
312  inline agxData::EntityStorage* MaterialManager::getContactMaterialStorage()
313  {
314  return m_contactMaterialStorage;
315  }
316 
317  inline const agx::ContactMaterial* MaterialManager::getContactMaterial( agx::Physics::MaterialPtr material1, agx::Physics::MaterialPtr material2 ) const
318  {
319  return getContactMaterial( material1 ? material1.model() : getDefaultMaterial(), material2 ? material2.model() : getDefaultMaterial() );
320  }
321 
322  AGX_FORCE_INLINE SymmetricMaterialPair MaterialManager::getSymmetricPair( const agx::ContactMaterial* contactMaterial ) const
323  {
324  agxAssert( contactMaterial );
325  const agx::Material* m1 = contactMaterial ? contactMaterial->getMaterial1() : nullptr;
326  const agx::Material* m2 = contactMaterial ? contactMaterial->getMaterial2() : nullptr;
327  return SymmetricMaterialPair( m1 ? m1 : getDefaultMaterial(), m2 ? m2 : getDefaultMaterial() );
328  }
329 
330  AGX_FORCE_INLINE SymmetricMaterialPair MaterialManager::getSymmetricPair( const agx::Material* material1, const agx::Material* material2 ) const
331  {
332  return SymmetricMaterialPair( material1 ? material1 : getDefaultMaterial(), material2 ? material2 : getDefaultMaterial() );
333  }
334 }
335 
This class store the combine material properties between two agx::Material&#39;s.
Definition: Material.h:515
AGXTERRAIN_EXPORT void clear()
agx::Vector< const agx::ContactMaterial * > ContactMaterialPtrVector
const Material * getMaterial1() const
Definition: Material.h:1127
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a) ...
Definition: SymmetricPair.h:31
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...
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:38
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
Pointer to a entity instance of type Physics.Material.
A contact between two geometries.
Definition: Contacts.h:270
agx::HashTable< agx::String, agx::MaterialRef > StringMaterialRefTable
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_FORCE_INLINE
Definition: Object.h:59
Internal class for store/restore of MaterialManager.
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Templated vector class.
Definition: Vector.h:52
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
agx::Vector< agx::ref_ptr< agx::ContactMaterial > > ContactMaterialVector
AGXPHYSICS_EXPORT size_t getContactMaterialVector(agxSDK::MaterialManager *mgr, agx::ContactMaterialPtrVector &contactMaterials)
Get all contact materials from the material manager and add them to the supplied vector.
static Material * getDefaultMaterial()
agx::SymmetricPair< const agx::Material *> SymmetricMaterialPair
#define agxAssert(expr)
Definition: debug.h:143
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:375
AGXPHYSICS_EXPORT agx::Material *& model()
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:41
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
std::mutex Mutex
Definition: Referenced.h:99
Simulation unique manager that handles logics around and parameters in contact materials given two ag...
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
AGXPHYSICS_EXPORT size_t getMaterialVector(agxSDK::MaterialManager *mgr, agx::MaterialPtrVector &materials)
Get all materials from the material manager and add them to the supplied vector.
agx::QuadraticProbingHashTable< SymmetricMaterialPair, agx::ContactMaterialRef > MaterialSPairContactMaterialRefTable
Inheritance with partial specialization due to bug with ref_ptr containers.
agx::Vector< const agx::Material * > MaterialPtrVector
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agx::SymmetricPair< const agx::Material * > MaterialPair
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
const Material * getMaterial2() const
Definition: Material.h:1132