From e50ad5f9ba547e4ef325717c00a33095712bb9dd Mon Sep 17 00:00:00 2001 From: codereader Date: Wed, 15 Sep 2021 20:41:50 +0200 Subject: [PATCH] #5128: More interface definitions of methods we're going to need --- include/ibrush.h | 6 ++ include/itexturetoolmodel.h | 18 +++++- radiant/textool/TexTool.cpp | 31 ++++++++-- radiantcore/brush/Face.cpp | 7 ++- radiantcore/brush/Face.h | 5 +- .../TextureToolRotateManipulator.cpp | 3 + radiantcore/selection/textool/FaceNode.h | 56 +++++++++++++++++++ radiantcore/selection/textool/PatchNode.h | 17 ++++++ 8 files changed, 130 insertions(+), 13 deletions(-) diff --git a/include/ibrush.h b/include/ibrush.h index f4cd213b62..0f8d0aa629 100644 --- a/include/ibrush.h +++ b/include/ibrush.h @@ -156,6 +156,12 @@ class IFace // If possible, aligns the assigned texture at the given anchor edge virtual void alignTexture(AlignEdge alignType) = 0; + // Reverts any transform that has been applied since the last time freezeTransform() was called + virtual void revertTransform() = 0; + + // Promotes the current transformed state to the new base state + virtual void freezeTransform() = 0; + // Get access to the actual Winding object virtual IWinding& getWinding() = 0; virtual const IWinding& getWinding() const = 0; diff --git a/include/itexturetoolmodel.h b/include/itexturetoolmodel.h index 228845e4a6..86fc344864 100644 --- a/include/itexturetoolmodel.h +++ b/include/itexturetoolmodel.h @@ -24,10 +24,19 @@ namespace textool class ITransformable { public: - /** - * Applies the given transform to all selected components of this node. - */ + // Let this object save a snapshot of its current texture state to have something + // to base the upcoming transformation on + virtual void beginTransformation() = 0; + + // Move the state back to the base state we saved in beginTransformation() + // Is called right before applyTransformationToSelected() is invoked with a new transform + virtual void revertTransformation() = 0; + + // Applies the given transform to all selected components of this node. virtual void applyTransformToSelected(const Matrix3& transform) = 0; + + // "Saves" the current transformed state as the new base state + virtual void commitTransformation() = 0; }; // The base element of every node in the ITextureToolSceneGraph @@ -41,6 +50,9 @@ class INode : virtual ~INode() {} using Ptr = std::shared_ptr; + + // Renders this node, with all coords relative to UV space origin + virtual void render() = 0; }; /** diff --git a/radiant/textool/TexTool.cpp b/radiant/textool/TexTool.cpp index c9e3ed7335..91cb494e54 100644 --- a/radiant/textool/TexTool.cpp +++ b/radiant/textool/TexTool.cpp @@ -586,11 +586,19 @@ Vector2 TexTool::getTextureCoords(const double& x, const double& y) { return result; } -void TexTool::drawUVCoords() { +void TexTool::drawUVCoords() +{ + GlobalTextureToolSceneGraph().foreachNode([&](const textool::INode::Ptr& node) + { + node->render(); + return true; + }); +#if 0 // Cycle through the items and tell them to render themselves for (std::size_t i = 0; i < _items.size(); i++) { _items[i]->render(); - } + } +#endif } textool::TexToolItemVec @@ -1362,22 +1370,35 @@ Matrix4 TexTool::getPivot2World() void TexTool::onManipulationStart() { - + GlobalTextureToolSceneGraph().foreachSelectedNode([&] (const textool::INode::Ptr& node) + { + node->beginTransformation(); + return true; + }); } void TexTool::onManipulationChanged() { - } void TexTool::onManipulationEnd() { + GlobalTextureToolSceneGraph().foreachSelectedNode([&](const textool::INode::Ptr& node) + { + node->commitTransformation(); + return true; + }); + _activeManipulator->setSelected(false); } void TexTool::onManipulationCancelled() { - + GlobalTextureToolSceneGraph().foreachSelectedNode([&](const textool::INode::Ptr& node) + { + node->revertTransformation(); + return true; + }); } diff --git a/radiantcore/brush/Face.cpp b/radiantcore/brush/Face.cpp index 0759ffac83..7c2b66675b 100644 --- a/radiantcore/brush/Face.cpp +++ b/radiantcore/brush/Face.cpp @@ -553,9 +553,12 @@ void Face::setTexDefFromPoints(const Vector3 points[3], const Vector2 uvs[3]) auto textureMatrix = uv * xyz.getFullInverse(); - _texdef.setTransform(textureMatrix); + m_texdefTransformed.setTransform(textureMatrix); - texdefChanged(); + EmitTextureCoordinates(); + + // Fire the signal to update the Texture Tools + signal_texdefChanged().emit(); } void Face::shiftTexdef(float s, float t) diff --git a/radiantcore/brush/Face.h b/radiantcore/brush/Face.h index 92dee35b8a..c9fa9279b8 100644 --- a/radiantcore/brush/Face.h +++ b/radiantcore/brush/Face.h @@ -114,8 +114,8 @@ class Face : void assign_planepts(const PlanePoints planepts); /// \brief Reverts the transformable state of the brush to identity. - void revertTransform(); - void freezeTransform(); + void revertTransform() override; + void freezeTransform() override; void update_move_planepts_vertex(std::size_t index, PlanePoints planePoints); @@ -144,7 +144,6 @@ class Face : // Constructs the texture projection matrix from the given (world) vertex and texture coords. // Three vertices and their UV coordinates are enough to construct the texdef. - // Will fire texDefChanged() after assigning the new texture matrix. void setTexDefFromPoints(const Vector3 points[3], const Vector2 uvs[3]); ShiftScaleRotation getShiftScaleRotation() const override; diff --git a/radiantcore/selection/manipulators/TextureToolRotateManipulator.cpp b/radiantcore/selection/manipulators/TextureToolRotateManipulator.cpp index b35ab5b7fc..4ca203cda3 100644 --- a/radiantcore/selection/manipulators/TextureToolRotateManipulator.cpp +++ b/radiantcore/selection/manipulators/TextureToolRotateManipulator.cpp @@ -46,6 +46,8 @@ void TextureRotator::transform(const Matrix4& pivot2world, const VolumeTest& vie auto sign = _start.crossProduct(current) < 0 ? +1 : -1; _curAngle *= sign; + rMessage() << "Current angle: " << _curAngle << std::endl; + _rotateFunctor(Vector2(pivot2world.tx(), pivot2world.ty()), _curAngle); } @@ -154,6 +156,7 @@ void TextureToolRotateManipulator::rotateSelected(const Vector2& pivot, double a GlobalTextureToolSceneGraph().foreachSelectedNode([&](const textool::INode::Ptr& node) { + node->revertTransformation(); node->applyTransformToSelected(transform); return true; }); diff --git a/radiantcore/selection/textool/FaceNode.h b/radiantcore/selection/textool/FaceNode.h index 425a47d792..dcd773968e 100644 --- a/radiantcore/selection/textool/FaceNode.h +++ b/radiantcore/selection/textool/FaceNode.h @@ -19,6 +19,16 @@ class FaceNode : _face(face) {} + void beginTransformation() override + { + _face.undoSave(); + } + + void revertTransformation() override + { + _face.revertTransform(); + } + void applyTransformToSelected(const Matrix3& transform) override { for (auto& vertex : _face.getWinding()) @@ -32,6 +42,11 @@ class FaceNode : _face.setTexDefFromPoints(vertices, texcoords); } + void commitTransformation() override + { + _face.freezeTransform(); + } + const AABB& localAABB() const { _bounds = AABB(); @@ -65,6 +80,47 @@ class FaceNode : Selector_add(selector, *this); } } + + void render() override + { + glEnable(GL_BLEND); + glBlendColor(0, 0, 0, 0.3f); + glBlendFunc(GL_CONSTANT_ALPHA_EXT, GL_ONE_MINUS_CONSTANT_ALPHA_EXT); + + if (isSelected()) + { + glColor3f(1, 0.5f, 0); + } + else { + glColor3f(0.8f, 0.8f, 0.8f); + } + + glBegin(GL_TRIANGLE_FAN); + + for (const auto& vertex : _face.getWinding()) + { + glVertex2d(vertex.texcoord[0], vertex.texcoord[1]); + } + + glEnd(); + glDisable(GL_BLEND); + + glPointSize(5); + glBegin(GL_POINTS); + /*for (Winding::const_iterator i = _winding.begin(); i != _winding.end(); ++i) + { + glVertex2f(i->texcoord[0], i->texcoord[1]); + }*/ + + //glColor3f(1, 1, 1); + + //Vector2 centroid = _face.getWinding(); + //glVertex2d(centroid[0], centroid[1]); + + glEnd(); + + glDisable(GL_BLEND); + } }; } diff --git a/radiantcore/selection/textool/PatchNode.h b/radiantcore/selection/textool/PatchNode.h index 24ad0158fb..0a8aeae254 100644 --- a/radiantcore/selection/textool/PatchNode.h +++ b/radiantcore/selection/textool/PatchNode.h @@ -18,11 +18,23 @@ class PatchNode : _patch(patch) {} + void beginTransformation() override + { + } + + void revertTransformation() override + { + } + void applyTransformToSelected(const Matrix3& transform) override { // TODO } + void commitTransformation() override + { + } + const AABB& localAABB() const { _bounds = AABB(); @@ -41,7 +53,12 @@ class PatchNode : void testSelect(Selector& selector, SelectionTest& test) override { + // TODO + } + void render() override + { + // TODO } };