19 #include <agx/config/AGX_USE_AGXTERRAIN.h> 191 void setCompaction(
agx::Real compaction,
bool replaceCompactedSoil=
true )
const;
214 void setEnable(
bool enable );
220 bool getEnable()
const;
226 void setPosition(
const agx::Vec3& position);
237 void setRotation(
const agx::Quat& rotation);
309 void setDeformable(
bool deformable );
316 inline bool getDeformable()
const;
321 void setNoMergeEdgeMargin(
size_t noMergeEdgeMargin);
326 void setNoMerge(
bool noMerge);
347 const ModifiedVerticesVector& getModifiedVertices()
const;
353 const ModifiedVerticesVector& getModifiedParticleVertices()
const;
358 void removeModifiedParticleVertice(
agx::Vec2i terrainIndex);
364 const ModifiedVerticesVector& getParticleVertices()
const;
374 size_t getResolutionX()
const;
379 size_t getResolutionY()
const;
391 size_t getMemoryUsage();
396 agx::Real getMinimumAllowedHeight()
const;
404 agx::Vec3 getSurfacePosition(
const agx::Vec2i& terrainIndex,
bool includeSurfaceParticles =
false)
const;
412 agx::Vec3 getSurfacePositionWorld(
const agx::Vec2i& terrainIndex,
bool includeSurfaceParticles =
false)
const;
420 agx::Vec2i getClosestGridPoint(
const agx::Vec3& worldPosition,
bool clampToBound=
false)
const;
436 bool isBorderIndex(
const agx::Vec2i& terrainIndex)
const;
443 bool isIndexWithinBounds(
const agx::Vec2i& terrainIndex)
const;
450 bool isWorldPositionWithinBounds(
const agx::Vec3& position)
const;
457 bool isLocalPositionWithinBounds(
const agx::Vec3& position)
const;
472 agx::Real getHeight(
const agx::Vec2i& terrainIndex,
bool includeSurfaceParticles =
false)
const;
482 agx::Real calculateTotalSolidMass()
const;
487 agx::Real calculateTotalFluidMass()
const;
492 agx::Real calculateTotalDynamicMass()
const;
512 bool remove(
Shovel* shovel);
620 agx::Real getLastExcavatedVolume()
const;
627 bool isDigging(
const Shovel* shovel)
const;
650 bool contains(
const Shovel* shovel)
const;
737 void clearTerrainMaterials(
bool clearAddedMaterials =
true);
806 bool loadLibraryMaterial(
const agx::String& materialName );
830 bool loadMaterialFile(
const agx::String& filename );
849 bool setShovelAggregateContactMaterial(
const Shovel* shovel,
873 bool setHeights(
const agx::RealVector& heights,
bool flipY =
false,
bool resetCompaction =
true );
886 void triggerForceAvalancheAll();
895 agx::RealVector getResizedHeightField(
size_t factorX,
size_t factorY)
const;
916 agx::Real getTotalSoilParticleMass()
const;
990 float getParticleNominalRadius()
const;
995 size_t getNumSoilParticles()
const;
1001 size_t getNumCreatedParticles()
const;
1021 static agx::Real getTerrainParticlePackingRatio();
1026 bool isOfHomogeneousTerrainMaterial()
const;
1073 size_t getNumActiveVoxels()
const;
1076 size_t getNumModifiedVoxels()
const;
1085 bool verifyMassColumnIntegrity(
const agx::Vec2i& terrainIndex)
const;
1090 bool isVoxelIndexBelowMaximumDepth(
const agx::Vec3i& index)
const;
1119 bool isVoxelIndexInsideGeometryBound(
const agx::Vec3i& index)
const;
1129 bool isBorderIndexAndBordersLocked(
const agx::Vec2i& terrainIndex)
const;
1133 TerrainDataAtlas* getTerrainDataAtlas()
const;
1136 virtual void runBuildIslandsTask()
override;
1138 void clearAllSoilParticles();
1147 float addFluidMassToColumn(
const agx::Vec2i& terrainIndex,
float fluidMass)
const;
1156 float removeFluidMassFromColumn(
const agx::Vec2i& terrainIndex,
float fluidMass);
1165 float addFluidMass(
const agx::Vec3i& voxelIndex,
float fluidMass)
const;
1174 float removeFluidMass(
const agx::Vec3i& voxelIndex,
float fluidMass);
1182 agx::Real calculateFluidOccupancy()
const;
1190 agx::Real getTotalSoilParticleOccupancy()
const;
1247 void setForbiddenVoxelsForDynamicMass(
const agx::Vec3iVector& voxelIndices);
1254 bool getForbiddenVoxelsForDynamicMass(
agx::Vec3iVector& voxelIndices)
const;
1262 bool isForbiddenVoxelsForDynamicMass(
const agx::Vec3i& voxelIndex)
const;
1269 bool voxelContainsShovel(
const agx::Vec3i& voxelIndex)
const;
1300 TerrainMaterialController* getMaterialController()
const;
1302 void adjustFluidMassInGrid(
agx::Vec3i binIndex,
int binVoxels,
float availableFluidMass,
float remainingFluidMass);
1306 bool isPointSubmerged(
const agx::Vec3& point )
const;
1308 bool voxelHasParticles(
const agx::Vec3i& voxelIndex)
const;
1310 bool isForbiddenIndex(
const agx::Vec3i& index);
1312 void addTerrainIndexToAvalanche(
const agx::Vec2i& index);
1314 int getLowestAllowableVoxelIndexZ()
const;
1316 agx::Vec3 constructVoxelFieldOffset()
const;
1318 void setIsTerrainPagerTile(
bool isPagerTile);
1320 bool getIsTerrainPagerTile()
const;
1322 bool hasEnabledToolCollections()
const;
1324 bool shouldUpdateTerrain()
const;
1326 bool hasParticlesInTerrain()
const;
1328 void debugRenderFluidMass();
1332 bool isSolidVoxel(
const agx::Vec3i& index )
const;
1334 bool isActiveSolidVoxel(
const agx::Vec3i& index )
const;
1347 virtual void addNotification()
override;
1352 virtual void removeNotification()
override;
1357 virtual void preCollide()
override;
1362 virtual void pre()
override;
1367 virtual void post()
override;
1372 virtual void last()
override;
1388 bool isSurfaceVoxel(
const agx::Vec3i& index)
const;
1389 bool isSolidBoundaryVoxel(
const agx::Vec3i& index)
const;
1390 bool isSubmergedVoxel(
const agx::Vec3i& index)
const;
1391 bool isFilledSolidVoxel(
const agx::Vec3i& index)
const;
1392 bool hasVoxelCompaction(
const agx::Vec3i& index)
const;
1393 bool isVoxelWithinTerrainIndexBounds(
const agx::Vec3i& index)
const;
1395 bool findPathToSurfaceVoxel(
const agx::Vec3i& startVoxel, std::deque<agx::Vec3i>& result);
1400 void updateSurfaceHeightFieldFromDirtyVoxels();
1401 void updateSurfaceHeightFieldFromVoxelIndices(
const agx::Vec3iVector& updateIndices);
1403 void updateSurfaceHeightFieldFromVoxelIndex(
const agx::Vec3i& voxelIndex);
1404 void updateSurfaceHeightFieldFromHeightsTable(
agx::HashTable<
agx::Vec2i, std::pair<agx::Vec3i, agx::Real> >& table );
1408 void initializeSurfaceHeightFieldFromVoxelGrid();
1409 void initVoxelStructureFromHeightField(
bool adjustForCompaction =
false );
1410 void convertVoxelsInActiveZonesToDynamicMass();
1413 void convertRemovedOccupancyToDynamicMass();
1414 void createSoilParticles();
1416 void addDirtyVoxelsToAvalanche();
1417 void removeSoilParticlesOutsideTerrainBounds();
1418 void updateTransformationFromParentBody();
1419 void storeModifiedTerrainIndex(
const agx::Vec2i& terrainVertex );
1420 void addModifiedParticleTerrainIndex(
const agx::Vec2i& terrainIndex);
1426 bool _getIntersectingGridElements(
1430 bool isOccupied =
true)
const;
1432 void sortParticlesIntoVoxels();
1433 void sortParticlesIntoColumns();
1444 bool parallelExecute);
1453 void debugRenderContactGeometryVoxels();
1457 void preSortSynchronizeParticleHeightField();
1458 void postSortSynchronizeParticleHeightField();
1461 void sampleParticleMassVelocity();
1463 void preUpdateTerrainContacts();
1464 void postUpdateCompaction();
1466 void markVoxelToAvalanche(
const agx::Vec3i& changedVoxel);
1467 void postSolveShovels();
1468 void updateOccupancyFromHeightChange(
const agx::Vec2i& heightFieldIndex);
1470 void computeForbiddenBounds();
1471 void initializeFromHeightField();
1472 void sanitizeMaxDepthData(
agx::Real maximumDepth);
1475 void resizeSoilParticles();
1476 void computeParticleGrowthTables(
const agx::UInt64Vector& particleIndices, ParticleDeltaVector& particles);
1477 void growParticlesFromFluidMass(
agx::Vec3i binIndex,
int binVoxels,
float availableFluidMass, ParticleDeltaVector& particles);
1478 void growSmallParticlesFromParticleMass(ParticleDeltaVector& particles,
float particleRadiusUpperLimit);
1479 void growLargeParticlesFromParticleMass(ParticleDeltaVector& particles,
float particleRadiusUpperLimit);
1482 void mergeSoilParticlesAndFluidMass();
1484 bool mergeFluidMass();
1487 void resizeOrRemoveParticles(
const agx::HashTable<SoilParticlePtr, std::array<agx::Real, 2>>& particlesToUpdate );
1491 void mergeSoilToCuttingEdge();
1493 float convertParticlesToSolidMass(
agx::Vec3i voxel, ParticleWeightPairVector particles,
float massToRemove,
agx::Vec3iVector& changedIndices);
1497 void stepFluidMass();
1500 void enforceIncompressibilityColumnwise();
1503 void createFluidMassOnTerrainSurface(
const agx::Vec2i& terrainIndex,
int surfaceVoxelOffset,
agx::Real32 amount);
1506 float convertParticleRadiusToOccupancy(
float radius)
const;
1507 float convertOccupancyToParticleRadius(
float occupancy)
const;
1508 float getDynamicMassCompaction(
const agx::Vec3i& voxelIndex)
const;
1509 bool particleIslandShouldMerge(
const agx::Vector<std::pair<agx::Vec3i, offsetIndexInfo>>& island);
1510 bool voxelColumnHasParticles(
const agx::Vec2i& vertex)
const;
1516 void removeEmptyTerrainMaterialVoxels();
1520 void calculateShovelVoxelIntersection();
1529 agx::Quat generateRandomSoilParticleRotation();
1531 void debugRenderForbiddenBounds();
1532 void debugRenderShovelForbiddenBounds();
1534 AvalancheController* getAvalancheController()
const;
1540 void toolCollectionsPreCollide();
1542 void initBuildIslandTask();
1543 void updateInternalTransforms();
1550 void moveEntityDataToCurrentThread();
1552 void sanityCheckHeightFieldAgainstMaxDepth();
1554 friend class AvalancheController;
1560 friend class TerrainMaterialController;
1580 float m_nominalSoilParticleRadius;
1589 TerrainDataAtlasRef m_terrainDataAtlas;
1591 TerrainMaterialControllerRef m_materialController;
1594 AvalancheControllerRef m_avalancheController;
1609 size_t m_noMergeEdgeMargin;
1617 VoxelIndexSet m_voxelHasCreatedParticle;
1618 VoxelIndexSet m_forbiddenVoxelsForDynamicMass;
1620 ModifiedVerticesSetVector m_modifiedVoxelColumns;
1621 ModifiedVerticesSetVector m_modifiedTerrainVertices;
1622 ModifiedVerticesSetVector m_modifiedParticleVertices;
1623 ModifiedVerticesSetVector m_particleTerrainVertices;
1626 size_t m_numCreatedParticles;
1627 float m_averageSoilParticleRadius;
1631 ParticleWeightPairVector m_voxelParticleWeightPairVector;
1638 ParticleWeightPairVector m_columnParticleWeightPairVector;
1645 bool m_isTerrainPagerTile;
1663 agx::Job m_updateHeightfieldsJobs[2];
1667 bool m_enableFluidMerge;
1673 inline TerrainDataAtlas* Terrain::getTerrainDataAtlas()
const 1675 return m_terrainDataAtlas;
1680 return m_materialController->getDefaultTerrainMaterial();
1686 return m_materialController->getDefaultTerrainMaterial();
1692 auto voxelIndex = getVoxelIndexFromWorldPosition(position);
1693 return m_materialController->getTerrainMaterial(voxelIndex);
1699 return m_surfaceHeightField->getResolutionX();
1705 return m_surfaceHeightField->getResolutionY();
1718 return m_voxelSpaceTransform;
1725 return m_invVoxelSpaceTransform;
1739 return m_invTransform;
1743 inline agx::Vec3i Terrain::getSurfaceVoxelIndexFromTerrainIndex(
const agx::Vec2i& terrainIndex)
const 1745 auto solidGrid =
static_cast<ColumnHeightGrid*
>(m_terrainDataAtlas->getGridMassOccupancyData(TerrainDataAtlas::MassType::SOLID));
1748 return agx::Vec3i( terrainIndex.
x(), terrainIndex.
y(), voxelHeight);
1751 inline bool Terrain::getIsTerrainPagerTile()
const 1753 return m_isTerrainPagerTile;
1758 return m_properties->getEnableDeformation();
agxTerrain::Terrain instance in a simulation, receiving step and contact callbacks in a controllable ...
int getSurfaceHeightIndex(const agx::Vec2i terrainIndex)
Class that handles and sanity checks the mass logic in the terrain.
Interface class for accessing and manipulating the underlying 3D grid data in the terrain using terra...
Pure virtual interface class for the data storage grid classes we have.
const agx::AffineMatrix4x4 & _getInvVoxelSpaceTransform() const
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
const agx::AffineMatrix4x4 & _getVoxelSpaceTransform() const
Pointer to a entity instance of type Physics.GranularBody.
An abstract job/workblock representation, which allows work threads to execute arbitrary tasks...
A class holding 4 dimensional vectors and providing basic arithmetic.
Class for containing and managing the different agxTerrain::Terrain settings.
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes...
agx::Physics::GranularBodyPtrVector SoilParticlePtrVector
The HighAccurayTimer class can replace the regular Timer class in high level applications where the n...
agx::Vector< agx::Vec2i > ModifiedVerticesVector
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
#define AGX_DECLARE_POINTER_TYPES(type)
ExcavationMode
Enum for describing the different excavation modes of a shovel: PRIMARY - The primary mode of excavat...
Representation of a name string.
agx::UInt groundParticleIndex
Class representing the mathematical concept of a plane, also called a half- space.
std::function< bool(const agx::Vec3i &index)> GoToStopCondition
agx::Real getElementSize() const
Returns the element size of a cell in agxTerrain, which is incidentally the distance between the cent...
This class is used to describe the general material properties of the Terrain.
agx::Physics::GranularBodyPtr SoilParticlePtr
The geometry representation used by the collision detection engine.
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Vector containing 'raw' data.
std::pair< SoilParticlePtr, agx::Real > ParticleWeightPair
The TerrainCache is used internally by the TerrainPager to provide requested terrain tiles...
agx::Vector< ParticleWeightPair > ParticleWeightPairVector
Controller that handles compaction in the terrain from generated terrain contacts in TerrainContactGe...
Utility class where most of the physics calculation used in agxTerrain is gathered.
agx::HashSet< agx::Vec2i > TerrainIndexSet
agx::Vector< std::pair< SoilParticlePtr, float > > ParticleDeltaVector
size_t getResolutionY() const
Returns the element resolution of the terrain in the local Y-axis.
const agx::AffineMatrix4x4 & _getInverseTransform() const
#define AGXTERRAIN_EXPORT
Class implementing the BasicGrid interface.
The rigid body class, combining a geometric model and a frame of reference.
Main material class which acts as a holder of a Surface Material and a Bulk material.
TerrainMaterial * getDefaultTerrainMaterial() const
Returns the default terrain material which is used to derive material and contact material parameters...
TerrainMaterial * getTerrainMaterial() const
Returns the default terrain material which is used to derive material and contact material parameters...
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Interface class for accessing data and functions for the internal soil particle simulation used in ag...
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
agx::HashSet< agx::Vec3i > VoxelIndexSet
static agx::Vec3 transformVectorToWorld(const agx::Vec3 &v, const agxCollide::Geometry *g)
Transforms a vector given in shape coordinates to world coordinates given geometry g...
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
const agx::AffineMatrix4x4 & _getTransform() const
size_t getResolutionX() const
Returns the element resolution of the terrain in the local X-axis.
#define AGX_DECLARE_VECTOR_TYPES(type)
agx::HashTable< agx::Vec3i, ParticleWeightPairVector > IndexToParticleWeightPairVector
bool getDeformable() const
Gets whether or not deformations are enabled for this terrain.
static agx::Vec3 transformPointToWorld(const agx::Vec3 &p, const agxCollide::Geometry *g)
Transforms a point given in shape coordinates to world given geometry g.
Inheritance with partial specialization due to bug with ref_ptr containers.
agx::SetVector< agx::Vec2i > ModifiedVerticesSetVector
Pointer to a entity instance of type Physics.Particle.
A HeightField is a collision shape that can be created from a grid structure, like an image...
#define DOXYGEN_END_INTERNAL_BLOCK()
#define DOXYGEN_START_INTERNAL_BLOCK()