Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cli reader options #1860

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions application/F3DOptionsTools.cxx
Original file line number Diff line number Diff line change
@@ -65,6 +65,7 @@ static inline const std::array<CLIGroup, 8> CLIOptions = {{
{ "no-background", "", "No background when render to file", "<bool>", "1" },
{ "help", "h", "Print help", "", "" }, { "version", "", "Print version details", "", "" },
{ "list-readers", "", "Print the list of readers", "", "" },
{ "force-reader", "", "Force a specific reader to be used, disrigarding the file extension", "<reader>", "1"},
{ "list-bindings", "", "Print the list of interaction bindings and exits, ignored with `--no-render`, only considers the first file group.", "<bool>", "1" },
{ "config", "", "Specify the configuration file to use. absolute/relative path or filename/filestem to search in configuration file locations", "<filePath/filename/fileStem>", "" },
{ "no-config", "", "Do not read the configuration file", "<bool>", "1" },
1 change: 1 addition & 0 deletions application/F3DOptionsTools.h
Original file line number Diff line number Diff line change
@@ -80,6 +80,7 @@ static inline const std::map<std::string_view, std::string_view> LibOptionsNames
{ "animation-autoplay", "scene.animation.autoplay" },
{ "animation-index", "scene.animation.index" },
{ "animation-speed-factor", "scene.animation.speed_factor" },
{ "force-reader", "scene.force_reader" },
{ "font-file", "ui.font_file" },
{ "font-scale", "ui.scale" },
{ "point-sprites", "model.point_sprites.enable" },
10 changes: 10 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1159,6 +1159,16 @@ if(F3D_PLUGIN_BUILD_ALEMBIC AND F3D_PLUGIN_BUILD_ASSIMP)
f3d_test(NAME TestReadersListMultiplePlugins ARGS --list-readers --load-plugins=assimp,alembic NO_BASELINE REGEXP_FAIL "Plugin failed to load")
endif()

if(F3D_PLUGIN_BUILD_EXODUS)
f3d_test(NAME TestForceReaderExodusFail DATA BoxAnimated.gltf ARGS --load-plugins=exodus --force-reader=ExodusII NO_BASELINE REGEXP "is not a file of a supported file format|failed to load scene")
f3d_test(NAME TestForceReaderExodusPass DATA disk_out_ref.ex2 ARGS --load-plugins=exodus --force-reader=ExodusII NO_BASELINE REGEXP_FAIL "is not a file of a supported file format|failed to load scene")
endif()

if(F3D_PLUGIN_BUILD_DRACO)
f3d_test(NAME TestForceReaderGLTFDraco DATA BoxAnimated.gltf ARGS --load-plugins=draco --force-reader=GLTFDraco NO_BASELINE REGEXP_FAIL "is not a file of a supported file format|failed to load scene")
f3d_test(NAME TestForceReaderGLTF DATA BoxAnimated.gltf ARGS --load-plugins=draco --force-reader=GLTF NO_BASELINE REGEXP_FAIL "is not a file of a supported file format|failed to load scene")
endif()

# Test bindings-list display
f3d_test(NAME TestBindingsList ARGS --list-bindings REGEXP "Any.5 Toggle Orthographic Projection")

1 change: 1 addition & 0 deletions doc/libf3d/OPTIONS.md
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ See the [APIs](#APIs) details below for more info.
| scene.animation.time | double<br>optional<br>load | Set the animation time to load. | \-\-animation-time |
| scene.camera.index | int<br>optional<br>load | Select the scene camera to use when available in the file.<br>The default scene always uses automatic camera. | \-\-camera-index |
| scene.up_direction | direction<br>+Y<br>load | Define the Up direction. It impacts the grid, the axis, the HDRI and the camera. | \-\-up |
| scene.force_reader | string<br>optional<br>load | Force a specific reader to be used, disregarding the file extension. | \-\-force-reader |
| scene.camera.orthographic | bool<br>optional<br>load | Set to true to force orthographic projection. Model specified by default, which is false if not specified. | \-\-camera\-orthographic |

## Interactor Options
1 change: 1 addition & 0 deletions doc/user/OPTIONS.md
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ F3D behavior can be fully controlled from the command line using the following o
| -h, \-\-help | | Print _help_ and exit. Ignore `--verbose`. |
| \-\-version | | Show _version_ information and exit. Ignore `--verbose`. |
| \-\-list-readers | | List available _readers_ and exit. Ignore `--verbose`. |
| \-\-force-reader=\<reader\> | string<br>- | Force a specific reader to be used, disregarding the file extension. |
| \-\-list-bindings | | List available _bindings_ and exit. Ignore `--verbose`. |
| \-\-list-rendering-backends | | List available _rendering backends_ and exit. Ignore `--verbose`. |
| \-\-config=\<config file path/name/stem\> | string<br>config | Specify the [configuration file](CONFIGURATION_FILE.md) to use. Supports absolute/relative path but also filename/filestem to search for in standard configuration file locations. |
3 changes: 3 additions & 0 deletions library/options.json
Original file line number Diff line number Diff line change
@@ -25,6 +25,9 @@
"orthographic": {
"type": "bool"
}
},
"force_reader": {
"type": "string"
}
},
"render": {
10 changes: 5 additions & 5 deletions library/plugin/plugin.h
Original file line number Diff line number Diff line change
@@ -37,31 +37,31 @@ class plugin
/**
* Get the name of this plugin
*/
const std::string& getName()
const std::string& getName() const
{
return this->Name;
}

/**
* Get the description of this plugin
*/
const std::string& getDescription()
const std::string& getDescription() const
{
return this->Description;
}

/**
* Get the version of this plugin
*/
const std::string& getVersion()
const std::string& getVersion() const
{
return this->Version;
}

/**
* Get the list of readers created by this plugin
*/
const std::vector<std::shared_ptr<reader>>& getReaders()
const std::vector<std::shared_ptr<reader>>& getReaders() const
{
return this->Readers;
}
@@ -71,7 +71,7 @@ class plugin
* Set/Get the origin of this plugin, usually static, system or an actual path
* Set by the engine.
*/
const std::string& getOrigin()
const std::string& getOrigin() const
{
return this->Origin;
}
4 changes: 3 additions & 1 deletion library/private/factory.h
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@
#include "reader.h"

#include <map>
#include <optional>
#include <string_view>
#include <vector>

namespace f3d
@@ -44,7 +46,7 @@ class factory
/**
* Get the reader that can read the given file, nullptr if none
*/
reader* getReader(const std::string& fileName);
reader* getReader(const std::string& fileName, std::optional<std::string> forceReader);

/**
* Get the list of the registered plugins
13 changes: 10 additions & 3 deletions library/src/factory.cxx.in
Original file line number Diff line number Diff line change
@@ -40,16 +40,23 @@ factory::plugin_initializer_t factory::getStaticInitializer(const std::string& p
}

//----------------------------------------------------------------------------
reader* factory::getReader(const std::string& fileName)
reader* factory::getReader(const std::string& fileName, std::optional<std::string> forceReader)
{
int bestScore = -1;
reader* bestReader = nullptr;

for (const auto& plugin : this->Plugins)
for (const auto* plugin : this->Plugins)
{
for (const auto& reader : plugin->getReaders())
{
if (reader->getScore() > bestScore && reader->canRead(fileName))
if (forceReader.has_value())
{
if (reader->getName() == *forceReader)
{
return reader.get();
}
}
else if (reader->getScore() > bestScore && reader->canRead(fileName))
{
bestScore = reader->getScore();
bestReader = reader.get();
8 changes: 6 additions & 2 deletions library/src/scene_impl.cxx
Original file line number Diff line number Diff line change
@@ -4,13 +4,15 @@
#include "interactor_impl.h"
#include "log.h"
#include "options.h"
#include "scene.h"
#include "window_impl.h"

#include "factory.h"
#include "vtkF3DGenericImporter.h"
#include "vtkF3DMemoryMesh.h"
#include "vtkF3DMetaImporter.h"

#include <optional>
#include <vtkCallbackCommand.h>
#include <vtkProgressBarRepresentation.h>
#include <vtkProgressBarWidget.h>
@@ -240,7 +242,8 @@ scene& scene_impl::add(const std::vector<fs::path>& filePaths)
}

// Recover the importer for the provided file path
f3d::reader* reader = f3d::factory::instance()->getReader(filePath.string());
f3d::reader* reader = f3d::factory::instance()->getReader(
filePath.string(), this->Internals->Options.scene.force_reader);
if (reader)
{
log::debug(
@@ -322,7 +325,8 @@ scene& scene_impl::clear()
//----------------------------------------------------------------------------
bool scene_impl::supports(const fs::path& filePath)
{
return f3d::factory::instance()->getReader(filePath.string()) != nullptr;
return f3d::factory::instance()->getReader(
filePath.string(), this->Internals->Options.scene.force_reader) != nullptr;
}

//----------------------------------------------------------------------------
1 change: 1 addition & 0 deletions library/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ list(APPEND libf3dSDKTests_list
TestSDKMultiColoring.cxx
TestSDKOptions.cxx
TestSDKOptionsIO.cxx
TestSDKReaderSelection.cxx
TestSDKRenderFinalShader.cxx
TestSDKUtils.cxx
TestSDKWindowAuto.cxx
45 changes: 45 additions & 0 deletions library/testing/TestSDKReaderSelection.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "PseudoUnitTest.h"
#include "TestSDKHelpers.h"

#include <engine.h>
#include <log.h>
#include <scene.h>
#include <window.h>

namespace fs = std::filesystem;
int TestSDKReaderSelection(int argc, char* argv[])
{
PseudoUnitTest test;

f3d::log::setVerboseLevel(f3d::log::VerboseLevel::DEBUG);
f3d::engine::autoloadPlugins();

// Test file path setup
std::string monkey = std::string(argv[1]) + "data/red_translucent_monkey.gltf";

// Test default reader (no preference)
{
f3d::engine engine = f3d::engine::create(true);
f3d::scene& scene = engine.getScene();
test("add with a single path", [&]() { scene.add(fs::path(monkey)); });
}

// Test Draco reader; GLTF is by-default
{
f3d::engine engine = f3d::engine::create(true);
engine.getOptions().scene.force_reader = "GLTFDraco";
f3d::scene& scene = engine.getScene();
test("Draco reader works", [&]() { scene.add(fs::path(monkey)); });
test("Reader is GLTFDraco", engine.getOptions().scene.force_reader == "GLTFDraco");
}

// Test GLTF reader;
{
f3d::engine engine = f3d::engine::create(true);
engine.getOptions().scene.force_reader = "GLTF";
f3d::scene& scene = engine.getScene();
test("GLTF reader works", [&]() { scene.add(fs::path(monkey)); });
test("Reader is GLTF", engine.getOptions().scene.force_reader == "GLTF");
}
return test.result();
}
Loading
Oops, something went wrong.