From c5ffcc6296fa06899e742529c0bf7af174f12214 Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 19 Sep 2021 07:19:04 +0200 Subject: [PATCH] #5746: Another drag-manipulation test targeting patches --- test/TextureTool.cpp | 109 +++++++++++++++++++++++++++++++------------ 1 file changed, 78 insertions(+), 31 deletions(-) diff --git a/test/TextureTool.cpp b/test/TextureTool.cpp index c22eb3834d..9bb87b72e9 100644 --- a/test/TextureTool.cpp +++ b/test/TextureTool.cpp @@ -201,18 +201,26 @@ TEST_F(TextureToolTest, ForeachSelectedNode) EXPECT_EQ(selectedCount, selectedNodes.size()) << "Selection count didn't match"; } -inline AABB getTextureSpaceBounds(const IPatch& patch) +inline void foreachPatchVertex(const IPatch& patch, const std::function& functor) { - AABB bounds; - for (std::size_t col = 0; col < patch.getWidth(); ++col) { for (std::size_t row = 0; row < patch.getHeight(); ++row) { - const auto& uv = patch.ctrlAt(row, col).texcoord; - bounds.includePoint({ uv.x(), uv.y(), 0 }); + functor(patch.ctrlAt(row, col)); } } +} + +inline AABB getTextureSpaceBounds(const IPatch& patch) +{ + AABB bounds; + + foreachPatchVertex(patch, [&](const PatchControl& control) + { + const auto& uv = control.texcoord; + bounds.includePoint({ uv.x(), uv.y(), 0 }); + }); return bounds; } @@ -421,6 +429,36 @@ inline std::vector getTexcoords(const IFace* face) return uvs; } +void dragManipulateSelectionTowardsLowerRight(const Vector2& startTexcoord, const render::View& view) +{ + auto centroid = startTexcoord; + auto centroidTransformed = view.GetViewProjection().transformPoint(Vector3(centroid.x(), centroid.y(), 0)); + Vector2 devicePoint(centroidTransformed.x(), centroidTransformed.y()); + + GlobalTextureToolSelectionSystem().onManipulationStart(); + + // Simulate a transformation by click-and-drag + auto manipulator = GlobalTextureToolSelectionSystem().getActiveManipulator(); + EXPECT_EQ(manipulator->getType(), selection::IManipulator::Drag) << "Wrong manipulator"; + + render::View scissored(view); + ConstructSelectionTest(scissored, selection::Rectangle::ConstructFromPoint(devicePoint, Vector2(0.05, 0.05))); + + auto manipComponent = manipulator->getActiveComponent(); + auto pivot2World = GlobalTextureToolSelectionSystem().getPivot2World(); + manipComponent->beginTransformation(pivot2World, scissored, devicePoint); + + // Move the device point a bit to the lower right + auto secondDevicePoint = devicePoint + (Vector2(1, -1) - devicePoint) / 2; + + render::View scissored2(view); + ConstructSelectionTest(scissored2, selection::Rectangle::ConstructFromPoint(secondDevicePoint, Vector2(0.05, 0.05))); + + manipComponent->transform(pivot2World, scissored2, secondDevicePoint, selection::IManipulator::Component::Constraint::Unconstrained); + + GlobalTextureToolSelectionSystem().onManipulationFinished(); +} + TEST_F(TextureToolTest, DragManipulateFace) { auto worldspawn = GlobalMapModule().findOrInsertWorldspawn(); @@ -448,33 +486,9 @@ TEST_F(TextureToolTest, DragManipulateFace) render::TextureToolView view; view.constructFromTextureSpaceBounds(bounds, TEXTOOL_WIDTH, TEXTOOL_HEIGHT); - // Check the device coords of the face centroid + // Check the device coords of the face centroid and manipulate from that point auto centroid = algorithm::getFaceCentroid(faceUp); - auto centroidTransformed = view.GetViewProjection().transformPoint(Vector3(centroid.x(), centroid.y(), 0)); - Vector2 devicePoint(centroidTransformed.x(), centroidTransformed.y()); - - GlobalTextureToolSelectionSystem().onManipulationStart(); - - // Simulate a transformation by click-and-drag - auto manipulator = GlobalTextureToolSelectionSystem().getActiveManipulator(); - EXPECT_EQ(manipulator->getType(), selection::IManipulator::Drag) << "Wrong manipulator"; - - render::View scissored(view); - ConstructSelectionTest(scissored, selection::Rectangle::ConstructFromPoint(devicePoint, Vector2(0.05, 0.05))); - - auto manipComponent = manipulator->getActiveComponent(); - auto pivot2World = GlobalTextureToolSelectionSystem().getPivot2World(); - manipComponent->beginTransformation(pivot2World, scissored, devicePoint); - - // Move the device point a bit to the lower right - auto secondDevicePoint = devicePoint + (Vector2(1, -1) - devicePoint) / 2; - - render::View scissored2(view); - ConstructSelectionTest(scissored2, selection::Rectangle::ConstructFromPoint(secondDevicePoint, Vector2(0.05, 0.05))); - - manipComponent->transform(pivot2World, scissored2, secondDevicePoint, selection::IManipulator::Component::Constraint::Unconstrained); - - GlobalTextureToolSelectionSystem().onManipulationFinished(); + dragManipulateSelectionTowardsLowerRight(centroid, view); // All the texcoords should have been moved to the lower right (U increased, V increased) auto oldUv = oldFaceUpUvs.begin(); @@ -495,4 +509,37 @@ TEST_F(TextureToolTest, DragManipulateFace) } } +TEST_F(TextureToolTest, DragManipulatePatch) +{ + auto patchNode = setupPatchNodeForTextureTool(); + auto patch = Node_getIPatch(patchNode); + + // Remember the texcoords before manipulation + std::vector oldTexcoords; + foreachPatchVertex(*patch, [&](const PatchControl& control) { oldTexcoords.push_back(control.texcoord); }); + + auto texToolPatch = getFirstTextureToolNode(); + texToolPatch->setSelected(true); + + // Get the texture space bounds of this patch + auto bounds = getTextureSpaceBounds(*patch); + bounds.extents *= 1.2f; + + render::TextureToolView view; + view.constructFromTextureSpaceBounds(bounds, TEXTOOL_WIDTH, TEXTOOL_HEIGHT); + + // Check the device coords of the face centroid + auto centroid = Vector2(bounds.origin.x(), bounds.origin.y()); + dragManipulateSelectionTowardsLowerRight(centroid, view); + + // All the texcoords should have been moved to the lower right (U increased, V increased) + auto oldUv = oldTexcoords.begin(); + foreachPatchVertex(*patch, [&](const PatchControl& control) + { + EXPECT_LT(oldUv->x(), control.texcoord.x()); + EXPECT_LT(oldUv->y(), control.texcoord.y()); + ++oldUv; + }); +} + }