From 6fe68e7fbf0cf64a5cdf370d531606e08a931331 Mon Sep 17 00:00:00 2001 From: Mathias Paulin <mathias.paulin@irit.fr> Date: Mon, 19 Apr 2021 17:53:55 +0200 Subject: [PATCH] Add Skeleton animation control widget --- src/Mara/Gui/MainWindow.cpp | 70 +++++++++++++++++++++++++------------ src/Mara/Gui/MainWindow.hpp | 6 ++++ 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/Mara/Gui/MainWindow.cpp b/src/Mara/Gui/MainWindow.cpp index 7036622..8a259fe 100644 --- a/src/Mara/Gui/MainWindow.cpp +++ b/src/Mara/Gui/MainWindow.cpp @@ -28,6 +28,9 @@ #include <RadiumPlayer.hpp> +#include <Engine/Scene/SkeletonBasedAnimationSystem.hpp> +#include <Gui/SkeletonBasedAnimation/SkeletonBasedAnimationUI.hpp> + using namespace Ra::Gui; using namespace Ra::Engine; using namespace Ra::Engine::Rendering; @@ -86,21 +89,15 @@ void MainWindow::addTimelineToolBar() { m_timeline->onChangeEnd( Ra::Engine::RadiumEngine::getInstance()->getEndTime() ); // Timeline setup connect( m_timeline, &Ra::Gui::Timeline::playClicked, this, &MainWindow::timelinePlay ); + connect( m_timeline, &Ra::Gui::Timeline::cursorChanged, this, &MainWindow::timelineGoTo ); connect( - m_timeline, &Ra::Gui::Timeline::cursorChanged, this, &MainWindow::timelineGoTo ); - connect( m_timeline, - &Ra::Gui::Timeline::startChanged, - this, - &MainWindow::timelineStartChanged ); + m_timeline, &Ra::Gui::Timeline::startChanged, this, &MainWindow::timelineStartChanged ); + connect( m_timeline, &Ra::Gui::Timeline::endChanged, this, &MainWindow::timelineEndChanged ); + connect( m_timeline, &Ra::Gui::Timeline::setPingPong, this, &MainWindow::timelineSetPingPong ); connect( - m_timeline, &Ra::Gui::Timeline::endChanged, this, &MainWindow::timelineEndChanged ); - connect( m_timeline, - &Ra::Gui::Timeline::setPingPong, - this, - &MainWindow::timelineSetPingPong ); - connect( m_timeline, &Ra::Gui::Timeline::keyFrameChanged, [=]( Scalar ) { - emit frameUpdate(); - } ); + m_timeline, &Ra::Gui::Timeline::keyFrameChanged, [=]( Scalar ) { emit frameUpdate(); } ); + connect( this, &MainWindow::selectedItem, m_timeline, &Ra::Gui::Timeline::selectionChanged ); + timelineToolbar->addWidget( m_timeline ); this->addToolBar( Qt::BottomToolBarArea, timelineToolbar ); @@ -116,7 +113,7 @@ void MainWindow::addTimelineToolBar() { connect( showTimelineToolbar, &QAction::triggered, timelineToolbar, &QToolBar::setVisible ); connect( timelineToolbar, &QToolBar::visibilityChanged, [showTimelineToolbar]( bool b ) { - showTimelineToolbar->setChecked( b ); + showTimelineToolbar->setChecked( b ); } ); menuToolbars->addAction( showTimelineToolbar ); @@ -223,6 +220,7 @@ void MainWindow::addSelectionToolBar() { void MainWindow::postOpenGLInitializations() { addSelectionToolBar(); addTimelineToolBar(); + addRadiumSystemsUI(); } void MainWindow::createConnections() { @@ -290,7 +288,6 @@ void MainWindow::onFrameComplete() { m_timeline->onChangeCursor( engine->getTime() ); m_lockTimeSystem = false; } - } void MainWindow::activateCamera( const std::string& sceneName ) { @@ -384,6 +381,12 @@ void MainWindow::loadFile() { auto sceneStats = std::make_tuple( objectCount, polyCount, vertexCount ); m_controlWindow->setFileInfo( pathList.first().toStdString(), sceneStats ); activateCamera( pathList.first().toStdString() ); + + std::string loadedEntityName = + Ra::Core::Utils::getBaseName( pathList.first().toStdString(), false ); + auto rootEntity = Ra::Engine::RadiumEngine::getInstance()->getEntityManager()->getEntity( + loadedEntityName ); + if ( rootEntity != nullptr ) { emit entityAdded( rootEntity ); } } } @@ -496,41 +499,64 @@ void MainWindow::onSelectionChanged( const QItemSelection& /*selected*/, { emit selectedItem( ItemEntry() ); } } - void MainWindow::timelinePlay( bool play ) { actionPlay->setChecked( play ); - if ( !m_lockTimeSystem ) { + if ( !m_lockTimeSystem ) + { Ra::Engine::RadiumEngine::getInstance()->play( play ); - // mainApp->setContinuousUpdate( play ); + // mainApp->setContinuousUpdate( play ); } } void MainWindow::timelineGoTo( double t ) { - if ( !m_lockTimeSystem ) { + if ( !m_lockTimeSystem ) + { Ra::Engine::RadiumEngine::getInstance()->setTime( Scalar( t ) ); emit frameUpdate(); } } void MainWindow::timelineStartChanged( double t ) { - if ( !m_lockTimeSystem ) { + if ( !m_lockTimeSystem ) + { Ra::Engine::RadiumEngine::getInstance()->setStartTime( Scalar( t ) ); emit frameUpdate(); } } void MainWindow::timelineEndChanged( double t ) { - if ( !m_lockTimeSystem ) { + if ( !m_lockTimeSystem ) + { Ra::Engine::RadiumEngine::getInstance()->setEndTime( Scalar( t ) ); emit frameUpdate(); } } void MainWindow::timelineSetPingPong( bool status ) { - if ( !m_lockTimeSystem ) { + if ( !m_lockTimeSystem ) + { Ra::Engine::RadiumEngine::getInstance()->setForwardBackward( status ); emit frameUpdate(); } } +void MainWindow::addRadiumSystemsUI() { + // Register the Skeleton-based animation UI + auto animSystem = static_cast<Ra::Engine::Scene::SkeletonBasedAnimationSystem*>( + Ra::Engine::RadiumEngine::getInstance()->getSystem( "SkeletonBasedAnimationSystem" ) ); + auto skelAnimUI = new Ra::Gui::SkeletonBasedAnimationUI( animSystem, m_timeline ); + m_controlWindow->addTab( skelAnimUI, "Skeleton Animation" ); + addControl( "Skeleton Animation", tr( "Ctrl+A" ) ); + connect( skelAnimUI, &Ra::Gui::SkeletonBasedAnimationUI::askForUpdate, [this]() { + emit frameUpdate(); + } ); + connect( this, + &MainWindow::entityAdded, + skelAnimUI, + &Ra::Gui::SkeletonBasedAnimationUI::postLoadFile ); + connect( this, + &MainWindow::selectedItem, + skelAnimUI, + &Ra::Gui::SkeletonBasedAnimationUI::selectionChanged ); +} } // namespace Mara diff --git a/src/Mara/Gui/MainWindow.hpp b/src/Mara/Gui/MainWindow.hpp index 791c397..a245b1d 100644 --- a/src/Mara/Gui/MainWindow.hpp +++ b/src/Mara/Gui/MainWindow.hpp @@ -84,6 +84,9 @@ class MainWindow : public Ra::Gui::MainWindowInterface, private Ui::MainWindow /// Emitted when a new item is selected. An invalid entry is sent when no item is selected. void selectedItem( const Ra::Engine::Scene::ItemEntry& entry ); + /// Emitted when a new entity is added to the application + void entityAdded( Ra::Engine::Scene::Entity* entity ); + public slots: /// Called when a scene is ready to display to parameterize the application window and the /// viewer. @@ -176,6 +179,9 @@ class MainWindow : public Ra::Gui::MainWindowInterface, private Ui::MainWindow /// add the selection toolbar void addTimelineToolBar(); + /// add the Radium Engine default systems UI + void addRadiumSystemsUI(); + bool m_lockTimeSystem{false}; /// create the UI connections -- GitLab