Skip to content

Commit

Permalink
Merge pull request #1328 from Azaezel/alpha41/terrainTooling
Browse files Browse the repository at this point in the history
terrain mask work
  • Loading branch information
Azaezel authored Oct 29, 2024
2 parents 4350112 + 218caea commit ba088db
Show file tree
Hide file tree
Showing 7 changed files with 682 additions and 56 deletions.
81 changes: 59 additions & 22 deletions Engine/source/gui/worldEditor/terrainActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,35 @@
#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;
}
if (tile.mHeight < mTerrainEditor->mTileMinHeight || tile.mHeight > mTerrainEditor->mTileMaxHeight)
return false;

return true;
}

void SelectAction::process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type)
{
Expand Down Expand Up @@ -200,32 +229,13 @@ void PaintMaterialAction::process(Selection * sel, const Gui3DMouseEvent &, bool
if ( !selChanged || mat < 0 )
return;

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;


for( U32 i = 0; i < sel->size(); i++ )
{
GridInfo &inf = (*sel)[i];

if ( slopeLimit )
{
p.x = inf.mGridPoint.gridPos.x * squareSize;
p.y = inf.mGridPoint.gridPos.y * squareSize;
if ( !terrain->getNormal( p, &norm, true ) )
continue;

if ( norm.z > minSlope ||
norm.z < maxSlope )
continue;
}
if (!isValid(inf))
continue;

// If grid is already set to our material, or it is an
// empty grid spot, then skip painting.
Expand Down Expand Up @@ -298,6 +308,9 @@ void RaiseHeightAction::process( Selection *sel, const Gui3DMouseEvent &evt, boo

for ( U32 i = 0; i < sel->size(); i++ )
{
if (!isValid((*sel)[i]))
continue;

mTerrainEditor->getUndoSel()->add((*sel)[i]);
if ( (*sel)[i].mHeight < maxHeight )
{
Expand Down Expand Up @@ -344,6 +357,9 @@ void LowerHeightAction::process(Selection * sel, const Gui3DMouseEvent &, bool s

for(U32 i = 0; i < sel->size(); i++)
{
if (!isValid((*sel)[i]))
continue;

mTerrainEditor->getUndoSel()->add((*sel)[i]);
if((*sel)[i].mHeight > maxHeight)
{
Expand All @@ -365,6 +381,9 @@ void SetHeightAction::process(Selection * sel, const Gui3DMouseEvent &, bool sel
{
for(U32 i = 0; i < sel->size(); i++)
{
if (!isValid((*sel)[i]))
continue;

mTerrainEditor->getUndoSel()->add((*sel)[i]);
(*sel)[i].mHeight = mTerrainEditor->mSetHeightVal;
mTerrainEditor->setGridInfo((*sel)[i]);
Expand All @@ -390,6 +409,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;
Expand Down Expand Up @@ -441,6 +463,9 @@ void ScaleHeightAction::process(Selection * sel, const Gui3DMouseEvent &, bool s
{
for(U32 i = 0; i < sel->size(); i++)
{
if (!isValid((*sel)[i]))
continue;

mTerrainEditor->getUndoSel()->add((*sel)[i]);
(*sel)[i].mHeight *= mTerrainEditor->mScaleVal;
mTerrainEditor->setGridInfo((*sel)[i]);
Expand Down Expand Up @@ -579,6 +604,9 @@ void FlattenHeightAction::process(Selection * sel, const Gui3DMouseEvent &, bool
// set it
for(U32 i = 0; i < sel->size(); i++)
{
if (!isValid((*sel)[i]))
continue;

mTerrainEditor->getUndoSel()->add((*sel)[i]);

//
Expand Down Expand Up @@ -666,7 +694,7 @@ void SmoothSlopeAction::process(Selection * sel, const Gui3DMouseEvent &, bool s

F32 goalHeight;
for(U32 i = 0; i < sel->size(); i++)
{
{
goalHeight = avgHeight + ((*sel)[i].mGridPoint.gridPos.x - avgPos.x)*avgSlope.x +
((*sel)[i].mGridPoint.gridPos.y - avgPos.y)*avgSlope.y;
(*sel)[i].mHeight += (goalHeight - (*sel)[i].mHeight) * (*sel)[i].mWeight;
Expand Down Expand Up @@ -694,6 +722,9 @@ void PaintNoiseAction::process(Selection * sel, const Gui3DMouseEvent &, bool se
{
for( U32 i = 0; i < sel->size(); i++ )
{
if (!isValid((*sel)[i]))
continue;

mTerrainEditor->getUndoSel()->add((*sel)[i]);

const Point2I &gridPos = (*sel)[i].mGridPoint.gridPos;
Expand All @@ -703,6 +734,12 @@ void PaintNoiseAction::process(Selection * sel, const Gui3DMouseEvent &, bool se

(*sel)[i].mHeight += (noiseVal - mMinMaxNoise.y * mScale) * (*sel)[i].mWeight * mTerrainEditor->mNoiseFactor;

if ((*sel)[i].mHeight > mTerrainEditor->mTileMaxHeight)
(*sel)[i].mHeight = mTerrainEditor->mTileMaxHeight;

if ((*sel)[i].mHeight < mTerrainEditor->mTileMinHeight)
(*sel)[i].mHeight = mTerrainEditor->mTileMinHeight;

mTerrainEditor->setGridInfo((*sel)[i]);
}

Expand Down
2 changes: 1 addition & 1 deletion Engine/source/gui/worldEditor/terrainActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TerrainAction
End,
Process
};

bool isValid(GridInfo tile);
//
virtual void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type) = 0;
virtual bool useMouseBrush() { return(true); }
Expand Down
34 changes: 34 additions & 0 deletions Engine/source/gui/worldEditor/terrainEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ TerrainEditor::TerrainEditor() :

mSlopeMinAngle = 0.0f;
mSlopeMaxAngle = 90.0f;
mTileMinHeight = 0;
mTileMaxHeight = 2047;
}

TerrainEditor::~TerrainEditor()
Expand Down Expand Up @@ -2858,6 +2860,38 @@ DefineEngineMethod( TerrainEditor, setSlopeLimitMaxAngle, F32, (F32 angle), , ""
return angle;
}

DefineEngineMethod(TerrainEditor, getTileLimitMinHeight, F32, (), , "")
{
return object->mTileMinHeight;
}

DefineEngineMethod(TerrainEditor, setTileLimitMinHeight, F32, (F32 height), , "")
{
if (height < 0.0f)
height = 0.0f;

if (height > object->mTileMaxHeight)
height = object->mTileMaxHeight;

object->mTileMinHeight = height;
return height;
}

DefineEngineMethod(TerrainEditor, getTileLimitMaxHeight, F32, (), , "")
{
return object->mTileMaxHeight;
}

DefineEngineMethod(TerrainEditor, setTileLimitMaxHeight, F32, (F32 height), , "")
{
if (height > 2047.0f)
height = 2047.0f;
if (height < object->mTileMinHeight)
height = object->mTileMinHeight;

object->mTileMaxHeight = height;
return height;
}
//------------------------------------------------------------------------------
void TerrainEditor::autoMaterialLayer( F32 mMinHeight, F32 mMaxHeight, F32 mMinSlope, F32 mMaxSlope, F32 mCoverage )
{
Expand Down
2 changes: 2 additions & 0 deletions Engine/source/gui/worldEditor/terrainEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ class TerrainEditor : public EditTSCtrl

F32 mSlopeMinAngle;
F32 mSlopeMaxAngle;
F32 mTileMinHeight;
F32 mTileMaxHeight;

public:

Expand Down
Loading

0 comments on commit ba088db

Please sign in to comment.