From e9125c0c8a2523d4de13cf9010759e09a377d5c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 20 Sep 2022 01:52:27 +0200 Subject: [PATCH] sceneconverter: recognize whole-scene converters. Just a minimal support to get single-mesh conversion working with GltfSceneConverter. The whole thing has to be subsequently reworked to not be oriented around meshes, but this is the first step. --- src/Magnum/SceneTools/Test/CMakeLists.txt | 2 + .../SceneTools/Test/SceneConverterTest.cpp | 49 ++++++++++------- .../Test/SceneConverterTestFiles/quad.bin | Bin 0 -> 72 bytes .../Test/SceneConverterTestFiles/quad.gltf | 50 ++++++++++++++++++ src/Magnum/SceneTools/sceneconverter.cpp | 2 +- 5 files changed, 82 insertions(+), 21 deletions(-) create mode 100644 src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad.bin create mode 100644 src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad.gltf diff --git a/src/Magnum/SceneTools/Test/CMakeLists.txt b/src/Magnum/SceneTools/Test/CMakeLists.txt index 51f448cbb..3c5821a3c 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.bin + SceneConverterTestFiles/quad.gltf SceneConverterTestFiles/quad.obj SceneConverterTestFiles/quad.ply SceneConverterTestFiles/two-triangles-transformed.bin diff --git a/src/Magnum/SceneTools/Test/SceneConverterTest.cpp b/src/Magnum/SceneTools/Test/SceneConverterTest.cpp index 7c581dd06..bc10d1a29 100644 --- a/src/Magnum/SceneTools/Test/SceneConverterTest.cpp +++ b/src/Magnum/SceneTools/Test/SceneConverterTest.cpp @@ -118,23 +118,29 @@ const struct { const char* requiresImporter; const char* requiresConverter; const char* expected; + const char* expected2; Containers::String message; } ConvertData[]{ {"one mesh", Containers::array({ Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), "ObjImporter", "StanfordSceneConverter", - "quad.ply", + "quad.ply", nullptr, + {}}, + {"one mesh, whole scene converter", Containers::array({ + Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.gltf")}), + "ObjImporter", "GltfSceneConverter", + "quad.gltf", "quad.bin", {}}, {"one mesh, explicit importer and converter", Containers::array({ "-I", "ObjImporter", "-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", + "quad.ply", nullptr, {}}, {"one mesh, map", Containers::array({ Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), "ObjImporter", "StanfordSceneConverter", - "quad.ply", + "quad.ply", nullptr, {}}, {"one mesh, options", Containers::array({ /* It's silly, but since we have option propagation tested in @@ -143,7 +149,7 @@ const struct { "-i", "nonexistentOption=13", "-c", "nonexistentConverterOption=26", Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), "ObjImporter", "StanfordSceneConverter", - "quad.ply", + "quad.ply", nullptr, "Trade::AnySceneImporter::openFile(): option nonexistentOption not recognized by ObjImporter\n" "Trade::AnySceneConverter::convertToFile(): option nonexistentConverterOption not recognized by StanfordSceneConverter\n"}, {"one mesh, options, explicit importer and converter", Containers::array({ @@ -154,33 +160,33 @@ const struct { "-I", "ObjImporter", "-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", + "quad.ply", nullptr, "Option nonexistentOption not recognized by ObjImporter\n" "Option nonexistentConverterOption not recognized by StanfordSceneConverter\n"}, {"concatenate meshes without a scene", Containers::array({ "--concatenate-meshes", Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/two-triangles.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad-duplicates.ply")}), "ObjImporter", "StanfordSceneConverter", - "quad-duplicates.ply", + "quad-duplicates.ply", nullptr, {}}, {"concatenate meshes with a scene", Containers::array({ "--concatenate-meshes", Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/two-triangles-transformed.gltf"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad-duplicates.ply")}), "GltfImporter", "StanfordSceneConverter", - "quad-duplicates.ply", + "quad-duplicates.ply", nullptr, {}}, {"filter mesh attributes", Containers::array({ /* Only 0 gets picked from here, others ignored */ "--only-mesh-attributes", "17,0,25-36", Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad-normals-texcoords.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), "ObjImporter", "StanfordSceneConverter", - "quad.ply", + "quad.ply", nullptr, {}}, {"remove duplicate vertices", Containers::array({ "--remove-duplicate-vertices", Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad-duplicates.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), "ObjImporter", "StanfordSceneConverter", - "quad.ply", + "quad.ply", nullptr, {}}, {"remove duplicate vertices, verbose", Containers::array({ /* Forcing the importer and converter to avoid AnySceneImporter / @@ -188,13 +194,13 @@ const struct { "--remove-duplicate-vertices", "-v", "-I", "ObjImporter", "-C", "StanfordSceneConverter", Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad-duplicates.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), "ObjImporter", "StanfordSceneConverter", - "quad.ply", + "quad.ply", nullptr, "Duplicate removal: 6 -> 4 vertices\n"}, {"remove duplicate vertices fuzzy", Containers::array({ "--remove-duplicate-vertices-fuzzy", "1.0e-1", Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad-duplicates-fuzzy.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), "ObjImporter", "StanfordSceneConverter", - "quad.ply", + "quad.ply", nullptr, {}}, {"remove duplicate vertices fuzzy, verbose", Containers::array({ /* Forcing the importer and converter to avoid AnySceneImporter / @@ -202,25 +208,25 @@ const struct { "--remove-duplicate-vertices-fuzzy 1.0e-1", "-v", "-I", "ObjImporter", "-C", "StanfordSceneConverter", Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad-duplicates-fuzzy.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), "ObjImporter", "StanfordSceneConverter", - "quad.ply", + "quad.ply", nullptr, "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", + "quad.ply", nullptr, {}}, {"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", + "quad.ply", nullptr, {}}, {"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", + "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" @@ -242,7 +248,7 @@ const struct { "-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", + "quad.ply", nullptr, /* 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 */ @@ -267,7 +273,7 @@ const struct { "-c", "nonexistentMeshOptimizerOption=yes", Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), "ObjImporter", "StanfordSceneConverter", - "quad.ply", + "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", @@ -275,7 +281,7 @@ const struct { "-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", + "quad.ply", nullptr, "Option nonexistentMeshOptimizerOption not recognized by MeshOptimizerSceneConverter\n"}, {"one mesh, two converters, options for both", Containers::array({ "-C", "MeshOptimizerSceneConverter", @@ -283,7 +289,7 @@ const struct { "-c", "nonexistentAnyConverterOption=no", Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), "ObjImporter", "StanfordSceneConverter", - "quad.ply", + "quad.ply", nullptr, "Option nonexistentMeshOptimizerOption not recognized by MeshOptimizerSceneConverter\n" "Trade::AnySceneConverter::convertToFile(): option nonexistentAnyConverterOption not recognized by StanfordSceneConverter\n"}, {"one mesh, two converters, explicit last, options for both", Containers::array({ @@ -293,7 +299,7 @@ const struct { "-c", "nonexistentStanfordConverterOption=no", Utility::Path::join(SCENETOOLS_TEST_DIR, "SceneConverterTestFiles/quad.obj"), Utility::Path::join(SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles/quad.ply")}), "ObjImporter", "StanfordSceneConverter", - "quad.ply", + "quad.ply", nullptr, "Option nonexistentMeshOptimizerOption not recognized by MeshOptimizerSceneConverter\n" "Option nonexistentStanfordConverterOption not recognized by StanfordSceneConverter\n"}, }; @@ -1641,6 +1647,9 @@ void SceneConverterTest::convert() { CORRADE_COMPARE_AS(Utility::Path::join({SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles", data.expected}), Utility::Path::join({SCENETOOLS_TEST_DIR, "SceneConverterTestFiles", data.expected}), TestSuite::Compare::File); + if(data.expected2) CORRADE_COMPARE_AS(Utility::Path::join({SCENETOOLS_TEST_OUTPUT_DIR, "SceneConverterTestFiles", data.expected2}), + Utility::Path::join({SCENETOOLS_TEST_DIR, "SceneConverterTestFiles", data.expected2}), + TestSuite::Compare::File); #endif } diff --git a/src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad.bin b/src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad.bin new file mode 100644 index 0000000000000000000000000000000000000000..94c80e884dc8f58f100c4c39ff631fa97d412216 GIT binary patch literal 72 lcmZQzU|?VbVkRgCv6+FGfuUhP1cTZ3NNkWekPjCJvjN|b2m$~A literal 0 HcmV?d00001 diff --git a/src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad.gltf b/src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad.gltf new file mode 100644 index 000000000..69519f700 --- /dev/null +++ b/src/Magnum/SceneTools/Test/SceneConverterTestFiles/quad.gltf @@ -0,0 +1,50 @@ +{ + "asset": { + "version": "2.0", + "generator": "Magnum GltfSceneConverter" + }, + "buffers": [ + { + "uri": "quad.bin", + "byteLength": 72 + } + ], + "bufferViews": [ + { + "buffer": 0, + "byteOffset": 0, + "byteLength": 24 + }, + { + "buffer": 0, + "byteOffset": 24, + "byteLength": 48 + } + ], + "accessors": [ + { + "bufferView": 0, + "componentType": 5125, + "count": 6, + "type": "SCALAR" + }, + { + "bufferView": 1, + "componentType": 5126, + "count": 4, + "type": "VEC3" + } + ], + "meshes": [ + { + "primitives": [ + { + "indices": 0, + "attributes": { + "POSITION": 1 + } + } + ] + } + ] +} diff --git a/src/Magnum/SceneTools/sceneconverter.cpp b/src/Magnum/SceneTools/sceneconverter.cpp index 3c79d81a7..edc62a1e3 100644 --- a/src/Magnum/SceneTools/sceneconverter.cpp +++ b/src/Magnum/SceneTools/sceneconverter.cpp @@ -518,7 +518,7 @@ the first mesh.)") /* This is the last --converter (or the implicit AnySceneConverter at the end), output to a file and exit the loop */ - if(i + 1 >= converterCount && (converter->features() & Trade::SceneConverterFeature::ConvertMeshToFile)) { + if(i + 1 >= converterCount && ((converter->features() & Trade::SceneConverterFeature::ConvertMeshToFile) || converter->features() >= (Trade::SceneConverterFeature::ConvertMultipleToFile|Trade::SceneConverterFeature::AddMeshes))) { /* No verbose output for just one converter */ if(converterCount > 1 && args.isSet("verbose")) Debug{} << "Saving output (" << Debug::nospace << (i+1) << Debug::nospace << "/" << Debug::nospace << converterCount << Debug::nospace << ") with" << converterName << Debug::nospace << "...";