Skip to content

Commit

Permalink
SceneViewer3D GUI: add button to enable shadow casting
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Sep 21, 2024
1 parent 605ca3c commit 8ab4b3c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
39 changes: 32 additions & 7 deletions apps/SceneViewer3D/_DSceneViewerMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ const long _DSceneViewerFrame::ID_BUTTON5 = wxNewId();
const long _DSceneViewerFrame::ID_STATICLINE2 = wxNewId();
const long _DSceneViewerFrame::ID_BUTTON6 = wxNewId();
const long _DSceneViewerFrame::ID_BUTTON7 = wxNewId();
const long _DSceneViewerFrame::ID_BUTTON_SHADOWS = wxNewId();
const long _DSceneViewerFrame::ID_BUTTON8 = wxNewId();
const long _DSceneViewerFrame::ID_BUTTON9 = wxNewId();
const long _DSceneViewerFrame::ID_STATICLINE3 = wxNewId();
Expand Down Expand Up @@ -480,6 +481,17 @@ _DSceneViewerFrame::_DSceneViewerFrame(wxWindow* parent, wxWindowID id) : maxv(0
wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_TICK_MARK")), wxART_TOOLBAR));
btnOrtho->SetMargins(wxSize(5, 5));
FlexGridSizer2->Add(btnOrtho, 1, wxEXPAND, 1);

btnShadows = new wxCustomButton(
this, ID_BUTTON_SHADOWS, _(" Shadows "),
wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_TICK_MARK")), wxART_TOOLBAR),
wxDefaultPosition, wxDefaultSize, wxCUSTBUT_TOGGLE | wxCUSTBUT_BOTTOM, wxDefaultValidator,
_T("ID_BUTTON_SHADOWS"));
btnShadows->SetBitmapDisabled(
wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_TICK_MARK")), wxART_TOOLBAR));
btnShadows->SetMargins(wxSize(5, 5));
FlexGridSizer2->Add(btnShadows, 1, wxEXPAND, 1);

btnAutoplay = new wxCustomButton(
this, ID_BUTTON8, _(" Autoplay "),
wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_REMOVABLE")), wxART_TOOLBAR),
Expand Down Expand Up @@ -657,6 +669,7 @@ _DSceneViewerFrame::_DSceneViewerFrame(wxWindow* parent, wxWindowID id) : maxv(0
Bind(wxEVT_BUTTON, &svf::OnReload, this, ID_BUTTON5);
Bind(wxEVT_BUTTON, &svf::OnMenuOptions, this, ID_BUTTON6);
Bind(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, &svf::OnbtnOrthoClicked, this, ID_BUTTON7);
Bind(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, &svf::OnbtnShadowsClicked, this, ID_BUTTON_SHADOWS);
Bind(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, &svf::OnbtnAutoplayClicked, this, ID_BUTTON8);
Bind(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, &svf::OnBtnRecordClicked, this, ID_BUTTON9);
Bind(wxEVT_BUTTON, &svf::OnAbout, this, ID_BUTTON10);
Expand Down Expand Up @@ -923,13 +936,7 @@ void _DSceneViewerFrame::OntimLoadFileCmdLineTrigger(wxTimerEvent&)
}

// Enable shadows?
if (0)
{
if (auto vw = m_canvas->getOpenGLSceneRef()->getViewport(); vw)
{
vw->enableShadowCasting();
}
}
applyShadowsOptions();
}

void _DSceneViewerFrame::OnbtnAutoplayClicked(wxCommandEvent& event)
Expand Down Expand Up @@ -1048,6 +1055,24 @@ void _DSceneViewerFrame::OnbtnOrthoClicked(wxCommandEvent& event)
m_canvas->Refresh(false);
}

void _DSceneViewerFrame::OnbtnShadowsClicked(wxCommandEvent& event)
{
applyShadowsOptions();
m_canvas->Refresh(false);
}

void _DSceneViewerFrame::applyShadowsOptions()
{
bool shadowsEnabled = btnShadows->GetValue();
auto scene = m_canvas->getOpenGLSceneRef();
if (!scene) return;

auto vw = scene->getViewport();
if (!vw) return;

vw->enableShadowCasting(shadowsEnabled);
}

void _DSceneViewerFrame::OnReload(wxCommandEvent& event)
{
if (fileExists(loadedFileName)) loadFromFile(loadedFileName);
Expand Down
5 changes: 5 additions & 0 deletions apps/SceneViewer3D/_DSceneViewerMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class _DSceneViewerFrame : public wxFrame
void OnClose(wxCloseEvent& event);
void OnBtnRecordClicked(wxCommandEvent& event);
void OnbtnOrthoClicked(wxCommandEvent& event);
void OnbtnShadowsClicked(wxCommandEvent& event);
void OnReload(wxCommandEvent& event);
void OnInsert3DS(wxCommandEvent& event);
void OnMenuSave(wxCommandEvent& event);
Expand Down Expand Up @@ -104,6 +105,8 @@ class _DSceneViewerFrame : public wxFrame

void OntimAutoplay(wxTimerEvent& event);

void applyShadowsOptions();

//(*Identifiers(_DSceneViewerFrame)
static const long ID_BUTTON1;
static const long ID_BUTTON2;
Expand All @@ -114,6 +117,7 @@ class _DSceneViewerFrame : public wxFrame
static const long ID_STATICLINE2;
static const long ID_BUTTON6;
static const long ID_BUTTON7;
static const long ID_BUTTON_SHADOWS;
static const long ID_BUTTON8;
static const long ID_BUTTON9;
static const long ID_STATICLINE3;
Expand Down Expand Up @@ -187,6 +191,7 @@ class _DSceneViewerFrame : public wxFrame
wxMenuItem* mnuSelectionScale;
wxMenuItem* mnuImportLAS;
wxCustomButton* btnOrtho;
wxCustomButton* btnShadows;
wxStatusBar* StatusBar1;
wxMenuItem* MenuItem6;
wxStaticLine* StaticLine3;
Expand Down
2 changes: 2 additions & 0 deletions doc/source/doxygen-docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
\page changelog Change Log

# Version 2.14.1: UNRELEASED
- Changes in apps:
- SceneViewer3D: New button to enable shadow casting.
- Changes in libraries:
- \ref mrpt_opengl_grp:
- New method mrpt::opengl::CAssimpModel::split_triangles_rendering_bbox() to enable a new feature in Assimp 3D models: splitting into smaller triangle sets for correct z-ordering of semitransparent objects; e.g. required for trees with masked leaves.
Expand Down

0 comments on commit 8ab4b3c

Please sign in to comment.