From 88879298a7032fccaf81be047f9287bb81a2da0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 4 Sep 2020 22:02:12 +0200 Subject: [PATCH] sceneconverter: enumerate lights in --info. --- doc/changelog.dox | 4 +- src/Magnum/MeshTools/sceneconverter.cpp | 69 ++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 583e11322..4992773ed 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -114,8 +114,8 @@ See also: - Added a `--bounds` option to @ref magnum-sceneconverter "magnum-sceneconverter", showing data ranges of known attributes -- @ref magnum-sceneconverter "magnum-sceneconverter" now lists also materials - and textures in `--info` +- @ref magnum-sceneconverter "magnum-sceneconverter" now lists also lights, + materials and textures in `--info` @subsubsection changelog-latest-changes-platform Platform libraries diff --git a/src/Magnum/MeshTools/sceneconverter.cpp b/src/Magnum/MeshTools/sceneconverter.cpp index 617d16497..63a396373 100644 --- a/src/Magnum/MeshTools/sceneconverter.cpp +++ b/src/Magnum/MeshTools/sceneconverter.cpp @@ -39,6 +39,7 @@ #include "Magnum/Math/FunctionsBatch.h" #include "Magnum/MeshTools/RemoveDuplicates.h" #include "Magnum/Trade/AbstractImporter.h" +#include "Magnum/Trade/LightData.h" #include "Magnum/Trade/MaterialData.h" #include "Magnum/Trade/MeshData.h" #include "Magnum/Trade/MeshObjectData3D.h" @@ -108,8 +109,8 @@ Arguments: - `-v`, `--verbose` --- verbose output from importer and converter plugins - `--profile` --- measure import and conversion time -If `--info` is given, the utility will print information about all meshes -and images present in the file. +If `--info` is given, the utility will print information about all lights, +materials, meshes, images and textures present in the file. The `-i` / `--importer-options` and `-c` / `--converter-options` arguments accept a comma-separated list of key/value pairs to set in the importer / @@ -222,8 +223,8 @@ int main(int argc, char** argv) { }) .setGlobalHelp(R"(Converts scenes of different formats. -If --info is given, the utility will print information about all meshes and -images present in the file. +If --info is given, the utility will print information about all all lights, +materials, meshes, images and textures present in the file. The -i / --importer-options and -c / --converter-options arguments accept a comma-separated list of key/value pairs to set in the importer / converter @@ -270,6 +271,13 @@ save its output; if no --converter is specified, AnySceneConverter is used.)") return 0; } + struct LightInfo { + UnsignedInt light; + UnsignedInt references; + Trade::LightData data{{}, {}, {}}; + std::string name; + }; + struct MaterialInfo { UnsignedInt material; UnsignedInt references; @@ -307,23 +315,49 @@ save its output; if no --converter is specified, AnySceneConverter is used.)") /* Parse everything first to avoid errors interleaved with output */ /* Scene properties. Currently just counting how much is each mesh / - material shared. Texture reference count is calculated when parsing - materials. */ + light / material shared. Texture reference count is calculated when + parsing materials. */ Containers::Array materialReferenceCount{importer->materialCount()}; + Containers::Array lightReferenceCount{importer->lightCount()}; Containers::Array meshReferenceCount{importer->meshCount()}; for(UnsignedInt i = 0; i != importer->object3DCount(); ++i) { Containers::Pointer object = importer->object3D(i); - if(object && object->instanceType() == Trade::ObjectInstanceType3D::Mesh) { + if(!object) continue; + if(object->instanceType() == Trade::ObjectInstanceType3D::Mesh) { auto& meshObject = static_cast(*object); if(std::size_t(meshObject.instance()) < meshReferenceCount.size()) ++meshReferenceCount[meshObject.instance()]; if(std::size_t(meshObject.material()) < materialReferenceCount.size()) ++materialReferenceCount[meshObject.material()]; + } else if(object->instanceType() == Trade::ObjectInstanceType3D::Light) { + if(std::size_t(object->instance()) < lightReferenceCount.size()) + ++lightReferenceCount[object->instance()]; } } - /* Material properties */ + /* Light properties */ bool error = false; + Containers::Array lightInfos; + for(UnsignedInt i = 0; i != importer->lightCount(); ++i) { + Containers::Optional light; + { + Duration d{importTime}; + if(!(light = importer->light(i))) { + error = true; + continue; + } + } + + LightInfo info{}; + info.light = i; + info.name = importer->lightName(i); + info.references = lightReferenceCount[i]; + info.data = *std::move(light); + + arrayAppend(lightInfos, std::move(info)); + } + + /* Material properties */ Containers::Array materialInfos; Containers::Array textureReferenceCount{importer->textureCount()}; for(UnsignedInt i = 0; i != importer->materialCount(); ++i) { @@ -469,6 +503,25 @@ save its output; if no --converter is specified, AnySceneConverter is used.)") Containers::Array imageInfos = Trade::Implementation::imageInfo(*importer, error, compactImages); + for(const LightInfo& info: lightInfos) { + Debug d; + d << "Light" << info.light; + /* Print reference count only if there actually is a scene, + otherwise this information is useless */ + if(importer->object3DCount()) + d << Utility::formatString("(referenced by {} objects)", info.references); + d << Debug::nospace << ":"; + if(!info.name.empty()) d << info.name; + + d << Debug::newline << " Type:" << info.data.type(); + d << Debug::newline << " Color:" << info.data.color(); + d << Debug::newline << " Intensity:" << info.data.intensity(); + d << Debug::newline << " Attenuation:" << info.data.attenuation(); + d << Debug::newline << " Range:" << info.data.range(); + if(info.data.type() == Trade::LightData::Type::Spot) + d << Debug::newline << " Cone angles:" << Deg(info.data.innerConeAngle()) << Deg(info.data.outerConeAngle()); + } + for(const MaterialInfo& info: materialInfos) { Debug d; d << "Material" << info.material;