Skip to content

Commit

Permalink
Merge branch 'cs-terrain-equalize-mode' into 'master'
Browse files Browse the repository at this point in the history
Add OpenMW-CS Terrain Equalize tool

See merge request OpenMW/openmw!4260
  • Loading branch information
psi29a committed Jul 21, 2024
2 parents f65f9c1 + 4ffea31 commit 7026bfd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
Feature #1415: Infinite fall failsafe
Feature #2566: Handle NAM9 records for manual cell references
Feature #3537: Shader-based water ripples
Feature #4260: OpenMW-CS Terrain Equalize tool
Feature #5173: Support for NiFogProperty
Feature #5492: Let rain and snow collide with statics
Feature #5926: Refraction based on water depth
Expand Down
36 changes: 34 additions & 2 deletions apps/opencs/view/render/terrainshapemode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void CSVRender::TerrainShapeMode::primaryEditPressed(const WorldspaceHitResult&
{
if (hit.hit && hit.tag == nullptr)
{
if (mShapeEditTool == ShapeEditTool_Flatten)
if (mShapeEditTool == ShapeEditTool_Flatten || mShapeEditTool == ShapeEditTool_Equalize)
setFlattenToolTargetHeight(hit);
if (mDragMode == InteractionType_PrimaryEdit && mShapeEditTool != ShapeEditTool_Drag)
{
Expand Down Expand Up @@ -167,7 +167,7 @@ bool CSVRender::TerrainShapeMode::primaryEditStartDrag(const QPoint& pos)
{
mEditingPos = hit.worldPos;
mIsEditing = true;
if (mShapeEditTool == ShapeEditTool_Flatten)
if (mShapeEditTool == ShapeEditTool_Flatten || mShapeEditTool == ShapeEditTool_Equalize)
setFlattenToolTargetHeight(hit);
}

Expand Down Expand Up @@ -463,6 +463,8 @@ void CSVRender::TerrainShapeMode::editTerrainShapeGrid(const std::pair<int, int>
smoothHeight(cellCoords, x, y, mShapeEditToolStrength);
if (mShapeEditTool == ShapeEditTool_Flatten)
flattenHeight(cellCoords, x, y, mShapeEditToolStrength, mTargetHeight);
if (mShapeEditTool == ShapeEditTool_Equalize)
equalizeHeight(cellCoords, x, y, mTargetHeight);
}

if (mBrushShape == CSVWidget::BrushShape_Square)
Expand All @@ -489,6 +491,8 @@ void CSVRender::TerrainShapeMode::editTerrainShapeGrid(const std::pair<int, int>
smoothHeight(cellCoords, x, y, mShapeEditToolStrength);
if (mShapeEditTool == ShapeEditTool_Flatten)
flattenHeight(cellCoords, x, y, mShapeEditToolStrength, mTargetHeight);
if (mShapeEditTool == ShapeEditTool_Equalize)
equalizeHeight(cellCoords, x, y, mTargetHeight);
}
}
}
Expand Down Expand Up @@ -529,6 +533,8 @@ void CSVRender::TerrainShapeMode::editTerrainShapeGrid(const std::pair<int, int>
smoothHeight(cellCoords, x, y, mShapeEditToolStrength);
if (mShapeEditTool == ShapeEditTool_Flatten)
flattenHeight(cellCoords, x, y, mShapeEditToolStrength, mTargetHeight);
if (mShapeEditTool == ShapeEditTool_Equalize)
equalizeHeight(cellCoords, x, y, mTargetHeight);
}
}
}
Expand Down Expand Up @@ -558,6 +564,8 @@ void CSVRender::TerrainShapeMode::editTerrainShapeGrid(const std::pair<int, int>
smoothHeight(cellCoords, x, y, mShapeEditToolStrength);
if (mShapeEditTool == ShapeEditTool_Flatten)
flattenHeight(cellCoords, x, y, mShapeEditToolStrength, mTargetHeight);
if (mShapeEditTool == ShapeEditTool_Equalize)
equalizeHeight(cellCoords, x, y, mTargetHeight);
}
}
}
Expand Down Expand Up @@ -889,6 +897,30 @@ void CSVRender::TerrainShapeMode::flattenHeight(
alterHeight(cellCoords, inCellX, inCellY, thisAlteredHeight + toolStrength);
}

void CSVRender::TerrainShapeMode::equalizeHeight(
const CSMWorld::CellCoordinates& cellCoords, int inCellX, int inCellY, int targetHeight)
{
CSMDoc::Document& document = getWorldspaceWidget().getDocument();
CSMWorld::IdTable& landTable
= dynamic_cast<CSMWorld::IdTable&>(*document.getData().getTableModel(CSMWorld::UniversalId::Type_Land));
int landshapeColumn = landTable.findColumnIndex(CSMWorld::Columns::ColumnId_LandHeightsIndex);

float thisHeight = 0.0f;

const std::string cellId = CSMWorld::CellCoordinates::generateId(cellCoords.getX(), cellCoords.getY());

if (!noCell(cellId) && !noLand(cellId))
{
const CSMWorld::LandHeightsColumn::DataType landShapePointer
= landTable.data(landTable.getModelIndex(cellId, landshapeColumn))
.value<CSMWorld::LandHeightsColumn::DataType>();

thisHeight = landShapePointer[inCellY * ESM::Land::LAND_SIZE + inCellX];
}

alterHeight(cellCoords, inCellX, inCellY, targetHeight - thisHeight);
}

void CSVRender::TerrainShapeMode::updateKeyHeightValues(const CSMWorld::CellCoordinates& cellCoords, int inCellX,
int inCellY, float* thisHeight, float* thisAlteredHeight, float* leftHeight, float* leftAlteredHeight,
float* upHeight, float* upAlteredHeight, float* rightHeight, float* rightAlteredHeight, float* downHeight,
Expand Down
6 changes: 5 additions & 1 deletion apps/opencs/view/render/terrainshapemode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ namespace CSVRender
ShapeEditTool_PaintToRaise = 1,
ShapeEditTool_PaintToLower = 2,
ShapeEditTool_Smooth = 3,
ShapeEditTool_Flatten = 4
ShapeEditTool_Flatten = 4,
ShapeEditTool_Equalize = 5
};

/// Editmode for terrain shape grid
Expand Down Expand Up @@ -145,6 +146,9 @@ namespace CSVRender
void flattenHeight(
const CSMWorld::CellCoordinates& cellCoords, int inCellX, int inCellY, int toolStrength, int targetHeight);

/// Do a single equalize alteration for transient shape edit map
void equalizeHeight(const CSMWorld::CellCoordinates& cellCoords, int inCellX, int inCellY, int targetHeight);

/// Get altered height values around one vertex
void updateKeyHeightValues(const CSMWorld::CellCoordinates& cellCoords, int inCellX, int inCellY,
float* thisHeight, float* thisAlteredHeight, float* leftHeight, float* leftAlteredHeight, float* upHeight,
Expand Down
1 change: 1 addition & 0 deletions apps/opencs/view/widget/scenetoolshapebrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ CSVWidget::ShapeBrushWindow::ShapeBrushWindow(CSMDoc::Document& document, QWidge
mToolSelector->addItem(tr("Height, lower (paint)"));
mToolSelector->addItem(tr("Smooth (paint)"));
mToolSelector->addItem(tr("Flatten (paint)"));
mToolSelector->addItem(tr("Equalize (paint)"));

QLabel* brushStrengthLabel = new QLabel(this);
brushStrengthLabel->setText("Brush strength:");
Expand Down

0 comments on commit 7026bfd

Please sign in to comment.