AGX Dynamics 2.42.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#include <agx/FrictionModel.h>
24
25#include <agxCollide/Contacts.h>
26
28
29namespace agx
30{
33}
34
35namespace agxSDK
36{
38 typedef agx::ContactMaterial* (*ContactMaterialFunction)(const agx::Material* m1, const agx::Material* m2);
39
43
45
51 {
52 public:
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
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
138
142 const agx::Material* getMaterial( const agx::String& name ) const;
143
148
152 const agx::Material* getDefaultMaterial() const;
153
158
166
171
179
184
193
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:
222 class MaterialManagerSerializer : public agxStream::Serializable
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
249
250 protected:
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
278
285
290
296 bool loadLibraryContactMaterial( const agx::Material* material1, const agx::Material* material2, agx::ContactMaterial* contactMaterial );
297
298 private:
299 StringMaterialRefTable m_materials;
300 MaterialSPairContactMaterialRefTable m_contactMaterials;
301
302 bool m_hasMaterialsWithContactReduction;
303 agxData::EntityStorageRef m_contactMaterialStorage;
304
305 agx::Mutex m_mutex;
306 };
307
309 {
311 }
312
314 {
315 return m_contactMaterialStorage;
316 }
317
319 {
320 return getContactMaterial( material1 ? material1.model() : getDefaultMaterial(), material2 ? material2.model() : getDefaultMaterial() );
321 }
322
324 {
325 agxAssert( contactMaterial );
326 const agx::Material* m1 = contactMaterial ? contactMaterial->getMaterial1() : nullptr;
327 const agx::Material* m2 = contactMaterial ? contactMaterial->getMaterial2() : nullptr;
328 return SymmetricMaterialPair( m1 ? m1 : getDefaultMaterial(), m2 ? m2 : getDefaultMaterial() );
329 }
330
332 {
333 return SymmetricMaterialPair( material1 ? material1 : getDefaultMaterial(), material2 ? material2 : getDefaultMaterial() );
334 }
335}
336
#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:207
#define AGXPHYSICS_EXPORT
A contact between two geometries.
Definition: Contacts.h:354
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:518
const Material * getMaterial2() const
Definition: Material.h:1142
const Material * getMaterial1() const
Definition: Material.h:1137
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:378
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