Skip to content

Commit

Permalink
#5746: Implement the code recalculating the Pivot-to-World transform …
Browse files Browse the repository at this point in the history
…in Vertex mode
  • Loading branch information
codereader committed Sep 19, 2021
1 parent 536a7ae commit 25b0258
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
3 changes: 3 additions & 0 deletions include/itexturetoolmodel.h
Expand Up @@ -66,6 +66,9 @@ class IComponentSelectable

// Perform a selection test using the given selector and test volume
virtual void testSelectComponents(Selector& selector, SelectionTest& test) = 0;

// Returns the bounds containing all the selected vertices
virtual AABB getSelectedComponentBounds() = 0;
};

// A Texture Tool node that allows its components to be transformed
Expand Down
14 changes: 14 additions & 0 deletions radiantcore/selection/textool/NodeBase.h
Expand Up @@ -66,6 +66,20 @@ class NodeBase :
}
}

virtual AABB getSelectedComponentBounds() override
{
AABB bounds;

for (const auto& vertex : _vertices)
{
if (!vertex.isSelected()) continue;

bounds.includePoint({ vertex.getVertex().x(), vertex.getVertex().y(), 0 });
}

return bounds;
}

protected:
virtual void renderComponents()
{
Expand Down
34 changes: 23 additions & 11 deletions radiantcore/selection/textool/TextureToolManipulationPivot.cpp
Expand Up @@ -11,22 +11,34 @@ void TextureToolManipulationPivot::updateFromSelection()
_userLocked = false;

// Check the centerpoint of all selected items
Vector2 sum(0, 0);
std::size_t count = 0;
AABB bounds;

GlobalTextureToolSelectionSystem().foreachSelectedNode([&](const INode::Ptr& node)
if (GlobalTextureToolSelectionSystem().getMode() == SelectionMode::Surface)
{
auto bounds = node->localAABB();
sum += Vector2(bounds.origin.x(), bounds.origin.y());
count++;
GlobalTextureToolSelectionSystem().foreachSelectedNode([&](const INode::Ptr& node)
{
bounds.includeAABB(node->localAABB());
return true;
});
}
else
{
GlobalTextureToolSelectionSystem().foreachSelectedComponentNode([&](const INode::Ptr& node)
{
auto componentSelectable = std::dynamic_pointer_cast<IComponentSelectable>(node);

return true;
});
if (componentSelectable)
{
bounds.includeAABB(componentSelectable->getSelectedComponentBounds());
}

return true;
});
}

if (count > 0)
if (bounds.isValid())
{
sum /= count;
setFromMatrix(Matrix4::getTranslation(Vector3(sum.x(), sum.y(), 0)));
setFromMatrix(Matrix4::getTranslation(Vector3(bounds.origin.x(), bounds.origin.y(), 0)));
}
else
{
Expand Down
7 changes: 6 additions & 1 deletion radiantcore/selection/textool/TextureToolSelectionSystem.cpp
Expand Up @@ -45,6 +45,7 @@ void TextureToolSelectionSystem::initialiseModule(const IApplicationContext& ctx

void TextureToolSelectionSystem::shutdownModule()
{
_sigSelectionModeChanged.clear();
_sigActiveManipulatorChanged.clear();
_manipulators.clear();
}
Expand All @@ -60,6 +61,9 @@ void TextureToolSelectionSystem::setMode(SelectionMode mode)
{
_mode = mode;
_sigSelectionModeChanged.emit(_mode);

_manipulationPivot.setUserLocked(false);
_manipulationPivot.setNeedsRecalculation(true);
}
}

Expand Down Expand Up @@ -289,7 +293,8 @@ void TextureToolSelectionSystem::toggleManipulatorModeById(std::size_t manipId)

Matrix4 TextureToolSelectionSystem::getPivot2World()
{
_manipulationPivot.updateFromSelection();
// For now, we recalculate the whole thing every time it is requested
_manipulationPivot.setNeedsRecalculation(true);

return _manipulationPivot.getMatrix4();
}
Expand Down

0 comments on commit 25b0258

Please sign in to comment.