Skip to content

Cli reader options #1860

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

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
Expand Up @@ -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", "", "Enforce a specific reader", "<reader>", "1"},
{ "list-bindings", "", "Print the list of interaction bindings and exits, ignored with `--no-render`, only considers the first file group.", "", "" },
{ "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" },
Expand Down
1 change: 1 addition & 0 deletions application/F3DOptionsTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
{ "point-sprites", "model.point_sprites.enable" },
{ "point-sprites-type", "model.point_sprites.type" },
Expand Down
1 change: 1 addition & 0 deletions doc/user/OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Options|Type<br>Default|Description
-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`.
\-\-reader=\<reader\>|string<br>-|Enforce a specific reader.
\-\-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.
Expand Down
3 changes: 3 additions & 0 deletions library/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"orthographic": {
"type": "bool"
}
},
"force_reader": {
"type": "string"
}
},
"render": {
Expand Down
4 changes: 3 additions & 1 deletion library/private/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "reader.h"

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

namespace f3d
Expand Down Expand Up @@ -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_view> forceReader);

/**
* Get the list of the registered plugins
Expand Down
10 changes: 7 additions & 3 deletions library/src/factory.cxx.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ 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_view> forceReader)
{
int bestScore = -1;
reader* bestReader = nullptr;
Expand All @@ -49,7 +49,11 @@ reader* factory::getReader(const std::string& fileName)
{
for (auto r : p->getReaders())
{
if (r->getScore() > bestScore && r->canRead(fileName))
if (forceReader.has_value() && r->getName() == *forceReader)
{
return r->canRead(fileName) ? r.get() : nullptr;
}
if (r->canRead(fileName) && r->getScore() > bestScore)
{
bestScore = r->getScore();
bestReader = r.get();
Expand Down Expand Up @@ -99,4 +103,4 @@ bool factory::registerOnce(plugin* plug)
}
return false;
}
}
}
8 changes: 6 additions & 2 deletions library/src/scene_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -232,7 +234,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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe improve this log to dinstinguish between:

"Found a reader for .."

"Forcing BLABLA reader for"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and maybe the exception below should also be improved, to dinstinguish when a reader was not found vs when the forced reader did not exists at all.

Expand Down Expand Up @@ -314,7 +317,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;
}

//----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions library/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ list(APPEND libf3dSDKTests_list
TestSDKMultiColoring.cxx
TestSDKOptions.cxx
TestSDKOptionsIO.cxx
TestSDKReaderSelection.cxx
TestSDKRenderFinalShader.cxx
TestSDKUtils.cxx
TestSDKWindowAuto.cxx
Expand Down
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