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 all 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", "", "Force a specific reader to be used, disregarding 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" },
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" },
{ "font-scale", "ui.scale" },
{ "point-sprites", "model.point_sprites.enable" },
Expand Down
10 changes: 9 additions & 1 deletion application/F3DStarter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,15 @@ void F3DStarter::LoadFileGroup(
}
else
{
f3d::log::warn(tmpPath.string(), " is not a file of a supported file format");
auto forceReader = this->Internals->LibOptions.scene.force_reader;
if (forceReader)
{
f3d::log::warn("Forced reader ", *forceReader, " doesn't exist");
}
else
{
f3d::log::warn(tmpPath.string(), " is not a file of a supported file format");
}
unsupported = true;
}
}
Expand Down
11 changes: 11 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,17 @@ 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(VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240707)
f3d_test(NAME TestForceReaderFail DATA suzanne.stl ARGS --force-reader=OBJ NO_BASELINE REGEXP "is not supported by the given forced reader")
f3d_test(NAME TestForceReaderPass DATA suzanne.stl ARGS --force-reader=STL NO_BASELINE REGEXP_FAIL "failed to load scene")
f3d_test(NAME TestForceReaderInvalid DATA suzanne.stl ARGS --force-reader=INVALID NO_BASELINE REGEXP "Forced reader .* doesn't exist")

if(F3D_PLUGIN_BUILD_DRACO)
f3d_test(NAME TestForceReaderGLTFDraco DATA BoxAnimated.gltf ARGS --load-plugins=draco --force-reader=GLTFDraco NO_BASELINE REGEXP_FAIL "failed to load scene")
f3d_test(NAME TestForceReaderGLTFDracoIntoGLTF DATA Box_draco.gltf ARGS --load-plugins=draco --force-reader=GLTF NO_BASELINE REGEXP "failed to load scene")
endif()
endif()

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

Expand Down
1 change: 1 addition & 0 deletions doc/libf3d/OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. See [user documentation](../user/SUPPORTED_FORMATS.md) | \-\-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
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 @@ 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](SUPPORTED_FORMATS.md) 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. |
Expand Down
68 changes: 35 additions & 33 deletions doc/user/SUPPORTED_FORMATS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,41 @@

F3D supports the following file formats:

| Name | File Extension(s) | Full scene | Animation Supported? | Plugin |
| ----------------------------------------- | ---------------------------------------------- | ---------- | -------------------- | --------- |
| Legacy VTK | `.vtk` | No | No | `native` |
| VTK XML | `.vtp`, `.vtu`, `.vtr`, `.vti`, `.vts`, `.vtm` | No | No | `native` |
| VTKHDF | `.vtkhdf` | No | Yes | `hdf` |
| EXODUS II | `.e`, `.ex2`, `.exo`, `.g` | No | Yes | `hdf` |
| Polygon File Format | `.ply` | No | No | `native` |
| Standard Triangle Language | `.stl` | No | No | `native` |
| DICOM | `.dcm` | No | No | `native` |
| NRRD ("nearly raw raster data") | `.nrrd`, `.nhrd` | No | No | `native` |
| MetaHeader MetaIO | `.mhd`, `.mha` | No | No | `native` |
| Tag Image File Format 2D/3D | `.tif`, `.tiff` | No | No | `native` |
| QuakeMDL | `.mdl` | Yes | Yes | `native` |
| CityGML | `.gml` | No | No | `native` |
| Point Cloud | `.pts` | No | No | `native` |
| Standard for the Exchange of Product Data | `.step`, `.stp` | No | No | `occt` |
| Initial Graphics Exchange Specification | `.iges`, `.igs` | No | No | `occt` |
| Open CASCADE Technology BRep format | `.brep` | No | No | `native` |
| Alembic | `.abc` | No | Yes | `alembic` |
| Wavefront OBJ | `.obj` | Yes | Yes | `native` |
| GL Transmission Format | `.gltf`, `.glb` | Yes | Yes | `native` |
| Autodesk 3D Studio | `.3ds` | Yes | No | `native` |
| Virtual Reality Modeling Language | `.wrl` | Yes | No | `native` |
| Autodesk Filmbox | `.fbx` | Yes | Yes | `assimp` |
| COLLADA | `.dae` | Yes | Yes | `assimp` |
| Object File Format | `.off` | Yes | No | `assimp` |
| Drawing Exchange Format | `.dxf` | Yes | No | `assimp` |
| DirectX | `.x` | Yes | Yes | `assimp` |
| 3D Manufacturing Format | `.3mf` | Yes | No | `assimp` |
| Universal Scene Description | `.usd`, `.usda`, `.usdc`, `.usdz` | Yes | Yes | `usd` |
| VDB | `.vdb` | No | No | `vdb` |
| 3D Gaussian splatting | `.splat` | No | No | `native` |
| Compressed 3D Gaussian splatting | `.spz` | No | No | `native` |
| Name | File Extension(s) | Full scene | Animation Supported? | Plugin | Reader Name |
| ----------------------------------------- | ---------------------------------------------- | ---------- | -------------------- | --------- | ----------------------- |
| Legacy VTK | `.vtk` | No | No | `native` | `VTKLegacy` |
| VTK XML | `.vtp`, `.vtu`, `.vtr`, `.vti`, `.vts`, `.vtm` | No | No | `native` | `VTKXMLVT<P,U,R,I,S,M>` |
| VTKHDF | `.vtkhdf` | No | Yes | `hdf` | `VTKHDF` |
| EXODUS II | `.e`, `.ex2`, `.exo`, `.g` | No | Yes | `hdf` | `ExodusII` |
| Polygon File Format | `.ply` | No | No | `native` | `PLYReader` |
| Standard Triangle Language | `.stl` | No | No | `native` | `STL` |
| DICOM | `.dcm` | No | No | `native` | `DICOM` |
| NRRD ("nearly raw raster data") | `.nrrd`, `.nhdr` | No | No | `native` | `Nrrd` |
| MetaHeader MetaIO | `.mhd`, `.mha` | No | No | `native` | `MetaImage` |
| Tag Image File Format 2D/3D | `.tif`, `.tiff` | No | No | `native` | `TIFF` |
| QuakeMDL | `.mdl` | Yes | Yes | `native` | `QuakeMDL` |
| CityGML | `.gml` | No | No | `native` | `CityGML` |
| Point Cloud | `.pts` | No | No | `native` | `PTS` |
| Standard for the Exchange of Product Data | `.step`, `.stp`, `.stpnc`, `.p21`, `.210` | No | No | `occt` | `STEP` |
| Initial Graphics Exchange Specification | `.iges`, `.igs` | No | No | `occt` | `IGES` |
| Open CASCADE Technology BRep format | `.brep` | No | No | `native` | `BREP` |
| Open CASCADE Technology XBF format | `.xbf` | No | No | `occt` | `XBF` |
| Alembic | `.abc` | No | Yes | `alembic` | `Alembic` |
| Wavefront OBJ | `.obj` | Yes | Yes | `native` | `OBJ` |
| GL Transmission Format | `.gltf`, `.glb` | Yes | Yes | `native` | `GLTF`, `GLTFDraco` |
| Draco | `.drc` | No | No | `draco` | `Draco` |
| Autodesk 3D Studio | `.3ds` | Yes | No | `native` | `3DS` |
| Virtual Reality Modeling Language | `.wrl`, `.vrml` | Yes | No | `native` | `VRMLReader` |
| Autodesk Filmbox | `.fbx` | Yes | Yes | `assimp` | `FBX` |
| COLLADA | `.dae` | Yes | Yes | `assimp` | `COLLADA` |
| Object File Format | `.off` | Yes | No | `assimp` | `OFF` |
| Drawing Exchange Format | `.dxf` | Yes | No | `assimp` | `DXF` |
| DirectX | `.x` | Yes | Yes | `assimp` | `DirectX` |
| 3D Manufacturing Format | `.3mf` | Yes | No | `assimp` | `3MF` |
| Universal Scene Description | `.usd`, `.usda`, `.usdc`, `.usdz` | Yes | Yes | `usd` | `USD` |
| VDB | `.vdb` | No | No | `vdb` | `VDB` |
| 3D Gaussian splatting | `.splat` | No | No | `native` | `Splat` |
| Compressed 3D Gaussian splatting | `.spz` | No | No | `native` | `SPZ` |

## Reader options

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
2 changes: 1 addition & 1 deletion library/plugin/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class plugin
/**
* 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;
}
Expand Down
3 changes: 2 additions & 1 deletion library/private/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "reader.h"

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

namespace f3d
Expand Down Expand Up @@ -44,7 +45,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
Expand Down
13 changes: 10 additions & 3 deletions library/src/factory.cxx.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
if (reader->getName() == *forceReader)
{
return reader.get();
}
}
else if (reader->getScore() > bestScore && reader->canRead(fileName))
{
bestScore = reader->getScore();
bestReader = reader.get();
Expand Down
Loading