AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MaterialManager.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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>
24 
25 #include <agxCollide/Contacts.h>
26 
27 #include <agxData/EntityStorage.h>
28 
29 namespace agx
30 {
33 }
34 
35 namespace agxSDK
36 {
38  typedef agx::ContactMaterial *(*ContactMaterialFunction)(const agx::Material* m1, const agx::Material* m2);
39 
43 
45 
51  {
52  public:
56  static agx::Model* ClassModel();
57 
63  static void calculateContactMaterial( agx::ContactMaterial* contactMaterial );
64 
65  public:
70 
77  bool add( agx::Material* material );
78 
91  bool add( agx::ContactMaterial* contactMaterial );
92 
98  bool remove( agx::Material* material );
99 
105  bool remove( agx::ContactMaterial* contactMaterial );
106 
114  agx::ContactMaterial* getOrCreateContactMaterial( const agx::Material* material1, const agx::Material* material2 );
115 
123  const agx::ContactMaterial* getContactMaterial( const agx::Material* material1, const agx::Material* material2 ) const;
124 
132  const agx::ContactMaterial* getContactMaterial( agx::Physics::MaterialPtr material1, agx::Physics::MaterialPtr material2 ) const;
133 
137  agx::Material* getMaterial( const agx::String& name );
138 
142  const agx::Material* getMaterial( const agx::String& name ) const;
143 
147  agx::Material* getMaterial(const agx::Uuid& uuid);
148 
152  const agx::Material* getDefaultMaterial() const;
153 
157  const StringMaterialRefTable& getMaterials() const;
158 
166 
170  const MaterialSPairContactMaterialRefTable& getContactMaterials() const;
171 
179 
183  bool hasMaterialsWithContactReduction() const;
184 
192  bool setContactMaterial( agxCollide::LocalGeometryContact* localGeometryContact );
193 
197  agx::ContactMaterial* getOrCreateContactMaterial( const agxCollide::GeometryContact* geometryContact );
198 
202  agxData::EntityStorage* getContactMaterialStorage();
203 
209  agx::ContactMaterial* getContactMaterialOrCreateImplicit(const agx::Material* material1, const agx::Material* material2);
210 
215  agx::ContactMaterial* getContactMaterialOrCreateImplicit(const agxCollide::Geometry* geometry1, const agxCollide::Geometry* geometry2);
217 
218  public:
223  {
224  public:
226  : m_mgr( mgr ) {}
228 
229  const MaterialManager *get() const { return m_mgr; }
230  void set( MaterialManager* mgr ) { m_mgr = mgr; }
231 
234 
235  protected:
236  MaterialManagerSerializer() : m_mgr( nullptr ) {}
238  };
239 
243  void store( agxStream::OutputArchive& out ) const;
244 
248  void restore( const MaterialManagerSerializer& mgr );
249 
250  protected:
254  virtual ~MaterialManager();
255 
259  SymmetricMaterialPair getSymmetricPair( const agx::ContactMaterial* contactMaterial ) const;
260 
264  SymmetricMaterialPair getSymmetricPair( const agx::Material* material1, const agx::Material* material2 ) const;
265 
266  friend class Simulation;
267  friend class SimulationController;
268 
272  void clear();
273 
277  void resetDirtyMaterials() const;
278 
284  void initializeNewGeometryContacts( const agxCollide::GeometryContactPtrVector& geometryContacts );
285 
289  void updateContactMaterials( const agxCollide::GeometryContactPtrVector& geometryContacts );
290 
291  private:
292  StringMaterialRefTable m_materials;
293  MaterialSPairContactMaterialRefTable m_contactMaterials;
294 
295  bool m_hasMaterialsWithContactReduction;
296  agxData::EntityStorageRef m_contactMaterialStorage;
297 
298  agx::Mutex m_mutex;
299  };
300 
302  {
304  }
305 
307  {
308  return m_contactMaterialStorage;
309  }
310 
312  {
313  return getContactMaterial( material1 ? material1.model() : getDefaultMaterial(), material2 ? material2.model() : getDefaultMaterial() );
314  }
315 
317  {
318  agxAssert( contactMaterial );
319  const agx::Material* m1 = contactMaterial ? contactMaterial->getMaterial1() : nullptr;
320  const agx::Material* m2 = contactMaterial ? contactMaterial->getMaterial2() : nullptr;
321  return SymmetricMaterialPair( m1 ? m1 : getDefaultMaterial(), m2 ? m2 : getDefaultMaterial() );
322  }
323 
325  {
326  return SymmetricMaterialPair( material1 ? material1 : getDefaultMaterial(), material2 ? material2 : getDefaultMaterial() );
327  }
328 }
329 
This class store the combine material properties between two agx::Material&#39;s.
Definition: Material.h:503
AGXTERRAIN_EXPORT void clear()
const agx::ContactMaterial * getContactMaterial(const agx::Material *material1, const agx::Material *material2) const
Returns an implicit or explicit contact material if it exists.
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:73
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:248
#define AGX_FORCE_INLINE
Definition: Object.h:62
Internal class for store/restore of MaterialManager.
agx::Vector< const agx::Material * > MaterialPtrVector
The geometry representation used by the collision detection engine.
Definition: Geometry.h:88
agx::SymmetricPair< const agx::Material * > MaterialPair
Templated vector class.
Definition: Vector.h:52
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()
agxData::EntityStorage * getContactMaterialStorage()
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:384
const Material * getMaterial2() const
Definition: Material.h:1135
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:206
const Material * getMaterial1() const
Definition: Material.h:1130
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:93
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:121
SymmetricMaterialPair getSymmetricPair(const agx::ContactMaterial *contactMaterial) const
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
const agx::Material * getDefaultMaterial() const
agx::Vector< const agx::ContactMaterial * > ContactMaterialPtrVector
Inheritance with partial specialization due to bug with ref_ptr containers.
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:101
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:100