mirror of https://github.com/mosra/magnum.git
Browse Source
Similar to AnyImageImporter, but for whole scenes with meshes, objects etc.pull/205/head
9 changed files with 548 additions and 0 deletions
@ -0,0 +1,152 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <Corrade/PluginManager/Manager.h> |
||||
#include <Corrade/Utility/Assert.h> |
||||
#include <Corrade/Utility/String.h> |
||||
|
||||
#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<AbstractImporter>& 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<AbstractImporter> importer = static_cast<PluginManager::Manager<AbstractImporter>*>(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<SceneData> 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<LightData> 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<CameraData> 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<ObjectData2D> 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<ObjectData3D> 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<MeshData2D> 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<MeshData3D> 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<AbstractMaterialData> 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<TextureData> 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<ImageData1D> 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<ImageData2D> 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<ImageData3D> AnySceneImporter::doImage3D(const UnsignedInt id) { return _in->image3D(id); } |
||||
|
||||
}} |
||||
@ -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š <mosra@centrum.cz> |
||||
|
||||
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 <Magnum/Trade/AbstractImporter.h> |
||||
|
||||
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<AbstractImporter>& 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<SceneData> doScene(UnsignedInt id) override; |
||||
|
||||
UnsignedInt doLightCount() const override; |
||||
Int doLightForName(const std::string& name) override; |
||||
std::string doLightName(UnsignedInt id) override; |
||||
std::optional<LightData> doLight(UnsignedInt id) override; |
||||
|
||||
UnsignedInt doCameraCount() const override; |
||||
Int doCameraForName(const std::string& name) override; |
||||
std::string doCameraName(UnsignedInt id) override; |
||||
std::optional<CameraData> doCamera(UnsignedInt id) override; |
||||
|
||||
UnsignedInt doObject2DCount() const override; |
||||
Int doObject2DForName(const std::string& name) override; |
||||
std::string doObject2DName(UnsignedInt id) override; |
||||
std::unique_ptr<ObjectData2D> doObject2D(UnsignedInt id) override; |
||||
|
||||
UnsignedInt doObject3DCount() const override; |
||||
Int doObject3DForName(const std::string& name) override; |
||||
std::string doObject3DName(UnsignedInt id) override; |
||||
std::unique_ptr<ObjectData3D> doObject3D(UnsignedInt id) override; |
||||
|
||||
UnsignedInt doMesh2DCount() const override; |
||||
Int doMesh2DForName(const std::string& name) override; |
||||
std::string doMesh2DName(UnsignedInt id) override; |
||||
std::optional<MeshData2D> doMesh2D(UnsignedInt id) override; |
||||
|
||||
UnsignedInt doMesh3DCount() const override; |
||||
Int doMesh3DForName(const std::string& name) override; |
||||
std::string doMesh3DName(UnsignedInt id) override; |
||||
std::optional<MeshData3D> doMesh3D(UnsignedInt id) override; |
||||
|
||||
UnsignedInt doMaterialCount() const override; |
||||
Int doMaterialForName(const std::string& name) override; |
||||
std::string doMaterialName(UnsignedInt id) override; |
||||
std::unique_ptr<AbstractMaterialData> doMaterial(UnsignedInt id) override; |
||||
|
||||
UnsignedInt doTextureCount() const override; |
||||
Int doTextureForName(const std::string& name) override; |
||||
std::string doTextureName(UnsignedInt id) override; |
||||
std::optional<TextureData> doTexture(UnsignedInt id) override; |
||||
|
||||
UnsignedInt doImage1DCount() const override; |
||||
Int doImage1DForName(const std::string& name) override; |
||||
std::string doImage1DName(UnsignedInt id) override; |
||||
std::optional<ImageData1D> doImage1D(UnsignedInt id) override; |
||||
|
||||
UnsignedInt doImage2DCount() const override; |
||||
Int doImage2DForName(const std::string& name) override; |
||||
std::string doImage2DName(UnsignedInt id) override; |
||||
std::optional<ImageData2D> doImage2D(UnsignedInt id) override; |
||||
|
||||
UnsignedInt doImage3DCount() const override; |
||||
Int doImage3DForName(const std::string& name) override; |
||||
std::string doImage3DName(UnsignedInt id) override; |
||||
std::optional<ImageData3D> doImage3D(UnsignedInt id) override; |
||||
|
||||
private: |
||||
std::unique_ptr<AbstractImporter> _in; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,58 @@
|
||||
# |
||||
# This file is part of Magnum. |
||||
# |
||||
# Copyright © 2010, 2011, 2012, 2013, 2014 |
||||
# Vladimír Vondruš <mosra@centrum.cz> |
||||
# |
||||
# 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 |
||||
$<TARGET_OBJECTS:AnySceneImporterObjects> |
||||
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_OBJECTS:AnySceneImporterObjects>) |
||||
target_link_libraries(MagnumAnySceneImporterTestLib ${MAGNUM_LIBRARIES}) |
||||
add_subdirectory(Test) |
||||
endif() |
||||
@ -0,0 +1,34 @@
|
||||
# |
||||
# This file is part of Magnum. |
||||
# |
||||
# Copyright © 2010, 2011, 2012, 2013, 2014 |
||||
# Vladimír Vondruš <mosra@centrum.cz> |
||||
# |
||||
# 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) |
||||
@ -0,0 +1,97 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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 <sstream> |
||||
#include <Corrade/TestSuite/Tester.h> |
||||
#include <Corrade/PluginManager/Manager.h> |
||||
|
||||
#include "Magnum/Trade/ImageData.h" |
||||
#include <Trade/MeshData3D.h> |
||||
|
||||
#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<AbstractImporter> _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<MeshData3D> 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<MeshData3D> 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) |
||||
@ -0,0 +1,33 @@
|
||||
/* |
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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}" |
||||
@ -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 |
||||
@ -0,0 +1,29 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014 |
||||
Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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") |
||||
Loading…
Reference in new issue