| 1911 | } |
| 1912 | |
| 1913 | void performPatchVertexMergeTest(bool useBoundsOrigin) |
| 1914 | { |
| 1915 | auto patchNode1 = setupPatchNodeForTextureTool(); |
| 1916 | auto patchNode2 = setupPatchNodeForTextureTool(); |
| 1917 | auto patch1 = Node_getIPatch(patchNode1); |
| 1918 | auto patch2 = Node_getIPatch(patchNode2); |
| 1919 | |
| 1920 | patch1->fitTexture(1, 1); |
| 1921 | patch2->fitTexture(1, 1); |
| 1922 | patch2->translateTexture(20, -20); |
| 1923 | |
| 1924 | // Get the texture space bounds of both patches |
| 1925 | auto bounds = algorithm::getTextureSpaceBounds(*patch1); |
| 1926 | bounds.includeAABB(algorithm::getTextureSpaceBounds(*patch2)); |
| 1927 | bounds.extents *= 1.2f; |
| 1928 | |
| 1929 | render::TextureToolView view; |
| 1930 | view.constructFromTextureSpaceBounds(bounds, TEXTOOL_WIDTH, TEXTOOL_HEIGHT); |
| 1931 | |
| 1932 | // Switch to vertex mode |
| 1933 | GlobalTextureToolSelectionSystem().setSelectionMode(textool::SelectionMode::Vertex); |
| 1934 | |
| 1935 | // Get the texcoords of the first vertex |
| 1936 | auto definedRow = 2; |
| 1937 | auto definedCol = 1; |
| 1938 | const auto& vertex1 = patch1->ctrlAt(definedRow, definedCol).texcoord; |
| 1939 | const auto& vertex2 = patch2->ctrlAt(definedRow, definedCol).texcoord; |
| 1940 | |
| 1941 | performPointSelection(vertex1, view); |
| 1942 | performPointSelection(vertex2, view); |
| 1943 | |
| 1944 | EXPECT_EQ(getAllSelectedComponentNodes().size(), 2) << "2 patches should be selected"; |
| 1945 | EXPECT_NE(vertex1.x(), vertex2.x()) << "Vertex 1 is alredy merged with Vertex 2"; |
| 1946 | EXPECT_NE(vertex1.y(), vertex2.y()) << "Vertex 1 is alredy merged with Vertex 2"; |
| 1947 | |
| 1948 | // We expect the vertices to be at the center if merge items is called with no arguments |
| 1949 | auto center = (vertex1 + vertex2) * 0.5; |
| 1950 | |
| 1951 | if (useBoundsOrigin) |
| 1952 | { |
| 1953 | // When using bounds origin, call the command without argument |
| 1954 | GlobalCommandSystem().executeCommand("TexToolMergeItems"); |
| 1955 | } |
| 1956 | else |
| 1957 | { |
| 1958 | // Use an arbitrary position that is somewhere near other than center |
| 1959 | center += Vector2(-0.7, -0.3); |
| 1960 | GlobalCommandSystem().executeCommand("TexToolMergeItems", { cmd::Argument(center) }); |
| 1961 | } |
| 1962 | |
| 1963 | EXPECT_EQ(vertex1.x(), center.x()) << "Vertex 1 should be at center " << center; |
| 1964 | EXPECT_EQ(vertex1.y(), center.y()) << "Vertex 1 should be at center " << center; |
| 1965 | EXPECT_EQ(vertex2.x(), center.x()) << "Vertex 2 should be at center " << center; |
| 1966 | EXPECT_EQ(vertex2.y(), center.y()) << "Vertex 2 should be at center " << center; |
| 1967 | } |
| 1968 | |
| 1969 | TEST_F(TextureToolTest, MergePatchVertices) |
| 1970 | { |
no test coverage detected