AGX Dynamics 2.40.0.0
Loading...
Searching...
No Matches
Shovel.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 <agx/BitState.h>
27#include <agx/Plane.h>
28
29namespace agxCollide
30{
31 class Geometry;
32 class Shape;
33}
34
35namespace agxTerrain
36{
37 //--- Forward declarations ---//
38 class ShovelAggregateContactMaterialContainer;
41 class Terrain;
42 class TerrainMaterial;
43
45
48
63 {
64 public:
66 class Settings;
67
74 static Shovel* find(const agxSDK::Simulation* simulation, const agx::Name& name);
75
82 static Shovel* find(const agxSDK::Simulation* simulation, const agx::Uuid& uuid);
83
89 static ShovelPtrVector findAll(const agxSDK::Simulation* simulation);
90
106 Shovel( agx::RigidBody* shovelBody,
107 const agx::Line& topEdge,
108 const agx::Line& cuttingEdge,
109 const agx::Vec3& cuttingDirection,
110 Shovel* connectedShovel=nullptr,
111 ShovelDebugRenderSettings* settings = nullptr);
112
117 {
121 PRIMARY = 0,
126 DEFORM_BACK = 1,
131 DEFORM_RIGHT = 2,
136 DEFORM_LEFT = 3
137 };
138
139 /*
140 \return if the shovel is valid after construction. If it is not valid, it will not be possible to add the shovel to
141 a simulation.
142 */
143 virtual bool isValid() const override;
144
149
154
159
164
168 const agx::Line& getTopEdge() const;
169
174
178 const agx::Line& getCuttingEdge() const;
179
184
189
194
196 {
201 };
202
207
225
230 void setTopEdge(agx::Line topEdge);
231
236 void setCuttingEdge(agx::Line cuttingEdge);
237
241 void setCuttingDirection(agx::Vec3 cuttingDirection);
242
247 void setCutTopPlane(agx::Plane cutTopPlane);
248
253
258
263
274
287
292
297
305
313
325 agx::Real getTotalSoilBulkVolume( agx::Real packingFraction = 0.67 ) const;
326
331
338
344
350
355
362
370
376 void setEnable(bool enable);
377
382 bool getEnable() const;
383
389
394
395 public:
396
401
406
411
416
421
426
431
436
442
447 void setEnableForTerrain(Terrain* terrain, bool enable);
448
452 bool getEnableForTerrain(Terrain* terrain) const;
453
454
464 Shovel::ExcavationMode mode = Shovel::ExcavationMode::PRIMARY );
465
466
475 agx::ContactMaterial* getShovelAggregateContactMaterial( Shovel::ExcavationMode mode = Shovel::ExcavationMode::PRIMARY ) const;
476
477
482
487
492
500
507
515
522
529
538
548
558
566 bool getPenetrationForce(agx::Vec3& force, agx::Vec3& torque) const;
567
574
581
588
589
596
602 bool isDigging() const;
603
608
616
617 /*
618 \return the active terrain that the shovel is acting on. If the shovel is currently not excavating, return nullptr.
619 */
621
622 /*
623 \return if the shovel is currently active. The shovel is active either while interacting with a terrain, or if
624 there are particels in the inner shape.
625 */
626 bool isActive() const;
627
632 {
633 public:
638
644
649 void setEnable(bool enable);
650
655 void setEnableCreateDynamicMass(bool enable);
656
661 void setEnableForceFeedback(bool enable);
662
666 bool getEnable() const;
667
672
677
682
683 void store( agxStream::OutputArchive& out ) const { m_excavationFlags.store( out ); }
684 void restore( agxStream::InputArchive& in ) { m_excavationFlags.restore( in ); }
685
686 private:
687 enum StateFlags : agx::UInt32
688 {
689 ENABLED = 1 << 0,
690 ENABLE_CREATE_DYNAMIC_MASS = 1 << 1,
691 ENABLE_FORCE_FEEDBACK = 1 << 2
692 };
693 using Flags = agx::BitState<StateFlags, agx::UInt32>;
694 Flags m_excavationFlags;
695 };
696
704 agx::Plane calculateCutTopPlane();
705
711 void setEdgesCodirectional();
712
716 agx::Bool canDeformTerrain(Terrain* terrain) const;
717
718 bool getShovelPlanes(agx::Plane& bottomPlane,
719 agx::Plane& backPlane,
720 agx::Plane& leftPlane,
721 agx::Plane& rightPlane) const;
722
723 void removeTerrainShovelContacts(Terrain* terrain);
724
725 /* Contact filtering for deformers */
726 void removeTerrainShovelContactsDeformer(Terrain* terrain);
727
728 agx::Real getSubmergedEdgeLength(const agx::Line& edge, const Terrain* terrain) const;
729
730 agx::Vec3 getCuttingEdgeVelocity();
731
732 void setInnerContactArea( agx::Real contactArea );
733
734 /* Set whether the settings are dirty. Prompts the shovel to update internal classes due to changed settings. */
735 void setSettingsAreDirty(bool enable);
736
737 bool getSettingsAreDirty() const;
738
739 Shovel* getConnectedShovel();
740
741 agx::Physics::GranularBodySystem* getGranularBodySystem() const;
742
743 virtual void onAssemblyAdd( agxSDK::Assembly* assembly ) override;
744
750 agx::Vec3 getUpDirection() const;
751
752 const agx::Vec3iVector& getVoxelsInActiveZoneLastTimeStep();
753
754 ShovelDebugRenderSettings* getDebugRenderSettings() const { return m_debugRenderSettings; }
755
758
759 protected:
764
768 virtual ~Shovel();
769
770 /* Make sure cutting direction is normalized */
771 agx::Vec3 ensureCuttingDirectionIsNormalized(agx::Vec3 cuttingDirection);
772
773 /* Default value for contact region threshold */
774 agx::Real computeDefaultContactRegionThreshold() const;
775
776 /*
777 Creates a frame which uses the shovel body's frame as parent. Other shovel internals
778 attaches to this frame to make sure they follow along the shovel rigid body.
779 Requires that the shovel body isn't nullptr.
780 */
781 agx::Frame* createParentFrame();
782
783 agxSDK::TerrainManager* getTerrainManager();
784
785 TerrainPtrVec getTerrainsInSimulation();
786
790 virtual void addNotification() override;
791
795 virtual void removeNotification() override;
796
801 void setAggregateMaterial(agx::Material* material);
802
806 void initalizeContactMaterialsForExistingTerrains(agxSDK::Simulation* simulation);
807
808 /*
809 Checks if all internal contact materials are correct.
810 If there is an active terrain (ie, we are excavating or bulldozing)
811 the contact material will be customized for that terrain.
812 */
813 void checkContactMaterials();
814
823 virtual void preCollide() override;
824
834 virtual void pre() override;
835
840 virtual void post() override;
841
846 virtual void last() override;
847
848 void calculateDeadLoadFraction();
849
850 /*
851 Checks if there are particles inside the shovels collision geometries.
852 */
853 bool shovelHasParticles() const;
854
858 void clearActiveZoneWedges() const;
859
863 void calculateForbiddenBounds();
864
868 static agx::UInt excavationModeToDeformerCollectionIndex(Shovel::ExcavationMode excavationMode);
869
870 private:
871 enum DeformSide
872 {
873 BACK = 0,
874 LEFT = 1,
875 RIGHT = 2
876 };
877
878 private:
882 void createDeformers(const agx::Line& cuttingEdge,
883 const agx::Line& topEdge,
884 const agx::Vec3& forwardVector,
885 const agxCollide::GeometryRefVector& voxelCollisionGeometries);
886
887 agx::Vec3Vector extractVertices(const agxCollide::GeometryRefVector& voxelCollisionGeometries);
888
889 agx::Vec3 findEdgePoint(agx::Vec3Vector& vertices,
890 agx::Vec3 point,
891 agx::Plane& frontPlane,
892 agx::Plane& bottomPlane,
893 agx::Plane& sidePlane,
894 agx::Real tol);
895
896 void addDeformers(const std::array<DeformerCollectionRef, 3>& deformers);
897
898 bool shouldDeformMass(Terrain* terrain);
899
900 protected:
901 ShovelDebugRenderSettingsRef m_debugRenderSettings;
902
904 {
908 };
909
910 // Configuration:
916
917 // Settings
920 std::array< ExcavationSettings, 4 > m_excavationSettings;
921
922 // Caching of dead load
924 // Caching of inner contact area
926
927 agx::FrameRef m_parentFrame; /* Parent frame for shovel geometries synchronized with model center of shovel body. */
928
929 // Geometries used to find shovel-voxel collisions
932
934
938 // Voxel collision geometries HAVE to be calculated before creating the active zone otherwise it is not possible to create an inner shape.
941 std::array<DeformerCollectionRef, 3> m_deformers;
943
950 };
951
957 {
958 public:
960
962
963 bool setContactMaterial(Shovel::ExcavationMode excavationMode, agx::ContactMaterial* contactMaterial);
964
966
970
971 private:
972 agx::Vector< agx::ContactMaterialRef > m_contactMaterials;
973 };
974
976 {
977 friend class Shovel;
978 public:
979 /*
980 \return true if the given rigidBody is part of a shovel.
981 */
982 static bool isRigidBodyShovel(const agx::RigidBody* rigidBody);
983
984 /*
985 \return true if the given geometry is part of shovels rigidBody.
986 */
987 static bool isGeometryShovel(const agxCollide::Geometry* geometry);
988
989 protected:
990 /*
991 Set some properties on the rigid body to mark it as part of a shovel.
992 Used in the shovel constructor.
993 */
994 static void setIsRigidBodyShovel(agx::RigidBody* rigidBody, bool enable);
995 };
996}
#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 AGXTERRAIN_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:38
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:130
An agxTerrain::TerrainToolInstance in a simulation, receiving step and contact callbacks in a control...
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:57
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
Simple container class for storing and handling explicit contact material for shovel-aggregate contac...
Definition: Shovel.h:957
agx::ContactMaterial * getContactMaterial(Shovel::ExcavationMode excavationMode) const
bool setContactMaterial(Shovel::ExcavationMode excavationMode, agx::ContactMaterial *contactMaterial)
static bool isGeometryShovel(const agxCollide::Geometry *geometry)
static bool isRigidBodyShovel(const agx::RigidBody *rigidBody)
static void setIsRigidBodyShovel(agx::RigidBody *rigidBody, bool enable)
Class containing the settings for the different ExcavationModes for a shovel.
Definition: Shovel.h:632
ExcavationSettings()
Default constructor.
void setEnable(bool enable)
Set whether the excavation mode should be enabled, creating dynamic mass and generating force feedbac...
ExcavationSettings(agx::UInt32 state)
Constructor taking an internal state variable from another excavation setting object.
void store(agxStream::OutputArchive &out) const
Definition: Shovel.h:683
void setEnableForceFeedback(bool enable)
Set true/false if the excavation mode should generate force feedback from created aggregates.
void restore(agxStream::InputArchive &in)
Definition: Shovel.h:684
void setEnableCreateDynamicMass(bool enable)
Set true/false if the excavation mode should create dynamic mass.
Shovel object used to interact with a terrain via an active zone that converts solid terrain to dynam...
Definition: Shovel.h:63
bool setShovelAggregateContactMaterial(agx::ContactMaterial *contactMaterial, Shovel::ExcavationMode mode=Shovel::ExcavationMode::PRIMARY)
Explicitly set contact material properties in a shovel-aggregate contact for a specific excavation mo...
agx::Plane getCutTopPlaneWorld() const
agx::Vec3 getAggregateTerrainContactForce(Shovel::ExcavationMode excavationMode) const
Get the terrain <-> aggregate contact force for the given excavation mode.
agx::Real getTotalSoilBulkVolume(agx::Real packingFraction=0.67) const
Returns the total bulk volume moved by the shovel, both in the inner shapes and in the soil wedges in...
agx::Vec3 getContactForce() const
Given geometry contacts exists and the solver has solved them - calculates total shovel contact force...
agx::Real getInnerSoilBulkVolume() const
Get the last computed dead load bulk volume of the shovel, i.e the inner volume that is filled with d...
agx::Real getAggregateTerrainContactDepth(Shovel::ExcavationMode excavationMode) const
agx::Line m_topEdge
Definition: Shovel.h:913
void setCuttingDirection(agx::Vec3 cuttingDirection)
agx::RigidBodyRef m_shovelBody
Definition: Shovel.h:911
agx::Real getInnerSoilMass() const
agx::Vec3 getSeparationNormalForce() const
Given geometry contacts exists and the solver has solved them - calculates total contact normal force...
bool collisionGeometriesAreInsideTerrain(Terrain *terrain) const
Check if any of the collision geometries are inside terrain bounds.
agx::Real getInnerVolume() const
SoilParticleVector getInnerSoilParticles() const
ShovelDebugRenderSettingsRef m_debugRenderSettings
Definition: Shovel.h:901
agx::Vec3 m_cuttingDirection
Definition: Shovel.h:914
DeformController * getDeformController() const
static Shovel * find(const agxSDK::Simulation *simulation, const agx::Name &name)
Find first shovel with given name.
agx::Plane getCurrentSeparationPlane(ExcavationMode mode) const
virtual bool isValid() const override
Shovel(agx::RigidBody *shovelBody, const agx::Line &topEdge, const agx::Line &cuttingEdge, const agx::Vec3 &cuttingDirection, Shovel *connectedShovel=nullptr, ShovelDebugRenderSettings *settings=nullptr)
Basic constructor.
Shovel * m_connectedShovel
Definition: Shovel.h:933
const agx::Vector< agxCollide::BoundingAABB > & getForbiddenBounds()
Get the shovels forbidden bounds.
agx::Real m_deadLoadFraction
Definition: Shovel.h:923
static ShovelPtrVector findAll(const agxSDK::Simulation *simulation)
Finds all shovels in the given simulation.
agx::Frame * getParentFrame() const
SoilParticleAggregate * getSoilParticleAggregate() const
bool m_settingsAreDirty
Definition: Shovel.h:931
agx::Material * getAggregateMaterial() const
void setEnableShovelTerrainGeometryContacts(Terrain *terrain, bool enable)
Set if regular geometry contacts should be created between the shovel geometries and the associated t...
void setCutTopPlane(agx::Plane cutTopPlane)
Set the cutting plane in local space.
agx::Vector< agxCollide::BoundingAABB > m_forbiddenBounds
Definition: Shovel.h:947
const agx::RigidBody * getWedgeAggregate(Shovel::ExcavationMode excavationMode) const
agxCollide::GeometryContactPtrVector getShovelAggregateContacts(Shovel::ExcavationMode excavationMode) const
Get the shovel <-> aggregate contacts with the soil particle aggregate for the given excavation mode.
agx::Real getDynamicMass() const
agx::Real getTotalSoilMass() const
agx::MaterialRef m_aggregateMaterial
Definition: Shovel.h:944
agx::Vec3 getDeformationContactForce() const
Given geometry contacts exists and the solver has solved them - calculates total contact force betwee...
agx::FrameRef m_parentFrame
Definition: Shovel.h:927
void setTopEdge(agx::Line topEdge)
Set the top edge in local space.
ShovelAggregateContactMaterialContainer * getShovelTerrainContactMaterialContainer() const
const agxCollide::GeometryRefVector & getVoxelCollisionGeometries() const
agx::Real getSoilAggregateMass(Shovel::ExcavationMode excavationMode) const
Returns the total soil aggregate mass in the shovel for the specific excavation mode.
bool getEnable() const
Access the state enable flag.
agx::Vec3 getCuttingDirectionWorld() const
agx::Vec3 getSeparationContactForce() const
Given geometry contacts exists and the solver has solved them - calculates total contact force betwee...
ShovelAggregateContactMaterialContainerRef m_shovelAggregateCMContainer
Definition: Shovel.h:935
ShovelSettings * getSettings()
void setEnableForTerrain(Terrain *terrain, bool enable)
Set if the shovel is enabled for the particular terrain.
agxCollide::GeometryRefVector m_voxelCollisionGeometries
Definition: Shovel.h:930
SoilParticleAggregateRef m_soilParticleAggregate
Definition: Shovel.h:936
agx::Real getSecondarySeparationAngle() const
AggregateContactGenerator * getAggregateContactGenerator() const
SoilParticleVector getTotalSoilParticles() const
agx::Vec3 getSecondaryCuttingDirection() const
agx::Real getDeadLoadFraction() const
Get the last computed dead load fraction of the shovel, i.e how much of it's inner volume that is fil...
agx::Vec3 getAggregateTerrainTangentialForce(Shovel::ExcavationMode excavationMode) const
Get the terrain <-> aggregate tangential force for the given excavation mode.
agx::Vec3iVector m_voxelsInPrimaryActiveZoneLastTimeStep
Definition: Shovel.h:948
const agx::Plane & getCutTopPlane() const
PrimaryActiveZone * getActiveZone() const
agx::Line getTopEdgeWorld() const
Terrain * m_activeTerrain
Definition: Shovel.h:946
std::array< ExcavationSettings, 4 > m_excavationSettings
Definition: Shovel.h:920
const agx::Line & getTopEdge() const
void setEnable(bool enable)
Change state enable of this shovel.
SoilPenetrationResistanceRef m_penetrationResistance
Definition: Shovel.h:937
agx::ContactMaterial * getShovelAggregateContactMaterial(Shovel::ExcavationMode mode=Shovel::ExcavationMode::PRIMARY) const
Get the explicitly set contact material in a shovel-aggregate contact corresponding to a specified ex...
agx::Vec3 getSeparationFrictionForce() const
Given geometry contacts exists and the solver has solved them - calculates total contact friction for...
agxCollide::BoundingAABB m_collisionBound
Definition: Shovel.h:949
agx::Line getCuttingEdgeWorld() const
Terrain * getActiveTerrain() const
bool isDigging() const
Check if the shovel is currently in digging mode with a terrain, i.e if the cutting edge is submerged...
PrimaryActiveZoneRef m_activeZone
Definition: Shovel.h:939
void setExcavationSettings(ExcavationMode mode, ExcavationSettings excavationSettings)
Set a settings object for an ExcavationMode of the shovel.
agx::Real getInnerParticleVolume() const
AdvancedShovelSettings * getAdvancedSettings()
agxCollide::GeometryContactPtrVector getAggregateTerrainContacts(Shovel::ExcavationMode excavationMode) const
Get the aggregate <-> terrain geometry contacts with the shovel given an excavation mode.
bool getPenetrationForce(agx::Vec3 &force, agx::Vec3 &torque) const
The result includes the active force and torque from the penetration resistance from the active terra...
static Shovel * find(const agxSDK::Simulation *simulation, const agx::Uuid &uuid)
Find shovel with given UUID.
agx::Vec3 getAggregateTerrainNormalForce(Shovel::ExcavationMode excavationMode) const
Get the terrain <-> aggregate normal force for the given excavation mode.
agx::Real getInnerContactArea() const
Get the last computed inner contact area of the shovel, i.e the estimated cross-section area of the i...
agx::Real getAggregateTerrainContactArea(Shovel::ExcavationMode excavationMode) const
Get the aggregate <-> terrain contact area given an excavation mode and a shovel.
AggregateContactGeneratorRef m_aggregateContactGenerator
Definition: Shovel.h:940
SoilPenetrationResistance * getPenetrationResistance() const
agx::Line m_cuttingEdge
Definition: Shovel.h:912
ShovelSettingsRef m_shovelSettings
Definition: Shovel.h:919
std::array< DeformerCollectionRef, 3 > m_deformers
Definition: Shovel.h:941
agx::RigidBody * getRigidBody() const
bool getEnableForTerrain(Terrain *terrain) const
agx::Vec3 getExcavationModeContactForce(Shovel::ExcavationMode excavationMode) const
Calculates total contact force between the soil aggregate associated with the specified excavation mo...
bool setSoilPenetrationModel(agxTerrain::SoilPenetrationResistance::PenetrationModel model)
Set the soil penetration model used for the shovel.
bool getSoilPenetrationModel(agxTerrain::SoilPenetrationResistance::PenetrationModel &model) const
Get the soil penetration model used for the shovel.
const agx::Vec3 & getCuttingDirection() const
bool isActive() const
DeformControllerRef m_deformController
Definition: Shovel.h:942
agx::Real m_innerContactArea
Definition: Shovel.h:925
const agx::Line & getCuttingEdge() const
ExcavationSettings & getExcavationSettings(ExcavationMode mode)
ExcavationMode
Enum for describing the different excavation modes of a shovel:
Definition: Shovel.h:117
void setCuttingEdge(agx::Line cuttingEdge)
Set the cutting edge in local space.
agx::Plane m_cutTopPlane
Definition: Shovel.h:915
agx::Real computeCuttingEdgeLength() const
This class is used to describe the general material properties of the Terrain.
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition: Terrain.h:90
This class store the combine material properties between two agx::Material's.
Definition: Material.h:516
The object defining a frame of reference and providing transformations operations.
Definition: agx/Frame.h:68
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:376
Representation of a name string.
Definition: Name.h:33
Class representing the mathematical concept of a plane, also called a half- space.
Definition: agx/Plane.h:32
Base class providing referencing counted objects.
Definition: Referenced.h:120
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:42
Vector containing 'raw' data.
Definition: agx/Vector.h:246
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
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
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:59
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:32
uint64_t UInt
Definition: Integer.h:27
double Real
Definition: Real.h:42