AGX Dynamics 2.41.3.0
Loading...
Searching...
No Matches
MaterialManager.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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
27
28namespace agx
29{
32}
33
34namespace agxSDK
35{
37 typedef agx::ContactMaterial* (*ContactMaterialFunction)(const agx::Material* m1, const agx::Material* m2);
38
42
44
50 {
51 public:
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
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
137
141 const agx::Material* getMaterial( const agx::String& name ) const;
142
147
151 const agx::Material* getDefaultMaterial() const;
152
157
165
170
178
183
192
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:
221 class MaterialManagerSerializer : public agxStream::Serializable
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
233
234 protected:
235 MaterialManagerSerializer() : m_mgr( nullptr ) {}
237 };
238
242 void store( agxStream::OutputArchive& out ) const;
243
248
249 protected:
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
277
284
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
308 {
310 }
311
313 {
314 return m_contactMaterialStorage;
315 }
316
318 {
319 return getContactMaterial( material1 ? material1.model() : getDefaultMaterial(), material2 ? material2.model() : getDefaultMaterial() );
320 }
321
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
331 {
332 return SymmetricMaterialPair( material1 ? material1 : getDefaultMaterial(), material2 ? material2 : getDefaultMaterial() );
333 }
334}
335
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#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:208
#define AGXPHYSICS_EXPORT
A contact between two geometries.
Definition: Contacts.h:336
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:73
Internal class for store/restore of MaterialManager.
agx::Vector< agx::ref_ptr< agx::ContactMaterial > > ContactMaterialVector
Simulation unique manager that handles logics around and parameters in contact materials given two ag...
const MaterialSPairContactMaterialRefTable & getContactMaterials() const
static agx::Model * ClassModel()
agx::ContactMaterialPtrVector getContactMaterialVector() const
This method will create and return new vector with all ContactMaterials.
bool setContactMaterial(agxCollide::LocalGeometryContact *localGeometryContact)
Assigns contact material to a local geometry contact.
bool loadLibraryContactMaterial(const agx::Material *material1, const agx::Material *material2, agx::ContactMaterial *contactMaterial)
Try to load the Library ContactMaterial for the pair (material1, material2) and fill in the settings ...
agx::Material * getMaterial(const agx::String &name)
static void calculateContactMaterial(agx::ContactMaterial *contactMaterial)
Static method to calculate the parameters in a contact material given the two materials assigned to i...
bool remove(agx::ContactMaterial *contactMaterial)
Remove explicit contact material from this manager.
void initializeNewGeometryContacts(const agxCollide::GeometryContactPtrVector &geometryContacts)
For any geometry contact where the contact material is zero, this method performs getOrCreateContactM...
void updateContactMaterials(const agxCollide::GeometryContactPtrVector &geometryContacts)
Updates implicit, dirty, materials that are currently used.
bool remove(agx::Material *material)
Remove material from this manager.
agx::MaterialPtrVector getMaterialVector() const
This method will create and return new vector with all materials.
void clear()
Clears all internal structures.
void store(agxStream::OutputArchive &out) const
Saves necessary internal structures.
virtual ~MaterialManager()
Destructor.
SymmetricMaterialPair getSymmetricPair(const agx::ContactMaterial *contactMaterial) const
agx::Material * getMaterial(const agx::Uuid &uuid)
MaterialManager()
Default constructor.
agx::ContactMaterial * getOrCreateContactMaterial(const agxCollide::GeometryContact *geometryContact)
Not part of the public API.
const agx::ContactMaterial * getContactMaterial(const agx::Material *material1, const agx::Material *material2) const
Returns an implicit or explicit contact material if it exists.
bool hasMaterialsWithContactReduction() const
void restore(const MaterialManagerSerializer &mgr)
Restores necessary internal structures.
bool add(agx::ContactMaterial *contactMaterial)
Add explicit contact material to this manager.
const agx::Material * getMaterial(const agx::String &name) const
agx::ContactMaterial * getOrCreateContactMaterial(const agx::Material *material1, const agx::Material *material2)
Returns or creates an explicit contact material.
const StringMaterialRefTable & getMaterials() const
agxData::EntityStorage * getContactMaterialStorage()
const agx::Material * getDefaultMaterial() const
void resetDirtyMaterials() const
Updates implicit contact materials containing at least one dirty material.
bool add(agx::Material *material)
Add material to this manager.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:131
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:57
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:39
This class store the combine material properties between two agx::Material's.
Definition: Material.h:516
const Material * getMaterial2() const
Definition: Material.h:1145
const Material * getMaterial1() const
Definition: Material.h:1140
Inheritance with partial specialization due to bug with ref_ptr containers.
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:376
static Material * getDefaultMaterial()
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:41
Pointer to a entity instance of type Physics.Material.
AGXPHYSICS_EXPORT agx::Material *& model()
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a)
Definition: SymmetricPair.h:32
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:42
Templated vector class.
Definition: agx/Vector.h:53
#define agxAssert(expr)
Definition: debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
#define AGX_FORCE_INLINE
Definition: macros.h:58
This namespace consists of a set of classes for handling geometric intersection tests including boole...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
agx::HashTable< agx::String, agx::MaterialRef > StringMaterialRefTable
agx::QuadraticProbingHashTable< SymmetricMaterialPair, agx::ContactMaterialRef > MaterialSPairContactMaterialRefTable
agx::SymmetricPair< const agx::Material * > MaterialPair
agx::SymmetricPair< const agx::Material * > SymmetricMaterialPair
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
std::mutex Mutex
Definition: Referenced.h:99
agx::Vector< const agx::ContactMaterial * > ContactMaterialPtrVector
agx::Vector< const agx::Material * > MaterialPtrVector