Skip to content

Commit

Permalink
#5115: Add integration test, assuming that the exported LWO has the s…
Browse files Browse the repository at this point in the history
…ame number of vertices as the tesselation.
  • Loading branch information
codereader committed Nov 8, 2020
1 parent 3c68f76 commit 54d6632
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -69,3 +69,4 @@ Makefile.in
/tools/msvc/Tests/x64
/tools/msvc/x64
/tools/msvc/packages
/install/*.testdurations
1 change: 1 addition & 0 deletions test/Makefile.am
Expand Up @@ -34,6 +34,7 @@ drtest_SOURCES = math/Matrix4.cpp \
FacePlane.cpp \
Materials.cpp \
MapExport.cpp \
ModelExport.cpp \
ModelScale.cpp \
SelectionAlgorithm.cpp \
VFS.cpp
60 changes: 60 additions & 0 deletions test/ModelExport.cpp
@@ -0,0 +1,60 @@
#include "RadiantTest.h"

#include "imodel.h"
#include "imodelcache.h"
#include "imap.h"
#include "algorithm/Scene.h"
#include "scenelib.h"
#include "os/path.h"

namespace test
{

using ModelExportTest = RadiantTest;

TEST_F(ModelExportTest, ExportPatchMesh)
{
// Load a map with a cylinder patch
loadMap("modelexport_patch.map");

auto patchNode = algorithm::findFirstPatchWithMaterial(GlobalMapModule().findOrInsertWorldspawn(),
"textures/darkmod/wood/boards/ship_hull_medium");
EXPECT_TRUE(patchNode);

Node_setSelected(patchNode, true);

// Choose a file in our temp data folder
std::string modRelativePath = "models/temp/temp_patch.lwo";

fs::path outputFilename = _context.getTestResourcePath();
outputFilename /= modRelativePath;
os::makeDirectory(outputFilename.parent_path().string());

auto exporter = GlobalModelFormatManager().getExporter("lwo");

cmd::ArgumentList argList;

argList.push_back(outputFilename.string());
argList.push_back(std::string("lwo"));
argList.push_back(true); // centerObjects
argList.push_back(true); // skipCaulk
argList.push_back(false); // replaceSelectionWithModel
argList.push_back(false); // useEntityOrigin
argList.push_back(false); // exportLightsAsObjects

GlobalCommandSystem().executeCommand("ExportSelectedAsModel", argList);

auto model = GlobalModelCache().getModel(modRelativePath);

EXPECT_TRUE(model);

// We expect exactly the same amount of vertices as in the patch mesh
// This ensures that no vertices have been duplicated or faces separated
auto patch = std::dynamic_pointer_cast<IPatchNode>(patchNode);
EXPECT_EQ(model->getVertexCount(), patch->getPatch().getTesselatedPatchMesh().vertices.size());

// Clean up the file
fs::remove(outputFilename);
}

}
4 changes: 2 additions & 2 deletions test/RadiantTest.h
Expand Up @@ -121,9 +121,9 @@ class RadiantTest :
_coreModule->get()->getModuleRegistry().registerModule(_glContextModule);
}

virtual void loadMap(const std::string& modRelativePath)
virtual void loadMap(const std::string& mapsRelativePath)
{
GlobalCommandSystem().executeCommand("OpenMap", modRelativePath);
GlobalCommandSystem().executeCommand("OpenMap", mapsRelativePath);
}

void handleGameConfigMessage(game::ConfigurationNeeded& message)
Expand Down
32 changes: 32 additions & 0 deletions test/algorithm/Scene.h
Expand Up @@ -4,6 +4,7 @@
#include "inode.h"
#include "ientity.h"
#include "ibrush.h"
#include "ipatch.h"
#include "imodel.h"

namespace test::algorithm
Expand Down Expand Up @@ -61,6 +62,37 @@ inline scene::INodePtr findFirstBrushWithMaterial(const scene::INodePtr& parent,
});
}

// Finds the first matching child patch of the given parent node matching the given predicate
inline scene::INodePtr findFirstPatch(const scene::INodePtr& parent,
const std::function<bool(const IPatchNodePtr&)>& predicate)
{
scene::INodePtr candidate;

parent->foreachNode([&](const scene::INodePtr& node)
{
auto patchNode = std::dynamic_pointer_cast<IPatchNode>(node);

if (patchNode && predicate(patchNode))
{
candidate = node;
return false;
}

return true;
});

return candidate;
}

// Finds the first matching child patch of the given parent node, with the given material
inline scene::INodePtr findFirstPatchWithMaterial(const scene::INodePtr& parent, const std::string& material)
{
return findFirstPatch(parent, [&](const IPatchNodePtr& patch)
{
return patch->getPatch().getShader() == material;
});
}

inline scene::INodePtr findFirstEntity(const scene::INodePtr& parent,
const std::function<bool(IEntityNode&)>& predicate)
{
Expand Down
24 changes: 24 additions & 0 deletions test/resources/tdm/maps/modelexport_patch.map
@@ -0,0 +1,24 @@
Version 2
// entity 0
{
"classname" "worldspawn"
// primitive 0
{
patchDef3
{
"textures/darkmod/wood/boards/ship_hull_medium"
( 9 3 4 1 0 0 0 )
(
( ( 74 0 -25 0 0 ) ( 74 0 7 0 -0.25 ) ( 74 0 39 0 -0.5 ) )
( ( 74 -16 -25 0.0625 0 ) ( 74 -16 7 0.0625 -0.25 ) ( 74 -16 39 0.0625 -0.5 ) )
( ( 90 -16 -25 0.125 0 ) ( 90 -16 7 0.125 -0.25 ) ( 90 -16 39 0.125 -0.5 ) )
( ( 106 -16 -25 0.1875 0 ) ( 106 -16 7 0.1875 -0.25 ) ( 106 -16 39 0.1875 -0.5 ) )
( ( 106 0 -25 0.25 0 ) ( 106 0 7 0.25 -0.25 ) ( 106 0 39 0.25 -0.5 ) )
( ( 106 16 -25 0.3125 0 ) ( 106 16 7 0.3125 -0.25 ) ( 106 16 39 0.3125 -0.5 ) )
( ( 90 16 -25 0.375 0 ) ( 90 16 7 0.375 -0.25 ) ( 90 16 39 0.375 -0.5 ) )
( ( 74 16 -25 0.4375 0 ) ( 74 16 7 0.4375 -0.25 ) ( 74 16 39 0.4375 -0.5 ) )
( ( 74 0 -25 0.5 0 ) ( 74 0 7 0.5 -0.25 ) ( 74 0 39 0.5 -0.5 ) )
)
}
}
}
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj
Expand Up @@ -75,6 +75,7 @@
<ClCompile Include="..\..\..\test\math\Plane3.cpp" />
<ClCompile Include="..\..\..\test\math\Quaternion.cpp" />
<ClCompile Include="..\..\..\test\math\Vector3.cpp" />
<ClCompile Include="..\..\..\test\ModelExport.cpp" />
<ClCompile Include="..\..\..\test\ModelScale.cpp" />
<ClCompile Include="..\..\..\test\SelectionAlgorithm.cpp" />
<ClCompile Include="..\..\..\test\VFS.cpp" />
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj.filters
Expand Up @@ -21,6 +21,7 @@
<ClCompile Include="..\..\..\test\math\Plane3.cpp">
<Filter>math</Filter>
</ClCompile>
<ClCompile Include="..\..\..\test\ModelExport.cpp" />
<ClCompile Include="..\..\..\test\MapExport.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 54d6632

Please sign in to comment.