terrain mask work

adds an isValid(gridinfo tile) command to prefilter out grid elements of a specified nature
applies that to SetEmptyAction::process
also corrects sliderbar positions for terrain painting elements, as ell as adds a min/max slope for removal

potential TODOs: apply it more places pending feedback. add a min/max hieght filter as well
This commit is contained in:
AzaezelX 2024-10-23 17:50:07 -05:00
parent 43501127ec
commit 85955479c8
5 changed files with 230 additions and 8 deletions

View file

@ -27,6 +27,32 @@
#include "gui/core/guiCanvas.h"
//------------------------------------------------------------------------------
bool TerrainAction::isValid(GridInfo tile)
{
const bool slopeLimit = mTerrainEditor->mSlopeMinAngle > 0.0f || mTerrainEditor->mSlopeMaxAngle < 90.0f;
const F32 minSlope = mSin(mDegToRad(90.0f - mTerrainEditor->mSlopeMinAngle));
const F32 maxSlope = mSin(mDegToRad(90.0f - mTerrainEditor->mSlopeMaxAngle));
const TerrainBlock* terrain = mTerrainEditor->getActiveTerrain();
const F32 squareSize = terrain->getSquareSize();
Point2F p;
Point3F norm;
if (slopeLimit)
{
p.x = tile.mGridPoint.gridPos.x * squareSize;
p.y = tile.mGridPoint.gridPos.y * squareSize;
if (!terrain->getNormal(p, &norm, true))
return false;
if (norm.z > minSlope ||
norm.z < maxSlope)
return false;
}
return true;
}
void SelectAction::process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type)
{
@ -390,6 +416,9 @@ void SetEmptyAction::process(Selection * sel, const Gui3DMouseEvent &, bool selC
if ( inf.mMaterial == U8_MAX )
continue;
if (!isValid(inf))
continue;
// The change flag needs to be set on the undo
// so that it knows to restore materials.
inf.mMaterialChanged = true;