diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c9afdb3064..33735ab5f0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3705,6 +3705,8 @@ void Application::keyPressEvent(QKeyEvent* event) { Menu::getInstance()->triggerOption(MenuOption::Log); } else if (isMeta) { Menu::getInstance()->triggerOption(MenuOption::AddressBar); + } else if (isShifted) { + Menu::getInstance()->triggerOption(MenuOption::LodTools); } break; @@ -7527,6 +7529,17 @@ SharedSoundPointer Application::getSampleSound() const { return _sampleSound; } +void Application::loadLODToolsDialog() { + auto tabletScriptingInterface = DependencyManager::get(); + auto tablet = dynamic_cast(tabletScriptingInterface->getTablet(SYSTEM_TABLET)); + if (tablet->getToolbarMode() || (!tablet->getTabletRoot() && !isHMDMode())) { + auto dialogsManager = DependencyManager::get(); + dialogsManager->lodTools(); + } else { + tablet->pushOntoStack("hifi/dialogs/TabletLODTools.qml"); + } +} + void Application::loadEntityStatisticsDialog() { auto tabletScriptingInterface = DependencyManager::get(); auto tablet = dynamic_cast(tabletScriptingInterface->getTablet(SYSTEM_TABLET)); diff --git a/interface/src/Application.h b/interface/src/Application.h index 5a29dd23e8..17e28f0e6e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -65,6 +65,7 @@ #include "scripting/DialogsManagerScriptingInterface.h" #include "ui/ApplicationOverlay.h" #include "ui/EntityScriptServerLogDialog.h" +#include "ui/LodToolsDialog.h" #include "ui/LogDialog.h" #include "ui/OctreeStatsDialog.h" #include "ui/OverlayConductor.h" @@ -402,6 +403,7 @@ public slots: void addAssetToWorldMessageClose(); + void loadLODToolsDialog(); void loadEntityStatisticsDialog(); void loadDomainConnectionDialog(); void showScriptLogs(); diff --git a/interface/src/LODManager.cpp b/interface/src/LODManager.cpp index 090bec89b1..da1f14c450 100644 --- a/interface/src/LODManager.cpp +++ b/interface/src/LODManager.cpp @@ -122,7 +122,10 @@ void LODManager::autoAdjustLOD(float realTimeDelta) { } if (oldOctreeSizeScale != _octreeSizeScale) { - //TODO: check Preferences dialog + auto lodToolsDialog = DependencyManager::get()->getLodToolsDialog(); + if (lodToolsDialog) { + lodToolsDialog->reloadSliders(); + } } } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 6bc93c2e5c..499ceae81c 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -479,6 +479,10 @@ Menu::Menu() { }); } + // Developer > Render > LOD Tools + addActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::LodTools, 0, + qApp, SLOT(loadLODToolsDialog())); + // HACK enable texture decimation { auto action = addCheckableActionToQMenuAndActionHash(renderOptionsMenu, "Decimate Textures"); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 526ca5f88f..4a957fcb69 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -121,6 +121,7 @@ namespace MenuOption { const QString ActionMotorControl = "Enable Default Motor Control"; const QString LoadScript = "Open and Run Script File..."; const QString LoadScriptURL = "Open and Run Script from URL..."; + const QString LodTools = "LOD Tools"; const QString Login = "Login/Sign Up"; const QString Log = "Log"; const QString LogExtraTimings = "Log Extra Timing Details"; diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp index 05fc3e48ba..d01e7d6671 100644 --- a/interface/src/ui/DialogsManager.cpp +++ b/interface/src/ui/DialogsManager.cpp @@ -23,6 +23,7 @@ #include "ConnectionFailureDialog.h" #include "DomainConnectionDialog.h" #include "HMDToolsDialog.h" +#include "LodToolsDialog.h" #include "LoginDialog.h" #include "OctreeStatsDialog.h" #include "PreferencesDialog.h" @@ -125,6 +126,16 @@ void DialogsManager::octreeStatsDetails() { _octreeStatsDialog->raise(); } +void DialogsManager::lodTools() { + if (!_lodToolsDialog) { + maybeCreateDialog(_lodToolsDialog); + + connect(_lodToolsDialog, SIGNAL(closed()), _lodToolsDialog, SLOT(deleteLater())); + _lodToolsDialog->show(); + } + _lodToolsDialog->raise(); +} + void DialogsManager::hmdTools(bool showTools) { if (showTools) { if (!_hmdToolsDialog) { diff --git a/interface/src/ui/DialogsManager.h b/interface/src/ui/DialogsManager.h index c24f0fc4c0..f17ac39a7e 100644 --- a/interface/src/ui/DialogsManager.h +++ b/interface/src/ui/DialogsManager.h @@ -22,6 +22,7 @@ class AnimationsDialog; class AttachmentsDialog; class CachesSizeDialog; +class LodToolsDialog; class OctreeStatsDialog; class ScriptEditorWindow; class TestingDialog; @@ -34,6 +35,7 @@ class DialogsManager : public QObject, public Dependency { public: QPointer getHMDToolsDialog() const { return _hmdToolsDialog; } + QPointer getLodToolsDialog() const { return _lodToolsDialog; } QPointer getOctreeStatsDialog() const { return _octreeStatsDialog; } QPointer getTestingDialog() const { return _testingDialog; } void emitAddressBarShown(bool visible) { emit addressBarShown(visible); } @@ -47,6 +49,7 @@ public slots: void toggleLoginDialog(); void showLoginDialog(); void octreeStatsDetails(); + void lodTools(); void hmdTools(bool showTools); void showDomainConnectionDialog(); void showTestingResults(); @@ -73,6 +76,7 @@ private: QPointer _cachesSizeDialog; QPointer _ircInfoBox; QPointer _hmdToolsDialog; + QPointer _lodToolsDialog; QPointer _octreeStatsDialog; QPointer _testingDialog; QPointer _domainConnectionDialog; diff --git a/interface/src/ui/HMDToolsDialog.cpp b/interface/src/ui/HMDToolsDialog.cpp index d3ff239553..fb49c4f4c4 100644 --- a/interface/src/ui/HMDToolsDialog.cpp +++ b/interface/src/ui/HMDToolsDialog.cpp @@ -83,7 +83,10 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) : if (dialogsManager->getOctreeStatsDialog()) { watchWindow(dialogsManager->getOctreeStatsDialog()->windowHandle()); } - + if (dialogsManager->getLodToolsDialog()) { + watchWindow(dialogsManager->getLodToolsDialog()->windowHandle()); + } + connect(_switchModeButton, &QPushButton::clicked, [this]{ toggleHMDMode(); }); diff --git a/interface/src/ui/LodToolsDialog.cpp b/interface/src/ui/LodToolsDialog.cpp new file mode 100644 index 0000000000..e2f2d9e011 --- /dev/null +++ b/interface/src/ui/LodToolsDialog.cpp @@ -0,0 +1,132 @@ +// +// LodToolsDialog.cpp +// interface/src/ui +// +// Created by Brad Hefta-Gaub on 7/19/13. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "LodToolsDialog.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "Menu.h" + + +LodToolsDialog::LodToolsDialog(QWidget* parent) : + QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) +{ + this->setWindowTitle("LOD Tools"); + auto lodManager = DependencyManager::get(); + + // Create layouter + QFormLayout* form = new QFormLayout(this); + + // Create a label with feedback... + _feedback = new QLabel(this); + QPalette palette = _feedback->palette(); + const unsigned redish = 0xfff00000; + palette.setColor(QPalette::WindowText, QColor::fromRgb(redish)); + _feedback->setPalette(palette); + _feedback->setText(lodManager->getLODFeedbackText()); + const int FEEDBACK_WIDTH = 350; + _feedback->setFixedWidth(FEEDBACK_WIDTH); + form->addRow("You can see... ", _feedback); + + form->addRow("Manually Adjust Level of Detail:", _manualLODAdjust = new QCheckBox(this)); + _manualLODAdjust->setChecked(!lodManager->getAutomaticLODAdjust()); + connect(_manualLODAdjust, SIGNAL(toggled(bool)), SLOT(updateAutomaticLODAdjust())); + + _lodSize = new QSlider(Qt::Horizontal, this); + const int MAX_LOD_SIZE = 2000; // ~20:4 vision -- really good. + const int MIN_LOD_SIZE = 5; // ~20:1600 vision -- really bad! + const int STEP_LOD_SIZE = 1; + const int PAGE_STEP_LOD_SIZE = 100; + const int SLIDER_WIDTH = 300; + _lodSize->setMaximum(MAX_LOD_SIZE); + _lodSize->setMinimum(MIN_LOD_SIZE); + _lodSize->setSingleStep(STEP_LOD_SIZE); + _lodSize->setTickInterval(PAGE_STEP_LOD_SIZE); + _lodSize->setTickPosition(QSlider::TicksBelow); + _lodSize->setFixedWidth(SLIDER_WIDTH); + _lodSize->setPageStep(PAGE_STEP_LOD_SIZE); + int sliderValue = lodManager->getOctreeSizeScale() / TREE_SCALE; + _lodSize->setValue(sliderValue); + form->addRow("Level of Detail:", _lodSize); + connect(_lodSize,SIGNAL(valueChanged(int)),this,SLOT(sizeScaleValueChanged(int))); + + // Add a button to reset + QPushButton* resetButton = new QPushButton("Reset", this); + form->addRow("", resetButton); + connect(resetButton, SIGNAL(clicked(bool)), this, SLOT(resetClicked(bool))); + + this->QDialog::setLayout(form); + + updateAutomaticLODAdjust(); +} + +void LodToolsDialog::reloadSliders() { + auto lodManager = DependencyManager::get(); + _lodSize->setValue(lodManager->getOctreeSizeScale() / TREE_SCALE); + _feedback->setText(lodManager->getLODFeedbackText()); +} + +void LodToolsDialog::updateAutomaticLODAdjust() { + auto lodManager = DependencyManager::get(); + lodManager->setAutomaticLODAdjust(!_manualLODAdjust->isChecked()); + _lodSize->setEnabled(_manualLODAdjust->isChecked()); +} + +void LodToolsDialog::sizeScaleValueChanged(int value) { + auto lodManager = DependencyManager::get(); + float realValue = value * TREE_SCALE; + lodManager->setOctreeSizeScale(realValue); + + _feedback->setText(lodManager->getLODFeedbackText()); +} + +void LodToolsDialog::resetClicked(bool checked) { + + int sliderValue = DEFAULT_OCTREE_SIZE_SCALE / TREE_SCALE; + _lodSize->setValue(sliderValue); + _manualLODAdjust->setChecked(false); + + updateAutomaticLODAdjust(); // tell our LOD manager about the reset +} + +void LodToolsDialog::reject() { + // Just regularly close upon ESC + this->QDialog::close(); +} + +void LodToolsDialog::closeEvent(QCloseEvent* event) { + this->QDialog::closeEvent(event); + emit closed(); + +#if RESET_TO_AUTOMATIC_WHEN_YOU_CLOSE_THE_DIALOG_BOX + auto lodManager = DependencyManager::get(); + + // always revert back to automatic LOD adjustment when closed + lodManager->setAutomaticLODAdjust(true); + + // if the user adjusted the LOD above "normal" then always revert back to default + if (lodManager->getOctreeSizeScale() > DEFAULT_OCTREE_SIZE_SCALE) { + lodManager->setOctreeSizeScale(DEFAULT_OCTREE_SIZE_SCALE); + } +#endif +} + diff --git a/interface/src/ui/LodToolsDialog.h b/interface/src/ui/LodToolsDialog.h new file mode 100644 index 0000000000..3ae59661dc --- /dev/null +++ b/interface/src/ui/LodToolsDialog.h @@ -0,0 +1,55 @@ +// +// LodToolsDialog.h +// interface/src/ui +// +// Created by Brad Hefta-Gaub on 7/19/13. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_LodToolsDialog_h +#define hifi_LodToolsDialog_h + +#include + +class QCheckBox; +class QDoubleSpinBox; +class QLabel; +class QSlider; + +class LodToolsDialog : public QDialog { + Q_OBJECT +public: + // Sets up the UI + LodToolsDialog(QWidget* parent); + +signals: + void closed(); + +public slots: + void reject() override; + void sizeScaleValueChanged(int value); + void resetClicked(bool checked); + void reloadSliders(); + void updateAutomaticLODAdjust(); + +protected: + + // Emits a 'closed' signal when this dialog is closed. + void closeEvent(QCloseEvent* event) override; + +private: + QSlider* _lodSize; + + QCheckBox* _manualLODAdjust; + + QDoubleSpinBox* _desktopLODDecreaseFPS; + + QDoubleSpinBox* _hmdLODDecreaseFPS; + + QLabel* _feedback; +}; + +#endif // hifi_LodToolsDialog_h \ No newline at end of file