Skip to content

Commit

Permalink
#5771: Add one more unit test using a face that ends up using a 90 de…
Browse files Browse the repository at this point in the history
…gree rotated texture after pasting. The current algorithm doesn't deal with that correctly, yielding an invalid texture matrix.
  • Loading branch information
codereader committed Oct 3, 2021
1 parent f2d9756 commit 99bd25c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
50 changes: 49 additions & 1 deletion test/TextureManipulation.cpp
Expand Up @@ -352,7 +352,8 @@ std::vector<std::pair<const WindingVertex*, const WindingVertex*>> findSharedVer
return vertexPairs;
}

TEST_F(TextureManipulationTest, PasteTextureToOrthogonalFace)
// Paste texture from the top face of a brush to the one one the front side (X)
TEST_F(TextureManipulationTest, PasteTextureToOrthogonalFace1)
{
std::string mapPath = "maps/simple_brushes.map";
GlobalCommandSystem().executeCommand("OpenMap", mapPath);
Expand Down Expand Up @@ -398,4 +399,51 @@ TEST_F(TextureManipulationTest, PasteTextureToOrthogonalFace)
}
}

// Paste shader from top face of a brush to the one on the left (Y)
TEST_F(TextureManipulationTest, PasteTextureToOrthogonalFace2)
{
std::string mapPath = "maps/simple_brushes.map";
GlobalCommandSystem().executeCommand("OpenMap", mapPath);

auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brushNode = algorithm::findFirstBrushWithMaterial(worldspawn, "textures/numbers/4");

auto faceUp = algorithm::findBrushFaceWithNormal(Node_getIBrush(brushNode), Vector3(0, 0, 1));
auto faceYDown = algorithm::findBrushFaceWithNormal(Node_getIBrush(brushNode), Vector3(0, -1, 0));

// Find the shared vertices of the two faces
auto sharedVertices = findSharedVertices(*faceUp, *faceYDown);
EXPECT_EQ(sharedVertices.size(), 2) << "There should be 2 shared 3D vertices between the two faces";

for (const auto& pair : sharedVertices)
{
EXPECT_FALSE(math::isNear(pair.first->texcoord, pair.second->texcoord, 0.01))
<< "Texture coordinates are the same before pasting the texture projection";
}

// Position the camera top-down, similar to what an XY view is seeing
render::View viewFaceUp(true);
algorithm::constructCameraView(viewFaceUp, brushNode->localAABB(), { 0, 0, -1 }, { -90, 0, 0 });

SelectionVolume testFaceUp(viewFaceUp);
GlobalShaderClipboard().pickFromSelectionTest(testFaceUp);

EXPECT_EQ(GlobalShaderClipboard().getSourceType(), selection::IShaderClipboard::SourceType::Face)
<< "Selection test failed to select the face";

render::View viewFacingYUp(true);
algorithm::constructCameraView(viewFacingYUp, brushNode->localAABB(), { 0, 1, 0 }, { 0, 90, 0 });

ConstructSelectionTest(viewFacingYUp, selection::Rectangle::ConstructFromPoint({ 0, 0 }, { 0.1, 0.1 }));

SelectionVolume testFacingYUp(viewFacingYUp);
GlobalShaderClipboard().pasteShader(testFacingYUp, selection::PasteMode::Natural, false);

for (const auto& pair : sharedVertices)
{
EXPECT_TRUE(math::isNear(pair.first->texcoord, pair.second->texcoord, 0.01))
<< "Texture coordinates should be the same after pasting the texture projection";
}
}

}
24 changes: 18 additions & 6 deletions test/resources/tdm/maps/simple_brushes.map
Expand Up @@ -30,12 +30,24 @@ brushDef3
{
brushDef3
{
( 0 0 1 -120 ) ( ( 0.004044952234337379 -0.00108465597368291 2.287123998509404 ) ( 0.00131243373171216 0.004894392216808566 -2.650458278304971 ) ) "textures/numbers/3" 0 0 0
( 0 1 0 24 ) ( ( 0.004186428926872321 0 66.18890442096517 ) ( 0 0.005065579015239352 63.15889732805238 ) ) "textures/numbers/3" 0 0 0
( 1 0 0 -1208 ) ( ( 0.004044952234337379 -0.00108465597368291 0.8467008675203296 ) ( 0.00131243373171216 0.004894392216808566 -9.150211276657021 ) ) "textures/numbers/3" 0 0 0
( 0 0 -1 -48 ) ( ( 0.00418642892687222 0 1.236819619159144 ) ( 0 0.00506557901523913 67.16456131746124 ) ) "textures/numbers/3" 0 0 0
( 0 -0.8502650260925293 0.5263550281524658 -301.2368202209473 ) ( ( 0.004044952234337379 -0.00108465597368291 -4.992842832697871 ) ( 0.00131243373171216 0.004894392216808566 -6.388033809310831 ) ) "textures/numbers/3" 0 0 0
( -1 0 0 976 ) ( ( 0.004186428926872238 0 62.76318038084089 ) ( 0 0.005065579015239963 63.15889732805255 ) ) "textures/numbers/3" 0 0 0
( 0 0 1 -360 ) ( ( 0.004044952336698771 -0.001084655988961458 2.25241494178772 ) ( 0.001312433741986752 0.004894392099231482 61.50616073608398 ) ) "textures/numbers/3" 0 0 0
( 0 1 0 24 ) ( ( 0.004186429083347321 0 2.054934978485107 ) ( 0 0.00506557896733284 0.3746414184570313 ) ) "textures/numbers/3" 0 0 0
( 1 0 0 -1176 ) ( ( 0.004044952336698771 -0.001084655988961458 0.5863834023475647 ) ( 0.001312433741986752 0.004894392099231482 56.02444076538086 ) ) "textures/numbers/3" 0 0 0
( 0 0 -1 192 ) ( ( 0.004186429083347321 0 1.236819624900818 ) ( 0 0.00506557896733284 3.002462148666382 ) ) "textures/numbers/3" 0 0 0
( 0 -0.8502650260925293 0.5263550281524658 -427.5620231628418 ) ( ( 0.004044952336698771 -0.001084655988961459 58.91525650024414 ) ( 0.001312433741986752 0.004894392099231482 58.65273284912109 ) ) "textures/numbers/3" 0 0 0
( -1 0 0 944 ) ( ( 0.004186429083347321 0 62.76317977905273 ) ( 0 0.00506557896733284 0.3746414184570313 ) ) "textures/numbers/3" 0 0 0
}
}
// primitive 3
{
brushDef3
{
( 0 0 1 -376 ) ( ( 0.003266689270040298 0 -0.5408562421798706 ) ( 0 0.00343125305239949 0.3779624998569489 ) ) "textures/numbers/4" 0 0 0
( 0 1 0 24 ) ( ( 0.004186429083347321 0 57.95000839233398 ) ( 0 0.00506557896733284 0.4556884765625 ) ) "textures/numbers/4" 0 0 0
( 1 0 0 760 ) ( ( 0.004044952336698771 -0.001084655988961458 0.56902676820755 ) ( 0.001312433741986752 0.004894392099231482 56.10275268554688 ) ) "textures/numbers/4" 0 0 0
( 0 0 -1 208 ) ( ( 0.004186429083347321 0 1.236819624900818 ) ( 0 0.00506557896733284 57.19549942016602 ) ) "textures/numbers/4" 0 0 0
( -1 0 0 -992 ) ( ( 0.004186429083347321 0 62.76318359375 ) ( 0 0.00506557896733284 0.4556884765625 ) ) "textures/numbers/4" 0 0 0
( 0 -1 0 -280 ) ( ( 0.015625 0 0 ) ( 0 0.015625 0 ) ) "textures/numbers/4" 0 0 0
}
}
}

0 comments on commit 99bd25c

Please sign in to comment.