19 #include <agx/config/AGX_USE_AGXTERRAIN.h>
192 void setCompaction(
agx::Real compaction,
bool replaceCompactedSoil=
true )
const;
215 void setEnable(
bool enable );
221 bool getEnable()
const;
227 void setPosition(
const agx::Vec3& position);
238 void setRotation(
const agx::Quat& rotation);
302 void setDeformable(
bool deformable );
309 inline bool getDeformable()
const;
314 void setNoMergeEdgeMargin(
size_t noMergeEdgeMargin);
319 void setNoMerge(
bool noMerge);
361 void removeModifiedParticleVertice(
agx::Vec2i terrainIndex);
377 size_t getResolutionX()
const;
382 size_t getResolutionY()
const;
394 size_t getMemoryUsage();
399 agx::Real getMinimumAllowedHeight()
const;
407 agx::Vec3 getSurfacePosition(
const agx::Vec2i& terrainIndex,
bool includeSurfaceParticles =
false)
const;
415 agx::Vec3 getSurfacePositionWorld(
const agx::Vec2i& terrainIndex,
bool includeSurfaceParticles =
false)
const;
423 agx::Vec2i getClosestGridPoint(
const agx::Vec3& worldPosition,
bool clampToBound=
false)
const;
439 bool isBorderIndex(
const agx::Vec2i& terrainIndex)
const;
446 bool isIndexWithinBounds(
const agx::Vec2i& terrainIndex)
const;
453 bool isWorldPositionWithinBounds(
const agx::Vec3& position)
const;
460 bool isLocalPositionWithinBounds(
const agx::Vec3& position)
const;
475 agx::Real getHeight(
const agx::Vec2i& terrainIndex,
bool includeSurfaceParticles =
false)
const;
485 agx::Real calculateTotalSolidMass()
const;
490 agx::Real calculateTotalFluidMass()
const;
495 agx::Real calculateTotalDynamicMass()
const;
515 bool remove(
Shovel* shovel);
607 agx::Real getLastExcavatedVolume()
const;
614 bool isDigging(
const Shovel* shovel)
const;
637 bool contains(
const Shovel* shovel)
const;
717 bool loadLibraryMaterial(
const agx::String materialName );
731 bool loadMaterialFile(
const agx::String& filename );
743 bool setShovelAggregateContactMaterial(
const Shovel* shovel,
767 bool setHeights(
const agx::RealVector& heights,
bool flipY =
false,
bool resetCompaction =
true );
779 void triggerForceAvalancheAll();
788 agx::RealVector getResizedHeightField(
size_t factorX,
size_t factorY)
const;
809 agx::Real getTotalSoilParticleMass()
const;
851 MassType massType )
const;
870 float getParticleNominalRadius();
875 size_t getNumSoilParticles()
const;
881 size_t getNumCreatedParticles()
const;
903 size_t getNumActiveVoxels();
906 size_t getNumModifiedVoxels();
915 bool verifyMassColumnIntegrity(const
agx::
Vec2i& terrainIndex);
920 bool isVoxelIndexBelowMaximumDepth(const
agx::
Vec3i& index) const;
941 bool isVoxelIndexInsideGeometryBound(const
agx::
Vec3i& index) const;
946 bool isBorderIndexAndBordersLocked(const
agx::
Vec2i& terrainIndex) const;
952 virtual
void runBuildIslandsTask() override;
954 void clearAllSoilParticles();
963 float addFluidMassToColumn(const
agx::
Vec2i& terrainIndex,
float fluidMass) const;
972 float removeFluidMassFromColumn(const
agx::
Vec2i& terrainIndex,
float fluidMass);
981 float addFluidMass(const
agx::
Vec3i& voxelIndex,
float fluidMass) const;
990 float removeFluidMass(const
agx::
Vec3i& voxelIndex,
float fluidMass);
998 agx::
Real calculateFluidOccupancy() const;
1006 agx::
Real getTotalSoilParticleOccupancy() const;
1013 agx::
Vec3 getLocalPositionFromVoxelIndex(const
agx::
Vec3i& voxelIndex) const;
1020 agx::
Vec3 getWorldPositionFromVoxelIndex(const
agx::
Vec3i& voxelIndex) const;
1034 agx::
Vec3i getVoxelIndexFromWorldPosition(const
agx::
Vec3& position) const;
1041 agx::
Vec3i getSurfaceVoxelIndexFromTerrainIndex(const
agx::
Vec2i& terrainIndex) const;
1048 agx::
Vec3 getSurfacePositionFromVoxelXY(const
agx::
Vec2i& voxelXY) const;
1055 agx::
Vec3 getSurfacePositionWorldFromVoxelXY(const
agx::
Vec2i& voxelXY) const;
1062 agx::
Vec2i getTerrainIndexFromVoxelIndexXY(const
agx::
Vec2i& voxelXY) const;
1069 agx::
Vec2i getVoxelIndexXYFromTerrainIndex(const
agx::
Vec2i& terrainIndex) const;
1076 agx::
Vec3i getSurfaceVoxelIndexFromVoxelXY(const
agx::
Vec2i& voxelXY) const;
1083 bool voxelContainsShovel(const
agx::
Vec3i& voxelIndex) const;
1091 bool hasCreatedParticle(
agx::Physics::ParticlePtr particle ) const;
1100 bool hasSameParticleMaterial(
agx::Physics::ParticlePtr particle) const;
1136 void adjustFluidMassInGrid(
agx::
Vec3i binIndex,
int binVoxels,
float availableFluidMass,
float remainingFluidMass);
1140 bool voxelHasParticles(const
agx::
Vec3i& voxelIndex) const;
1142 bool isForbiddenIndex(const
agx::
Vec3i& index);
1144 void addTerrainIndexToAvalanche(const
agx::
Vec2i& index);
1146 int getLowestAllowableVoxelIndexZ() const;
1148 agx::
Vec3 constructHeightFieldOffset() const;
1150 void setIsTerrainPagerTile(
bool isPagerTile);
1152 bool getIsTerrainPagerTile() const;
1154 bool hasEnabledToolCollections() const;
1156 bool shouldUpdateTerrain() const;
1158 bool hasParticlesInTerrain() const;
1160 void debugRenderFluidMass();
1162 void clampHeights(
agx::
Real minValue);
1175 virtual
void addNotification() override;
1180 virtual
void removeNotification() override;
1185 virtual
void preCollide() override;
1190 virtual
void pre() override;
1195 virtual
void post() override;
1200 virtual
void last() override;
1216 bool isSurfaceVoxel(
const agx::Vec3i& index)
const;
1217 bool isSolidBoundaryVoxel(
const agx::Vec3i& index)
const;
1218 bool isSubmergedVoxel(
const agx::Vec3i& index)
const;
1219 bool isFilledSolidVoxel(
const agx::Vec3i& index)
const;
1220 bool isSolidVoxel(
const agx::Vec3i& index)
const;
1221 bool isActiveSolidVoxel(
const agx::Vec3i& index)
const;
1222 bool hasVoxelCompaction(
const agx::Vec3i& index)
const;
1223 bool isVoxelWithinTerrainIndexBounds(
const agx::Vec3i& index)
const;
1225 bool findPathToSurfaceVoxel(
const agx::Vec3i& startVoxel, std::deque<agx::Vec3i>& result);
1230 void updateSurfaceHeightFieldFromDirtyVoxels();
1231 void updateSurfaceHeightFieldFromVoxelIndices(
const agx::Vec3iVector& updateIndices);
1233 void updateSurfaceHeightFieldFromVoxelIndex(
const agx::Vec3i& voxelIndex);
1234 void updateSurfaceHeightFieldFromHeightsTable(
agx::HashTable<
agx::Vec2i, std::pair<agx::Vec3i, agx::Real> >& table );
1238 void initializeSurfaceHeightFieldFromVoxelGrid();
1239 void initVoxelStructureFromHeightField(
bool adjustForCompaction =
false );
1240 void convertVoxelsInActiveZonesToDynamicMass();
1243 void convertRemovedOccupancyToDynamicMass();
1244 void createSoilParticles();
1246 void addDirtyVoxelsToAvalanche();
1247 void removeSoilParticlesOutsideTerrainBounds();
1248 void updateTransformationFromParentBody();
1249 void storeModifiedTerrainIndex(
const agx::Vec2i& terrainVertex );
1250 void addModifiedParticleTerrainIndex(
const agx::Vec2i& terrainIndex);
1258 bool _getIntersectingGridElements(
1262 bool isOccupied =
true)
const;
1264 void sortParticlesIntoVoxels();
1265 void sortParticlesIntoColumns();
1268 void preSortSynchronizeParticleHeightField();
1269 void postSortSynchronizeParticleHeightField();
1272 void sampleParticleMassVelocity();
1274 void preUpdateTerrainContacts();
1275 void postUpdateCompaction();
1277 void markVoxelToAvalanche(
const agx::Vec3i& changedVoxel);
1278 void postSolveShovels();
1279 void updateOccupancyFromHeightChange(
const agx::Vec2i& heightFieldIndex);
1281 void computeForbiddenBounds();
1282 void initializeFromHeightField();
1283 void sanitizeMaxDepthData(
agx::Real maximumDepth);
1286 void resizeSoilParticles();
1289 void growSmallParticlesFromParticleMass(
ParticleDeltaVector& particles,
float particleRadiusUpperLimit);
1290 void growLargeParticlesFromParticleMass(
ParticleDeltaVector& particles,
float particleRadiusUpperLimit);
1293 void mergeSoilParticlesAndFluidMass();
1295 bool mergeFluidMass();
1302 void mergeSoilToCuttingEdge();
1308 void stepFluidMass();
1311 void enforceIncompressibilityColumnwise();
1314 void createFluidMassOnTerrainSurface(
const agx::Vec2i& terrainIndex,
int surfaceVoxelOffset,
agx::Real32 amount);
1317 float convertParticleRadiusToOccupancy(
float radius)
const;
1318 float convertOccupancyToParticleRadius(
float occupancy)
const;
1319 float getDynamicMassCompaction()
const;
1321 bool particleIslandShouldMerge(
const agx::Vector<std::pair<agx::Vec3i, offsetIndexInfo>>& island);
1322 bool voxelColumnHasParticles(
const agx::Vec2i& vertex)
const;
1323 void debugRenderGeometryContactVoxels()
const;
1325 void calculateShovelVoxelIntersection();
1334 agx::Quat generateRandomSoilParticleRotation();
1336 void debugRenderForbiddenBounds();
1337 void debugRenderShovelForbiddenBounds();
1345 void toolCollectionsPreCollide();
1347 void initBuildIslandTask();
1352 void moveEntityDataToCurrentThread();
1354 void sanityCheckHeightFieldAgainstMaxDepth();
1381 float m_nominalSoilParticleRadius;
1387 agx::Vec2i m_voxelToHeightFieldIndexSpaceOffset;
1410 size_t m_noMergeEdgeMargin;
1427 size_t m_numCreatedParticles;
1428 float m_averageSoilParticleRadius;
1443 bool m_isTerrainPagerTile;
1461 agx::Job m_updateHeightfieldsJobs[2];
1464 bool m_enableFluidMerge;
1472 position *= (1.0 / m_voxelSize);
1475 (
agx::Int)std::floor(position.
y() + 0.5),
1476 (
agx::Int)std::floor(position.
z() + 0.5));
1480 inline TerrainDataAtlas* Terrain::getTerrainDataAtlas()
const
1482 return m_terrainDataAtlas;
1488 return m_terrainMaterial;
1494 return m_surfaceHeightField->getResolutionX();
1500 return m_surfaceHeightField->getResolutionY();
1512 return voxelXY + m_voxelToHeightFieldIndexSpaceOffset;
1516 inline agx::Vec2i Terrain::getVoxelIndexXYFromTerrainIndex(
const agx::Vec2i& terrainIndex)
const
1518 return terrainIndex - m_voxelToHeightFieldIndexSpaceOffset;
1531 return m_invTransform;
1535 inline agx::Vec3i Terrain::getSurfaceVoxelIndexFromTerrainIndex(
const agx::Vec2i& terrainIndex)
const
1537 agx::Vec2i voxelXY = getVoxelIndexXYFromTerrainIndex(terrainIndex);
1539 auto solidGrid =
static_cast<ColumnHeightGrid*
>(m_terrainDataAtlas->getGridMassData(TerrainDataAtlas::MassType::SOLID));
1542 return agx::Vec3i(voxelXY.
x(), voxelXY.
y(), voxelHeight);
1546 inline agx::Vec3 Terrain::getSurfacePositionFromVoxelXY(
const agx::Vec2i& voxelXY )
const
1552 inline agx::Vec3 Terrain::getSurfacePositionWorldFromVoxelXY(
const agx::Vec2i& voxelXY )
const
1558 inline bool Terrain::getIsTerrainPagerTile()
const
1560 return m_isTerrainPagerTile;
1565 return m_properties->getEnableDeformation();