From 050efe5b66cb99d4be86d076828f46ab0ed1c064 Mon Sep 17 00:00:00 2001 From: codereader Date: Mon, 13 Sep 2021 17:22:14 +0200 Subject: [PATCH] #5746: Introduce a texture tool scene graph module which is going to be hosted in the core module. It will collect and represent the editable faces, patches and their vertices, and expose them to both the UI module for rendering as well as to the Manipulator algorithms which are in the same binary. --- include/itexturetoolmodel.h | 51 +++++++++++++++++++ .../TextureToolRotateManipulator.cpp | 14 ++--- .../TextureToolRotateManipulator.h | 11 +++- tools/msvc/include.vcxproj | 1 + 4 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 include/itexturetoolmodel.h diff --git a/include/itexturetoolmodel.h b/include/itexturetoolmodel.h new file mode 100644 index 0000000000..5a0c2598d5 --- /dev/null +++ b/include/itexturetoolmodel.h @@ -0,0 +1,51 @@ +#pragma once + +#include "imodule.h" +#include "inode.h" + +namespace textool +{ + +// The base element of every node in the ITextureToolSceneGraph +class INode +{ +public: + virtual ~INode() {} + + using Ptr = std::shared_ptr; + + // The scene node this texture tool node is relating to + virtual scene::INodePtr getSceneNode() = 0; +}; + +/** + * The scene graph of all texture tool items. From all the selected + * items in the regular SceneGraph the texture-editable elements + * are extracted and put into this graph. + * + * It can have multiple top-level elements (faces, patches) each of which + * can have an arbitrary number of child elements (vertices). + * + * Like in the regular scene graph, some of the elements have special + * properties like being renderable or transformable, which manifests + * in them implementing the corresponding interface. + */ +class ITextureToolSceneGraph : + public RegisterableModule +{ +public: + virtual ~ITextureToolSceneGraph() {} + + // Iterate over every node in this graph calling the given functor + virtual void foreachNode(const std::function& functor) = 0; +}; + +} + +constexpr const char* const MODULE_TEXTOOL_SCENEGRAPH("TextureToolSceneGraph"); + +inline textool::ITextureToolSceneGraph& GlobalTextureToolSceneGraph() +{ + static module::InstanceReference _reference(MODULE_TEXTOOL_SCENEGRAPH); + return _reference; +} diff --git a/radiantcore/selection/manipulators/TextureToolRotateManipulator.cpp b/radiantcore/selection/manipulators/TextureToolRotateManipulator.cpp index 1562f3568d..95a729283a 100644 --- a/radiantcore/selection/manipulators/TextureToolRotateManipulator.cpp +++ b/radiantcore/selection/manipulators/TextureToolRotateManipulator.cpp @@ -44,7 +44,7 @@ void TextureRotator::transform(const Matrix4& pivot2world, const VolumeTest& vie auto sign = _start.crossProduct(current) < 0 ? +1 : -1; _curAngle *= sign; - //rMessage() << "Angle " << radians_to_degrees(angle) << std::endl; + _rotateFunctor(_curAngle); } void TextureRotator::resetCurAngle() @@ -58,6 +58,7 @@ Vector3::ElementType TextureRotator::getCurAngle() const } TextureToolRotateManipulator::TextureToolRotateManipulator() : + _rotator(std::bind(&TextureToolRotateManipulator::rotateSelected, this, std::placeholders::_1)), _renderableCircle(8 << 3) { draw_circle(8, 1.0f, &_renderableCircle.front(), RemapXYZ()); @@ -110,14 +111,8 @@ void TextureToolRotateManipulator::testSelect(SelectionTest& test, const Matrix4 if (!selector.empty()) { - //rMessage() << "Got the circle!" << std::endl; - selector.begin()->second->setSelected(true); } - else - { - //rMessage() << "MISSED" << std::endl; - } } void TextureToolRotateManipulator::renderComponents(const Matrix4& pivot2World) @@ -148,4 +143,9 @@ void TextureToolRotateManipulator::renderComponents(const Matrix4& pivot2World) glPopMatrix(); } +void TextureToolRotateManipulator::rotateSelected(double angle) +{ + // TODO +} + } diff --git a/radiantcore/selection/manipulators/TextureToolRotateManipulator.h b/radiantcore/selection/manipulators/TextureToolRotateManipulator.h index 2ea989be4a..2eeaf55d94 100644 --- a/radiantcore/selection/manipulators/TextureToolRotateManipulator.h +++ b/radiantcore/selection/manipulators/TextureToolRotateManipulator.h @@ -16,9 +16,13 @@ class TextureRotator : // The most recently calculated angle for rendering purposes Vector2::ElementType _curAngle; + + std::function _rotateFunctor; + public: - TextureRotator() : - _curAngle(0) + TextureRotator(const std::function& rotateFunctor) : + _curAngle(0), + _rotateFunctor(rotateFunctor) {} void beginTransformation(const Matrix4& pivot2world, const VolumeTest& view, const Vector2& devicePoint) override; @@ -55,6 +59,9 @@ class TextureToolRotateManipulator : virtual bool isSelected() const override; virtual void testSelect(SelectionTest& test, const Matrix4& pivot2world) override; virtual void renderComponents(const Matrix4& pivot2World) override; + +private: + void rotateSelected(double angle); }; } diff --git a/tools/msvc/include.vcxproj b/tools/msvc/include.vcxproj index 6005485cd9..4499f72bb0 100644 --- a/tools/msvc/include.vcxproj +++ b/tools/msvc/include.vcxproj @@ -198,6 +198,7 @@ +