Skip to content

Commit

Permalink
Add support for dropping HDRI (#861)
Browse files Browse the repository at this point in the history
- Add simple support for dropping HDRI by pressing Ctrl while dropping
- Fix #34 
- Fix an issue when options are changed before a file is loaded and add a test
- Ctrl pressed down cannot be tested 
- Update Doc and dropzone
  • Loading branch information
mwestphal authored Jun 21, 2023
1 parent b89b2f5 commit 797ba75
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 37 deletions.
31 changes: 14 additions & 17 deletions application/F3DStarter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ F3DStarter::F3DStarter()
: Internals(std::make_unique<F3DStarter::F3DInternals>())
{
// Set option outside of command line and config file
this->Internals->DynamicOptions.set(
"ui.dropzone-info", "Drop a file to open it\nPress H to show cheatsheet");
this->Internals->DynamicOptions.set("ui.dropzone-info",
"Drop a file to open it\nCtrl+Drop to load a HDRI\nPress H to show cheatsheet");
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -372,24 +372,21 @@ int F3DStarter::Start(int argc, char** argv)
//----------------------------------------------------------------------------
void F3DStarter::LoadFile(int index, bool relativeIndex)
{
if (this->Internals->LoadedFile)
{
// When loading a file after another, store the changed options
// into the dynamic options and use these dynamic option as the default
// for loading the next file while still applying file specific options on top of it
// When loading a file, store any changed options
// into the dynamic options and use these dynamic option as the default
// for loading the file while still applying file specific options on top of it

// Recover previous options from the engine
const f3d::options& previousOptions = this->Internals->Engine->getOptions();
// Recover previous options from the engine
const f3d::options& previousOptions = this->Internals->Engine->getOptions();

// Detect changed options and apply the change to the dynamic options
// options names are shared between options instance
std::vector<std::string> optionNames = this->Internals->DynamicOptions.getNames();
for (const auto& name : optionNames)
// Detect changed options and apply the change to the dynamic options
// options names are shared between options instance
std::vector<std::string> optionNames = this->Internals->DynamicOptions.getNames();
for (const auto& name : optionNames)
{
if (!previousOptions.isSame(this->Internals->FileOptions, name))
{
if (!previousOptions.isSame(this->Internals->FileOptions, name))
{
this->Internals->DynamicOptions.copy(previousOptions, name);
}
this->Internals->DynamicOptions.copy(previousOptions, name);
}
}

Expand Down
2 changes: 1 addition & 1 deletion application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ if(VTK_VERSION VERSION_GREATER_EQUAL 9.1.20220519) # Drop file test uses stream
configure_file("${CMAKE_SOURCE_DIR}/testing/recordings/TestInteractionDropFiles.log.in"
"${CMAKE_BINARY_DIR}/TestInteractionDropFiles.log")

f3d_test(NAME TestInteractionDropFiles ARGS -x "--interaction-test-play=${CMAKE_BINARY_DIR}/TestInteractionDropFiles.log")#DropEvent cow.vtp;#DropEvent dragon.vtu suzanne.stl;
f3d_test(NAME TestInteractionDropFiles ARGS "--interaction-test-play=${CMAKE_BINARY_DIR}/TestInteractionDropFiles.log")#X;DropEvent cow.vtp;DropEvent dragon.vtu suzanne.stl;

configure_file("${CMAKE_SOURCE_DIR}/testing/recordings/TestInteractionGroupGeometriesDrop.log.in"
"${CMAKE_BINARY_DIR}/TestInteractionGroupGeometriesDrop.log")
Expand Down
3 changes: 2 additions & 1 deletion doc/user/INTERACTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Simple interaction with the displayed data is possible directly within the windo
* *Move the mouse wheel* to zoom in/out.
* *Click and drag* with the *middle* mouse button to translate the camera.
* *Click* with the *middle* mouse button to center the camera on the point under the cursor (hold *Shift* to allow forward or backward movement).
* Drag and drop a file or directory into the F3D window to load it
* Drag and drop a file or directory into the F3D window to load it.
* Press Control and Drag and drop a HDRI file to load a HDRI as with the `--hdri` option.

> Note: When playing an animation with a scene camera, camera interactions are locked.
Expand Down
20 changes: 11 additions & 9 deletions library/VTKExtensions/Rendering/vtkF3DRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -961,15 +961,17 @@ void vtkF3DRenderer::ConfigureCheatSheet()
std::stringstream cheatSheetText;
cheatSheetText << "\n";
this->FillCheatSheetHotkeys(cheatSheetText);
cheatSheetText << "\n H : Cheat sheet \n";
cheatSheetText << " ? : Print scene descr to terminal\n";
cheatSheetText << " ESC : Quit \n";
cheatSheetText << " ENTER: Reset camera to initial parameters\n";
cheatSheetText << " SPACE: Play animation if any\n";
cheatSheetText << " LEFT : Previous file \n";
cheatSheetText << " RIGHT: Next file \n";
cheatSheetText << " UP : Reload current file \n";
cheatSheetText << " DOWN : Add files from dir of current file\n";
cheatSheetText << "\n H : Cheat sheet \n";
cheatSheetText << " ? : Print scene descr to terminal \n";
cheatSheetText << " ESC : Quit \n";
cheatSheetText << " ENTER : Reset camera to initial parameters \n";
cheatSheetText << " SPACE : Play animation if any \n";
cheatSheetText << " LEFT : Previous file \n";
cheatSheetText << " RIGHT : Next file \n";
cheatSheetText << " UP : Reload current file \n";
cheatSheetText << " DOWN : Add files from dir of current file \n";
cheatSheetText << " Drop : Load dropped file or folder \n";
cheatSheetText << " Ctrl+Drop : Load dropped file as a HDRI \n";

this->CheatSheetActor->SetText(vtkCornerAnnotation::LeftEdge, cheatSheetText.str().c_str());
this->CheatSheetActor->RenderOpaqueGeometry(this);
Expand Down
4 changes: 3 additions & 1 deletion library/src/interactor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const std::vector<std::pair<std::string, std::string> >& interactor::getDefaultI
{ "Left", "Previous file" },
{ "Right", "Next file" },
{ "Up", "Reload current file" },
{ "Down", "Add current file parent directory to the list of files and reload the current file" }
{ "Down", "Add current file parent directory to the list of files and reload the current file" },
{ "Drop", "Load dropped file or folder" },
{ "Ctrl+Drop", "Load dropped file as HDRI" }
};
// clang-format on

Expand Down
12 changes: 12 additions & 0 deletions library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,18 @@ class interactor_impl::internals
filesVec[i] = filesArr->GetValue(i);
}

vtkRenderWindowInteractor* rwi = self->Style->GetInteractor();
if (rwi->GetControlKey() == 1)
{
// When Ctrl Key is pressed, load the first file as an HDRI instead
// of loading a file.
// This bypass the DropFilesUserCallBack logic and will be reworked
// once https://github.com/f3d-app/f3d/issues/443 is addressed.
self->Options.set("render.background.hdri", filesVec[0]);
self->Window.render();
return;
}

if (self->DropFilesUserCallBack(filesVec))
{
return;
Expand Down
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetRaytracing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetScalars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/recordings/TestInteractionDropFiles.log.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# StreamVersion 1.2
ExposeEvent 0 599 0 0 0 0 0
RenderEvent 0 599 0 0 0 0 0
KeyPressEvent 474 416 0 115 1 x 0
CharEvent 474 416 0 115 1 x 0
KeyReleaseEvent 474 416 0 115 1 x 0
KeyPressEvent 677 699 0 0 1 Super_L 0
CharEvent 677 699 0 0 1 Super_L 0
UpdateDropLocationEvent 677 699 0 0 1 Super_L 0
Expand Down

0 comments on commit 797ba75

Please sign in to comment.