diff --git a/doc/changelog.dox b/doc/changelog.dox index 760bf2ada..1c672a5b9 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -99,6 +99,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` @subsubsection changelog-latest-changes-trade Trade library diff --git a/src/Magnum/MeshTools/sceneconverter.cpp b/src/Magnum/MeshTools/sceneconverter.cpp index 4c94391a0..aa25e19b2 100644 --- a/src/Magnum/MeshTools/sceneconverter.cpp +++ b/src/Magnum/MeshTools/sceneconverter.cpp @@ -42,6 +42,7 @@ #include "Magnum/Trade/MaterialData.h" #include "Magnum/Trade/MeshData.h" #include "Magnum/Trade/MeshObjectData3D.h" +#include "Magnum/Trade/TextureData.h" #include "Magnum/Trade/AbstractSceneConverter.h" #include "Magnum/Trade/Implementation/converterUtilities.h" @@ -276,6 +277,13 @@ save its output; if no --converter is specified, AnySceneConverter is used.)") std::string name; }; + struct TextureInfo { + UnsignedInt texture; + UnsignedInt references; + Trade::TextureData data{{}, {}, {}, {}, {}, {}}; + std::string name; + }; + struct MeshAttributeInfo { std::size_t offset; UnsignedInt stride, arraySize; @@ -299,7 +307,8 @@ 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. */ + material shared. Texture reference count is calculated when parsing + materials. */ Containers::Array materialReferenceCount{importer->materialCount()}; Containers::Array meshReferenceCount{importer->meshCount()}; for(UnsignedInt i = 0; i != importer->object3DCount(); ++i) { @@ -316,6 +325,7 @@ save its output; if no --converter is specified, AnySceneConverter is used.)") /* Material properties */ bool error = false; Containers::Array materialInfos; + Containers::Array textureReferenceCount{importer->textureCount()}; for(UnsignedInt i = 0; i != importer->materialCount(); ++i) { Containers::Optional material; { @@ -326,6 +336,19 @@ save its output; if no --converter is specified, AnySceneConverter is used.)") } } + /* Calculate texture reference count for all properties that + look like a texture */ + for(UnsignedInt j = 0; j != material->layerCount(); ++j) { + for(UnsignedInt k = 0; k != material->attributeCount(j); ++k) { + if(material->attributeType(j, k) != Trade::MaterialAttributeType::UnsignedInt || !Utility::String::endsWith(material->attributeName(j, k), "Texture")) + continue; + + const UnsignedInt texture = material->attribute(j, k); + if(texture < textureReferenceCount.size()) + ++textureReferenceCount[texture]; + } + } + MaterialInfo info{}; info.material = i; info.name = importer->materialName(i); @@ -419,6 +442,27 @@ save its output; if no --converter is specified, AnySceneConverter is used.)") } } + /* Texture properties */ + Containers::Array textureInfos; + for(UnsignedInt i = 0; i != importer->textureCount(); ++i) { + Containers::Optional texture; + { + Duration d{importTime}; + if(!(texture = importer->texture(i))) { + error = true; + continue; + } + } + + TextureInfo info{}; + info.texture = i; + info.name = importer->textureName(i); + info.references = textureReferenceCount[i]; + info.data = *std::move(texture); + + arrayAppend(textureInfos, std::move(info)); + } + /* In case the images have all just a single level and no names, write them in a compact way without listing levels. */ bool compactImages = false; @@ -544,6 +588,24 @@ save its output; if no --converter is specified, AnySceneConverter is used.)") d << Debug::newline << " bounds:" << attribute.bounds; } } + + for(const TextureInfo& info: textureInfos) { + Debug d; + d << "Texture" << info.texture; + /* Print reference count only if there actually are some + materials, otherwise this information is useless */ + if(importer->materialCount()) + d << Utility::formatString("(referenced by {} materials)", info.references); + d << Debug::nospace << ":"; + if(!info.name.empty()) d << info.name; + d << Debug::newline; + d << " Type:" << info.data.type(); + d << "\n Minification:" << info.data.minificationFilter() << info.data.mipmapFilter(); + d << "\n Magnification:" << info.data.magnificationFilter(); + d << "\n Wrapping:" << info.data.wrapping(); + d << "\n Image:" << info.data.image(); + } + for(const Trade::Implementation::ImageInfo& info: imageInfos) { Debug d; if(info.level == 0) {