AGX Dynamics  2.37.2.0
DeformController.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 
20 #include <agx/Plane.h>
23 #include <array>
24 
25 namespace agxTerrain
26 {
28 
30  {
31  public:
32  DeformController(agx::Frame* parentFrame,
33  const agx::Line& cuttingEdge,
34  const agx::Line& topEdge,
35  const agx::Vec3& forwardVector,
36  const agxCollide::GeometryRefVector& voxelCollisionGeometries);
37 
38  void addNotification(agxSDK::Simulation* simulation, Terrain* terrain);
39 
40  void removeNotification(agxSDK::Simulation* simulation, Terrain* terrain);
41 
42  void onPreCollide(TerrainToolCollection* collection);
43 
44  void onPre(TerrainToolCollection* collection);
45 
46  void onPost(TerrainToolCollection* collection);
47 
48  DeformerCollection* getDeformerCollection(size_t i);
49 
50  ActiveZonePtrVector getActiveZones();
51 
52  agxCollide::GeometryPtrVector getActiveZoneGeometries();
53 
54  SoilParticleAggregatePtrVector getSoilParticleAggregates();
55 
56  agxCollide::GeometryContactPtrVector getGeometryContacts(agxSDK::Simulation *simulation) const;
57 
58  void onEnableChanged(bool enable);
59 
60  void initializeContactMaterials(TerrainToolCollection* collection);
61 
62  void initializeFrictionModels( TerrainToolCollection* collection );
63 
64  void resetAggregateContactHistories();
65 
66  void resetAggregateContactHistory(agx::UInt i);
67 
68  const agxTerrain::AggregateContactDepthModel& getAggregateDepthModel(agx::UInt i) const;
69 
70  void setEnableCustomFrictionModels( bool enable );
71 
72  bool getEnableCustomFrictionModels() const;
73 
74  agx::Real calculateShovelAggregateContactArea(const agx::Vec3Vector& contactPoints, agx::Real voxelArea) const;
75 
82  agx::ContactMaterial* getAggregateShovelContactMaterial( agx::UInt i ) const;
83 
90  agx::ContactMaterial* getAggregateTerrainContactMaterial( agx::UInt i ) const;
91 
92  protected:
93  virtual ~DeformController();
94 
95  private:
96  enum DeformSide
97  {
98  BACK = 0,
99  LEFT = 1,
100  RIGHT = 2
101  };
102 
103  private:
104 
105  void createEdges(const agx::Line& cuttingEdge,
106  const agx::Line& topEdge,
107  const agx::Vec3& forwardVector,
108  const agxCollide::GeometryRefVector& voxelCollisionGeometries);
109 
110  agx::Vec3Vector extractVertices(const agxCollide::GeometryRefVector& voxelCollisionGeometries);
111 
112  agx::Vec3 findEdgePoint( agx::Vec3Vector& vertices,
113  agx::Vec3 point,
114  agx::Plane& frontPlane,
115  agx::Plane& bottomPlane,
116  agx::Plane& sidePlane,
117  agx::Real tol );
118 
119  void deformSolidMass(TerrainToolCollection* collection);
120 
121  bool shouldDeformMass(TerrainToolCollection* collection);
122 
123  void createAggregateContactPoints(TerrainToolCollection* collection);
124 
125  void createShovelContacts(TerrainToolCollection* collection);
126 
127  void createTerrainContacts(TerrainToolCollection* collection);
128 
129  agx::Vec3Vector findShovelTerrainIntersectionPoints( TerrainToolCollection* collection,
130  DeformerCollection* deformer );
131 
132  agx::Vec3Vector findAggregateTerrainIntersectionPoints( const agx::Line& wedgeCuttingEdge,
133  const agx::Line& wedgeFailureEdge );
134 
135  agx::Vec3 calculateAggregateNormal( const agx::Line& wedgeCuttingEdge,
136  const agx::Line& wedgeFailureEdge ) const;
137 
138  void pushSoilToSides(TerrainToolCollection* collection,
139  const agx::Vec3& fromVoxelWorldPos,
140  const agx::Real& elementSize,
141  const agx::Vec3& topVectorNormalized,
142  const agx::Vec3& deformerNormal,
143  const agx::Real& timeStep,
144  const agx::Real& voxelSpeed,
145  const agx::Vec2i& fromTerrainIndex,
146  const float& occupancyInVoxel,
147  const float& dynamicMassCompaction,
148  const agx::Vec3i& voxel,
149  agx::Vec3* voxelSideVelocity);
150 
151  void updateFrictionModels( TerrainToolCollection* collection );
152 
153  void DEBUG_DRAW();
154 
155  private:
156 
157  agx::Frame* m_parentFrame;
158  std::array<DeformerCollectionRef, 3> m_deformers;
159  std::array<AggregateContactDepthModel, 3> m_depthModels;
160  std::array<ShovelAggregateFrictionModelRef, 3> m_frictionModels;
162  std::array<agx::ContactMaterialRef, 3> m_aggregateTerrainContactMaterials;
163  std::array<agx::ContactMaterialRef, 3> m_aggregateShovelContactMaterials;
164  bool m_enableCustomFrictionModels;
165  };
166 }
This class store the combine material properties between two agx::Material&#39;s.
Definition: Material.h:515
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes...
Definition: Geometry.h:59
Collection of terrain tool (currently Shovel) related objects which are terrain instance specific...
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Class representing the mathematical concept of a plane, also called a half- space.
Definition: Plane.h:31
Class used to calculate the contact depth in the soil aggregate <-> terrain contacts to mimic an elas...
Base class providing referencing counted objects.
Definition: Referenced.h:119
uint32_t UInt
Definition: Integer.h:34
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
#define AGXTERRAIN_EXPORT
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
double Real
Definition: Real.h:42