From bfca053140c239a65ef7eeda89d303bf5d4e1ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 20 Sep 2022 01:54:31 +0200 Subject: [PATCH] sceneconverter: properly test that converters get chained together. What was there didn't really check that the output of one converter was used as input for the next one. Especially with the upcoming rework for full scene conversion that could lead to dangerous regressions. --- src/Magnum/SceneTools/Test/CMakeLists.txt | 2 + .../SceneTools/Test/SceneConverterTest.cpp | 60 +++++++++--------- .../SceneConverterTestFiles/quad-strip.bin | Bin 0 -> 48 bytes .../SceneConverterTestFiles/quad-strip.bin.in | 13 ++++ .../SceneConverterTestFiles/quad-strip.gltf | 38 +++++++++++ 5 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad-strip.bin create mode 100644 src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad-strip.bin.in create mode 100644 src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad-strip.gltf diff --git a/src/Magnum/SceneTools/Test/CMakeLists.txt b/src/Magnum/SceneTools/Test/CMakeLists.txt index 3c5821a3c..c896d66b6 100644 --- a/src/Magnum/SceneTools/Test/CMakeLists.txt +++ b/src/Magnum/SceneTools/Test/CMakeLists.txt @@ -80,6 +80,8 @@ corrade_add_test(SceneToolsSceneConverterTest SceneConverterTest.cpp SceneConverterTestFiles/quad-duplicates.obj SceneConverterTestFiles/quad-duplicates.ply SceneConverterTestFiles/quad-normals-texcoords.obj + SceneConverterTestFiles/quad-strip.bin + SceneConverterTestFiles/quad-strip.gltf SceneConverterTestFiles/quad.bin SceneConverterTestFiles/quad.gltf SceneConverterTestFiles/quad.obj diff --git a/src/Magnum/SceneTools/Test/SceneConverterTest.cpp b/src/Magnum/SceneTools/Test/SceneConverterTest.cpp index bc10d1a29..2dad7f2f9 100644 --- a/src/Magnum/SceneTools/Test/SceneConverterTest.cpp +++ b/src/Magnum/SceneTools/Test/SceneConverterTest.cpp @@ -212,24 +212,26 @@ const struct { "Fuzzy duplicate removal: 6 -> 4 vertices\n"}, {"one mesh, two converters", Containers::array({ "-C", "MeshOptimizerSceneConverter", - Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), - "ObjImporter", "StanfordSceneConverter", - "quad.ply", nullptr, + Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad-strip.gltf"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.gltf")}), + "GltfImporter", "GltfSceneConverter", + "quad.gltf", "quad.bin", {}}, {"one mesh, two converters, explicit last", Containers::array({ - "-C", "MeshOptimizerSceneConverter", "-C", "StanfordSceneConverter", - Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), - "ObjImporter", "StanfordSceneConverter", - "quad.ply", nullptr, + "-C", "MeshOptimizerSceneConverter", "-C", "GltfSceneConverter", + Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad-strip.gltf"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.gltf")}), + "GltfImporter", "GltfSceneConverter", + "quad.gltf", "quad.bin", {}}, {"one mesh, two converters, verbose", Containers::array({ "-C", "MeshOptimizerSceneConverter", "-v", - Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), - "ObjImporter", "StanfordSceneConverter", - "quad.ply", nullptr, - /** @todo this is a no-op, use some other converter that tests also - that the resulting mesh is actually passed further */ - "Trade::AnySceneImporter::openFile(): using ObjImporter\n" + Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad-strip.gltf"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.gltf")}), + "GltfImporter", "GltfSceneConverter", + "quad.gltf", "quad.bin", + /* While this looks like a no-op in the output, it converts a + triangle strip to indexed triangles, which verifies that the output + of MeshOptimizerSceneConverter got actually passed further and not + discarded */ + "Trade::AnySceneImporter::openFile(): using GltfImporter\n" "Trade::MeshOptimizerSceneConverter::convert(): processing stats:\n" " vertex cache:\n" " 4 -> 4 transformed vertices\n" @@ -243,16 +245,16 @@ const struct { " 65536 -> 65536 shaded pixels\n" " 65536 -> 65536 covered pixels\n" " overdraw 1 -> 1\n" - "Trade::AnySceneConverter::convertToFile(): using StanfordSceneConverter\n"}, + "Trade::AnySceneConverter::convertToFile(): using GltfSceneConverter\n"}, {"one mesh, two converters, explicit last, verbose", Containers::array({ - "-C", "MeshOptimizerSceneConverter", "-C", "StanfordSceneConverter", "-v", - Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), - "ObjImporter", "StanfordSceneConverter", - "quad.ply", nullptr, + "-C", "MeshOptimizerSceneConverter", "-C", "GltfSceneConverter", "-v", + Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad-strip.gltf"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.gltf")}), + "GltfImporter", "GltfSceneConverter", + "quad.gltf", "quad.bin", /* As the importers and converters are specified explicitly, there's no messages from AnySceneConverter, OTOH as we have more than one -C option the verbose output includes a progress info */ - "Trade::AnySceneImporter::openFile(): using ObjImporter\n" + "Trade::AnySceneImporter::openFile(): using GltfImporter\n" "Processing (1/2) with MeshOptimizerSceneConverter...\n" "Trade::MeshOptimizerSceneConverter::convert(): processing stats:\n" " vertex cache:\n" @@ -267,38 +269,38 @@ const struct { " 65536 -> 65536 shaded pixels\n" " 65536 -> 65536 covered pixels\n" " overdraw 1 -> 1\n" - "Saving output (2/2) with StanfordSceneConverter...\n"}, + "Saving output (2/2) with GltfSceneConverter...\n"}, {"one mesh, two converters, options for the first only", Containers::array({ "-C", "MeshOptimizerSceneConverter", "-c", "nonexistentMeshOptimizerOption=yes", - Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), - "ObjImporter", "StanfordSceneConverter", + Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad-strip.gltf"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), + "GltfImporter", "GltfSceneConverter", "quad.ply", nullptr, "Option nonexistentMeshOptimizerOption not recognized by MeshOptimizerSceneConverter\n"}, {"one mesh, two converters, explicit last, options for the first only", Containers::array({ "-C", "MeshOptimizerSceneConverter", "-c", "nonexistentMeshOptimizerOption=yes", "-C", "StanfordSceneConverter", - Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), - "ObjImporter", "StanfordSceneConverter", + Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad-strip.gltf"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), + "GltfImporter", "GltfSceneConverter", "quad.ply", nullptr, "Option nonexistentMeshOptimizerOption not recognized by MeshOptimizerSceneConverter\n"}, {"one mesh, two converters, options for both", Containers::array({ "-C", "MeshOptimizerSceneConverter", "-c", "nonexistentMeshOptimizerOption=yes", "-c", "nonexistentAnyConverterOption=no", - Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), - "ObjImporter", "StanfordSceneConverter", + Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad-strip.gltf"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.gltf")}), + "GltfImporter", "GltfSceneConverter", "quad.ply", nullptr, "Option nonexistentMeshOptimizerOption not recognized by MeshOptimizerSceneConverter\n" - "Trade::AnySceneConverter::convertToFile(): option nonexistentAnyConverterOption not recognized by StanfordSceneConverter\n"}, + "Trade::AnySceneConverter::convertToFile(): option nonexistentAnyConverterOption not recognized by GltfSceneConverter\n"}, {"one mesh, two converters, explicit last, options for both", Containers::array({ "-C", "MeshOptimizerSceneConverter", "-c", "nonexistentMeshOptimizerOption=yes", "-C", "StanfordSceneConverter", "-c", "nonexistentStanfordConverterOption=no", - Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), - "ObjImporter", "StanfordSceneConverter", + Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad-strip.gltf"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.gltf")}), + "GltfImporter", "GltfSceneConverter", "quad.ply", nullptr, "Option nonexistentMeshOptimizerOption not recognized by MeshOptimizerSceneConverter\n" "Option nonexistentStanfordConverterOption not recognized by StanfordSceneConverter\n"}, diff --git a/src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad-strip.bin b/src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad-strip.bin new file mode 100644 index 0000000000000000000000000000000000000000..bc7b194eb3338d5f6d6f4ea64382e02732774760 GIT binary patch literal 48 bcmZQzXxPsH#tcBvV2{KGi39m?aWESI-Dn5- literal 0 HcmV?d00001 diff --git a/src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad-strip.bin.in b/src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad-strip.bin.in new file mode 100644 index 000000000..8792d7ef4 --- /dev/null +++ b/src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad-strip.bin.in @@ -0,0 +1,13 @@ +type = "3f3f3f3f" +input = [ + # 2--3 2 2--3 + # |\ | -> |\ \ | + # | \| | \ \| + # 0--1 0--1 1 + -1, -1, 0, + 1, -1, 0, + -1, 1, 0, + 1, 1, 0, +] + +# kate: hl python diff --git a/src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad-strip.gltf b/src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad-strip.gltf new file mode 100644 index 000000000..ec94c181d --- /dev/null +++ b/src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad-strip.gltf @@ -0,0 +1,38 @@ +{ + "asset": { + "version": "2.0" + }, + "buffers": [ + { + "uri": "quad-strip.bin", + "byteLength": 48 + } + ], + "bufferViews": [ + { + "buffer": 0, + "byteOffset": 0, + "byteLength": 48 + } + ], + "accessors": [ + { + "bufferView": 0, + "componentType": 5126, + "count": 4, + "type": "VEC3" + } + ], + "meshes": [ + { + "primitives": [ + { + "attributes": { + "POSITION": 0 + }, + "mode": 5 + } + ] + } + ] +}