From 24c8b32d4cefa0bf65bb51e98a58c643058139a1 Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Fri, 7 Feb 2020 19:04:28 +0200 Subject: [PATCH 1/9] Implement brush outline for terrainshapemode --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/view/render/brushdraw.cpp | 136 ++++++++++++++++++ apps/opencs/view/render/brushdraw.hpp | 31 ++++ apps/opencs/view/render/editmode.cpp | 2 + apps/opencs/view/render/editmode.hpp | 2 + apps/opencs/view/render/terrainshapemode.cpp | 17 +++ apps/opencs/view/render/terrainshapemode.hpp | 4 + .../opencs/view/render/terraintexturemode.cpp | 2 + .../opencs/view/render/terraintexturemode.hpp | 2 + apps/opencs/view/render/worldspacewidget.cpp | 2 + 10 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 apps/opencs/view/render/brushdraw.cpp create mode 100644 apps/opencs/view/render/brushdraw.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index af8bf8d55..6d0f2ad9f 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -89,7 +89,7 @@ opencs_units (view/render scenewidget worldspacewidget pagedworldspacewidget unpagedworldspacewidget previewwidget editmode instancemode instanceselectionmode instancemovemode orbitcameramode pathgridmode selectionmode pathgridselectionmode cameracontroller - cellwater terraintexturemode actor terrainselection terrainshapemode + cellwater terraintexturemode actor terrainselection terrainshapemode brushdraw ) opencs_units_noqt (view/render diff --git a/apps/opencs/view/render/brushdraw.cpp b/apps/opencs/view/render/brushdraw.cpp new file mode 100644 index 000000000..a2874bd31 --- /dev/null +++ b/apps/opencs/view/render/brushdraw.cpp @@ -0,0 +1,136 @@ +#include "brushdraw.hpp" + +#include +#include +#include +#include +#include +#include + +#include + +#include "mask.hpp" + +CSVRender::BrushDraw::BrushDraw(osg::Group* parentNode) : + mParentNode(parentNode) +{ + mBrushDrawNode = new osg::Group(); + mGeometry = new osg::Geometry(); + mBrushDrawNode->addChild(mGeometry); + mParentNode->addChild(mBrushDrawNode); +} + +CSVRender::BrushDraw::~BrushDraw() +{ + if (mBrushDrawNode->containsNode(mGeometry)) mBrushDrawNode->removeChild(mGeometry); + if (mParentNode->containsNode(mBrushDrawNode)) mParentNode->removeChild(mBrushDrawNode); +} + +float CSVRender::BrushDraw::getIntersectionHeight (const osg::Vec3d& point) +{ + osg::Vec3d start = point; + osg::Vec3d end = point; + start.z() += 8000.0f; // these numbers need fixing + end.z() -= 8000.0f; + osg::Vec3d direction = end - start; + + // Get intersection + osg::ref_ptr intersector (new osgUtil::LineSegmentIntersector( + osgUtil::Intersector::MODEL, start, end) ); + intersector->setIntersectionLimit(osgUtil::LineSegmentIntersector::NO_LIMIT); + osgUtil::IntersectionVisitor visitor(intersector); + + visitor.setTraversalMask(Mask_Terrain); + + mParentNode->accept(visitor); + + for (osgUtil::LineSegmentIntersector::Intersections::iterator it = intersector->getIntersections().begin(); + it != intersector->getIntersections().end(); ++it) + { + osgUtil::LineSegmentIntersector::Intersection intersection = *it; + + // reject back-facing polygons + if (direction * intersection.getWorldIntersectNormal() > 0) + { + continue; + } + + return intersection.getWorldIntersectPoint().z(); + } + return 0.0f; +} + + +void CSVRender::BrushDraw::buildGeometry(const float& radius, const osg::Vec3d& point, int amountOfPoints) +{ + osg::ref_ptr geom = new osg::Geometry(); + osg::ref_ptr vertices (new osg::Vec3Array()); + osg::ref_ptr colors (new osg::Vec4Array()); + const float step ((osg::PI * 2.0f) / static_cast(amountOfPoints)); + + for (int i = 0; i < amountOfPoints + 2; i++) + { + float angle (static_cast(i) * step); + vertices->push_back(osg::Vec3d( + point.x() + radius * cosf(angle), + point.y() + radius * sinf(angle), + getIntersectionHeight(osg::Vec3d( + point.x() + radius * cosf(angle), + point.y() + radius * sinf(angle), + point.z()) ))); + colors->push_back(osg::Vec4f( + 50.0f, + 50.0f, + 50.0f, + 100.0f)); + angle = static_cast(i + 1) * step; + vertices->push_back(osg::Vec3d( + point.x() + radius * cosf(angle), + point.y() + radius * sinf(angle), + getIntersectionHeight(osg::Vec3d( + point.x() + radius * cosf(angle), + point.y() + radius * sinf(angle), + point.z()) ) + 200.0f)); + colors->push_back(osg::Vec4f( + 50.0f, + 50.0f, + 50.0f, + 100.0f)); + } + + geom->setVertexArray(vertices); + geom->setColorArray(colors, osg::Array::BIND_PER_VERTEX); + geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP, 0, (amountOfPoints + 2) * 2 - 2)); + mGeometry = geom; +} + +void CSVRender::BrushDraw::update(osg::Vec3d point, int brushSize) +{ + if (mBrushDrawNode->containsNode(mGeometry)) mBrushDrawNode->removeChild(mGeometry); + mBrushDrawNode->setNodeMask (Mask_EditModeCursor); + float radius = static_cast(brushSize * mLandSizeFactor); + int amountOfPoints = (osg::PI * 2.0f) * radius / 20; + + buildGeometry(radius, point, amountOfPoints); + + osg::BlendFunc* blendFunc = new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA); + mGeometry->getOrCreateStateSet()->setAttributeAndModes(blendFunc); + + mGeometry->getOrCreateStateSet()->setMode( GL_CULL_FACE, osg::StateAttribute::OFF ); + + osg::ref_ptr material = new osg::Material; + material->setColorMode(osg::Material::AMBIENT); + material->setAmbient (osg::Material::FRONT_AND_BACK, osg::Vec4(0.3, 0.3, 0.3, 1)); + material->setAlpha(osg::Material::FRONT_AND_BACK, 0.5); + + mGeometry->getOrCreateStateSet()->setAttributeAndModes(material.get(), osg::StateAttribute::ON); + mGeometry->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON); + mGeometry->getOrCreateStateSet()->setRenderingHint (osg::StateSet::TRANSPARENT_BIN); + + mBrushDrawNode->addChild(mGeometry); +} + +void CSVRender::BrushDraw::hide() +{ + if (mBrushDrawNode->containsNode(mGeometry)) mBrushDrawNode->removeChild(mGeometry); +} diff --git a/apps/opencs/view/render/brushdraw.hpp b/apps/opencs/view/render/brushdraw.hpp new file mode 100644 index 000000000..5e0a095ce --- /dev/null +++ b/apps/opencs/view/render/brushdraw.hpp @@ -0,0 +1,31 @@ +#ifndef CSV_RENDER_BRUSHDRAW_H +#define CSV_RENDER_BRUSHDRAW_H + +#include +#include + +#include + +namespace CSVRender +{ + class BrushDraw + { + public: + BrushDraw(osg::Group* parentNode); + ~BrushDraw(); + + void update(osg::Vec3d point, int brushSize); + void hide(); + + private: + void buildGeometry(const float& radius, const osg::Vec3d& point, int amountOfPoints); + float getIntersectionHeight (const osg::Vec3d& point); + + osg::Group* mParentNode; + osg::ref_ptr mBrushDrawNode; + osg::ref_ptr mGeometry; + float mLandSizeFactor = ESM::Land::REAL_SIZE / ESM::Land::LAND_SIZE / 2; + }; +} + +#endif diff --git a/apps/opencs/view/render/editmode.cpp b/apps/opencs/view/render/editmode.cpp index 03451bc1b..ca4aa0fd5 100644 --- a/apps/opencs/view/render/editmode.cpp +++ b/apps/opencs/view/render/editmode.cpp @@ -73,6 +73,8 @@ void CSVRender::EditMode::dropEvent (QDropEvent *event) {} void CSVRender::EditMode::dragMoveEvent (QDragMoveEvent *event) {} +void CSVRender::EditMode::mouseMoveEvent (QMouseEvent *event) {} + int CSVRender::EditMode::getSubMode() const { return -1; diff --git a/apps/opencs/view/render/editmode.hpp b/apps/opencs/view/render/editmode.hpp index 9f3b28957..911594327 100644 --- a/apps/opencs/view/render/editmode.hpp +++ b/apps/opencs/view/render/editmode.hpp @@ -98,6 +98,8 @@ namespace CSVRender /// Default-implementation: ignored virtual void dragMoveEvent (QDragMoveEvent *event); + virtual void mouseMoveEvent (QMouseEvent *event); + /// Default: return -1 virtual int getSubMode() const; }; diff --git a/apps/opencs/view/render/terrainshapemode.cpp b/apps/opencs/view/render/terrainshapemode.cpp index 2a6d7f33f..53fe92f8e 100644 --- a/apps/opencs/view/render/terrainshapemode.cpp +++ b/apps/opencs/view/render/terrainshapemode.cpp @@ -37,6 +37,7 @@ #include "../../model/world/tablemimedata.hpp" #include "../../model/world/universalid.hpp" +#include "brushdraw.hpp" #include "editmode.hpp" #include "pagedworldspacewidget.hpp" #include "tagbase.hpp" @@ -49,6 +50,12 @@ CSVRender::TerrainShapeMode::TerrainShapeMode (WorldspaceWidget *worldspaceWidge { } +CSVRender::TerrainShapeMode::~TerrainShapeMode () +{ + if (mBrushDraw) + mBrushDraw.reset(); +} + void CSVRender::TerrainShapeMode::activate(CSVWidget::SceneToolbar* toolbar) { if (!mTerrainShapeSelection) @@ -67,6 +74,9 @@ void CSVRender::TerrainShapeMode::activate(CSVWidget::SceneToolbar* toolbar) connect(mShapeBrushScenetool->mShapeBrushWindow->mToolStrengthSlider, SIGNAL(valueChanged(int)), this, SLOT(setShapeEditToolStrength(int))); } + if (!mBrushDraw) + mBrushDraw.reset(new BrushDraw(mParentNode)); + EditMode::activate(toolbar); toolbar->addTool (mShapeBrushScenetool); } @@ -1382,6 +1392,13 @@ void CSVRender::TerrainShapeMode::dragMoveEvent (QDragMoveEvent *event) { } +void CSVRender::TerrainShapeMode::mouseMoveEvent (QMouseEvent *event) +{ + WorldspaceHitResult hit = getWorldspaceWidget().mousePick(event->pos(), getInteractionMask()); + if (hit.hit && mBrushDraw && !(mShapeEditTool == ShapeEditTool_Drag && mIsEditing)) mBrushDraw->update(hit.worldPos, mBrushSize); + if (!hit.hit && !(mShapeEditTool == ShapeEditTool_Drag && mIsEditing)) mBrushDraw->hide(); +} + void CSVRender::TerrainShapeMode::setBrushSize(int brushSize) { mBrushSize = brushSize; diff --git a/apps/opencs/view/render/terrainshapemode.hpp b/apps/opencs/view/render/terrainshapemode.hpp index 68f2fbf9d..fb80e79af 100644 --- a/apps/opencs/view/render/terrainshapemode.hpp +++ b/apps/opencs/view/render/terrainshapemode.hpp @@ -19,6 +19,7 @@ #include "../widget/brushshapes.hpp" #endif +#include "brushdraw.hpp" #include "terrainselection.hpp" namespace CSVWidget @@ -57,6 +58,7 @@ namespace CSVRender /// Editmode for terrain shape grid TerrainShapeMode(WorldspaceWidget*, osg::Group* parentNode, QWidget* parent = nullptr); + ~TerrainShapeMode(); void primaryOpenPressed (const WorldspaceHitResult& hit) final; @@ -89,6 +91,7 @@ namespace CSVRender void dragWheel (int diff, double speedFactor) final; void dragMoveEvent (QDragMoveEvent *event) final; + void mouseMoveEvent (QMouseEvent *event) final; private: @@ -168,6 +171,7 @@ namespace CSVRender std::string mBrushTexture; int mBrushSize = 1; CSVWidget::BrushShape mBrushShape = CSVWidget::BrushShape_Point; + std::unique_ptr mBrushDraw; std::vector> mCustomBrushShape; CSVWidget::SceneToolShapeBrush *mShapeBrushScenetool = nullptr; int mDragMode = InteractionType_None; diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index efdb600b8..e25d65a89 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -707,6 +707,8 @@ void CSVRender::TerrainTextureMode::dragMoveEvent (QDragMoveEvent *event) { } +void CSVRender::TerrainTextureMode::mouseMoveEvent (QMouseEvent *event) {} + void CSVRender::TerrainTextureMode::setBrushSize(int brushSize) { mBrushSize = brushSize; diff --git a/apps/opencs/view/render/terraintexturemode.hpp b/apps/opencs/view/render/terraintexturemode.hpp index 4176abefe..3b94097ee 100644 --- a/apps/opencs/view/render/terraintexturemode.hpp +++ b/apps/opencs/view/render/terraintexturemode.hpp @@ -81,6 +81,8 @@ namespace CSVRender void dragWheel (int diff, double speedFactor) final; void dragMoveEvent (QDragMoveEvent *event) final; + void mouseMoveEvent (QMouseEvent *event) final; + private: /// \brief Handle brush mechanics, maths regarding worldspace hit etc. void editTerrainTextureGrid (const WorldspaceHitResult& hit); diff --git a/apps/opencs/view/render/worldspacewidget.cpp b/apps/opencs/view/render/worldspacewidget.cpp index 6ab4b041b..4755de97b 100644 --- a/apps/opencs/view/render/worldspacewidget.cpp +++ b/apps/opencs/view/render/worldspacewidget.cpp @@ -613,6 +613,8 @@ void CSVRender::WorldspaceWidget::updateOverlay() void CSVRender::WorldspaceWidget::mouseMoveEvent (QMouseEvent *event) { + dynamic_cast (*mEditMode->getCurrent()).mouseMoveEvent (event); + if (mDragging) { int diffX = event->x() - mDragX; From 731e5b57f5b13923ec3b512f7ab9cc9a7b0fa93f Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Sat, 15 Feb 2020 16:09:49 +0200 Subject: [PATCH 2/9] Tool outline for terraintexturemode and square shape. Various fixes. --- apps/opencs/view/render/brushdraw.cpp | 100 ++++++++++++++++-- apps/opencs/view/render/brushdraw.hpp | 14 ++- apps/opencs/view/render/terrainshapemode.cpp | 5 +- .../opencs/view/render/terraintexturemode.cpp | 44 +++++--- .../opencs/view/render/terraintexturemode.hpp | 18 ++-- .../view/widget/scenetooltexturebrush.cpp | 23 ++-- .../view/widget/scenetooltexturebrush.hpp | 11 +- 7 files changed, 162 insertions(+), 53 deletions(-) diff --git a/apps/opencs/view/render/brushdraw.cpp b/apps/opencs/view/render/brushdraw.cpp index a2874bd31..b963b09f5 100644 --- a/apps/opencs/view/render/brushdraw.cpp +++ b/apps/opencs/view/render/brushdraw.cpp @@ -1,5 +1,7 @@ #include "brushdraw.hpp" +#include + #include #include #include @@ -9,29 +11,33 @@ #include +#include "../widget/brushshapes.hpp" + #include "mask.hpp" -CSVRender::BrushDraw::BrushDraw(osg::Group* parentNode) : +CSVRender::BrushDraw::BrushDraw(osg::ref_ptr parentNode, bool textureMode) : mParentNode(parentNode) { mBrushDrawNode = new osg::Group(); mGeometry = new osg::Geometry(); mBrushDrawNode->addChild(mGeometry); mParentNode->addChild(mBrushDrawNode); + if (textureMode) mLandSizeFactor = ESM::Land::REAL_SIZE / ESM::Land::LAND_TEXTURE_SIZE / 2; + else mLandSizeFactor = ESM::Land::REAL_SIZE / ESM::Land::LAND_SIZE / 2; } CSVRender::BrushDraw::~BrushDraw() { - if (mBrushDrawNode->containsNode(mGeometry)) mBrushDrawNode->removeChild(mGeometry); - if (mParentNode->containsNode(mBrushDrawNode)) mParentNode->removeChild(mBrushDrawNode); + mBrushDrawNode->removeChild(mGeometry); + mParentNode->removeChild(mBrushDrawNode); } float CSVRender::BrushDraw::getIntersectionHeight (const osg::Vec3d& point) { osg::Vec3d start = point; osg::Vec3d end = point; - start.z() += 8000.0f; // these numbers need fixing - end.z() -= 8000.0f; + start.z() = std::numeric_limits::max(); + end.z() = std::numeric_limits::min(); osg::Vec3d direction = end - start; // Get intersection @@ -60,13 +66,67 @@ float CSVRender::BrushDraw::getIntersectionHeight (const osg::Vec3d& point) return 0.0f; } +void CSVRender::BrushDraw::buildPointGeometry(const float& radius, const osg::Vec3d& point) +{ + // Not implemented +} -void CSVRender::BrushDraw::buildGeometry(const float& radius, const osg::Vec3d& point, int amountOfPoints) +void CSVRender::BrushDraw::buildSquareGeometry(const float& radius, const osg::Vec3d& point) { osg::ref_ptr geom = new osg::Geometry(); osg::ref_ptr vertices (new osg::Vec3Array()); osg::ref_ptr colors (new osg::Vec4Array()); + std::vector corners; + const float brushOutLineHeight (200.0f); + + corners.push_back(osg::Vec3d(point.x() - radius, point.y() - radius, point.z())); + corners.push_back(osg::Vec3d(point.x() + radius, point.y() - radius, point.z())); + corners.push_back(osg::Vec3d(point.x() + radius, point.y() + radius, point.z())); + corners.push_back(osg::Vec3d(point.x() - radius, point.y() + radius, point.z())); + corners.push_back(osg::Vec3d(point.x() - radius, point.y() - radius, point.z())); + + for (const auto& point : corners) + { + vertices->push_back(osg::Vec3d( + point.x(), + point.y(), + getIntersectionHeight(osg::Vec3d( + point.x(), + point.y(), + point.z()) ))); + colors->push_back(osg::Vec4f( + 50.0f, + 50.0f, + 50.0f, + 100.0f)); + vertices->push_back(osg::Vec3d( + point.x(), + point.y(), + getIntersectionHeight(osg::Vec3d( + point.x(), + point.y(), + point.z())) + brushOutLineHeight)); + colors->push_back(osg::Vec4f( + 50.0f, + 50.0f, + 50.0f, + 100.0f)); + } + + geom->setVertexArray(vertices); + geom->setColorArray(colors, osg::Array::BIND_PER_VERTEX); + geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP, 0, (10 + 2) - 2)); + mGeometry = geom; +} + +void CSVRender::BrushDraw::buildCircleGeometry(const float& radius, const osg::Vec3d& point) +{ + osg::ref_ptr geom = new osg::Geometry(); + osg::ref_ptr vertices (new osg::Vec3Array()); + osg::ref_ptr colors (new osg::Vec4Array()); + const int amountOfPoints = (osg::PI * 2.0f) * radius / 20; const float step ((osg::PI * 2.0f) / static_cast(amountOfPoints)); + const float brushOutLineHeight (200.0f); for (int i = 0; i < amountOfPoints + 2; i++) { @@ -90,7 +150,7 @@ void CSVRender::BrushDraw::buildGeometry(const float& radius, const osg::Vec3d& getIntersectionHeight(osg::Vec3d( point.x() + radius * cosf(angle), point.y() + radius * sinf(angle), - point.z()) ) + 200.0f)); + point.z()) ) + brushOutLineHeight)); colors->push_back(osg::Vec4f( 50.0f, 50.0f, @@ -104,14 +164,34 @@ void CSVRender::BrushDraw::buildGeometry(const float& radius, const osg::Vec3d& mGeometry = geom; } -void CSVRender::BrushDraw::update(osg::Vec3d point, int brushSize) +void CSVRender::BrushDraw::buildCustomGeometry(const float& radius, const osg::Vec3d& point) +{ + // Not implemented +} + +void CSVRender::BrushDraw::update(osg::Vec3d point, int brushSize, CSVWidget::BrushShape toolShape) { if (mBrushDrawNode->containsNode(mGeometry)) mBrushDrawNode->removeChild(mGeometry); mBrushDrawNode->setNodeMask (Mask_EditModeCursor); float radius = static_cast(brushSize * mLandSizeFactor); - int amountOfPoints = (osg::PI * 2.0f) * radius / 20; - buildGeometry(radius, point, amountOfPoints); + switch (toolShape) + { + case (CSVWidget::BrushShape_Point) : + buildSquareGeometry(1, point); + //buildPointGeometry(radius, point); + break; + case (CSVWidget::BrushShape_Square) : + buildSquareGeometry(radius, point); + break; + case (CSVWidget::BrushShape_Circle) : + buildCircleGeometry(radius, point); + break; + case (CSVWidget::BrushShape_Custom) : + buildSquareGeometry(1, point); + //buildCustomGeometry + break; + } osg::BlendFunc* blendFunc = new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA); mGeometry->getOrCreateStateSet()->setAttributeAndModes(blendFunc); diff --git a/apps/opencs/view/render/brushdraw.hpp b/apps/opencs/view/render/brushdraw.hpp index 5e0a095ce..6ecfccde7 100644 --- a/apps/opencs/view/render/brushdraw.hpp +++ b/apps/opencs/view/render/brushdraw.hpp @@ -5,26 +5,30 @@ #include #include +#include "../widget/brushshapes.hpp" namespace CSVRender { class BrushDraw { public: - BrushDraw(osg::Group* parentNode); + BrushDraw(osg::ref_ptr parentNode, bool textureMode = false); ~BrushDraw(); - void update(osg::Vec3d point, int brushSize); + void update(osg::Vec3d point, int brushSize, CSVWidget::BrushShape toolShape); void hide(); private: - void buildGeometry(const float& radius, const osg::Vec3d& point, int amountOfPoints); + void buildPointGeometry(const float& radius, const osg::Vec3d& point); + void buildSquareGeometry(const float& radius, const osg::Vec3d& point); + void buildCircleGeometry(const float& radius, const osg::Vec3d& point); + void buildCustomGeometry(const float& radius, const osg::Vec3d& point); float getIntersectionHeight (const osg::Vec3d& point); - osg::Group* mParentNode; + osg::ref_ptr mParentNode; osg::ref_ptr mBrushDrawNode; osg::ref_ptr mGeometry; - float mLandSizeFactor = ESM::Land::REAL_SIZE / ESM::Land::LAND_SIZE / 2; + float mLandSizeFactor; }; } diff --git a/apps/opencs/view/render/terrainshapemode.cpp b/apps/opencs/view/render/terrainshapemode.cpp index 53fe92f8e..31292645d 100644 --- a/apps/opencs/view/render/terrainshapemode.cpp +++ b/apps/opencs/view/render/terrainshapemode.cpp @@ -93,6 +93,9 @@ void CSVRender::TerrainShapeMode::deactivate(CSVWidget::SceneToolbar* toolbar) mTerrainShapeSelection.reset(); } + if (mBrushDraw) + mBrushDraw.reset(); + EditMode::deactivate(toolbar); } @@ -1395,7 +1398,7 @@ void CSVRender::TerrainShapeMode::dragMoveEvent (QDragMoveEvent *event) void CSVRender::TerrainShapeMode::mouseMoveEvent (QMouseEvent *event) { WorldspaceHitResult hit = getWorldspaceWidget().mousePick(event->pos(), getInteractionMask()); - if (hit.hit && mBrushDraw && !(mShapeEditTool == ShapeEditTool_Drag && mIsEditing)) mBrushDraw->update(hit.worldPos, mBrushSize); + if (hit.hit && mBrushDraw && !(mShapeEditTool == ShapeEditTool_Drag && mIsEditing)) mBrushDraw->update(hit.worldPos, mBrushSize, mBrushShape); if (!hit.hit && !(mShapeEditTool == ShapeEditTool_Drag && mIsEditing)) mBrushDraw->hide(); } diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index e25d65a89..c1bbb2825 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -32,7 +32,9 @@ #include "../../model/world/resourcetable.hpp" #include "../../model/world/tablemimedata.hpp" #include "../../model/world/universalid.hpp" +#include "../widget/brushshapes.hpp" +#include "brushdraw.hpp" #include "editmode.hpp" #include "pagedworldspacewidget.hpp" #include "object.hpp" // Something small needed regarding pointers from here () @@ -50,6 +52,12 @@ CSVRender::TerrainTextureMode::TerrainTextureMode (WorldspaceWidget *worldspaceW { } +CSVRender::TerrainTextureMode::~TerrainTextureMode () +{ + if (mBrushDraw) + mBrushDraw.reset(); +} + void CSVRender::TerrainTextureMode::activate(CSVWidget::SceneToolbar* toolbar) { if(!mTextureBrushScenetool) @@ -57,7 +65,7 @@ void CSVRender::TerrainTextureMode::activate(CSVWidget::SceneToolbar* toolbar) mTextureBrushScenetool = new CSVWidget::SceneToolTextureBrush (toolbar, "scenetooltexturebrush", getWorldspaceWidget().getDocument()); connect(mTextureBrushScenetool, SIGNAL (clicked()), mTextureBrushScenetool, SLOT (activate())); connect(mTextureBrushScenetool->mTextureBrushWindow, SIGNAL(passBrushSize(int)), this, SLOT(setBrushSize(int))); - connect(mTextureBrushScenetool->mTextureBrushWindow, SIGNAL(passBrushShape(int)), this, SLOT(setBrushShape(int))); + connect(mTextureBrushScenetool->mTextureBrushWindow, SIGNAL(passBrushShape(CSVWidget::BrushShape)), this, SLOT(setBrushShape(CSVWidget::BrushShape))); connect(mTextureBrushScenetool->mTextureBrushWindow->mSizeSliders->mBrushSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(setBrushSize(int))); connect(mTextureBrushScenetool, SIGNAL(passTextureId(std::string)), this, SLOT(setBrushTexture(std::string))); connect(mTextureBrushScenetool->mTextureBrushWindow, SIGNAL(passTextureId(std::string)), this, SLOT(setBrushTexture(std::string))); @@ -72,6 +80,9 @@ void CSVRender::TerrainTextureMode::activate(CSVWidget::SceneToolbar* toolbar) mTerrainTextureSelection.reset(new TerrainSelection(mParentNode, &getWorldspaceWidget(), TerrainSelectionType::Texture)); } + if (!mBrushDraw) + mBrushDraw.reset(new BrushDraw(mParentNode, true)); + EditMode::activate(toolbar); toolbar->addTool (mTextureBrushScenetool); } @@ -90,6 +101,9 @@ void CSVRender::TerrainTextureMode::deactivate(CSVWidget::SceneToolbar* toolbar) mTerrainTextureSelection.reset(); } + if (mBrushDraw) + mBrushDraw.reset(); + EditMode::deactivate(toolbar); } @@ -332,7 +346,7 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe int r = mBrushSize / 2 + 1; int distance = 0; - if (mBrushShape == 0) + if (mBrushShape == CSVWidget::BrushShape_Point) { CSMWorld::LandTexturesColumn::DataType newTerrainPointer = landTable.data(landTable.getModelIndex(mCellId, textureColumn)).value(); CSMWorld::LandTexturesColumn::DataType newTerrain(newTerrainPointer); @@ -344,7 +358,7 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe } } - if (mBrushShape == 1) + if (mBrushShape == CSVWidget::BrushShape_Square) { int upperLeftCellX = cellX - std::floor(r / landTextureSize); int upperLeftCellY = cellY - std::floor(r / landTextureSize); @@ -394,7 +408,7 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe } } - if (mBrushShape == 2) + if (mBrushShape == CSVWidget::BrushShape_Circle) { int upperLeftCellX = cellX - std::floor(r / landTextureSize); int upperLeftCellY = cellY - std::floor(r / landTextureSize); @@ -454,7 +468,7 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe } } - if (mBrushShape == 3) + if (mBrushShape == CSVWidget::BrushShape_Custom) { CSMWorld::LandTexturesColumn::DataType newTerrainPointer = landTable.data(landTable.getModelIndex(mCellId, textureColumn)).value(); CSMWorld::LandTexturesColumn::DataType newTerrain(newTerrainPointer); @@ -506,12 +520,12 @@ void CSVRender::TerrainTextureMode::selectTerrainTextures(const std::pair> selections; - if (mBrushShape == 0) + if (mBrushShape == CSVWidget::BrushShape_Point) { if (isInCellSelection(texCoords.first, texCoords.second)) selections.emplace_back(texCoords); } - if (mBrushShape == 1) + if (mBrushShape == CSVWidget::BrushShape_Square) { for (int i = -r; i <= r; i++) { @@ -527,7 +541,7 @@ void CSVRender::TerrainTextureMode::selectTerrainTextures(const std::pairpos(), getInteractionMask()); + if (hit.hit && mBrushDraw) mBrushDraw->update(hit.worldPos, mBrushSize, mBrushShape); + if (!hit.hit) mBrushDraw->hide(); +} + void CSVRender::TerrainTextureMode::setBrushSize(int brushSize) { mBrushSize = brushSize; } -void CSVRender::TerrainTextureMode::setBrushShape(int brushShape) +void CSVRender::TerrainTextureMode::setBrushShape(CSVWidget::BrushShape brushShape) { mBrushShape = brushShape; //Set custom brush shape - if (mBrushShape == 3 && !mTerrainTextureSelection->getTerrainSelection().empty()) + if (mBrushShape == CSVWidget::BrushShape_Custom && !mTerrainTextureSelection->getTerrainSelection().empty()) { auto terrainSelection = mTerrainTextureSelection->getTerrainSelection(); int selectionCenterX = 0; diff --git a/apps/opencs/view/render/terraintexturemode.hpp b/apps/opencs/view/render/terraintexturemode.hpp index 3b94097ee..cc77bb331 100644 --- a/apps/opencs/view/render/terraintexturemode.hpp +++ b/apps/opencs/view/render/terraintexturemode.hpp @@ -17,6 +17,8 @@ #include "../../model/world/commands.hpp" #include "../../model/world/idtable.hpp" #include "../../model/world/landtexture.hpp" +#include "../widget/brushshapes.hpp" +#include "brushdraw.hpp" #endif #include "terrainselection.hpp" @@ -50,6 +52,7 @@ namespace CSVRender /// \brief Editmode for terrain texture grid TerrainTextureMode(WorldspaceWidget*, osg::Group* parentNode, QWidget* parent = nullptr); + ~TerrainTextureMode(); void primaryOpenPressed (const WorldspaceHitResult& hit) final; @@ -104,14 +107,15 @@ namespace CSVRender bool allowLandTextureEditing(std::string textureFileName); std::string mCellId; - std::string mBrushTexture; - int mBrushSize; - int mBrushShape; + std::string mBrushTexture = "L0#0"; + int mBrushSize = 1; + CSVWidget::BrushShape mBrushShape = CSVWidget::BrushShape_Point; + std::unique_ptr mBrushDraw; std::vector> mCustomBrushShape; - CSVWidget::SceneToolTextureBrush *mTextureBrushScenetool; - int mDragMode; + CSVWidget::SceneToolTextureBrush *mTextureBrushScenetool = nullptr; + int mDragMode = InteractionType_None; osg::Group* mParentNode; - bool mIsEditing; + bool mIsEditing = false; std::unique_ptr mTerrainTextureSelection; const int cellSize {ESM::Land::REAL_SIZE}; @@ -123,7 +127,7 @@ namespace CSVRender public slots: void handleDropEvent(QDropEvent *event); void setBrushSize(int brushSize); - void setBrushShape(int brushShape); + void setBrushShape(CSVWidget::BrushShape brushShape); void setBrushTexture(std::string brushShape); }; } diff --git a/apps/opencs/view/widget/scenetooltexturebrush.cpp b/apps/opencs/view/widget/scenetooltexturebrush.cpp index 408187279..0a1ed6683 100644 --- a/apps/opencs/view/widget/scenetooltexturebrush.cpp +++ b/apps/opencs/view/widget/scenetooltexturebrush.cpp @@ -57,9 +57,6 @@ CSVWidget::BrushSizeControls::BrushSizeControls(const QString &title, QWidget *p CSVWidget::TextureBrushWindow::TextureBrushWindow(CSMDoc::Document& document, QWidget *parent) : QFrame(parent, Qt::Popup), - mBrushShape(0), - mBrushSize(1), - mBrushTexture("L0#0"), mDocument(document) { mBrushTextureLabel = "Selected texture: " + mBrushTexture + " "; @@ -207,10 +204,10 @@ void CSVWidget::TextureBrushWindow::setBrushSize(int brushSize) void CSVWidget::TextureBrushWindow::setBrushShape() { - if(mButtonPoint->isChecked()) mBrushShape = 0; - if(mButtonSquare->isChecked()) mBrushShape = 1; - if(mButtonCircle->isChecked()) mBrushShape = 2; - if(mButtonCustom->isChecked()) mBrushShape = 3; + if(mButtonPoint->isChecked()) mBrushShape = CSVWidget::BrushShape_Point; + if(mButtonSquare->isChecked()) mBrushShape = CSVWidget::BrushShape_Square; + if(mButtonCircle->isChecked()) mBrushShape = CSVWidget::BrushShape_Circle; + if(mButtonCustom->isChecked()) mBrushShape = CSVWidget::BrushShape_Custom; emit passBrushShape(mBrushShape); } @@ -228,7 +225,7 @@ CSVWidget::SceneToolTextureBrush::SceneToolTextureBrush (SceneToolbar *parent, c mBrushHistory[0] = "L0#0"; setAcceptDrops(true); - connect(mTextureBrushWindow, SIGNAL(passBrushShape(int)), this, SLOT(setButtonIcon(int))); + connect(mTextureBrushWindow, SIGNAL(passBrushShape(CSVWidget::BrushShape)), this, SLOT(setButtonIcon(CSVWidget::BrushShape))); setButtonIcon(mTextureBrushWindow->mBrushShape); mPanel = new QFrame (this, Qt::Popup); @@ -258,31 +255,31 @@ CSVWidget::SceneToolTextureBrush::SceneToolTextureBrush (SceneToolbar *parent, c } -void CSVWidget::SceneToolTextureBrush::setButtonIcon (int brushShape) +void CSVWidget::SceneToolTextureBrush::setButtonIcon (CSVWidget::BrushShape brushShape) { QString tooltip = "Change brush settings

Currently selected: "; switch (brushShape) { - case 0: + case BrushShape_Point: setIcon (QIcon (QPixmap (":scenetoolbar/brush-point"))); tooltip += mTextureBrushWindow->toolTipPoint; break; - case 1: + case BrushShape_Square: setIcon (QIcon (QPixmap (":scenetoolbar/brush-square"))); tooltip += mTextureBrushWindow->toolTipSquare; break; - case 2: + case BrushShape_Circle: setIcon (QIcon (QPixmap (":scenetoolbar/brush-circle"))); tooltip += mTextureBrushWindow->toolTipCircle; break; - case 3: + case BrushShape_Custom: setIcon (QIcon (QPixmap (":scenetoolbar/brush-custom"))); tooltip += mTextureBrushWindow->toolTipCustom; diff --git a/apps/opencs/view/widget/scenetooltexturebrush.hpp b/apps/opencs/view/widget/scenetooltexturebrush.hpp index 80e9a9382..5f5ccc6b1 100644 --- a/apps/opencs/view/widget/scenetooltexturebrush.hpp +++ b/apps/opencs/view/widget/scenetooltexturebrush.hpp @@ -15,6 +15,7 @@ #include #ifndef Q_MOC_RUN +#include "brushshapes.hpp" #include "scenetool.hpp" #include "../../model/doc/document.hpp" @@ -65,9 +66,9 @@ namespace CSVWidget const QString toolTipCustom = "Paint custom selection (not implemented yet)"; private: - int mBrushShape; - int mBrushSize; - std::string mBrushTexture; + CSVWidget::BrushShape mBrushShape = CSVWidget::BrushShape_Point; + int mBrushSize = 1; + std::string mBrushTexture = "L0#0"; CSMDoc::Document& mDocument; QLabel *mSelectedBrush; QGroupBox *mHorizontalGroupBox; @@ -88,7 +89,7 @@ namespace CSVWidget signals: void passBrushSize (int brushSize); - void passBrushShape(int brushShape); + void passBrushShape(CSVWidget::BrushShape brushShape); void passTextureId(std::string brushTexture); }; @@ -120,7 +121,7 @@ namespace CSVWidget friend class CSVRender::TerrainTextureMode; public slots: - void setButtonIcon(int brushShape); + void setButtonIcon(CSVWidget::BrushShape brushShape); void updateBrushHistory (const std::string& mBrushTexture); void clicked (const QModelIndex& index); virtual void activate(); From e14c390a9b15135a4a0280c52ba893829c608605 Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Sat, 15 Feb 2020 16:28:41 +0200 Subject: [PATCH 3/9] Fix crash --- apps/opencs/view/render/terrainshapemode.cpp | 2 +- apps/opencs/view/render/terraintexturemode.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/opencs/view/render/terrainshapemode.cpp b/apps/opencs/view/render/terrainshapemode.cpp index 31292645d..cf380e791 100644 --- a/apps/opencs/view/render/terrainshapemode.cpp +++ b/apps/opencs/view/render/terrainshapemode.cpp @@ -1399,7 +1399,7 @@ void CSVRender::TerrainShapeMode::mouseMoveEvent (QMouseEvent *event) { WorldspaceHitResult hit = getWorldspaceWidget().mousePick(event->pos(), getInteractionMask()); if (hit.hit && mBrushDraw && !(mShapeEditTool == ShapeEditTool_Drag && mIsEditing)) mBrushDraw->update(hit.worldPos, mBrushSize, mBrushShape); - if (!hit.hit && !(mShapeEditTool == ShapeEditTool_Drag && mIsEditing)) mBrushDraw->hide(); + if (!hit.hit && mBrushDraw && !(mShapeEditTool == ShapeEditTool_Drag && mIsEditing)) mBrushDraw->hide(); } void CSVRender::TerrainShapeMode::setBrushSize(int brushSize) diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index c1bbb2825..c6b3ea134 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -725,7 +725,7 @@ void CSVRender::TerrainTextureMode::mouseMoveEvent (QMouseEvent *event) { WorldspaceHitResult hit = getWorldspaceWidget().mousePick(event->pos(), getInteractionMask()); if (hit.hit && mBrushDraw) mBrushDraw->update(hit.worldPos, mBrushSize, mBrushShape); - if (!hit.hit) mBrushDraw->hide(); + if (!hit.hit && mBrushDraw) mBrushDraw->hide(); } From 8f625474fd6ce740cb8e75d2f655ef3a58503e0f Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Sat, 15 Feb 2020 16:46:03 +0200 Subject: [PATCH 4/9] Hotfix terraintexturemode circle brush radius calculations --- apps/opencs/view/render/terraintexturemode.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index c6b3ea134..95dcd4112 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -342,9 +342,7 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe std::string mBrushTextureInt = mBrushTexture.substr (hashlocation+1); int brushInt = stoi(mBrushTexture.substr (hashlocation+1))+1; // All indices are offset by +1 - int rf = mBrushSize / 2; - int r = mBrushSize / 2 + 1; - int distance = 0; + int r = static_cast(mBrushSize) / 2; if (mBrushShape == CSVWidget::BrushShape_Point) { @@ -433,7 +431,6 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe { for(int j = 0; j < landTextureSize; j++) { - if (i_cell == cellX && j_cell == cellY && abs(i-xHitInCell) < r && abs(j-yHitInCell) < r) { int distanceX(0); @@ -444,7 +441,8 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe if (j_cell > cellY) distanceY = -yHitInCell + landTextureSize * abs(j_cell-cellY) + j; if (i_cell == cellX) distanceX = abs(i-xHitInCell); if (j_cell == cellY) distanceY = abs(j-yHitInCell); - distance = std::round(sqrt(pow(distanceX, 2)+pow(distanceY, 2))); + float distance = std::round(sqrt(pow(distanceX, 2)+pow(distanceY, 2))); + float rf = static_cast(mBrushSize) / 2; if (distance < rf) newTerrain[j*landTextureSize+i] = brushInt; } else @@ -457,7 +455,8 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe if (j_cell > cellY) distanceY = -yHitInCell + landTextureSize * abs(j_cell-cellY) + j; if (i_cell == cellX) distanceX = abs(i-xHitInCell); if (j_cell == cellY) distanceY = abs(j-yHitInCell); - distance = std::round(sqrt(pow(distanceX, 2)+pow(distanceY, 2))); + float distance = std::round(sqrt(pow(distanceX, 2)+pow(distanceY, 2))); + float rf = static_cast(mBrushSize) / 2; if (distance < rf) newTerrain[j*landTextureSize+i] = brushInt; } } @@ -548,7 +547,8 @@ void CSVRender::TerrainTextureMode::selectTerrainTextures(const std::pair(mBrushSize) / 2; + if (std::round(coords.length()) < rf) { int x = i + texCoords.first; int y = j + texCoords.second; From da0add904b0cb99702696eecffe2ef6bcaaee8e2 Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Thu, 5 Mar 2020 20:10:55 +0200 Subject: [PATCH 5/9] Fix and simplify brush outlines and coordinate calculations --- apps/opencs/model/world/cellcoordinates.cpp | 9 +- apps/opencs/model/world/cellcoordinates.hpp | 7 +- apps/opencs/view/render/brushdraw.cpp | 235 +++++++++++++------ apps/opencs/view/render/brushdraw.hpp | 3 +- apps/opencs/view/render/terrainselection.cpp | 35 ++- 5 files changed, 192 insertions(+), 97 deletions(-) diff --git a/apps/opencs/model/world/cellcoordinates.cpp b/apps/opencs/model/world/cellcoordinates.cpp index 9f98c7b4c..af8c26d70 100644 --- a/apps/opencs/model/world/cellcoordinates.cpp +++ b/apps/opencs/model/world/cellcoordinates.cpp @@ -91,9 +91,14 @@ std::pair CSMWorld::CellCoordinates::toVertexCoords(const osg::Vec3d& return std::make_pair(x, y); } -float CSMWorld::CellCoordinates::textureGlobalToWorldCoords(int textureGlobal) +float CSMWorld::CellCoordinates::textureGlobalXToWorldCoords(int textureGlobal) { - return ESM::Land::REAL_SIZE * static_cast(textureGlobal) / ESM::Land::LAND_TEXTURE_SIZE; + return ESM::Land::REAL_SIZE * (static_cast(textureGlobal) + 0.25f) / ESM::Land::LAND_TEXTURE_SIZE; +} + +float CSMWorld::CellCoordinates::textureGlobalYToWorldCoords(int textureGlobal) +{ + return ESM::Land::REAL_SIZE * (static_cast(textureGlobal) - 0.25f) / ESM::Land::LAND_TEXTURE_SIZE; } float CSMWorld::CellCoordinates::vertexGlobalToWorldCoords(int vertexGlobal) diff --git a/apps/opencs/model/world/cellcoordinates.hpp b/apps/opencs/model/world/cellcoordinates.hpp index 77d76f6ef..9317c28b2 100644 --- a/apps/opencs/model/world/cellcoordinates.hpp +++ b/apps/opencs/model/world/cellcoordinates.hpp @@ -54,8 +54,11 @@ namespace CSMWorld ///Converts worldspace coordinates to global vertex selection. static std::pair toVertexCoords(const osg::Vec3d& worldPos); - ///Converts global texture coordinate to worldspace coordinate that is at the upper left corner of the selected texture. - static float textureGlobalToWorldCoords(int textureGlobal); + ///Converts global texture coordinate X to worldspace coordinate, offset by 0.25f. + static float textureGlobalXToWorldCoords(int textureGlobal); + + ///Converts global texture coordinate Y to worldspace coordinate, offset by 0.25f. + static float textureGlobalYToWorldCoords(int textureGlobal); ///Converts global vertex coordinate to worldspace coordinate static float vertexGlobalToWorldCoords(int vertexGlobal); diff --git a/apps/opencs/view/render/brushdraw.cpp b/apps/opencs/view/render/brushdraw.cpp index b963b09f5..0280d19ce 100644 --- a/apps/opencs/view/render/brushdraw.cpp +++ b/apps/opencs/view/render/brushdraw.cpp @@ -5,25 +5,23 @@ #include #include #include -#include -#include -#include #include +#include "../../model/world/cellcoordinates.hpp" #include "../widget/brushshapes.hpp" #include "mask.hpp" CSVRender::BrushDraw::BrushDraw(osg::ref_ptr parentNode, bool textureMode) : - mParentNode(parentNode) + mParentNode(parentNode), mTextureMode(textureMode) { mBrushDrawNode = new osg::Group(); mGeometry = new osg::Geometry(); mBrushDrawNode->addChild(mGeometry); mParentNode->addChild(mBrushDrawNode); - if (textureMode) mLandSizeFactor = ESM::Land::REAL_SIZE / ESM::Land::LAND_TEXTURE_SIZE / 2; - else mLandSizeFactor = ESM::Land::REAL_SIZE / ESM::Land::LAND_SIZE / 2; + if (mTextureMode) mLandSizeFactor = ESM::Land::REAL_SIZE / ESM::Land::LAND_TEXTURE_SIZE; + else mLandSizeFactor = ESM::Land::REAL_SIZE / ESM::Land::LAND_SIZE; } CSVRender::BrushDraw::~BrushDraw() @@ -37,7 +35,7 @@ float CSVRender::BrushDraw::getIntersectionHeight (const osg::Vec3d& point) osg::Vec3d start = point; osg::Vec3d end = point; start.z() = std::numeric_limits::max(); - end.z() = std::numeric_limits::min(); + end.z() = std::numeric_limits::lowest(); osg::Vec3d direction = end - start; // Get intersection @@ -66,9 +64,52 @@ float CSVRender::BrushDraw::getIntersectionHeight (const osg::Vec3d& point) return 0.0f; } -void CSVRender::BrushDraw::buildPointGeometry(const float& radius, const osg::Vec3d& point) +void CSVRender::BrushDraw::buildPointGeometry(const osg::Vec3d& point) { - // Not implemented + osg::ref_ptr geom = new osg::Geometry(); + osg::ref_ptr vertices (new osg::Vec3Array()); + osg::ref_ptr colors (new osg::Vec4Array()); + const float brushOutlineHeight (1.0f); + const float crossHeadSize (8.0f); + osg::Vec4f lineColor(1.0f, 1.0f, 1.0f, 0.6f); + + vertices->push_back(osg::Vec3d( + point.x() - crossHeadSize, + point.y() - crossHeadSize, + getIntersectionHeight(osg::Vec3d( + point.x() - crossHeadSize, + point.y() - crossHeadSize, + point.z()) ) + brushOutlineHeight)); + colors->push_back(lineColor); + vertices->push_back(osg::Vec3d( + point.x() + crossHeadSize, + point.y() + crossHeadSize, + getIntersectionHeight(osg::Vec3d( + point.x() + crossHeadSize, + point.y() + crossHeadSize, + point.z()) ) + brushOutlineHeight)); + colors->push_back(lineColor); + vertices->push_back(osg::Vec3d( + point.x() + crossHeadSize, + point.y() - crossHeadSize, + getIntersectionHeight(osg::Vec3d( + point.x() + crossHeadSize, + point.y() - crossHeadSize, + point.z()) ) + brushOutlineHeight)); + colors->push_back(lineColor); + vertices->push_back(osg::Vec3d( + point.x() - crossHeadSize, + point.y() + crossHeadSize, + getIntersectionHeight(osg::Vec3d( + point.x() - crossHeadSize, + point.y() + crossHeadSize, + point.z()) ) + brushOutlineHeight)); + colors->push_back(lineColor); + + geom->setVertexArray(vertices); + geom->setColorArray(colors, osg::Array::BIND_PER_VERTEX); + geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, 4)); + mGeometry = geom; } void CSVRender::BrushDraw::buildSquareGeometry(const float& radius, const osg::Vec3d& point) @@ -76,46 +117,95 @@ void CSVRender::BrushDraw::buildSquareGeometry(const float& radius, const osg::V osg::ref_ptr geom = new osg::Geometry(); osg::ref_ptr vertices (new osg::Vec3Array()); osg::ref_ptr colors (new osg::Vec4Array()); - std::vector corners; - const float brushOutLineHeight (200.0f); - corners.push_back(osg::Vec3d(point.x() - radius, point.y() - radius, point.z())); - corners.push_back(osg::Vec3d(point.x() + radius, point.y() - radius, point.z())); - corners.push_back(osg::Vec3d(point.x() + radius, point.y() + radius, point.z())); - corners.push_back(osg::Vec3d(point.x() - radius, point.y() + radius, point.z())); - corners.push_back(osg::Vec3d(point.x() - radius, point.y() - radius, point.z())); + const float brushOutlineHeight (1.0f); + float diameter = radius * 2; + int resolution = (diameter / mLandSizeFactor) * 2; //half a vertex resolution + float resAdjustedLandSizeFactor = mLandSizeFactor / 2; + osg::Vec4f lineColor(1.0f, 1.0f, 1.0f, 0.6f); - for (const auto& point : corners) + for (int i = 0; i < resolution; i++) { - vertices->push_back(osg::Vec3d( - point.x(), - point.y(), + int step = i * resAdjustedLandSizeFactor; + int step2 = (i + 1) * resAdjustedLandSizeFactor; + + osg::Vec3d upHorizontalLinePoint1( + point.x() - radius + step, + point.y() - radius, getIntersectionHeight(osg::Vec3d( - point.x(), - point.y(), - point.z()) ))); - colors->push_back(osg::Vec4f( - 50.0f, - 50.0f, - 50.0f, - 100.0f)); - vertices->push_back(osg::Vec3d( - point.x(), - point.y(), + point.x() - radius + step, + point.y() - radius, + point.z())) + brushOutlineHeight); + osg::Vec3d upHorizontalLinePoint2( + point.x() - radius + step2, + point.y() - radius, getIntersectionHeight(osg::Vec3d( - point.x(), - point.y(), - point.z())) + brushOutLineHeight)); - colors->push_back(osg::Vec4f( - 50.0f, - 50.0f, - 50.0f, - 100.0f)); + point.x() - radius + step2, + point.y() - radius, + point.z())) + brushOutlineHeight); + osg::Vec3d upVerticalLinePoint1( + point.x() - radius, + point.y() - radius + step, + getIntersectionHeight(osg::Vec3d( + point.x() - radius, + point.y() - radius + step, + point.z())) + brushOutlineHeight); + osg::Vec3d upVerticalLinePoint2( + point.x() - radius, + point.y() - radius + step2, + getIntersectionHeight(osg::Vec3d( + point.x() - radius, + point.y() - radius + step2, + point.z())) + brushOutlineHeight); + osg::Vec3d downHorizontalLinePoint1( + point.x() + radius - step, + point.y() + radius, + getIntersectionHeight(osg::Vec3d( + point.x() + radius - step, + point.y() + radius, + point.z())) + brushOutlineHeight); + osg::Vec3d downHorizontalLinePoint2( + point.x() + radius - step2, + point.y() + radius, + getIntersectionHeight(osg::Vec3d( + point.x() + radius - step2, + point.y() + radius, + point.z())) + brushOutlineHeight); + osg::Vec3d downVerticalLinePoint1( + point.x() + radius, + point.y() + radius - step, + getIntersectionHeight(osg::Vec3d( + point.x() + radius, + point.y() + radius - step, + point.z())) + brushOutlineHeight); + osg::Vec3d downVerticalLinePoint2( + point.x() + radius, + point.y() + radius - step2, + getIntersectionHeight(osg::Vec3d( + point.x() + radius, + point.y() + radius - step2, + point.z())) + brushOutlineHeight); + vertices->push_back(upHorizontalLinePoint1); + colors->push_back(lineColor); + vertices->push_back(upHorizontalLinePoint2); + colors->push_back(lineColor); + vertices->push_back(upVerticalLinePoint1); + colors->push_back(lineColor); + vertices->push_back(upVerticalLinePoint2); + colors->push_back(lineColor); + vertices->push_back(downHorizontalLinePoint1); + colors->push_back(lineColor); + vertices->push_back(downHorizontalLinePoint2); + colors->push_back(lineColor); + vertices->push_back(downVerticalLinePoint1); + colors->push_back(lineColor); + vertices->push_back(downVerticalLinePoint2); + colors->push_back(lineColor); } geom->setVertexArray(vertices); geom->setColorArray(colors, osg::Array::BIND_PER_VERTEX); - geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP, 0, (10 + 2) - 2)); + geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, resolution * 8)); mGeometry = geom; } @@ -126,7 +216,8 @@ void CSVRender::BrushDraw::buildCircleGeometry(const float& radius, const osg::V osg::ref_ptr colors (new osg::Vec4Array()); const int amountOfPoints = (osg::PI * 2.0f) * radius / 20; const float step ((osg::PI * 2.0f) / static_cast(amountOfPoints)); - const float brushOutLineHeight (200.0f); + const float brushOutlineHeight (1.0f); + osg::Vec4f lineColor(1.0f, 1.0f, 1.0f, 0.6f); for (int i = 0; i < amountOfPoints + 2; i++) { @@ -137,12 +228,8 @@ void CSVRender::BrushDraw::buildCircleGeometry(const float& radius, const osg::V getIntersectionHeight(osg::Vec3d( point.x() + radius * cosf(angle), point.y() + radius * sinf(angle), - point.z()) ))); - colors->push_back(osg::Vec4f( - 50.0f, - 50.0f, - 50.0f, - 100.0f)); + point.z()) ) + brushOutlineHeight)); + colors->push_back(lineColor); angle = static_cast(i + 1) * step; vertices->push_back(osg::Vec3d( point.x() + radius * cosf(angle), @@ -150,17 +237,13 @@ void CSVRender::BrushDraw::buildCircleGeometry(const float& radius, const osg::V getIntersectionHeight(osg::Vec3d( point.x() + radius * cosf(angle), point.y() + radius * sinf(angle), - point.z()) ) + brushOutLineHeight)); - colors->push_back(osg::Vec4f( - 50.0f, - 50.0f, - 50.0f, - 100.0f)); + point.z()) ) + brushOutlineHeight)); + colors->push_back(lineColor); } geom->setVertexArray(vertices); geom->setColorArray(colors, osg::Array::BIND_PER_VERTEX); - geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP, 0, (amountOfPoints + 2) * 2 - 2)); + geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, 0, amountOfPoints * 2)); mGeometry = geom; } @@ -173,39 +256,45 @@ void CSVRender::BrushDraw::update(osg::Vec3d point, int brushSize, CSVWidget::Br { if (mBrushDrawNode->containsNode(mGeometry)) mBrushDrawNode->removeChild(mGeometry); mBrushDrawNode->setNodeMask (Mask_EditModeCursor); - float radius = static_cast(brushSize * mLandSizeFactor); + float radius = (mLandSizeFactor * brushSize) / 2; + osg::Vec3d snapToGridPoint = point; + if (mTextureMode) + { + std::pair snapToGridXY = CSMWorld::CellCoordinates::toTextureCoords(point); + float offsetToMiddle = mLandSizeFactor * 0.5f; + snapToGridPoint = osg::Vec3d( + CSMWorld::CellCoordinates::textureGlobalXToWorldCoords(snapToGridXY.first) + offsetToMiddle, + CSMWorld::CellCoordinates::textureGlobalYToWorldCoords(snapToGridXY.second) + offsetToMiddle, + point.z()); + } + else + { + std::pair snapToGridXY = CSMWorld::CellCoordinates::toVertexCoords(point); + snapToGridPoint = osg::Vec3d( + CSMWorld::CellCoordinates::vertexGlobalToWorldCoords(snapToGridXY.first), + CSMWorld::CellCoordinates::vertexGlobalToWorldCoords(snapToGridXY.second), + point.z()); + } + switch (toolShape) { case (CSVWidget::BrushShape_Point) : - buildSquareGeometry(1, point); - //buildPointGeometry(radius, point); + buildPointGeometry(snapToGridPoint); break; case (CSVWidget::BrushShape_Square) : - buildSquareGeometry(radius, point); + buildSquareGeometry(radius, snapToGridPoint); break; case (CSVWidget::BrushShape_Circle) : - buildCircleGeometry(radius, point); + buildCircleGeometry(radius, snapToGridPoint); break; case (CSVWidget::BrushShape_Custom) : - buildSquareGeometry(1, point); + buildSquareGeometry(1, snapToGridPoint); //buildCustomGeometry break; } - osg::BlendFunc* blendFunc = new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA); - mGeometry->getOrCreateStateSet()->setAttributeAndModes(blendFunc); - - mGeometry->getOrCreateStateSet()->setMode( GL_CULL_FACE, osg::StateAttribute::OFF ); - - osg::ref_ptr material = new osg::Material; - material->setColorMode(osg::Material::AMBIENT); - material->setAmbient (osg::Material::FRONT_AND_BACK, osg::Vec4(0.3, 0.3, 0.3, 1)); - material->setAlpha(osg::Material::FRONT_AND_BACK, 0.5); - - mGeometry->getOrCreateStateSet()->setAttributeAndModes(material.get(), osg::StateAttribute::ON); - mGeometry->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON); - mGeometry->getOrCreateStateSet()->setRenderingHint (osg::StateSet::TRANSPARENT_BIN); + mGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); mBrushDrawNode->addChild(mGeometry); } diff --git a/apps/opencs/view/render/brushdraw.hpp b/apps/opencs/view/render/brushdraw.hpp index 6ecfccde7..0551631cd 100644 --- a/apps/opencs/view/render/brushdraw.hpp +++ b/apps/opencs/view/render/brushdraw.hpp @@ -19,7 +19,7 @@ namespace CSVRender void hide(); private: - void buildPointGeometry(const float& radius, const osg::Vec3d& point); + void buildPointGeometry(const osg::Vec3d& point); void buildSquareGeometry(const float& radius, const osg::Vec3d& point); void buildCircleGeometry(const float& radius, const osg::Vec3d& point); void buildCustomGeometry(const float& radius, const osg::Vec3d& point); @@ -28,6 +28,7 @@ namespace CSVRender osg::ref_ptr mParentNode; osg::ref_ptr mBrushDrawNode; osg::ref_ptr mGeometry; + bool mTextureMode; float mLandSizeFactor; }; } diff --git a/apps/opencs/view/render/terrainselection.cpp b/apps/opencs/view/render/terrainselection.cpp index e16a69048..4e209af57 100644 --- a/apps/opencs/view/render/terrainselection.cpp +++ b/apps/opencs/view/render/terrainselection.cpp @@ -171,9 +171,6 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptrpush_back(osg::Vec3f(drawPreviousX + nudgeOffset, CSMWorld::CellCoordinates::textureGlobalToWorldCoords(y + 1) - nudgeOffset, calculateLandHeight(x1+(i-1), y2)+2)); - vertices->push_back(osg::Vec3f(drawCurrentX + nudgeOffset, CSMWorld::CellCoordinates::textureGlobalToWorldCoords(y + 1) - nudgeOffset, calculateLandHeight(x1+i, y2)+2)); + float drawPreviousX = CSMWorld::CellCoordinates::textureGlobalXToWorldCoords(x) + (i - 1) * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1)); + float drawCurrentX = CSMWorld::CellCoordinates::textureGlobalXToWorldCoords(x) + i * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1)); + vertices->push_back(osg::Vec3f(drawPreviousX, CSMWorld::CellCoordinates::textureGlobalYToWorldCoords(y + 1), calculateLandHeight(x1+(i-1), y2)+2)); + vertices->push_back(osg::Vec3f(drawCurrentX, CSMWorld::CellCoordinates::textureGlobalYToWorldCoords(y + 1), calculateLandHeight(x1+i, y2)+2)); } } @@ -208,10 +205,10 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptrpush_back(osg::Vec3f(drawPreviousX + nudgeOffset, CSMWorld::CellCoordinates::textureGlobalToWorldCoords(y) - nudgeOffset, calculateLandHeight(x1+(i-1), y1)+2)); - vertices->push_back(osg::Vec3f(drawCurrentX + nudgeOffset, CSMWorld::CellCoordinates::textureGlobalToWorldCoords(y) - nudgeOffset, calculateLandHeight(x1+i, y1)+2)); + float drawPreviousX = CSMWorld::CellCoordinates::textureGlobalXToWorldCoords(x) + (i - 1) *(ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1)); + float drawCurrentX = CSMWorld::CellCoordinates::textureGlobalXToWorldCoords(x) + i * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1)); + vertices->push_back(osg::Vec3f(drawPreviousX, CSMWorld::CellCoordinates::textureGlobalYToWorldCoords(y), calculateLandHeight(x1+(i-1), y1)+2)); + vertices->push_back(osg::Vec3f(drawCurrentX, CSMWorld::CellCoordinates::textureGlobalYToWorldCoords(y), calculateLandHeight(x1+i, y1)+2)); } } @@ -220,10 +217,10 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptrpush_back(osg::Vec3f(CSMWorld::CellCoordinates::textureGlobalToWorldCoords(x + 1) + nudgeOffset, drawPreviousY - nudgeOffset, calculateLandHeight(x2, y1+(i-1))+2)); - vertices->push_back(osg::Vec3f(CSMWorld::CellCoordinates::textureGlobalToWorldCoords(x + 1) + nudgeOffset, drawCurrentY - nudgeOffset, calculateLandHeight(x2, y1+i)+2)); + float drawPreviousY = CSMWorld::CellCoordinates::textureGlobalYToWorldCoords(y) + (i - 1) * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1)); + float drawCurrentY = CSMWorld::CellCoordinates::textureGlobalYToWorldCoords(y) + i * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1)); + vertices->push_back(osg::Vec3f(CSMWorld::CellCoordinates::textureGlobalXToWorldCoords(x + 1), drawPreviousY, calculateLandHeight(x2, y1+(i-1))+2)); + vertices->push_back(osg::Vec3f(CSMWorld::CellCoordinates::textureGlobalXToWorldCoords(x + 1), drawCurrentY, calculateLandHeight(x2, y1+i)+2)); } } @@ -232,10 +229,10 @@ void CSVRender::TerrainSelection::drawTextureSelection(const osg::ref_ptrpush_back(osg::Vec3f(CSMWorld::CellCoordinates::textureGlobalToWorldCoords(x) + nudgeOffset, drawPreviousY - nudgeOffset, calculateLandHeight(x1, y1+(i-1))+2)); - vertices->push_back(osg::Vec3f(CSMWorld::CellCoordinates::textureGlobalToWorldCoords(x) + nudgeOffset, drawCurrentY - nudgeOffset, calculateLandHeight(x1, y1+i)+2)); + float drawPreviousY = CSMWorld::CellCoordinates::textureGlobalYToWorldCoords(y) + (i - 1) * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1)); + float drawCurrentY = CSMWorld::CellCoordinates::textureGlobalYToWorldCoords(y) + i * (ESM::Land::REAL_SIZE / (ESM::Land::LAND_SIZE - 1)); + vertices->push_back(osg::Vec3f(CSMWorld::CellCoordinates::textureGlobalXToWorldCoords(x), drawPreviousY, calculateLandHeight(x1, y1+(i-1))+2)); + vertices->push_back(osg::Vec3f(CSMWorld::CellCoordinates::textureGlobalXToWorldCoords(x), drawCurrentY, calculateLandHeight(x1, y1+i)+2)); } } } From 18cdd3bd7ca9b6dc902944cd0364f84abe06f55d Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Fri, 6 Mar 2020 12:10:14 +0200 Subject: [PATCH 6/9] rebase-related fixes --- apps/opencs/view/render/brushdraw.cpp | 8 ++++---- apps/opencs/view/render/terraintexturemode.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/opencs/view/render/brushdraw.cpp b/apps/opencs/view/render/brushdraw.cpp index 0280d19ce..d33ef3367 100644 --- a/apps/opencs/view/render/brushdraw.cpp +++ b/apps/opencs/view/render/brushdraw.cpp @@ -8,11 +8,11 @@ #include +#include + #include "../../model/world/cellcoordinates.hpp" #include "../widget/brushshapes.hpp" -#include "mask.hpp" - CSVRender::BrushDraw::BrushDraw(osg::ref_ptr parentNode, bool textureMode) : mParentNode(parentNode), mTextureMode(textureMode) { @@ -44,7 +44,7 @@ float CSVRender::BrushDraw::getIntersectionHeight (const osg::Vec3d& point) intersector->setIntersectionLimit(osgUtil::LineSegmentIntersector::NO_LIMIT); osgUtil::IntersectionVisitor visitor(intersector); - visitor.setTraversalMask(Mask_Terrain); + visitor.setTraversalMask(SceneUtil::Mask_Terrain); mParentNode->accept(visitor); @@ -255,7 +255,7 @@ void CSVRender::BrushDraw::buildCustomGeometry(const float& radius, const osg::V void CSVRender::BrushDraw::update(osg::Vec3d point, int brushSize, CSVWidget::BrushShape toolShape) { if (mBrushDrawNode->containsNode(mGeometry)) mBrushDrawNode->removeChild(mGeometry); - mBrushDrawNode->setNodeMask (Mask_EditModeCursor); + mBrushDrawNode->setNodeMask (SceneUtil::Mask_GUI); float radius = (mLandSizeFactor * brushSize) / 2; osg::Vec3d snapToGridPoint = point; if (mTextureMode) diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index 95dcd4112..386ff2f90 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -44,7 +44,7 @@ CSVRender::TerrainTextureMode::TerrainTextureMode (WorldspaceWidget *worldspaceW : EditMode (worldspaceWidget, QIcon {":scenetoolbar/editing-terrain-texture"}, SceneUtil::Mask_Terrain | SceneUtil::Mask_EditorReference, "Terrain texture editing", parent), mBrushTexture("L0#0"), mBrushSize(1), - mBrushShape(0), + mBrushShape(CSVWidget::BrushShape_Point), mTextureBrushScenetool(nullptr), mDragMode(InteractionType_None), mParentNode(parentNode), From c8c7501d974204cad4cfdfb3e02be44eee8fe59b Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Thu, 26 Mar 2020 13:28:51 +0200 Subject: [PATCH 7/9] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85fffdd1f..dec3aa347 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -264,6 +264,7 @@ Feature #5170: Editor: Land shape editing, land selection Feature #5172: Editor: Delete instances/references with keypress in scene window Feature #5193: Weapon sheathing + Feature #5201: Editor: Show tool outline in scene view, when using editmodes Feature #5219: Impelement TestCells console command Feature #5224: Handle NiKeyframeController for NiTriShape Feature #5274: Editor: Keyboard shortcut to drop objects to ground/obstacle in scene view From ec2ff2a9b0150a887dc80b91754701bf31806e27 Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Thu, 26 Mar 2020 14:47:40 +0200 Subject: [PATCH 8/9] Fix if oneliners --- apps/opencs/view/render/brushdraw.cpp | 9 ++++++--- apps/opencs/view/render/terrainshapemode.cpp | 6 ++++-- apps/opencs/view/render/terraintexturemode.cpp | 6 ++++-- apps/opencs/view/widget/scenetooltexturebrush.cpp | 12 ++++++++---- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/apps/opencs/view/render/brushdraw.cpp b/apps/opencs/view/render/brushdraw.cpp index d33ef3367..478ff7a9d 100644 --- a/apps/opencs/view/render/brushdraw.cpp +++ b/apps/opencs/view/render/brushdraw.cpp @@ -20,7 +20,8 @@ CSVRender::BrushDraw::BrushDraw(osg::ref_ptr parentNode, bool textur mGeometry = new osg::Geometry(); mBrushDrawNode->addChild(mGeometry); mParentNode->addChild(mBrushDrawNode); - if (mTextureMode) mLandSizeFactor = ESM::Land::REAL_SIZE / ESM::Land::LAND_TEXTURE_SIZE; + if (mTextureMode) + mLandSizeFactor = ESM::Land::REAL_SIZE / ESM::Land::LAND_TEXTURE_SIZE; else mLandSizeFactor = ESM::Land::REAL_SIZE / ESM::Land::LAND_SIZE; } @@ -254,7 +255,8 @@ void CSVRender::BrushDraw::buildCustomGeometry(const float& radius, const osg::V void CSVRender::BrushDraw::update(osg::Vec3d point, int brushSize, CSVWidget::BrushShape toolShape) { - if (mBrushDrawNode->containsNode(mGeometry)) mBrushDrawNode->removeChild(mGeometry); + if (mBrushDrawNode->containsNode(mGeometry)) + mBrushDrawNode->removeChild(mGeometry); mBrushDrawNode->setNodeMask (SceneUtil::Mask_GUI); float radius = (mLandSizeFactor * brushSize) / 2; osg::Vec3d snapToGridPoint = point; @@ -301,5 +303,6 @@ void CSVRender::BrushDraw::update(osg::Vec3d point, int brushSize, CSVWidget::Br void CSVRender::BrushDraw::hide() { - if (mBrushDrawNode->containsNode(mGeometry)) mBrushDrawNode->removeChild(mGeometry); + if (mBrushDrawNode->containsNode(mGeometry)) + mBrushDrawNode->removeChild(mGeometry); } diff --git a/apps/opencs/view/render/terrainshapemode.cpp b/apps/opencs/view/render/terrainshapemode.cpp index cf380e791..ae8e6e89b 100644 --- a/apps/opencs/view/render/terrainshapemode.cpp +++ b/apps/opencs/view/render/terrainshapemode.cpp @@ -1398,8 +1398,10 @@ void CSVRender::TerrainShapeMode::dragMoveEvent (QDragMoveEvent *event) void CSVRender::TerrainShapeMode::mouseMoveEvent (QMouseEvent *event) { WorldspaceHitResult hit = getWorldspaceWidget().mousePick(event->pos(), getInteractionMask()); - if (hit.hit && mBrushDraw && !(mShapeEditTool == ShapeEditTool_Drag && mIsEditing)) mBrushDraw->update(hit.worldPos, mBrushSize, mBrushShape); - if (!hit.hit && mBrushDraw && !(mShapeEditTool == ShapeEditTool_Drag && mIsEditing)) mBrushDraw->hide(); + if (hit.hit && mBrushDraw && !(mShapeEditTool == ShapeEditTool_Drag && mIsEditing)) + mBrushDraw->update(hit.worldPos, mBrushSize, mBrushShape); + if (!hit.hit && mBrushDraw && !(mShapeEditTool == ShapeEditTool_Drag && mIsEditing)) + mBrushDraw->hide(); } void CSVRender::TerrainShapeMode::setBrushSize(int brushSize) diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index 386ff2f90..04189ce8c 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -724,8 +724,10 @@ void CSVRender::TerrainTextureMode::dragMoveEvent (QDragMoveEvent *event) void CSVRender::TerrainTextureMode::mouseMoveEvent (QMouseEvent *event) { WorldspaceHitResult hit = getWorldspaceWidget().mousePick(event->pos(), getInteractionMask()); - if (hit.hit && mBrushDraw) mBrushDraw->update(hit.worldPos, mBrushSize, mBrushShape); - if (!hit.hit && mBrushDraw) mBrushDraw->hide(); + if (hit.hit && mBrushDraw) + mBrushDraw->update(hit.worldPos, mBrushSize, mBrushShape); + if (!hit.hit && mBrushDraw) + mBrushDraw->hide(); } diff --git a/apps/opencs/view/widget/scenetooltexturebrush.cpp b/apps/opencs/view/widget/scenetooltexturebrush.cpp index 0a1ed6683..35937f1a6 100644 --- a/apps/opencs/view/widget/scenetooltexturebrush.cpp +++ b/apps/opencs/view/widget/scenetooltexturebrush.cpp @@ -204,10 +204,14 @@ void CSVWidget::TextureBrushWindow::setBrushSize(int brushSize) void CSVWidget::TextureBrushWindow::setBrushShape() { - if(mButtonPoint->isChecked()) mBrushShape = CSVWidget::BrushShape_Point; - if(mButtonSquare->isChecked()) mBrushShape = CSVWidget::BrushShape_Square; - if(mButtonCircle->isChecked()) mBrushShape = CSVWidget::BrushShape_Circle; - if(mButtonCustom->isChecked()) mBrushShape = CSVWidget::BrushShape_Custom; + if (mButtonPoint->isChecked()) + mBrushShape = CSVWidget::BrushShape_Point; + if (mButtonSquare->isChecked()) + mBrushShape = CSVWidget::BrushShape_Square; + if (mButtonCircle->isChecked()) + mBrushShape = CSVWidget::BrushShape_Circle; + if (mButtonCustom->isChecked()) + mBrushShape = CSVWidget::BrushShape_Custom; emit passBrushShape(mBrushShape); } From 66fba7cc514ed83f6cc113fad37615b44620af1c Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Thu, 26 Mar 2020 18:06:33 +0200 Subject: [PATCH 9/9] Remove unneeded constructors, only initialize in cpp, minor fixes --- apps/opencs/view/render/brushdraw.cpp | 8 ++++---- apps/opencs/view/render/terrainshapemode.cpp | 6 ------ apps/opencs/view/render/terrainshapemode.hpp | 1 - apps/opencs/view/render/terraintexturemode.cpp | 6 ------ apps/opencs/view/render/terraintexturemode.hpp | 13 ++++++------- 5 files changed, 10 insertions(+), 24 deletions(-) diff --git a/apps/opencs/view/render/brushdraw.cpp b/apps/opencs/view/render/brushdraw.cpp index 478ff7a9d..9a648336e 100644 --- a/apps/opencs/view/render/brushdraw.cpp +++ b/apps/opencs/view/render/brushdraw.cpp @@ -67,7 +67,7 @@ float CSVRender::BrushDraw::getIntersectionHeight (const osg::Vec3d& point) void CSVRender::BrushDraw::buildPointGeometry(const osg::Vec3d& point) { - osg::ref_ptr geom = new osg::Geometry(); + osg::ref_ptr geom (new osg::Geometry()); osg::ref_ptr vertices (new osg::Vec3Array()); osg::ref_ptr colors (new osg::Vec4Array()); const float brushOutlineHeight (1.0f); @@ -115,7 +115,7 @@ void CSVRender::BrushDraw::buildPointGeometry(const osg::Vec3d& point) void CSVRender::BrushDraw::buildSquareGeometry(const float& radius, const osg::Vec3d& point) { - osg::ref_ptr geom = new osg::Geometry(); + osg::ref_ptr geom (new osg::Geometry()); osg::ref_ptr vertices (new osg::Vec3Array()); osg::ref_ptr colors (new osg::Vec4Array()); @@ -212,7 +212,7 @@ void CSVRender::BrushDraw::buildSquareGeometry(const float& radius, const osg::V void CSVRender::BrushDraw::buildCircleGeometry(const float& radius, const osg::Vec3d& point) { - osg::ref_ptr geom = new osg::Geometry(); + osg::ref_ptr geom (new osg::Geometry()); osg::ref_ptr vertices (new osg::Vec3Array()); osg::ref_ptr colors (new osg::Vec4Array()); const int amountOfPoints = (osg::PI * 2.0f) * radius / 20; @@ -222,7 +222,7 @@ void CSVRender::BrushDraw::buildCircleGeometry(const float& radius, const osg::V for (int i = 0; i < amountOfPoints + 2; i++) { - float angle (static_cast(i) * step); + float angle (i * step); vertices->push_back(osg::Vec3d( point.x() + radius * cosf(angle), point.y() + radius * sinf(angle), diff --git a/apps/opencs/view/render/terrainshapemode.cpp b/apps/opencs/view/render/terrainshapemode.cpp index ae8e6e89b..6df5ee836 100644 --- a/apps/opencs/view/render/terrainshapemode.cpp +++ b/apps/opencs/view/render/terrainshapemode.cpp @@ -50,12 +50,6 @@ CSVRender::TerrainShapeMode::TerrainShapeMode (WorldspaceWidget *worldspaceWidge { } -CSVRender::TerrainShapeMode::~TerrainShapeMode () -{ - if (mBrushDraw) - mBrushDraw.reset(); -} - void CSVRender::TerrainShapeMode::activate(CSVWidget::SceneToolbar* toolbar) { if (!mTerrainShapeSelection) diff --git a/apps/opencs/view/render/terrainshapemode.hpp b/apps/opencs/view/render/terrainshapemode.hpp index fb80e79af..d0fec764f 100644 --- a/apps/opencs/view/render/terrainshapemode.hpp +++ b/apps/opencs/view/render/terrainshapemode.hpp @@ -58,7 +58,6 @@ namespace CSVRender /// Editmode for terrain shape grid TerrainShapeMode(WorldspaceWidget*, osg::Group* parentNode, QWidget* parent = nullptr); - ~TerrainShapeMode(); void primaryOpenPressed (const WorldspaceHitResult& hit) final; diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index 04189ce8c..d4656b578 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -52,12 +52,6 @@ CSVRender::TerrainTextureMode::TerrainTextureMode (WorldspaceWidget *worldspaceW { } -CSVRender::TerrainTextureMode::~TerrainTextureMode () -{ - if (mBrushDraw) - mBrushDraw.reset(); -} - void CSVRender::TerrainTextureMode::activate(CSVWidget::SceneToolbar* toolbar) { if(!mTextureBrushScenetool) diff --git a/apps/opencs/view/render/terraintexturemode.hpp b/apps/opencs/view/render/terraintexturemode.hpp index cc77bb331..0d8c4a94a 100644 --- a/apps/opencs/view/render/terraintexturemode.hpp +++ b/apps/opencs/view/render/terraintexturemode.hpp @@ -52,7 +52,6 @@ namespace CSVRender /// \brief Editmode for terrain texture grid TerrainTextureMode(WorldspaceWidget*, osg::Group* parentNode, QWidget* parent = nullptr); - ~TerrainTextureMode(); void primaryOpenPressed (const WorldspaceHitResult& hit) final; @@ -107,15 +106,15 @@ namespace CSVRender bool allowLandTextureEditing(std::string textureFileName); std::string mCellId; - std::string mBrushTexture = "L0#0"; - int mBrushSize = 1; - CSVWidget::BrushShape mBrushShape = CSVWidget::BrushShape_Point; + std::string mBrushTexture; + int mBrushSize; + CSVWidget::BrushShape mBrushShape; std::unique_ptr mBrushDraw; std::vector> mCustomBrushShape; - CSVWidget::SceneToolTextureBrush *mTextureBrushScenetool = nullptr; - int mDragMode = InteractionType_None; + CSVWidget::SceneToolTextureBrush *mTextureBrushScenetool; + int mDragMode; osg::Group* mParentNode; - bool mIsEditing = false; + bool mIsEditing; std::unique_ptr mTerrainTextureSelection; const int cellSize {ESM::Land::REAL_SIZE};