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

options: Add path_t and use it for hdri #2045

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions application/F3DStarter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,7 @@ void F3DStarter::AddCommands()
{
// Set the first file has an HDRI
f3d::options& options = this->Internals->Engine->getOptions();
options.render.hdri.file = files[0];
options.render.hdri.file = f3d::path_t(files[0]);
options.render.hdri.ambient = true;
options.render.background.skybox = true;

Expand All @@ -1794,7 +1794,7 @@ void F3DStarter::AddCommands()

// Load the file as an HDRI instead of adding it.
f3d::options& options = this->Internals->Engine->getOptions();
options.render.hdri.file = file;
options.render.hdri.file = f3d::path_t(file);
options.render.hdri.ambient = true;
options.render.background.skybox = true;

Expand Down
6 changes: 6 additions & 0 deletions cmake/f3dOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ function(_parse_json_option _top_json)
set(_option_variant_type "std::string")
set(_option_default_value_start "\"")
set(_option_default_value_end "\"")
elseif(_option_type STREQUAL "path")
set(_option_actual_type "f3d::path_t")
set(_option_explicit_constr "f3d::path_t")
set(_option_variant_type "std::string")
set(_option_default_value_start "\"")
set(_option_default_value_end "\"")
elseif(_option_type STREQUAL "ratio")
set(_option_actual_type "f3d::ratio_t")
set(_option_explicit_constr "f3d::ratio_t")
Expand Down
2 changes: 1 addition & 1 deletion library/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},
"hdri": {
"file": {
"type": "string"
"type": "path"
},
"ambient": {
"type": "bool",
Expand Down
21 changes: 21 additions & 0 deletions library/private/options_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ ratio_t parse(const std::string& str)
}
}

//----------------------------------------------------------------------------
/**
* Parse provided string into a path_t.
*/
template<>
path_t parse(const std::string& str)
{
return f3d::path_t(str);
}

//----------------------------------------------------------------------------
/**
* Parse provided string into a color_t.
Expand Down Expand Up @@ -323,6 +333,17 @@ std::string format(const std::string& var)
return var;
}

//----------------------------------------------------------------------------
/**
* Format provided var into a string from provided path_t
* rely on format(std::string&)
*/
std::string format(path_t var)
{
// TODO generate a proper path string
return options_tools::format(static_cast<std::string>(var));
}

//----------------------------------------------------------------------------
/**
* Format provided var into a string from provided double vector
Expand Down
29 changes: 29 additions & 0 deletions library/public/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <algorithm>
#include <array>
#include <filesystem>
#include <iostream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -81,6 +82,34 @@ class ratio_t
double Value;
};

/**
* Describe a path.
*/
class path_t
{
public:
inline path_t() = default;
inline explicit path_t(const std::string& val)
: Value(val)
{
}
inline operator std::string() const
{
return this->Value.string();
}
[[nodiscard]] bool operator==(const path_t& other) const
{
return this->Value == other.Value;
}
[[nodiscard]] bool operator!=(const path_t& other) const
{
return this->Value != other.Value;
}

private:
std::filesystem::path Value;
};

/**
* A base template type for an array of double
*/
Expand Down
1 change: 1 addition & 0 deletions library/src/options.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ F3D_DECL_TYPE_WITH_VEC(int);
F3D_DECL_TYPE_WITH_VEC(double);
F3D_DECL_TYPE_WITH_VEC(f3d::ratio_t);
F3D_DECL_TYPE_WITH_VEC(std::string);
F3D_DECL_TYPE_WITH_VEC(f3d::path_t);
F3D_DECL_TYPE(color_t);
F3D_DECL_TYPE(direction_t);

Expand Down
4 changes: 2 additions & 2 deletions library/testing/TestSDKDynamicHDRI.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int TestSDKDynamicHDRI(int argc, char* argv[])
}

// Change the hdri and make sure it is taken into account
opt.render.hdri.file = std::string(argv[1]) + "data/palermo_park_1k.hdr";
opt.render.hdri.file = f3d::path_t(std::string(argv[1]) + "data/palermo_park_1k.hdr");
ret = TestSDKHelpers::RenderTest(eng.getWindow(), std::string(argv[1]) + "baselines/",
std::string(argv[2]), "TestSDKDynamicHDRI");
if (!ret)
Expand Down Expand Up @@ -89,7 +89,7 @@ int TestSDKDynamicHDRI(int argc, char* argv[])

#if F3D_MODULE_EXR
// Change the hdri and make sure it is taken into account
opt.render.hdri.file = std::string(argv[1]) + "/data/kloofendal_43d_clear_1k.exr";
opt.render.hdri.file = f3d::path_t(std::string(argv[1]) + "/data/kloofendal_43d_clear_1k.exr");
ret = TestSDKHelpers::RenderTest(eng.getWindow(), std::string(argv[1]) + "baselines/",
std::string(argv[2]), "TestSDKDynamicHDRIExr");

Expand Down
3 changes: 2 additions & 1 deletion library/testing/TestSDKInteractorCommand.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ int TestSDKInteractorCommand(int argc, char* argv[])
inter.triggerCommand("set model.scivis.cells true");
test("triggerCommand set", options.model.scivis.cells == true);
inter.triggerCommand("set render.hdri.file filepath");
test("triggerCommand set double quotes", options.render.hdri.file.value() == "filepath");
test("triggerCommand set double quotes",
options.render.hdri.file.value() == f3d::path_t("filepath"));

// Test reset
inter.triggerCommand("reset model.scivis.cells");
Expand Down
Loading