1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 09:49:55 +00:00
openmw-tes3mp/apps/opencs/view/render/terrainshapemode.hpp

191 lines
7.9 KiB
C++
Raw Normal View History

2019-09-11 09:59:15 +00:00
#ifndef CSV_RENDER_TERRAINSHAPEMODE_H
#define CSV_RENDER_TERRAINSHAPEMODE_H
#include "editmode.hpp"
#include <string>
#include <memory>
#include <QWidget>
#include <QEvent>
#ifndef Q_MOC_RUN
#include "../../model/world/data.hpp"
#include "../../model/world/land.hpp"
#include "../../model/doc/document.hpp"
#include "../../model/world/commands.hpp"
#include "../../model/world/idtable.hpp"
#include "../../model/world/landtexture.hpp"
2019-10-06 23:57:09 +00:00
#include "../widget/brushshapes.hpp"
2019-09-11 09:59:15 +00:00
#endif
#include "terrainselection.hpp"
namespace CSVWidget
{
class SceneToolShapeBrush;
}
namespace CSVRender
{
class PagedWorldspaceWidget;
/// \brief EditMode for handling the terrain shape editing
class TerrainShapeMode : public EditMode
{
Q_OBJECT
public:
enum InteractionType
{
InteractionType_PrimaryEdit,
InteractionType_PrimarySelect,
InteractionType_SecondaryEdit,
InteractionType_SecondarySelect,
InteractionType_None
};
2019-10-06 23:57:09 +00:00
enum ShapeEditTool
2019-10-04 09:07:47 +00:00
{
2019-10-06 23:57:09 +00:00
ShapeEditTool_Drag = 0,
ShapeEditTool_PaintToRaise = 1,
ShapeEditTool_PaintToLower = 2,
ShapeEditTool_Smooth = 3,
ShapeEditTool_Flatten = 4
2019-10-04 09:07:47 +00:00
};
2019-09-11 09:59:15 +00:00
/// Editmode for terrain shape grid
TerrainShapeMode(WorldspaceWidget*, osg::Group* parentNode, QWidget* parent = nullptr);
2019-10-10 21:15:32 +00:00
void primaryOpenPressed (const WorldspaceHitResult& hit) final;
2019-09-11 09:59:15 +00:00
/// Create single command for one-click shape editing
2019-10-10 21:15:32 +00:00
void primaryEditPressed (const WorldspaceHitResult& hit) final;
2019-09-11 09:59:15 +00:00
/// Open brush settings window
2019-10-10 21:15:32 +00:00
void primarySelectPressed(const WorldspaceHitResult&) final;
2019-09-11 09:59:15 +00:00
2019-10-10 21:15:32 +00:00
void secondarySelectPressed(const WorldspaceHitResult&) final;
2019-09-11 09:59:15 +00:00
2019-10-10 21:15:32 +00:00
void activate(CSVWidget::SceneToolbar*) final;
void deactivate(CSVWidget::SceneToolbar*) final;
2019-09-11 09:59:15 +00:00
/// Start shape editing command macro
bool primaryEditStartDrag (const QPoint& pos) final;
2019-09-11 09:59:15 +00:00
bool secondaryEditStartDrag (const QPoint& pos) final;
bool primarySelectStartDrag (const QPoint& pos) final;
bool secondarySelectStartDrag (const QPoint& pos) final;
2019-09-11 09:59:15 +00:00
/// Handle shape edit behavior during dragging
void drag (const QPoint& pos, int diffX, int diffY, double speedFactor) final;
2019-09-11 09:59:15 +00:00
/// End shape editing command macro
void dragCompleted(const QPoint& pos) final;
2019-09-11 09:59:15 +00:00
/// Cancel shape editing, and reset all pending changes
void dragAborted() final;
2019-09-11 09:59:15 +00:00
void dragWheel (int diff, double speedFactor) final;
void dragMoveEvent (QDragMoveEvent *event) final;
2019-09-11 09:59:15 +00:00
private:
/// Remove duplicates and sort mAlteredCells, then limitAlteredHeights forward and reverse
void sortAndLimitAlteredCells();
/// Move pending alteredHeights changes to omwgame/omwaddon -data
void applyTerrainEditChanges();
2019-09-11 09:59:15 +00:00
/// Handle brush mechanics for shape editing
void editTerrainShapeGrid (const std::pair<int, int>& vertexCoords, bool dragOperation);
2019-10-22 17:58:23 +00:00
/// Calculate height, when aiming for bump-shaped terrain change
float calculateBumpShape(const float& distance, int radius, const float& height);
/// set the target height for flatten tool
void setFlattenToolTargetHeight(const WorldspaceHitResult& hit);
2019-09-11 09:59:15 +00:00
/// Do a single height alteration for transient shape edit map
void alterHeight(const CSMWorld::CellCoordinates& cellCoords, int inCellX, int inCellY, float alteredHeight, bool useTool = true);
/// Do a single smoothing height alteration for transient shape edit map
void smoothHeight(const CSMWorld::CellCoordinates& cellCoords, int inCellX, int inCellY, int toolStrength);
/// Do a single flattening height alteration for transient shape edit map
void flattenHeight(const CSMWorld::CellCoordinates& cellCoords, int inCellX, int inCellY, int toolStrength, int targetHeight);
2019-09-19 09:38:15 +00:00
/// Get altered height values around one vertex
2019-09-11 09:59:15 +00:00
void updateKeyHeightValues(const CSMWorld::CellCoordinates& cellCoords, int inCellX, int inCellY, float* thisHeight,
2019-09-19 09:38:15 +00:00
float* thisAlteredHeight, float* leftHeight, float* leftAlteredHeight, float* upHeight, float* upAlteredHeight,
float* rightHeight, float* rightAlteredHeight, float* downHeight, float* downAlteredHeight);
2019-09-11 09:59:15 +00:00
///Limit steepness based on either X or Y and return false if steepness is limited
void compareAndLimit(const CSMWorld::CellCoordinates& cellCoords, int inCellX, int inCellY, float* limitedAlteredHeightXAxis,
float* limitedAlteredHeightYAxis, bool* steepnessIsWithinLimits);
/// Check that the edit doesn't break save format limits, fix if necessary, return true if slope steepness is within limits
bool limitAlteredHeights(const CSMWorld::CellCoordinates& cellCoords, bool reverseMode = false);
2019-09-11 09:59:15 +00:00
/// Handle brush mechanics for terrain shape selection
void selectTerrainShapes (const std::pair<int, int>& vertexCoords, unsigned char selectMode, bool dragOperation);
/// Push terrain shape edits to command macro
void pushEditToCommand (const CSMWorld::LandHeightsColumn::DataType& newLandGrid, CSMDoc::Document& document,
2019-10-06 23:57:09 +00:00
CSMWorld::IdTable& landTable, const std::string& cellId);
2019-09-11 09:59:15 +00:00
/// Push land normals edits to command macro
void pushNormalsEditToCommand(const CSMWorld::LandNormalsColumn::DataType& newLandGrid, CSMDoc::Document& document,
2019-10-06 23:57:09 +00:00
CSMWorld::IdTable& landTable, const std::string& cellId);
/// Generate new land map LOD
void pushLodToCommand(const CSMWorld::LandMapLodColumn::DataType& newLandMapLod, CSMDoc::Document& document,
CSMWorld::IdTable& landTable, const std::string& cellId);
2019-09-11 09:59:15 +00:00
bool noCell(const std::string& cellId);
bool noLand(const std::string& cellId);
bool noLandLoaded(const std::string& cellId);
bool isLandLoaded(const std::string& cellId);
/// Create new blank height record and new normals, if there are valid adjancent cell, take sample points and set the average height based on that
void createNewLandData(const CSMWorld::CellCoordinates& cellCoords);
/// Create new cell and land if needed, only user tools may ask for opening new cells (useTool == false is for automated land changes)
bool allowLandShapeEditing(const std::string& textureFileName, bool useTool = true);
/// Bind the edging vertice to the values of the adjancent cells
void fixEdges(CSMWorld::CellCoordinates cellCoords);
2019-09-11 09:59:15 +00:00
std::string mBrushTexture;
int mBrushSize = 1;
CSVWidget::BrushShape mBrushShape = CSVWidget::BrushShape_Point;
2019-09-11 09:59:15 +00:00
std::vector<std::pair<int, int>> mCustomBrushShape;
CSVWidget::SceneToolShapeBrush *mShapeBrushScenetool = nullptr;
int mDragMode = InteractionType_None;
2019-09-11 09:59:15 +00:00
osg::Group* mParentNode;
bool mIsEditing = false;
2019-09-11 09:59:15 +00:00
std::unique_ptr<TerrainSelection> mTerrainShapeSelection;
int mTotalDiffY = 0;
2019-09-11 09:59:15 +00:00
std::vector<CSMWorld::CellCoordinates> mAlteredCells;
osg::Vec3d mEditingPos;
int mShapeEditTool = ShapeEditTool_Drag;
int mShapeEditToolStrength = 8;
int mTargetHeight = 0;
2019-09-11 09:59:15 +00:00
PagedWorldspaceWidget& getPagedWorldspaceWidget();
public slots:
void setBrushSize(int brushSize);
2019-10-06 23:57:09 +00:00
void setBrushShape(CSVWidget::BrushShape brushShape);
2019-09-11 09:59:15 +00:00
void setShapeEditTool(int shapeEditTool);
void setShapeEditToolStrength(int shapeEditToolStrength);
};
}
#endif