mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-12 00:40:44 +00:00
simplify erosion calcs
This commit is contained in:
parent
e106871350
commit
f9eeaf8869
2 changed files with 20 additions and 76 deletions
|
|
@ -758,22 +758,8 @@ void ThermalErosionAction::process(Selection * sel, const Gui3DMouseEvent &, boo
|
|||
if (!tblock)
|
||||
return;
|
||||
|
||||
Vector<F32> scratch = mNoiseData;
|
||||
if (type == Begin)
|
||||
{
|
||||
mNoise.setSeed(Sim::getCurrentTime());
|
||||
mNoise.fBm(&mNoiseData, mNoiseSize, 12, 1.0f, 5.0f);
|
||||
scratch = mNoiseData;
|
||||
mNoise.rigidMultiFractal(&mNoiseData, &scratch, mNoiseSize, 12, 1.0f, 5.0f);
|
||||
mNoise.getMinMax(&mNoiseData, &mMinMaxNoise.x, &mMinMaxNoise.y, mNoiseSize);
|
||||
}
|
||||
scratch = mNoiseData;
|
||||
//erodeThermal(Vector<F32> *src, Vector<F32> *dst, F32 slope, F32 materialLoss, U32 iterations, U32 size, U32 squareSize, F32 maxHeight );
|
||||
mNoise.erodeThermal(&scratch, &mNoiseData, 30.0f, 5.0f, 5, mNoiseSize, 1, tblock->getObjBox().len_z());
|
||||
mNoise.getMinMax(&mNoiseData, &mMinMaxNoise.x, &mMinMaxNoise.y, mNoiseSize);
|
||||
mScale = 1.5f / (mMinMaxNoise.x - mMinMaxNoise.y + 0.0001);
|
||||
|
||||
F32 selRange = sel->getMaxHeight()-sel->getMinHeight();
|
||||
F32 avg = sel->getAvgHeight();
|
||||
if (selChanged)
|
||||
{
|
||||
F32 heightDiff = 0;
|
||||
|
|
@ -785,23 +771,11 @@ void ThermalErosionAction::process(Selection * sel, const Gui3DMouseEvent &, boo
|
|||
|
||||
mTerrainEditor->getUndoSel()->add((*sel)[i]);
|
||||
|
||||
const Point2I& gridPos = (*sel)[i].mGridPoint.gridPos;
|
||||
|
||||
const F32 noiseVal = mNoiseData[(gridPos.x % mNoiseSize) +
|
||||
((gridPos.y % mNoiseSize) * mNoiseSize)]/(mMinMaxNoise.y-mMinMaxNoise.x) * selRange + mMinMaxNoise.y;
|
||||
|
||||
heightDiff = (noiseVal * mTerrainEditor->mNoiseFactor - (*sel)[i].mHeight) / tblock->getObjBox().len_z() * 2.0;
|
||||
|
||||
const F32 squareSize = tblock->getSquareSize();
|
||||
Point2F p;
|
||||
Point3F norm;
|
||||
|
||||
p.x = (*sel)[i].mGridPoint.gridPos.x * squareSize;
|
||||
p.y = (*sel)[i].mGridPoint.gridPos.y * squareSize;
|
||||
tblock->getNormal(p, &norm, true);
|
||||
|
||||
F32 bias = 0.75f-norm.z;
|
||||
(*sel)[i].mHeight += heightDiff * (*sel)[i].mWeight * bias;
|
||||
F32 bias = ((*sel)[i].mHeight - avg) / selRange;
|
||||
F32 nudge = mRandF(-mTerrainEditor->getBrushPressure(), mTerrainEditor->getBrushPressure());
|
||||
F32 heightTarg = mRoundF((*sel)[i].mHeight - bias * nudge, mTerrainEditor->getBrushPressure() * 2.0f) ;
|
||||
heightDiff = heightTarg - (*sel)[i].mHeight;
|
||||
(*sel)[i].mHeight += heightDiff * (*sel)[i].mWeight;
|
||||
|
||||
if ((*sel)[i].mHeight > mTerrainEditor->mTileMaxHeight)
|
||||
(*sel)[i].mHeight = mTerrainEditor->mTileMaxHeight;
|
||||
|
|
@ -824,22 +798,13 @@ void HydraulicErosionAction::process(Selection* sel, const Gui3DMouseEvent&, boo
|
|||
TerrainBlock* tblock = mTerrainEditor->getActiveTerrain();
|
||||
if (!tblock)
|
||||
return;
|
||||
Vector<F32> scratch = mNoiseData;
|
||||
if (type == Begin)
|
||||
{
|
||||
mNoise.setSeed(Sim::getCurrentTime());
|
||||
mNoise.fBm(&mNoiseData, mNoiseSize, 12, 1.0f, 5.0f);
|
||||
scratch = mNoiseData;
|
||||
}
|
||||
mNoise.erodeHydraulic(&scratch, &mNoiseData, 1, mNoiseSize);
|
||||
mNoise.getMinMax(&mNoiseData, &mMinMaxNoise.x, &mMinMaxNoise.y, mNoiseSize);
|
||||
mScale = 1.5f / (mMinMaxNoise.x - mMinMaxNoise.y + 0.0001);
|
||||
|
||||
F32 selRange = sel->getMaxHeight() - sel->getMinHeight();
|
||||
F32 avg = sel->getAvgHeight();
|
||||
if (selChanged)
|
||||
{
|
||||
F32 heightDiff = 0;
|
||||
const F32 squareSize = tblock->getSquareSize();
|
||||
|
||||
for (U32 i = 0; i < sel->size(); i++)
|
||||
{
|
||||
|
|
@ -848,15 +813,19 @@ void HydraulicErosionAction::process(Selection* sel, const Gui3DMouseEvent&, boo
|
|||
|
||||
mTerrainEditor->getUndoSel()->add((*sel)[i]);
|
||||
|
||||
const Point2I& gridPos = (*sel)[i].mGridPoint.gridPos;
|
||||
Point2F p;
|
||||
Point3F norm;
|
||||
|
||||
const F32 noiseVal = mNoiseData[(gridPos.x % mNoiseSize) +
|
||||
((gridPos.y % mNoiseSize) * mNoiseSize)] / (mMinMaxNoise.y - mMinMaxNoise.x) * selRange + mMinMaxNoise.y;
|
||||
p.x = (*sel)[i].mGridPoint.gridPos.x * squareSize;
|
||||
p.y = (*sel)[i].mGridPoint.gridPos.y * squareSize;
|
||||
tblock->getNormal(p, &norm, true);
|
||||
|
||||
heightDiff = (noiseVal * mTerrainEditor->mNoiseFactor - (*sel)[i].mHeight) / tblock->getObjBox().len_z() * 2.0;
|
||||
F32 bias = mPow(norm.z,3.0f) * ((*sel)[i].mHeight - avg) / selRange;
|
||||
F32 nudge = mRandF(-mTerrainEditor->getBrushPressure(), mTerrainEditor->getBrushPressure());
|
||||
|
||||
F32 bias = ((*sel)[i].mHeight - avg)/ selRange;
|
||||
(*sel)[i].mHeight += heightDiff * (*sel)[i].mWeight * bias;
|
||||
heightDiff = bias * (-(*sel)[i].mHeight + bias * nudge) / tblock->getObjBox().len_z() * 2.0;
|
||||
|
||||
(*sel)[i].mHeight += heightDiff * (*sel)[i].mWeight;
|
||||
|
||||
if ((*sel)[i].mHeight > mTerrainEditor->mTileMaxHeight)
|
||||
(*sel)[i].mHeight = mTerrainEditor->mTileMaxHeight;
|
||||
|
|
|
|||
|
|
@ -307,48 +307,23 @@ class ThermalErosionAction : public TerrainAction
|
|||
{
|
||||
public:
|
||||
ThermalErosionAction(TerrainEditor * editor)
|
||||
: TerrainAction(editor),
|
||||
mNoiseSize(256)
|
||||
: TerrainAction(editor)
|
||||
{
|
||||
mNoise.setSeed( 1 );//Sim::getCurrentTime() );
|
||||
mNoiseData.setSize(mNoiseSize * mNoiseSize);
|
||||
mNoise.fBm(&mNoiseData, mNoiseSize, 12, 1.0f, 5.0f);
|
||||
mNoise.getMinMax(&mNoiseData, &mMinMaxNoise.x, &mMinMaxNoise.y, mNoiseSize);
|
||||
mScale = 1.5f / (mMinMaxNoise.x - mMinMaxNoise.y);
|
||||
}
|
||||
|
||||
}
|
||||
StringTableEntry getName(){return("thermalErode");}
|
||||
|
||||
void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
|
||||
|
||||
const U32 mNoiseSize;
|
||||
Noise2D mNoise;
|
||||
Vector<F32> mNoiseData;
|
||||
Point2F mMinMaxNoise;
|
||||
F32 mScale;
|
||||
};
|
||||
|
||||
class HydraulicErosionAction : public TerrainAction
|
||||
{
|
||||
public:
|
||||
HydraulicErosionAction(TerrainEditor* editor)
|
||||
: TerrainAction(editor),
|
||||
mNoiseSize(256)
|
||||
: TerrainAction(editor)
|
||||
{
|
||||
mNoise.setSeed(1);//Sim::getCurrentTime() );
|
||||
mNoiseData.setSize(mNoiseSize * mNoiseSize);
|
||||
mNoise.fBm(&mNoiseData, mNoiseSize, 12, 1.0f, 5.0f);
|
||||
mNoise.getMinMax(&mNoiseData, &mMinMaxNoise.x, &mMinMaxNoise.y, mNoiseSize);
|
||||
mScale = 1.5f / (mMinMaxNoise.x - mMinMaxNoise.y);
|
||||
}
|
||||
|
||||
StringTableEntry getName() { return("hydraulicErode"); }
|
||||
void process(Selection* sel, const Gui3DMouseEvent& event, bool selChanged, Type type);
|
||||
const U32 mNoiseSize;
|
||||
Noise2D mNoise;
|
||||
Vector<F32> mNoiseData;
|
||||
Point2F mMinMaxNoise;
|
||||
F32 mScale;
|
||||
};
|
||||
|
||||
class TerrainScratchPad
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue