Skip to content

Commit

Permalink
#5746: Implement face vertex manipulation for a single selected verti…
Browse files Browse the repository at this point in the history
…ces - WIP
  • Loading branch information
codereader committed Sep 22, 2021
1 parent 050e3b7 commit 3d37002
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions radiantcore/selection/textool/FaceNode.h
Expand Up @@ -69,6 +69,8 @@ class FaceNode :
vertex.getTexcoord() = transform * vertex.getTexcoord();
}

if (selectedIndices.empty()) return; // nothing happened

// Now we need to pick three vertices to calculate the tex def from
// we have certain options, depending on the number of selected vertices
auto selectionCount = selectedIndices.size();
Expand All @@ -93,7 +95,9 @@ class FaceNode :
{
// Calculate the center point of the selection and pick the vertex that is farthest from it
auto selectionBounds = getSelectedComponentBounds();
auto farthestIndex = findIndexFarthestFrom({ selectionBounds.origin.x(), selectionBounds.origin.y() });
auto farthestIndex = findIndexFarthestFrom(
{ selectionBounds.origin.x(), selectionBounds.origin.y() },
selectedIndices);

for (std::size_t i = 0; i < 2; ++i)
{
Expand All @@ -104,6 +108,27 @@ class FaceNode :
vertices[2] = _vertices[farthestIndex].getVertex();
texcoords[2] = _vertices[farthestIndex].getTexcoord();

_face.setTexDefFromPoints(vertices, texcoords);
}
else // selectionCount == 1
{
assert(selectionCount == 1);
std::vector<std::size_t> fixedVerts{ selectedIndices[0] };

auto secondIndex = findIndexFarthestFrom(_vertices[selectedIndices[0]].getTexcoord(), fixedVerts);
fixedVerts.push_back(secondIndex);

// Now we've got two vertices, calculate the center and take the farthest of that one
auto center = (_vertices[secondIndex].getTexcoord() + _vertices[selectedIndices[0]].getTexcoord()) * 0.5;
auto thirdIndex = findIndexFarthestFrom(center, fixedVerts);
fixedVerts.push_back(thirdIndex);

for (std::size_t i = 0; i < 3; ++i)
{
vertices[i] = _vertices[fixedVerts[i]].getVertex();
texcoords[i] = _vertices[fixedVerts[i]].getTexcoord();
}

_face.setTexDefFromPoints(vertices, texcoords);
}
}
Expand Down Expand Up @@ -183,8 +208,9 @@ class FaceNode :
}

private:
// Locates the index of the unselected vertex that is farthest away from the given texcoord
std::size_t findIndexFarthestFrom(const Vector2& texcoord)
// Locates the index of the vertex that is farthest away from the given texcoord
// the indices contained in exludedIndices are not returned
std::size_t findIndexFarthestFrom(const Vector2& texcoord, const std::vector<std::size_t>& excludedIndices)
{
assert(!_vertices.empty());

Expand All @@ -193,7 +219,7 @@ class FaceNode :

for (std::size_t i = 0; i < _vertices.size(); ++i)
{
if (_vertices[i].isSelected()) continue;
if (std::find(excludedIndices.begin(), excludedIndices.end(), i) != excludedIndices.end()) continue;

auto candidateDistanceSquared = (_vertices[i].getTexcoord() - texcoord).getLengthSquared();

Expand Down

0 comments on commit 3d37002

Please sign in to comment.