From 312a4a9facc968a3295cd730ea25cb10fdd47c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 19 Sep 2022 21:50:06 +0200 Subject: [PATCH] sceneconverter: don't have an array of optionals for no reason. --- src/Magnum/SceneTools/sceneconverter.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Magnum/SceneTools/sceneconverter.cpp b/src/Magnum/SceneTools/sceneconverter.cpp index 47cbee698..733986263 100644 --- a/src/Magnum/SceneTools/sceneconverter.cpp +++ b/src/Magnum/SceneTools/sceneconverter.cpp @@ -397,10 +397,16 @@ the first mesh.)") /* Concatenate input meshes, if requested */ if(args.isSet("concatenate-meshes")) { - Containers::Array> meshes{importer->meshCount()}; - for(std::size_t i = 0; i != meshes.size(); ++i) if(!(meshes[i] = importer->mesh(i))) { - Error{} << "Cannot import mesh" << i; - return 1; + Containers::Array meshes; + arrayReserve(meshes, importer->meshCount()); + for(std::size_t i = 0, iMax = importer->meshCount(); i != iMax; ++i) { + Containers::Optional meshToConcatenate = importer->mesh(i); + if(!meshToConcatenate) { + Error{} << "Cannot import mesh" << i; + return 1; + } + + arrayAppend(meshes, *std::move(meshToConcatenate)); } /* If there's a scene, use it to flatten mesh hierarchy. If not, assume @@ -414,9 +420,9 @@ the first mesh.)") } /** @todo once there are 2D scenes, check the scene is 3D */ - Containers::Array> flattenedMeshes; + Containers::Array flattenedMeshes; for(const Containers::Triple& meshTransformation: SceneTools::flattenMeshHierarchy3D(*scene)) - arrayAppend(flattenedMeshes, MeshTools::transform3D(*meshes[meshTransformation.first()], meshTransformation.third())); + arrayAppend(flattenedMeshes, MeshTools::transform3D(meshes[meshTransformation.first()], meshTransformation.third())); meshes = std::move(flattenedMeshes); } @@ -425,7 +431,7 @@ the first mesh.)") references with the nasty NoInit, yet keeping the flexibility? */ Containers::Array> meshReferences{NoInit, meshes.size()}; for(std::size_t i = 0; i != meshes.size(); ++i) - meshReferences[i] = *meshes[i]; + meshReferences[i] = meshes[i]; /** @todo this will assert if the meshes have incompatible primitives (such as some triangles, some lines), or if they have loops/strips/fans -- handle that explicitly */