From 3fca35c81d176cfd53eb99d5db37a503a4e6de1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 23 Nov 2014 19:12:53 +0100 Subject: [PATCH] Added plugin AnySceneImporter. Similar to AnyImageImporter, but for whole scenes with meshes, objects etc. --- .../AnySceneImporter/AnySceneImporter.conf | 0 .../AnySceneImporter/AnySceneImporter.cpp | 152 ++++++++++++++++++ .../AnySceneImporter/AnySceneImporter.h | 135 ++++++++++++++++ .../AnySceneImporter/CMakeLists.txt | 58 +++++++ .../AnySceneImporter/Test/CMakeLists.txt | 34 ++++ .../AnySceneImporter/Test/Test.cpp | 97 +++++++++++ .../AnySceneImporter/Test/configure.h.cmake | 33 ++++ .../AnySceneImporter/Test/mesh.obj | 10 ++ .../AnySceneImporter/pluginRegistration.cpp | 29 ++++ 9 files changed, 548 insertions(+) create mode 100644 src/MagnumPlugins/AnySceneImporter/AnySceneImporter.conf create mode 100644 src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp create mode 100644 src/MagnumPlugins/AnySceneImporter/AnySceneImporter.h create mode 100644 src/MagnumPlugins/AnySceneImporter/CMakeLists.txt create mode 100644 src/MagnumPlugins/AnySceneImporter/Test/CMakeLists.txt create mode 100644 src/MagnumPlugins/AnySceneImporter/Test/Test.cpp create mode 100644 src/MagnumPlugins/AnySceneImporter/Test/configure.h.cmake create mode 100644 src/MagnumPlugins/AnySceneImporter/Test/mesh.obj create mode 100644 src/MagnumPlugins/AnySceneImporter/pluginRegistration.cpp diff --git a/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.conf b/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.conf new file mode 100644 index 000000000..e69de29bb diff --git a/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp b/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp new file mode 100644 index 000000000..5abca3132 --- /dev/null +++ b/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp @@ -0,0 +1,152 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + 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 "AnySceneImporter.h" + +#include +#include +#include + +#include "Magnum/Trade/AbstractMaterialData.h" +#include "Magnum/Trade/CameraData.h" +#include "Magnum/Trade/ImageData.h" +#include "Magnum/Trade/LightData.h" +#include "Magnum/Trade/MeshData2D.h" +#include "Magnum/Trade/MeshData3D.h" +#include "Magnum/Trade/ObjectData2D.h" +#include "Magnum/Trade/ObjectData3D.h" +#include "Magnum/Trade/SceneData.h" +#include "Magnum/Trade/TextureData.h" + +namespace Magnum { namespace Trade { + +AnySceneImporter::AnySceneImporter(PluginManager::Manager& manager): AbstractImporter{manager} {} + +AnySceneImporter::AnySceneImporter(PluginManager::AbstractManager& manager, std::string plugin): AbstractImporter{manager, std::move(plugin)} {} + +AnySceneImporter::~AnySceneImporter() = default; + +auto AnySceneImporter::doFeatures() const -> Features { return {}; } + +bool AnySceneImporter::doIsOpened() const { return !!_in; } + +void AnySceneImporter::doClose() { + _in = nullptr; +} + +void AnySceneImporter::doOpenFile(const std::string& filename) { + CORRADE_INTERNAL_ASSERT(manager()); + + /* Detect type from extension */ + std::string plugin; + if(Utility::String::endsWith(filename, ".obj")) + plugin = "ObjImporter"; + else if(Utility::String::endsWith(filename, ".dae")) + plugin = "ColladaImporter"; + else if(Utility::String::endsWith(filename, ".ply")) + plugin = "StanfordImporter"; + else { + Error() << "Trade::AnySceneImporter::openFile(): cannot determine type of file" << filename; + return; + } + + /* Try to load the plugin */ + if(!(manager()->load(plugin) & PluginManager::LoadState::Loaded)) { + Error() << "Trade::AnySceneImporter::openFile(): cannot load" << plugin << "plugin"; + return; + } + + /* Try to open the file (error output should be printed by the plugin + itself) */ + std::unique_ptr importer = static_cast*>(manager())->instance(plugin); + if(!importer->openFile(filename)) return; + + /* Success, save the instance */ + _in = std::move(importer); +} + +Int AnySceneImporter::doDefaultScene() { return _in->defaultScene(); } + +UnsignedInt AnySceneImporter::doSceneCount() const { return _in->sceneCount(); } +Int AnySceneImporter::doSceneForName(const std::string& name) { return _in->sceneForName(name); } +std::string AnySceneImporter::doSceneName(const UnsignedInt id) { return _in->sceneName(id); } +std::optional AnySceneImporter::doScene(const UnsignedInt id) { return _in->scene(id); } + +UnsignedInt AnySceneImporter::doLightCount() const { return _in->lightCount(); } +Int AnySceneImporter::doLightForName(const std::string& name) { return _in->lightForName(name); } +std::string AnySceneImporter::doLightName(const UnsignedInt id) { return _in->lightName(id); } +std::optional AnySceneImporter::doLight(const UnsignedInt id) { return _in->light(id); } + +UnsignedInt AnySceneImporter::doCameraCount() const { return _in->cameraCount(); } +Int AnySceneImporter::doCameraForName(const std::string& name) { return _in->cameraForName(name); } +std::string AnySceneImporter::doCameraName(const UnsignedInt id) { return _in->cameraName(id); } +std::optional AnySceneImporter::doCamera(const UnsignedInt id) { return _in->camera(id); } + +UnsignedInt AnySceneImporter::doObject2DCount() const { return _in->object2DCount(); } +Int AnySceneImporter::doObject2DForName(const std::string& name) { return _in->object2DForName(name); } +std::string AnySceneImporter::doObject2DName(const UnsignedInt id) { return _in->object2DName(id); } +std::unique_ptr AnySceneImporter::doObject2D(const UnsignedInt id) { return _in->object2D(id); } + +UnsignedInt AnySceneImporter::doObject3DCount() const { return _in->object3DCount(); } +Int AnySceneImporter::doObject3DForName(const std::string& name) { return _in->object3DForName(name); } +std::string AnySceneImporter::doObject3DName(const UnsignedInt id) { return _in->object3DName(id); } +std::unique_ptr AnySceneImporter::doObject3D(const UnsignedInt id) { return _in->object3D(id); } + +UnsignedInt AnySceneImporter::doMesh2DCount() const { return _in->mesh2DCount(); } +Int AnySceneImporter::doMesh2DForName(const std::string& name) { return _in->mesh2DForName(name); } +std::string AnySceneImporter::doMesh2DName(const UnsignedInt id) { return _in->mesh2DName(id); } +std::optional AnySceneImporter::doMesh2D(const UnsignedInt id) { return _in->mesh2D(id); } + +UnsignedInt AnySceneImporter::doMesh3DCount() const { return _in->mesh3DCount(); } +Int AnySceneImporter::doMesh3DForName(const std::string& name) { return _in->mesh3DForName(name); } +std::string AnySceneImporter::doMesh3DName(const UnsignedInt id) { return _in->mesh3DName(id); } +std::optional AnySceneImporter::doMesh3D(const UnsignedInt id) { return _in->mesh3D(id); } + +UnsignedInt AnySceneImporter::doMaterialCount() const { return _in->materialCount(); } +Int AnySceneImporter::doMaterialForName(const std::string& name) { return _in->materialForName(name); } +std::string AnySceneImporter::doMaterialName(const UnsignedInt id) { return _in->materialName(id); } +std::unique_ptr AnySceneImporter::doMaterial(const UnsignedInt id) { return _in->material(id); } + +UnsignedInt AnySceneImporter::doTextureCount() const { return _in->textureCount(); } +Int AnySceneImporter::doTextureForName(const std::string& name) { return _in->textureForName(name); } +std::string AnySceneImporter::doTextureName(const UnsignedInt id) { return _in->textureName(id); } +std::optional AnySceneImporter::doTexture(const UnsignedInt id) { return _in->texture(id); } + +UnsignedInt AnySceneImporter::doImage1DCount() const { return _in->image1DCount(); } +Int AnySceneImporter::doImage1DForName(const std::string& name) { return _in->image1DForName(name); } +std::string AnySceneImporter::doImage1DName(const UnsignedInt id) { return _in->image1DName(id); } +std::optional AnySceneImporter::doImage1D(const UnsignedInt id) { return _in->image1D(id); } + +UnsignedInt AnySceneImporter::doImage2DCount() const { return _in->image2DCount(); } +Int AnySceneImporter::doImage2DForName(const std::string& name) { return _in->image2DForName(name); } +std::string AnySceneImporter::doImage2DName(const UnsignedInt id) { return _in->image2DName(id); } +std::optional AnySceneImporter::doImage2D(const UnsignedInt id) { return _in->image2D(id); } + +UnsignedInt AnySceneImporter::doImage3DCount() const { return _in->image3DCount(); } +Int AnySceneImporter::doImage3DForName(const std::string& name) { return _in->image3DForName(name); } +std::string AnySceneImporter::doImage3DName(const UnsignedInt id) { return _in->image3DName(id); } +std::optional AnySceneImporter::doImage3D(const UnsignedInt id) { return _in->image3D(id); } + +}} diff --git a/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.h b/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.h new file mode 100644 index 000000000..14501ca2c --- /dev/null +++ b/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.h @@ -0,0 +1,135 @@ +#ifndef Magnum_Trade_AnySceneImporter_h +#define Magnum_Trade_AnySceneImporter_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + 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. +*/ + +/** @file + * @brief Class @ref Magnum::Trade::AnySceneImporter + */ + +#include + +namespace Magnum { namespace Trade { + +/** +@brief Any scene importer plugin + +Detects file type based on file extension, loads corresponding plugin and then +tries to open the file with it. Supported formats: + +- OBJ (`*.obj`), loaded with @ref ObjImporter or any other plugin that + provides it +- COLLADA (`*.dae`), loaded with @ref ColladaImporter or any other plugin + that provides it +- Stanford (`*.ply`), loaded with @ref StanfordImporter or any other plugin + that provides it + +Only loading from files is supported. +*/ +class AnySceneImporter: public AbstractImporter { + public: + /** @brief Constructor with access to plugin manager */ + explicit AnySceneImporter(PluginManager::Manager& manager); + + /** @brief Plugin manager constructor */ + explicit AnySceneImporter(PluginManager::AbstractManager& manager, std::string plugin); + + ~AnySceneImporter(); + + private: + Features doFeatures() const override; + bool doIsOpened() const override; + void doClose() override; + void doOpenFile(const std::string& filename) override; + + Int doDefaultScene() override; + + UnsignedInt doSceneCount() const override; + Int doSceneForName(const std::string& name) override; + std::string doSceneName(UnsignedInt id) override; + std::optional doScene(UnsignedInt id) override; + + UnsignedInt doLightCount() const override; + Int doLightForName(const std::string& name) override; + std::string doLightName(UnsignedInt id) override; + std::optional doLight(UnsignedInt id) override; + + UnsignedInt doCameraCount() const override; + Int doCameraForName(const std::string& name) override; + std::string doCameraName(UnsignedInt id) override; + std::optional doCamera(UnsignedInt id) override; + + UnsignedInt doObject2DCount() const override; + Int doObject2DForName(const std::string& name) override; + std::string doObject2DName(UnsignedInt id) override; + std::unique_ptr doObject2D(UnsignedInt id) override; + + UnsignedInt doObject3DCount() const override; + Int doObject3DForName(const std::string& name) override; + std::string doObject3DName(UnsignedInt id) override; + std::unique_ptr doObject3D(UnsignedInt id) override; + + UnsignedInt doMesh2DCount() const override; + Int doMesh2DForName(const std::string& name) override; + std::string doMesh2DName(UnsignedInt id) override; + std::optional doMesh2D(UnsignedInt id) override; + + UnsignedInt doMesh3DCount() const override; + Int doMesh3DForName(const std::string& name) override; + std::string doMesh3DName(UnsignedInt id) override; + std::optional doMesh3D(UnsignedInt id) override; + + UnsignedInt doMaterialCount() const override; + Int doMaterialForName(const std::string& name) override; + std::string doMaterialName(UnsignedInt id) override; + std::unique_ptr doMaterial(UnsignedInt id) override; + + UnsignedInt doTextureCount() const override; + Int doTextureForName(const std::string& name) override; + std::string doTextureName(UnsignedInt id) override; + std::optional doTexture(UnsignedInt id) override; + + UnsignedInt doImage1DCount() const override; + Int doImage1DForName(const std::string& name) override; + std::string doImage1DName(UnsignedInt id) override; + std::optional doImage1D(UnsignedInt id) override; + + UnsignedInt doImage2DCount() const override; + Int doImage2DForName(const std::string& name) override; + std::string doImage2DName(UnsignedInt id) override; + std::optional doImage2D(UnsignedInt id) override; + + UnsignedInt doImage3DCount() const override; + Int doImage3DForName(const std::string& name) override; + std::string doImage3DName(UnsignedInt id) override; + std::optional doImage3D(UnsignedInt id) override; + + private: + std::unique_ptr _in; +}; + +}} + +#endif diff --git a/src/MagnumPlugins/AnySceneImporter/CMakeLists.txt b/src/MagnumPlugins/AnySceneImporter/CMakeLists.txt new file mode 100644 index 000000000..544a4a073 --- /dev/null +++ b/src/MagnumPlugins/AnySceneImporter/CMakeLists.txt @@ -0,0 +1,58 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014 +# 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. +# + +set(AnySceneImporter_SRCS + AnySceneImporter.cpp) + +set(AnySceneImporter_HEADERS + AnySceneImporter.h) + +# Objects shared between plugin and test library +add_library(AnySceneImporterObjects OBJECT + ${AnySceneImporter_SRCS} + ${AnySceneImporter_HEADERS}) +set_target_properties(AnySceneImporterObjects PROPERTIES COMPILE_FLAGS "-DAnySceneImporterObjects_EXPORTS") +if(NOT BUILD_STATIC OR BUILD_STATIC_PIC) + set_target_properties(AnySceneImporterObjects PROPERTIES POSITION_INDEPENDENT_CODE ON) +endif() + +# AnySceneImporter plugin +add_plugin(AnySceneImporter ${MAGNUM_PLUGINS_IMPORTER_DEBUG_INSTALL_DIR} ${MAGNUM_PLUGINS_IMPORTER_RELEASE_INSTALL_DIR} + AnySceneImporter.conf + $ + pluginRegistration.cpp) +if(BUILD_STATIC_PIC) + set_target_properties(AnySceneImporter PROPERTIES POSITION_INDEPENDENT_CODE ON) +endif() + +target_link_libraries(AnySceneImporter ${MAGNUM_LIBRARIES}) + +install(FILES ${AnySceneImporter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/AnySceneImporter) + +if(BUILD_TESTS) + add_library(MagnumAnySceneImporterTestLib STATIC $) + target_link_libraries(MagnumAnySceneImporterTestLib ${MAGNUM_LIBRARIES}) + add_subdirectory(Test) +endif() diff --git a/src/MagnumPlugins/AnySceneImporter/Test/CMakeLists.txt b/src/MagnumPlugins/AnySceneImporter/Test/CMakeLists.txt new file mode 100644 index 000000000..375e9eb4d --- /dev/null +++ b/src/MagnumPlugins/AnySceneImporter/Test/CMakeLists.txt @@ -0,0 +1,34 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014 +# 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_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) + +set(OBJ_FILE ${CMAKE_SOURCE_DIR}/src/MagnumPlugins/AnySceneImporter/Test/mesh.obj) +set(PLY_FILE ${CMAKE_SOURCE_DIR}/src/MagnumPlugins/StanfordImporter/Test/common.ply) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/configure.h) + +corrade_add_test(AnySceneImporterTest Test.cpp LIBRARIES MagnumAnySceneImporterTestLib) diff --git a/src/MagnumPlugins/AnySceneImporter/Test/Test.cpp b/src/MagnumPlugins/AnySceneImporter/Test/Test.cpp new file mode 100644 index 000000000..6a04674b8 --- /dev/null +++ b/src/MagnumPlugins/AnySceneImporter/Test/Test.cpp @@ -0,0 +1,97 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + 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 "Magnum/Trade/ImageData.h" +#include + +#include "MagnumPlugins/AnySceneImporter/AnySceneImporter.h" + +#include "configure.h" + +namespace Magnum { namespace Trade { namespace Test { + +class AnySceneImporterTest: public TestSuite::Tester { + public: + explicit AnySceneImporterTest(); + + void obj(); + void ply(); + + void unknown(); + + private: + PluginManager::Manager _manager; +}; + +AnySceneImporterTest::AnySceneImporterTest(): _manager{MAGNUM_PLUGINS_IMPORTER_DIR} { + addTests({&AnySceneImporterTest::obj, + &AnySceneImporterTest::ply, + + &AnySceneImporterTest::unknown}); +} + +void AnySceneImporterTest::obj() { + if(_manager.loadState("ObjImporter") == PluginManager::LoadState::NotFound) + CORRADE_SKIP("ObjImporter plugin not found, cannot test"); + + AnySceneImporter importer{_manager}; + CORRADE_VERIFY(importer.openFile(OBJ_FILE)); + + /* Check only size, as it is good enough proof that it is working */ + std::optional mesh = importer.mesh3D(0); + CORRADE_VERIFY(mesh); + CORRADE_COMPARE(mesh->positions(0).size(), 3); +} + +void AnySceneImporterTest::ply() { + if(_manager.loadState("StanfordImporter") == PluginManager::LoadState::NotFound) + CORRADE_SKIP("StanfordImporter plugin not found, cannot test"); + + AnySceneImporter importer{_manager}; + CORRADE_VERIFY(importer.openFile(PLY_FILE)); + + /* Check only size, as it is good enough proof that it is working */ + std::optional mesh = importer.mesh3D(0); + CORRADE_VERIFY(mesh); + CORRADE_COMPARE(mesh->positions(0).size(), 5); +} + +void AnySceneImporterTest::unknown() { + std::ostringstream output; + Error::setOutput(&output); + + AnySceneImporter importer{_manager}; + CORRADE_VERIFY(!importer.openFile("mesh.stl")); + + CORRADE_COMPARE(output.str(), "Trade::AnySceneImporter::openFile(): cannot determine type of file mesh.stl\n"); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Trade::Test::AnySceneImporterTest) diff --git a/src/MagnumPlugins/AnySceneImporter/Test/configure.h.cmake b/src/MagnumPlugins/AnySceneImporter/Test/configure.h.cmake new file mode 100644 index 000000000..4a9940066 --- /dev/null +++ b/src/MagnumPlugins/AnySceneImporter/Test/configure.h.cmake @@ -0,0 +1,33 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + 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. +*/ + +#ifdef CORRADE_IS_DEBUG_BUILD +#define MAGNUM_PLUGINS_IMPORTER_DIR "${MAGNUM_PLUGINS_IMPORTER_DEBUG_DIR}" +#else +#define MAGNUM_PLUGINS_IMPORTER_DIR "${MAGNUM_PLUGINS_IMPORTER_DIR}" +#endif + +#define OBJ_FILE "${OBJ_FILE}" +#define PLY_FILE "${PLY_FILE}" diff --git a/src/MagnumPlugins/AnySceneImporter/Test/mesh.obj b/src/MagnumPlugins/AnySceneImporter/Test/mesh.obj new file mode 100644 index 000000000..c5991619c --- /dev/null +++ b/src/MagnumPlugins/AnySceneImporter/Test/mesh.obj @@ -0,0 +1,10 @@ +# Positions +v 0.5 2 3 +v 0 1.5 1 +v 2 3 5.0 + +# Points +p 1 +p 3 +p 2 +p 1 diff --git a/src/MagnumPlugins/AnySceneImporter/pluginRegistration.cpp b/src/MagnumPlugins/AnySceneImporter/pluginRegistration.cpp new file mode 100644 index 000000000..010663b6f --- /dev/null +++ b/src/MagnumPlugins/AnySceneImporter/pluginRegistration.cpp @@ -0,0 +1,29 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + 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 "AnySceneImporter.h" + +CORRADE_PLUGIN_REGISTER(AnySceneImporter, Magnum::Trade::AnySceneImporter, + "cz.mosra.magnum.Trade.AbstractImporter/0.3")