From 260dee1565b933cea1476af47ec47aa724f6549b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 23 Apr 2020 23:47:21 +0200 Subject: [PATCH] [wip] sceneconverter: support also plugins that can't output a file. Those will simply produce serialized blobs on output. TODO: make this more generic? like, if I specify a *.ply at the end, it uses some other converter after that? --- src/Magnum/Trade/sceneconverter.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Magnum/Trade/sceneconverter.cpp b/src/Magnum/Trade/sceneconverter.cpp index 9d1297e092..b16165d537 100644 --- a/src/Magnum/Trade/sceneconverter.cpp +++ b/src/Magnum/Trade/sceneconverter.cpp @@ -377,13 +377,36 @@ key=true; configuration subgroups are delimited with /.)") std::chrono::high_resolution_clock::duration conversionTime; - /* Save output file */ - { + /* Save output file directly, if it supports that */ + if(converter->features() & Trade::SceneConverterFeature::ConvertMeshToFile) { Duration d{conversionTime}; if(!converter->convertToFile(args.value("output"), *mesh)) { Error{} << "Cannot save file" << args.value("output"); return 5; } + + /* Otherwise convert the meshdata and then save as a blob */ + } else if(converter->features() & (Trade::SceneConverterFeature::ConvertMesh|Trade::SceneConverterFeature::ConvertMeshInPlace)) { + if(converter->features() & Trade::SceneConverterFeature::ConvertMesh) { + Duration d{conversionTime}; + if(!(mesh = converter->convert(*mesh))) { + Error{} << "Cannot convert the mesh"; + return 5; + } + } else if(converter->features() & Trade::SceneConverterFeature::ConvertMeshInPlace) { + Duration d{conversionTime}; + if(!converter->convertInPlace(*mesh)) { + Error{} << "Cannot convert the mesh in-place"; + return 5; + } + } else CORRADE_INTERNAL_ASSERT_UNREACHABLE(); + + Containers::Array out = Utility::Directory::mapWrite(args.value("output"), mesh->serializedSize()); + if(!out) { + Error{} << "Cannot save file" << args.value("output"); + return 6; + } + mesh->serializeInto(out); } if(args.isSet("profile")) {