diff --git a/CMakeLists.txt b/CMakeLists.txt index 83753f3d70..75912d567f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,7 @@ endif() # API-independent utilities option(WITH_IMAGECONVERTER "Build magnum-imageconverter utility" OFF) +option(WITH_SCENECONVERTER "Build magnum-sceneconverter utility" OFF) # Magnum AL Info option(WITH_AL_INFO "Build magnum-al-info utility" OFF) diff --git a/Doxyfile b/Doxyfile index 4e583f53d6..0045454a6f 100644 --- a/Doxyfile +++ b/Doxyfile @@ -921,6 +921,7 @@ INPUT = src/Magnum \ src/Magnum/Text/fontconverter.cpp \ src/Magnum/TextureTools/distancefieldconverter.cpp \ src/Magnum/Trade/imageconverter.cpp \ + src/Magnum/Trade/sceneconverter.cpp \ doc/ \ ../magnum-plugins/src/Magnum \ ../magnum-plugins/src/MagnumPlugins \ diff --git a/doc/utilities.dox b/doc/utilities.dox index 02c231c96f..1be24549a5 100644 --- a/doc/utilities.dox +++ b/doc/utilities.dox @@ -54,6 +54,7 @@ namespace Magnum { - @subpage magnum-distancefieldconverter --- @copybrief magnum-distancefieldconverter - @subpage magnum-fontconverter --- @copybrief magnum-fontconverter - @subpage magnum-imageconverter --- @copybrief magnum-imageconverter +- @subpage magnum-sceneconverter --- @copybrief magnum-sceneconverter */ } diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 09569afaf9..c12c35b10e 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -91,6 +91,7 @@ # distancefieldconverter - magnum-distancefieldconverter executable # fontconverter - magnum-fontconverter executable # imageconverter - magnum-imageconverter executable +# sceneconverterter - magnum-sceneconverter executable # gl-info - magnum-gl-info executable # al-info - magnum-al-info executable # @@ -357,7 +358,8 @@ set(_MAGNUM_PLUGIN_COMPONENT_LIST MagnumFont MagnumFontConverter ObjImporter TgaImageConverter TgaImporter WavAudioImporter) set(_MAGNUM_EXECUTABLE_COMPONENT_LIST - distancefieldconverter fontconverter imageconverter gl-info al-info) + distancefieldconverter fontconverter imageconverter sceneconverter gl-info + al-info) # Inter-component dependencies set(_MAGNUM_Audio_DEPENDENCIES ) diff --git a/package/archlinux/PKGBUILD b/package/archlinux/PKGBUILD index 8c6aff5aaa..0ab7c0642d 100644 --- a/package/archlinux/PKGBUILD +++ b/package/archlinux/PKGBUILD @@ -48,6 +48,7 @@ build() { -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/archlinux/PKGBUILD-clang b/package/archlinux/PKGBUILD-clang index 0092334736..2cd2963098 100644 --- a/package/archlinux/PKGBUILD-clang +++ b/package/archlinux/PKGBUILD-clang @@ -51,6 +51,7 @@ build() { -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/archlinux/PKGBUILD-clang-addressanitizer b/package/archlinux/PKGBUILD-clang-addressanitizer index ceff6c4d4c..fe09aa288e 100644 --- a/package/archlinux/PKGBUILD-clang-addressanitizer +++ b/package/archlinux/PKGBUILD-clang-addressanitizer @@ -52,6 +52,7 @@ build() { -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/archlinux/PKGBUILD-clang-analyzer b/package/archlinux/PKGBUILD-clang-analyzer index 203c5c153b..61f69baeb8 100644 --- a/package/archlinux/PKGBUILD-clang-analyzer +++ b/package/archlinux/PKGBUILD-clang-analyzer @@ -43,6 +43,7 @@ build() { -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/archlinux/PKGBUILD-clang-libc++ b/package/archlinux/PKGBUILD-clang-libc++ index ced9be4e50..a036b7f158 100644 --- a/package/archlinux/PKGBUILD-clang-libc++ +++ b/package/archlinux/PKGBUILD-clang-libc++ @@ -54,6 +54,7 @@ build() { -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/archlinux/PKGBUILD-coverage b/package/archlinux/PKGBUILD-coverage index 63cf7e35f3..18b02e4ea4 100644 --- a/package/archlinux/PKGBUILD-coverage +++ b/package/archlinux/PKGBUILD-coverage @@ -49,6 +49,7 @@ build() { -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/archlinux/PKGBUILD-es2 b/package/archlinux/PKGBUILD-es2 index 0239c30a76..4e883768b9 100644 --- a/package/archlinux/PKGBUILD-es2 +++ b/package/archlinux/PKGBUILD-es2 @@ -38,6 +38,7 @@ build() { -DWITH_TGAIMPORTER=ON \ -DWITH_WAVAUDIOIMPORTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/archlinux/PKGBUILD-es2desktop b/package/archlinux/PKGBUILD-es2desktop index ab1abb599b..7067de768e 100644 --- a/package/archlinux/PKGBUILD-es2desktop +++ b/package/archlinux/PKGBUILD-es2desktop @@ -42,6 +42,7 @@ build() { -DWITH_TGAIMPORTER=ON \ -DWITH_WAVAUDIOIMPORTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/archlinux/PKGBUILD-es3 b/package/archlinux/PKGBUILD-es3 index 88f88add08..5bb5d87d25 100644 --- a/package/archlinux/PKGBUILD-es3 +++ b/package/archlinux/PKGBUILD-es3 @@ -38,6 +38,7 @@ build() { -DWITH_TGAIMPORTER=ON \ -DWITH_WAVAUDIOIMPORTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/archlinux/PKGBUILD-es3desktop b/package/archlinux/PKGBUILD-es3desktop index 4b1e9a462e..01606f3c01 100644 --- a/package/archlinux/PKGBUILD-es3desktop +++ b/package/archlinux/PKGBUILD-es3desktop @@ -42,6 +42,7 @@ build() { -DWITH_TGAIMPORTER=ON \ -DWITH_WAVAUDIOIMPORTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/archlinux/PKGBUILD-gcc48 b/package/archlinux/PKGBUILD-gcc48 index bf9dc83935..7ca76d5119 100644 --- a/package/archlinux/PKGBUILD-gcc48 +++ b/package/archlinux/PKGBUILD-gcc48 @@ -54,6 +54,7 @@ build() { -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/archlinux/PKGBUILD-mingw-w64 b/package/archlinux/PKGBUILD-mingw-w64 index 1fc684f706..789b1845e6 100644 --- a/package/archlinux/PKGBUILD-mingw-w64 +++ b/package/archlinux/PKGBUILD-mingw-w64 @@ -38,6 +38,7 @@ build() { -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ @@ -66,6 +67,7 @@ build() { -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/archlinux/PKGBUILD-release b/package/archlinux/PKGBUILD-release index 39031a583c..ffccc86fa8 100644 --- a/package/archlinux/PKGBUILD-release +++ b/package/archlinux/PKGBUILD-release @@ -43,6 +43,7 @@ build() { -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ @@ -79,6 +80,7 @@ build() { -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/archlinux/magnum-git/PKGBUILD b/package/archlinux/magnum-git/PKGBUILD index 74c2aaaba1..1e636a8cc3 100644 --- a/package/archlinux/magnum-git/PKGBUILD +++ b/package/archlinux/magnum-git/PKGBUILD @@ -46,6 +46,7 @@ build() { -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON make diff --git a/package/archlinux/magnum/PKGBUILD b/package/archlinux/magnum/PKGBUILD index 0b5575ed7d..e7d6ee39d0 100644 --- a/package/archlinux/magnum/PKGBUILD +++ b/package/archlinux/magnum/PKGBUILD @@ -31,6 +31,7 @@ build() { -DWITH_GLXAPPLICATION=ON \ -DWITH_GLXCONTEXT=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_MAGNUMFONT=ON \ -DWITH_MAGNUMFONTCONVERTER=ON \ -DWITH_OBJIMPORTER=ON \ diff --git a/package/ci/appveyor-desktop-gles.bat b/package/ci/appveyor-desktop-gles.bat index 4a48947f77..cd93b02b99 100644 --- a/package/ci/appveyor-desktop-gles.bat +++ b/package/ci/appveyor-desktop-gles.bat @@ -43,6 +43,7 @@ cmake .. ^ -DWITH_DISTANCEFIELDCONVERTER=OFF ^ -DWITH_FONTCONVERTER=OFF ^ -DWITH_IMAGECONVERTER=ON ^ + -DWITH_SCENECONVERTER=ON ^ -DWITH_GL_INFO=ON ^ -DWITH_AL_INFO=ON ^ -DBUILD_TESTS=ON ^ diff --git a/package/ci/appveyor-desktop-mingw.bat b/package/ci/appveyor-desktop-mingw.bat index 2063be1951..ce69848d1f 100644 --- a/package/ci/appveyor-desktop-mingw.bat +++ b/package/ci/appveyor-desktop-mingw.bat @@ -42,6 +42,7 @@ cmake .. ^ -DWITH_DISTANCEFIELDCONVERTER=ON ^ -DWITH_FONTCONVERTER=ON ^ -DWITH_IMAGECONVERTER=ON ^ + -DWITH_SCENECONVERTER=ON ^ -DWITH_GL_INFO=ON ^ -DWITH_AL_INFO=ON ^ -DBUILD_TESTS=ON ^ diff --git a/package/ci/appveyor-desktop-vulkan.bat b/package/ci/appveyor-desktop-vulkan.bat index 1b6ed74a11..4b9ad216c9 100644 --- a/package/ci/appveyor-desktop-vulkan.bat +++ b/package/ci/appveyor-desktop-vulkan.bat @@ -53,6 +53,7 @@ cmake .. ^ -DWITH_DISTANCEFIELDCONVERTER=OFF ^ -DWITH_FONTCONVERTER=OFF ^ -DWITH_IMAGECONVERTER=OFF ^ + -DWITH_SCENECONVERTER=OFF ^ -DWITH_GL_INFO=OFF ^ -DWITH_AL_INFO=OFF ^ -DWITH_SDL2APPLICATION=ON ^ diff --git a/package/ci/appveyor-desktop.bat b/package/ci/appveyor-desktop.bat index 70fbf6a24c..409ec498f5 100644 --- a/package/ci/appveyor-desktop.bat +++ b/package/ci/appveyor-desktop.bat @@ -55,6 +55,7 @@ cmake .. ^ -DWITH_DISTANCEFIELDCONVERTER=ON ^ -DWITH_FONTCONVERTER=ON ^ -DWITH_IMAGECONVERTER=ON ^ + -DWITH_SCENECONVERTER=ON ^ -DWITH_GL_INFO=ON ^ -DWITH_AL_INFO=ON ^ -DBUILD_TESTS=ON ^ diff --git a/package/ci/travis-desktop-gles.sh b/package/ci/travis-desktop-gles.sh index 048da8da21..420eed6470 100755 --- a/package/ci/travis-desktop-gles.sh +++ b/package/ci/travis-desktop-gles.sh @@ -47,6 +47,7 @@ cmake .. \ -DWITH_DISTANCEFIELDCONVERTER=OFF \ -DWITH_FONTCONVERTER=OFF \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/ci/travis-desktop-vulkan.sh b/package/ci/travis-desktop-vulkan.sh index efe4e8cf33..a81b6ef837 100755 --- a/package/ci/travis-desktop-vulkan.sh +++ b/package/ci/travis-desktop-vulkan.sh @@ -57,6 +57,7 @@ cmake .. \ -DWITH_DISTANCEFIELDCONVERTER=OFF \ -DWITH_FONTCONVERTER=OFF \ -DWITH_IMAGECONVERTER=OFF \ + -DWITH_SCENECONVERTER=OFF \ -DWITH_SDL2APPLICATION=ON \ -DWITH_GLFWAPPLICATION=ON \ -DBUILD_TESTS=ON \ diff --git a/package/ci/travis-desktop.sh b/package/ci/travis-desktop.sh index 15bc7df0d4..be19cc463e 100755 --- a/package/ci/travis-desktop.sh +++ b/package/ci/travis-desktop.sh @@ -43,6 +43,7 @@ cmake .. \ -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON \ -DBUILD_TESTS=ON \ diff --git a/package/debian/rules b/package/debian/rules index 6087be994b..482d8bdb5c 100755 --- a/package/debian/rules +++ b/package/debian/rules @@ -35,6 +35,7 @@ override_dh_auto_configure: -DWITH_WAVAUDIOIMPORTER=ON \ -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON diff --git a/package/gentoo/dev-libs/magnum/magnum-9999.ebuild b/package/gentoo/dev-libs/magnum/magnum-9999.ebuild index 629e95843f..a4eb16c4b6 100644 --- a/package/gentoo/dev-libs/magnum/magnum-9999.ebuild +++ b/package/gentoo/dev-libs/magnum/magnum-9999.ebuild @@ -44,6 +44,7 @@ src_configure() { -DWITH_WAVAUDIOIMPORTER=ON -DWITH_DISTANCEFIELDCONVERTER=ON -DWITH_IMAGECONVERTER=ON + -DWITH_SCENECONVERTER=ON -DWITH_FONTCONVERTER=ON -DWITH_GL_INFO=ON -DWITH_AL_INFO=ON diff --git a/package/homebrew/magnum.rb b/package/homebrew/magnum.rb index 62cdba28e2..e52627d3d9 100644 --- a/package/homebrew/magnum.rb +++ b/package/homebrew/magnum.rb @@ -14,7 +14,7 @@ class Magnum < Formula def install system "mkdir build" cd "build" do - system "cmake", "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_INSTALL_PREFIX=#{prefix}", "-DMAGNUM_PLUGINS_DIR=#{HOMEBREW_PREFIX}/lib/magnum", "-DWITH_AUDIO=ON", "-DWITH_GLFWAPPLICATION=ON", "-DWITH_SDL2APPLICATION=ON", "-DWITH_WINDOWLESSCGLAPPLICATION=ON", "-DWITH_CGLCONTEXT=ON", "-DWITH_OPENGLTESTER=ON", "-DWITH_ANYAUDIOIMPORTER=ON", "-DWITH_ANYIMAGECONVERTER=ON", "-DWITH_ANYIMAGEIMPORTER=ON", "-DWITH_ANYSCENEIMPORTER=ON", "-DWITH_MAGNUMFONT=ON", "-DWITH_MAGNUMFONTCONVERTER=ON", "-DWITH_OBJIMPORTER=ON", "-DWITH_TGAIMAGECONVERTER=ON", "-DWITH_TGAIMPORTER=ON", "-DWITH_WAVAUDIOIMPORTER=ON", "-DWITH_DISTANCEFIELDCONVERTER=ON", "-DWITH_FONTCONVERTER=ON", "-DWITH_IMAGECONVERTER=ON", "-DWITH_GL_INFO=ON", "-DWITH_AL_INFO=ON", ".." + system "cmake", "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_INSTALL_PREFIX=#{prefix}", "-DMAGNUM_PLUGINS_DIR=#{HOMEBREW_PREFIX}/lib/magnum", "-DWITH_AUDIO=ON", "-DWITH_GLFWAPPLICATION=ON", "-DWITH_SDL2APPLICATION=ON", "-DWITH_WINDOWLESSCGLAPPLICATION=ON", "-DWITH_CGLCONTEXT=ON", "-DWITH_OPENGLTESTER=ON", "-DWITH_ANYAUDIOIMPORTER=ON", "-DWITH_ANYIMAGECONVERTER=ON", "-DWITH_ANYIMAGEIMPORTER=ON", "-DWITH_ANYSCENEIMPORTER=ON", "-DWITH_MAGNUMFONT=ON", "-DWITH_MAGNUMFONTCONVERTER=ON", "-DWITH_OBJIMPORTER=ON", "-DWITH_TGAIMAGECONVERTER=ON", "-DWITH_TGAIMPORTER=ON", "-DWITH_WAVAUDIOIMPORTER=ON", "-DWITH_DISTANCEFIELDCONVERTER=ON", "-DWITH_FONTCONVERTER=ON", "-DWITH_IMAGECONVERTER=ON", "-DWITH_SCENECONVERTER=ON", "-DWITH_GL_INFO=ON", "-DWITH_AL_INFO=ON", ".." system "cmake", "--build", "." system "cmake", "--build", ".", "--target", "install" end diff --git a/package/msys/PKGBUILD b/package/msys/PKGBUILD index f1d2bc6d8e..0b81f66d0f 100644 --- a/package/msys/PKGBUILD +++ b/package/msys/PKGBUILD @@ -50,6 +50,7 @@ build() { -DWITH_DISTANCEFIELDCONVERTER=ON \ -DWITH_FONTCONVERTER=ON \ -DWITH_IMAGECONVERTER=ON \ + -DWITH_SCENECONVERTER=ON \ -DWITH_GL_INFO=ON \ -DWITH_AL_INFO=ON ninja diff --git a/src/Magnum/Trade/CMakeLists.txt b/src/Magnum/Trade/CMakeLists.txt index 698ac1e35e..e41287968a 100644 --- a/src/Magnum/Trade/CMakeLists.txt +++ b/src/Magnum/Trade/CMakeLists.txt @@ -149,6 +149,19 @@ if(WITH_IMAGECONVERTER) add_executable(Magnum::imageconverter ALIAS magnum-imageconverter) endif() +if(WITH_SCENECONVERTER) + add_executable(magnum-sceneconverter sceneconverter.cpp) + target_link_libraries(magnum-sceneconverter PRIVATE + Magnum + MagnumTrade) + set_target_properties(magnum-sceneconverter PROPERTIES FOLDER "Magnum/Trade") + + install(TARGETS magnum-sceneconverter DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}) + + # Magnum sceneconverter target alias for superprojects + add_executable(Magnum::sceneconverter ALIAS magnum-sceneconverter) +endif() + if(BUILD_TESTS) # Library with graceful assert for testing add_library(MagnumTradeTestLib ${SHARED_OR_STATIC} diff --git a/src/Magnum/Trade/imageconverter.cpp b/src/Magnum/Trade/imageconverter.cpp index e447a8db92..b7ff9c5aee 100644 --- a/src/Magnum/Trade/imageconverter.cpp +++ b/src/Magnum/Trade/imageconverter.cpp @@ -126,6 +126,8 @@ Extracting raw (uncompressed, compressed) data from a DDS file for manual @code{.sh} magnum-imageconverter image.dds --converter raw data.dat @endcode + +@see @ref magnum-sceneconverter */ } diff --git a/src/Magnum/Trade/sceneconverter.cpp b/src/Magnum/Trade/sceneconverter.cpp new file mode 100644 index 0000000000..af30167b42 --- /dev/null +++ b/src/Magnum/Trade/sceneconverter.cpp @@ -0,0 +1,251 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include "Magnum/PixelFormat.h" +#include "Magnum/Trade/AbstractImporter.h" +#include "Magnum/Trade/MeshData.h" +#include "Magnum/Trade/Implementation/converterUtilities.h" + +namespace Magnum { + +/** @page magnum-sceneconverter Scene conversion utility +@brief Converts scenes of different formats + +@m_footernavigation +@m_keywords{magnum-sceneconverter sceneconverter} + +This utility is built if both `WITH_TRADE` and `WITH_SCENECONVERTER` is enabled +when building Magnum. To use this utility with CMake, you need to request the +`sceneconverter` component of the `Magnum` package and use the +`Magnum::sceneconverter` target for example in a custom command: + +@code{.cmake} +find_package(Magnum REQUIRED imageconverter) + +add_custom_command(OUTPUT ... COMMAND Magnum::sceneconverter ...) +@endcode + +See @ref building, @ref cmake and the @ref Trade namespace for more +information. + +@section magnum-sceneconverter-usage Usage + +@code{.sh} +magnum-sceneconverter [-h|--help] [--importer IMPORTER] [--plugin-dir DIR] + [-i|--importer-options key=val,key2=val2,…] [--info] [--] input +@endcode + +Arguments: + +- `input` --- input file +- `-h`, `--help` --- display this help message and exit +- `--importer IMPORTER` --- scene importer plugin (default: + @ref Trade::AnySceneImporter "AnySceneImporter") +- `--plugin-dir DIR` --- override base plugin dir +- `-i`, `--importer-options key=val,key2=val2,…` --- configuration options to + pass to the importer +- `--info` --- print info about the input file and exit + +If `--info` is given, the utility will print information about all meshes +and images present in the file. **This option is currently mandatory.** + +The `-i` / `--importer-options` argument accepts a comma-separated list of +key/value pairs to set in the importer plugin configuration. If the `=` +character is omitted, it's equivalent to saying `key=true`. + +@see @ref magnum-imageconverter +*/ +} + +using namespace Magnum; + +int main(int argc, char** argv) { + Utility::Arguments args; + args.addArgument("input").setHelp("input", "input file") + .addOption("importer", "AnySceneImporter").setHelp("importer", "scene importer plugin") + .addOption("plugin-dir").setHelp("plugin-dir", "override base plugin dir", "DIR") + .addOption('i', "importer-options").setHelp("importer-options", "configuration options to pass to the importer", "key=val,key2=val2,…") + .addBooleanOption("info").setHelp("info", "print info about the input file and exit") + /** @todo add the parse error callback from imageconverter once there's + an output argument, also remove the "mandatory" from all docs */ + .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. This option is currently mandatory. + +The -i / --importer-options argument accepts a comma-separated list of +key/value pairs to set in the importer plugin configuration. If the = character +is omitted, it's equivalent to saying key=true.)") + .parse(argc, argv); + + PluginManager::Manager importerManager{ + args.value("plugin-dir").empty() ? std::string{} : + Utility::Directory::join(args.value("plugin-dir"), Trade::AbstractImporter::pluginSearchPaths()[0])}; + + Containers::Pointer importer = importerManager.loadAndInstantiate(args.value("importer")); + if(!importer) { + Debug{} << "Available importer plugins:" << Utility::String::join(importerManager.aliasList(), ", "); + return 1; + } + + /* Set options, if passed */ + Trade::Implementation::setOptions(*importer, args.value("importer-options")); + + /* Print file info, if requested */ + if(args.isSet("info")) { + /* Open the file, but don't fail when an image can't be opened */ + if(!importer->openFile(args.value("input"))) { + Error() << "Cannot open file" << args.value("input"); + return 3; + } + + if(!importer->meshCount() && !importer->image1DCount() && !importer->image2DCount() && !importer->image2DCount()) { + Debug{} << "No meshes or images found."; + return 0; + } + + struct MeshAttributeInfo { + std::size_t offset; + UnsignedInt stride, arraySize; + Trade::MeshAttribute name; + std::string customName; + VertexFormat format; + }; + + struct MeshInfo { + UnsignedInt mesh, level; + MeshPrimitive primitive; + UnsignedInt indexCount, vertexCount; + MeshIndexType indexType; + Containers::Array attributes; + std::size_t indexDataSize, vertexDataSize; + std::string name; + }; + + /* Parse everything first to avoid errors interleaved with output */ + bool error = false; + Containers::Array meshInfos; + for(UnsignedInt i = 0; i != importer->meshCount(); ++i) { + for(UnsignedInt j = 0; j != importer->meshLevelCount(i); ++j) { + Containers::Optional mesh = importer->mesh(i, j); + if(!mesh) { + error = true; + continue; + } + + MeshInfo info{}; + info.mesh = i; + info.level = j; + info.primitive = mesh->primitive(); + info.vertexCount = mesh->vertexCount(); + info.vertexDataSize = mesh->vertexData().size(); + if(!j) info.name = importer->meshName(i); + if(mesh->isIndexed()) { + info.indexCount = mesh->indexCount(); + info.indexType = mesh->indexType(); + info.indexDataSize = mesh->indexData().size(); + } + for(UnsignedInt k = 0; k != mesh->attributeCount(); ++k) { + const Trade::MeshAttribute name = mesh->attributeName(k); + arrayAppend(info.attributes, Containers::InPlaceInit, + mesh->attributeOffset(k), + mesh->attributeStride(k), + mesh->attributeArraySize(k), + name, Trade::isMeshAttributeCustom(name) ? + importer->meshAttributeName(name) : "", + mesh->attributeFormat(k)); + } + + std::sort(info.attributes.begin(), info.attributes.end(), + [](const MeshAttributeInfo& a, const MeshAttributeInfo& b) { + return a.offset < b.offset; + }); + + arrayAppend(meshInfos, std::move(info)); + } + } + + Containers::Array imageInfos = + Trade::Implementation::imageInfo(*importer, error); + + for(const MeshInfo& info: meshInfos) { + Debug d; + if(info.level == 0) { + d << "Mesh" << info.mesh << Debug::nospace << ":"; + if(!info.name.empty()) d << info.name; + d << Debug::newline; + } + d << " Level" << info.level << Debug::nospace << ":" + << info.primitive << Debug::nospace << "," << info.vertexCount + << "vertices (" << Debug::nospace + << Utility::formatString("{:.1f}", info.vertexDataSize/1024.0f) + << "kB)"; + if(info.indexType != MeshIndexType{}) { + d << Debug::newline << " " << info.indexCount << "indices @" + << info.indexType << "(" << Debug::nospace + << Utility::formatString("{:.1f}", info.indexDataSize/1024.0f) + << "kB)"; + } + + for(const MeshAttributeInfo& attribute: info.attributes) { + d << Debug::newline << " Offset" << attribute.offset + << Debug::nospace << ":" << attribute.name; + if(Trade::isMeshAttributeCustom(attribute.name)) { + d << "(" << Debug::nospace << attribute.customName + << Debug::nospace << ")"; + } + d << "@" << attribute.format << Debug::nospace << ", stride" + << attribute.stride; + } + } + for(const Trade::Implementation::ImageInfo& info: imageInfos) { + Debug d; + if(info.level == 0) { + d << "Image" << info.image << Debug::nospace << ":"; + if(!info.name.empty()) d << info.name; + d << Debug::newline; + } + d << " Level" << info.level << Debug::nospace << ":"; + if(info.compressed) d << info.compressedFormat; + else d << info.format; + if(info.size.z()) d << info.size; + else if(info.size.y()) d << info.size.xy(); + else d << Math::Vector<1, Int>(info.size.x()); + } + + return error ? 1 : 0; + } + + Error{} << "Sorry, only the --info option is currently implemented"; + return 6; +}