From 78e365f382311d2cfa100a107a92e24445bc9b89 Mon Sep 17 00:00:00 2001 From: Sam Hellawell Date: Sat, 20 Jul 2024 02:28:00 +0100 Subject: [PATCH] Add OpenMW-CS Terrain Equalize tool --- apps/opencs/view/render/terrainshapemode.cpp | 36 +++++++++++++++++-- apps/opencs/view/render/terrainshapemode.hpp | 6 +++- .../view/widget/scenetoolshapebrush.cpp | 1 + 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/apps/opencs/view/render/terrainshapemode.cpp b/apps/opencs/view/render/terrainshapemode.cpp index eee1f20ec6..b9dc301efa 100644 --- a/apps/opencs/view/render/terrainshapemode.cpp +++ b/apps/opencs/view/render/terrainshapemode.cpp @@ -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) { @@ -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); } @@ -463,6 +463,8 @@ void CSVRender::TerrainShapeMode::editTerrainShapeGrid(const std::pair 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) @@ -489,6 +491,8 @@ void CSVRender::TerrainShapeMode::editTerrainShapeGrid(const std::pair smoothHeight(cellCoords, x, y, mShapeEditToolStrength); if (mShapeEditTool == ShapeEditTool_Flatten) flattenHeight(cellCoords, x, y, mShapeEditToolStrength, mTargetHeight); + if (mShapeEditTool == ShapeEditTool_Equalize) + equalizeHeight(cellCoords, x, y, mTargetHeight); } } } @@ -529,6 +533,8 @@ void CSVRender::TerrainShapeMode::editTerrainShapeGrid(const std::pair smoothHeight(cellCoords, x, y, mShapeEditToolStrength); if (mShapeEditTool == ShapeEditTool_Flatten) flattenHeight(cellCoords, x, y, mShapeEditToolStrength, mTargetHeight); + if (mShapeEditTool == ShapeEditTool_Equalize) + equalizeHeight(cellCoords, x, y, mTargetHeight); } } } @@ -558,6 +564,8 @@ void CSVRender::TerrainShapeMode::editTerrainShapeGrid(const std::pair smoothHeight(cellCoords, x, y, mShapeEditToolStrength); if (mShapeEditTool == ShapeEditTool_Flatten) flattenHeight(cellCoords, x, y, mShapeEditToolStrength, mTargetHeight); + if (mShapeEditTool == ShapeEditTool_Equalize) + equalizeHeight(cellCoords, x, y, mTargetHeight); } } } @@ -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(*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(); + + 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, diff --git a/apps/opencs/view/render/terrainshapemode.hpp b/apps/opencs/view/render/terrainshapemode.hpp index e772621c4c..2344676cbd 100644 --- a/apps/opencs/view/render/terrainshapemode.hpp +++ b/apps/opencs/view/render/terrainshapemode.hpp @@ -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 @@ -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, diff --git a/apps/opencs/view/widget/scenetoolshapebrush.cpp b/apps/opencs/view/widget/scenetoolshapebrush.cpp index 1430300622..d7034cac07 100644 --- a/apps/opencs/view/widget/scenetoolshapebrush.cpp +++ b/apps/opencs/view/widget/scenetoolshapebrush.cpp @@ -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:");