From 797ba75b29f2c656864f0b09bb97d010c91ca18c Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Wed, 21 Jun 2023 23:39:16 +0800 Subject: [PATCH] Add support for dropping HDRI (#861) - 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 --- application/F3DStarter.cxx | 31 +++++++++---------- application/testing/CMakeLists.txt | 2 +- doc/user/INTERACTIONS.md | 3 +- .../Rendering/vtkF3DRenderer.cxx | 20 ++++++------ library/src/interactor.cxx | 4 ++- library/src/interactor_impl.cxx | 12 +++++++ .../baselines/TestInteractionCheatsheet.png | 4 +-- .../TestInteractionCheatsheetRaytracing.png | 4 +-- .../TestInteractionCheatsheetScalars.png | 4 +-- ...InteractionCheatsheetScalarsRaytracing.png | 4 +-- .../TestInteractionDropFiles.log.in | 3 ++ 11 files changed, 54 insertions(+), 37 deletions(-) diff --git a/application/F3DStarter.cxx b/application/F3DStarter.cxx index b6cbac0db9..679a8b8a3e 100644 --- a/application/F3DStarter.cxx +++ b/application/F3DStarter.cxx @@ -95,8 +95,8 @@ F3DStarter::F3DStarter() : Internals(std::make_unique()) { // 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"); } //---------------------------------------------------------------------------- @@ -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 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 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); } } diff --git a/application/testing/CMakeLists.txt b/application/testing/CMakeLists.txt index 021feb7f13..f00891dbb0 100644 --- a/application/testing/CMakeLists.txt +++ b/application/testing/CMakeLists.txt @@ -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") diff --git a/doc/user/INTERACTIONS.md b/doc/user/INTERACTIONS.md index 2bb17f1eba..ea50f44b2a 100644 --- a/doc/user/INTERACTIONS.md +++ b/doc/user/INTERACTIONS.md @@ -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. diff --git a/library/VTKExtensions/Rendering/vtkF3DRenderer.cxx b/library/VTKExtensions/Rendering/vtkF3DRenderer.cxx index 9d7910b816..d0bf3a1de2 100644 --- a/library/VTKExtensions/Rendering/vtkF3DRenderer.cxx +++ b/library/VTKExtensions/Rendering/vtkF3DRenderer.cxx @@ -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); diff --git a/library/src/interactor.cxx b/library/src/interactor.cxx index 1855d0e5de..dc0b24de93 100644 --- a/library/src/interactor.cxx +++ b/library/src/interactor.cxx @@ -37,7 +37,9 @@ const std::vector >& 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 diff --git a/library/src/interactor_impl.cxx b/library/src/interactor_impl.cxx index 0b86532bb1..d1a77e47b7 100644 --- a/library/src/interactor_impl.cxx +++ b/library/src/interactor_impl.cxx @@ -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; diff --git a/testing/baselines/TestInteractionCheatsheet.png b/testing/baselines/TestInteractionCheatsheet.png index 30ce9569ed..79740bc18c 100644 --- a/testing/baselines/TestInteractionCheatsheet.png +++ b/testing/baselines/TestInteractionCheatsheet.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:630ef918776b4c6aab9153b10d45fdaf7e71a757c24f8b39ada68427458a8159 -size 38374 +oid sha256:f14d97f17a09cfbf6f1ee919d4955085edd7cffa4f3fd72386cc016905b79f8f +size 38231 diff --git a/testing/baselines/TestInteractionCheatsheetRaytracing.png b/testing/baselines/TestInteractionCheatsheetRaytracing.png index b1b496d424..955b905dc1 100644 --- a/testing/baselines/TestInteractionCheatsheetRaytracing.png +++ b/testing/baselines/TestInteractionCheatsheetRaytracing.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8973b2dec31da39ccf2c024129e817602fa04ede7ba4068a227e4989ca8626e1 -size 37952 +oid sha256:6bd39ea5ef96a81aa16f0a42ddc658e8cc3696f0c4f5e2254ed548462bccb7d2 +size 37844 diff --git a/testing/baselines/TestInteractionCheatsheetScalars.png b/testing/baselines/TestInteractionCheatsheetScalars.png index bf17d1b41a..4c232012c9 100644 --- a/testing/baselines/TestInteractionCheatsheetScalars.png +++ b/testing/baselines/TestInteractionCheatsheetScalars.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7f14e3f77dfb11781316d9da2f08c9d139eb7c8951f4219a81f5184fa6a14b08 -size 43716 +oid sha256:a435715136a232a75ada1b1db04a0ef197079ec0f03bd0ddb0433a6b4bddc2b5 +size 43834 diff --git a/testing/baselines/TestInteractionCheatsheetScalarsRaytracing.png b/testing/baselines/TestInteractionCheatsheetScalarsRaytracing.png index 8462c549ae..fc54940d81 100644 --- a/testing/baselines/TestInteractionCheatsheetScalarsRaytracing.png +++ b/testing/baselines/TestInteractionCheatsheetScalarsRaytracing.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:564a2d2131de939c847232ccde15bed43ac82b192e15a88e1a72588b0a38624d -size 43347 +oid sha256:5d3146ba0563f1239b8b05d21724cbe2310c10a19de8d1b1351d48082d60047d +size 43685 diff --git a/testing/recordings/TestInteractionDropFiles.log.in b/testing/recordings/TestInteractionDropFiles.log.in index d87120668a..582fd7a54f 100644 --- a/testing/recordings/TestInteractionDropFiles.log.in +++ b/testing/recordings/TestInteractionDropFiles.log.in @@ -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