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

Merged
merged 27 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
917db39
implemented reader option
0xfedcafe Jan 2, 2025
a039ed0
Merge branch 'f3d-app:master' into cli-reader-options
0xfedcafe Jan 2, 2025
c85a20c
added test & bugfix
0xfedcafe Jan 3, 2025
45ba1a9
spelling correction
0xfedcafe Jan 3, 2025
5b00fcb
reformat
0xfedcafe Jan 3, 2025
be829e3
Merge branch 'f3d-app:master' into cli-reader-options
0xfedcafe Jan 3, 2025
e916daf
force-reader to scene & fixes
0xfedcafe Jan 3, 2025
17c2dda
bugfix
0xfedcafe Jan 3, 2025
8e69e60
Merge branch 'f3d-app:master' into cli-reader-options
0xfedcafe Jan 14, 2025
bc26894
reader: Applied suggestions & refactor
0xfedcafe Jan 14, 2025
fc68b05
Merge branch 'master' into cli-reader-options
0xfedcafe Mar 3, 2025
d260c55
apllication tests for force-reader
0xfedcafe Mar 3, 2025
c93e954
reformat
0xfedcafe Mar 3, 2025
63c0456
test fix
0xfedcafe Mar 12, 2025
9a5bca2
Apply suggestions from code review
0xfedcafe Mar 13, 2025
4bb1ce4
Merge branch 'master' into cli-reader-options
0xfedcafe Mar 25, 2025
2db35e2
fix
0xfedcafe Mar 25, 2025
dbaf7ba
Removed unnecessary test
0xfedcafe Apr 21, 2025
d303d15
Merge branch 'f3d-app:master' into cli-reader-options
0xfedcafe May 26, 2025
cad1255
applied pr suggestions(improved error logging, corrected tests)
0xfedcafe May 26, 2025
5cfbd98
format
0xfedcafe May 26, 2025
e25b256
added sdk test, codestyle fix
0xfedcafe May 26, 2025
6a2dad4
Merge branch 'f3d-app:master' into cli-reader-options
0xfedcafe Jun 11, 2025
7141d9e
removed has_value, added reader name field in doc, fixed missed formats
0xfedcafe Jun 11, 2025
993e724
Update doc/user/OPTIONS.md
0xfedcafe Jun 11, 2025
34714af
prettier
0xfedcafe Jun 11, 2025
546f7ba
Merge branch 'cli-reader-options' of github.com:0xfedcafe/f3d into cl…
0xfedcafe Jun 11, 2025
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(
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