Skip to content

Commit

Permalink
#5746: All textool::INodes are implementing Bounded, to return their …
Browse files Browse the repository at this point in the history
…bounds in UV space.

Un-hook the old selection traversal code in the TexTool, use the Texture Tool SceneGraph.
  • Loading branch information
codereader committed Sep 13, 2021
1 parent 175bf4f commit a81c4c4
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 6 deletions.
26 changes: 25 additions & 1 deletion include/itexturetoolmodel.h
Expand Up @@ -2,12 +2,36 @@

#include "imodule.h"
#include "inode.h"
#include "Bounded.h"

class Matrix3;

namespace textool
{

/**
* A transformable node in the texture tool scene. This is usually
* implemented by Faces and Patches. They will accept a given transformation
* and apply it to their selected child elements.
* For faces, this could mean that three selected vertices (out of four)
* will be transformed by the given matrix. It's possible that unselected
* winding vertices will be affected by this transformation, due to the nature
* of the texture projection.
* Patch vertices can be transformed independently.
*/
class ITransformable
{
public:
/**
* Applies the given transform to all selected components of this node.
*/
virtual void applyTransformToSelected(const Matrix3& transform) = 0;
};

// The base element of every node in the ITextureToolSceneGraph
class INode
class INode :
public ITransformable,
public Bounded
{
public:
virtual ~INode() {}
Expand Down
13 changes: 8 additions & 5 deletions radiant/textool/TexTool.cpp
Expand Up @@ -2,6 +2,7 @@

#include "i18n.h"
#include "ieventmanager.h"
#include "itexturetoolmodel.h"
#include "imainframe.h"
#include "igl.h"
#include "iundo.h"
Expand Down Expand Up @@ -229,6 +230,7 @@ void TexTool::update()
std::string selectedShader = selection::getShaderFromSelection();
_shader = GlobalMaterialManager().getMaterial(selectedShader);

#if 0
// Clear the list to remove all the previously allocated items
_items.clear();

Expand Down Expand Up @@ -259,7 +261,7 @@ void TexTool::update()
});
}
}

#endif
recalculateVisibleTexSpace();
}

Expand Down Expand Up @@ -541,11 +543,12 @@ AABB& TexTool::getExtents()
{
_selAABB = AABB();

for (const auto& item : _items)
GlobalTextureToolSceneGraph().foreachNode([&](const textool::INode::Ptr& node)
{
// Expand the selection AABB by the extents of the item
_selAABB.includeAABB(item->getExtents());
}
// Expand the selection AABB by the extents of the item
_selAABB.includeAABB(node->localAABB());
return true;
});

return _selAABB;
}
Expand Down
18 changes: 18 additions & 0 deletions radiantcore/selection/textool/FaceNode.h
Expand Up @@ -11,11 +11,29 @@ class FaceNode :
{
private:
IFace& _face;
mutable AABB _bounds;

public:
FaceNode(IFace& face) :
_face(face)
{}

void applyTransformToSelected(const Matrix3& transform) override
{
// TODO
}

const AABB& localAABB() const
{
_bounds = AABB();

for (const auto& vertex : _face.getWinding())
{
_bounds.includePoint({ vertex.texcoord.x(), vertex.texcoord.y(), 0 });
}

return _bounds;
}
};

}
22 changes: 22 additions & 0 deletions radiantcore/selection/textool/PatchNode.h
Expand Up @@ -11,11 +11,33 @@ class PatchNode :
{
private:
IPatch& _patch;
mutable AABB _bounds;

public:
PatchNode(IPatch& patch) :
_patch(patch)
{}

void applyTransformToSelected(const Matrix3& transform) override
{
// TODO
}

const AABB& localAABB() const
{
_bounds = AABB();

for (std::size_t col = 0; col < _patch.getWidth(); ++col)
{
for (std::size_t row = 0; row < _patch.getHeight(); ++row)
{
const auto& ctrl = _patch.ctrlAt(row, col);
_bounds.includePoint({ ctrl.texcoord.x(), ctrl.texcoord.y(), 0 });
}
}

return _bounds;
}
};

}

0 comments on commit a81c4c4

Please sign in to comment.