Created application class to manage editor windows, improved camera AABox orbit
This commit is contained in:
parent
d263610d43
commit
3f3735ac7a
|
@ -154,21 +154,12 @@ void CCamera::SetOrbit(const CVector3f& OrbitTarget, float Distance)
|
|||
}
|
||||
}
|
||||
|
||||
void CCamera::SetOrbit(const CAABox& OrbitTarget, float DistScale /*= 4.f*/)
|
||||
void CCamera::SetOrbit(const CAABox& OrbitTarget, float DistScale /*= 1.75f*/)
|
||||
{
|
||||
CVector3f Min = OrbitTarget.Min();
|
||||
CVector3f Max = OrbitTarget.Max();
|
||||
|
||||
mOrbitTarget = OrbitTarget.Center();
|
||||
|
||||
// Find largest extent
|
||||
CVector3f Extent = (Max - Min) / 2.f;
|
||||
float Dist = 0.f;
|
||||
|
||||
if (Extent.X >= Extent.Y && Extent.X >= Extent.Z) Dist = Extent.X;
|
||||
else if (Extent.Y >= Extent.X && Extent.Y >= Extent.Z) Dist = Extent.Y;
|
||||
else Dist = Extent.Z;
|
||||
|
||||
// Determine orbit radius, which should be enough to cover the entire box with some buffer room
|
||||
float Dist = OrbitTarget.Center().Distance(OrbitTarget.Max());
|
||||
mOrbitDistance = Dist * DistScale;
|
||||
|
||||
if (mMode == eOrbitCamera)
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
|
||||
void SetMoveMode(ECameraMoveMode Mode);
|
||||
void SetOrbit(const CVector3f& rkOrbitTarget, float Distance);
|
||||
void SetOrbit(const CAABox& rkOrbitTarget, float DistScale = 4.f);
|
||||
void SetOrbit(const CAABox& rkOrbitTarget, float DistScale = 1.75f);
|
||||
void SetOrbitTarget(const CVector3f& rkOrbitTarget);
|
||||
void SetOrbitDistance(float Distance);
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
#include "CEditorApplication.h"
|
||||
#include "CEditorUpdateEvent.h"
|
||||
#include "IEditor.h"
|
||||
#include "CBasicViewport.h"
|
||||
#include <Common/CTimer.h>
|
||||
|
||||
CEditorApplication::CEditorApplication(int& rArgc, char **ppArgv)
|
||||
: QApplication(rArgc, ppArgv)
|
||||
{
|
||||
mLastUpdate = CTimer::GlobalTime();
|
||||
|
||||
connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(TickEditors()));
|
||||
mRefreshTimer.start(8);
|
||||
}
|
||||
|
||||
void CEditorApplication::TickEditors()
|
||||
{
|
||||
double LastUpdate = mLastUpdate;
|
||||
mLastUpdate = CTimer::GlobalTime();
|
||||
double DeltaTime = mLastUpdate - LastUpdate;
|
||||
|
||||
foreach(IEditor *pEditor, mEditorWindows)
|
||||
{
|
||||
if (pEditor->isVisible())
|
||||
{
|
||||
pEditor->EditorTick((float) DeltaTime);
|
||||
|
||||
CBasicViewport *pViewport = pEditor->Viewport();
|
||||
|
||||
if (pViewport && pViewport->isVisible())
|
||||
{
|
||||
pViewport->ProcessInput();
|
||||
pViewport->Render();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef CEDITORAPPLICATION_H
|
||||
#define CEDITORAPPLICATION_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTimer>
|
||||
#include <QVector>
|
||||
|
||||
class CBasicViewport;
|
||||
class IEditor;
|
||||
|
||||
class CEditorApplication : public QApplication
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QTimer mRefreshTimer;
|
||||
QVector<IEditor*> mEditorWindows;
|
||||
double mLastUpdate;
|
||||
|
||||
public:
|
||||
CEditorApplication(int& rArgc, char **ppArgv);
|
||||
|
||||
public slots:
|
||||
void TickEditors();
|
||||
|
||||
// Accessors
|
||||
public:
|
||||
inline void AddEditor(IEditor *pEditor) { mEditorWindows << pEditor; }
|
||||
inline void RemoveEditor(IEditor *pEditor) { mEditorWindows.removeOne(pEditor); }
|
||||
};
|
||||
|
||||
#define gpEdApp static_cast<CEditorApplication*>(qApp)
|
||||
|
||||
#endif // CEDITORAPPLICATION_H
|
|
@ -181,8 +181,8 @@ void CProjectOverviewDialog::LaunchEditor()
|
|||
|
||||
void CProjectOverviewDialog::LaunchResourceBrowser()
|
||||
{
|
||||
CResourceBrowser Browser(this);
|
||||
Browser.exec();
|
||||
CResourceBrowser *pBrowser = new CResourceBrowser(mpWorldEditor);
|
||||
pBrowser->show();
|
||||
}
|
||||
|
||||
void CProjectOverviewDialog::CookPackage()
|
||||
|
|
|
@ -11,15 +11,15 @@ const CVector3f CCharacterEditor::skDefaultOrbitTarget = CVector3f(0,0,1);
|
|||
const float CCharacterEditor::skDefaultOrbitDistance = 4.f;
|
||||
|
||||
CCharacterEditor::CCharacterEditor(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
: IEditor(parent)
|
||||
, ui(new Ui::CCharacterEditor)
|
||||
, mpScene(new CScene())
|
||||
, mpCharNode(new CCharacterNode(mpScene, -1))
|
||||
, mpSelectedBone(nullptr)
|
||||
, mBindPose(false)
|
||||
, mAnimTime(0.f)
|
||||
, mPlayAnim(true)
|
||||
, mLoopAnim(true)
|
||||
, mAnimTime(0.f)
|
||||
, mPlaybackSpeed(1.f)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
@ -43,9 +43,6 @@ CCharacterEditor::CCharacterEditor(QWidget *parent)
|
|||
mpAnimComboBox->setMinimumWidth(175);
|
||||
ui->ToolBar->addWidget(mpAnimComboBox);
|
||||
|
||||
connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(RefreshViewport()));
|
||||
mRefreshTimer.start(0);
|
||||
|
||||
connect(ui->Viewport, SIGNAL(HoverBoneChanged(u32)), this, SLOT(OnViewportHoverBoneChanged(u32)));
|
||||
connect(ui->Viewport, SIGNAL(ViewportClick(QMouseEvent*)), this, SLOT(OnViewportClick()));
|
||||
connect(ui->ActionOpen, SIGNAL(triggered()), this, SLOT(Open()));
|
||||
|
@ -84,12 +81,14 @@ CCharacterEditor::~CCharacterEditor()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void CCharacterEditor::UpdateAnimTime()
|
||||
void CCharacterEditor::EditorTick(float DeltaTime)
|
||||
{
|
||||
double Time = CTimer::GlobalTime();
|
||||
double DeltaTime = Time - mLastAnimUpdate;
|
||||
mLastAnimUpdate = Time;
|
||||
UpdateAnimTime(DeltaTime);
|
||||
UpdateCameraOrbit();
|
||||
}
|
||||
|
||||
void CCharacterEditor::UpdateAnimTime(float DeltaTime)
|
||||
{
|
||||
CAnimation *pAnim = CurrentAnimation();
|
||||
|
||||
if (pAnim && mPlayAnim && !mBindPose && !ui->AnimSlider->isSliderDown())
|
||||
|
@ -216,7 +215,7 @@ void CCharacterEditor::SetActiveAnimSet(CAnimSet *pSet)
|
|||
ui->SkeletonHierarchyTreeView->selectionModel()->setCurrentIndex( mSkeletonModel.index(0, 0, RootIndex), QItemSelectionModel::ClearAndSelect );
|
||||
|
||||
// Run CCamera::SetOrbit to reset orbit distance.
|
||||
ui->Viewport->Camera().SetOrbit(mpCharNode->AABox(), 4.f);
|
||||
ui->Viewport->Camera().SetOrbit(mpCharNode->AABox());
|
||||
}
|
||||
|
||||
void CCharacterEditor::SetSelectedBone(CBone *pBone)
|
||||
|
@ -229,6 +228,11 @@ void CCharacterEditor::SetSelectedBone(CBone *pBone)
|
|||
}
|
||||
}
|
||||
|
||||
CCharacterEditorViewport* CCharacterEditor::Viewport() const
|
||||
{
|
||||
return ui->Viewport;
|
||||
}
|
||||
|
||||
// ************ PUBLIC SLOTS ************
|
||||
void CCharacterEditor::Open()
|
||||
{
|
||||
|
@ -291,8 +295,6 @@ void CCharacterEditor::ToggleOrbit(bool Enable)
|
|||
|
||||
void CCharacterEditor::RefreshViewport()
|
||||
{
|
||||
UpdateAnimTime();
|
||||
UpdateCameraOrbit();
|
||||
ui->Viewport->ProcessInput();
|
||||
ui->Viewport->Render();
|
||||
}
|
||||
|
@ -341,7 +343,6 @@ void CCharacterEditor::SetActiveAnimation(int AnimIndex)
|
|||
{
|
||||
mCurrentAnim = AnimIndex;
|
||||
mpCharNode->SetActiveAnim((u32) AnimIndex);
|
||||
mLastAnimUpdate = CTimer::GlobalTime();
|
||||
|
||||
ui->AnimSlider->blockSignals(true);
|
||||
ui->AnimSlider->setMaximum((int) (CurrentAnimation() ? CurrentAnimation()->Duration() * 1000 : 0));
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef CCHARACTEREDITOR_H
|
||||
#define CCHARACTEREDITOR_H
|
||||
|
||||
#include "IEditor.h"
|
||||
#include "CCharacterEditorViewport.h"
|
||||
#include "CSkeletonHierarchyModel.h"
|
||||
#include <Core/Scene/CScene.h>
|
||||
|
@ -14,7 +15,7 @@ namespace Ui {
|
|||
class CCharacterEditor;
|
||||
}
|
||||
|
||||
class CCharacterEditor : public QMainWindow
|
||||
class CCharacterEditor : public IEditor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -26,7 +27,6 @@ class CCharacterEditor : public QMainWindow
|
|||
CSkeletonHierarchyModel mSkeletonModel;
|
||||
QComboBox *mpCharComboBox;
|
||||
QComboBox *mpAnimComboBox;
|
||||
QTimer mRefreshTimer;
|
||||
|
||||
TResPtr<CAnimSet> mpSet;
|
||||
u32 mCurrentChar;
|
||||
|
@ -34,10 +34,9 @@ class CCharacterEditor : public QMainWindow
|
|||
bool mBindPose;
|
||||
|
||||
// Playback Controls
|
||||
double mLastAnimUpdate;
|
||||
float mAnimTime;
|
||||
bool mPlayAnim;
|
||||
bool mLoopAnim;
|
||||
float mAnimTime;
|
||||
float mPlaybackSpeed;
|
||||
|
||||
// Constants
|
||||
|
@ -47,12 +46,14 @@ class CCharacterEditor : public QMainWindow
|
|||
public:
|
||||
explicit CCharacterEditor(QWidget *parent = 0);
|
||||
~CCharacterEditor();
|
||||
void UpdateAnimTime();
|
||||
void EditorTick(float DeltaTime);
|
||||
void UpdateAnimTime(float DeltaTime);
|
||||
void UpdateCameraOrbit();
|
||||
CSkeleton* CurrentSkeleton() const;
|
||||
CAnimation* CurrentAnimation() const;
|
||||
void SetActiveAnimSet(CAnimSet *pSet);
|
||||
void SetSelectedBone(CBone *pBone);
|
||||
CCharacterEditorViewport* Viewport() const;
|
||||
|
||||
public slots:
|
||||
void Open();
|
||||
|
|
|
@ -168,7 +168,9 @@ HEADERS += \
|
|||
ResourceBrowser/CResourceBrowser.h \
|
||||
ResourceBrowser/CResourceTableModel.h \
|
||||
ResourceBrowser/CResourceProxyModel.h \
|
||||
ResourceBrowser/CVirtualDirectoryModel.h
|
||||
ResourceBrowser/CVirtualDirectoryModel.h \
|
||||
CEditorApplication.h \
|
||||
IEditor.h
|
||||
|
||||
# Source Files
|
||||
SOURCES += \
|
||||
|
@ -230,7 +232,8 @@ SOURCES += \
|
|||
CharacterEditor/CCharacterEditorViewport.cpp \
|
||||
CharacterEditor/CSkeletonHierarchyModel.cpp \
|
||||
CProjectOverviewDialog.cpp \
|
||||
ResourceBrowser/CResourceBrowser.cpp
|
||||
ResourceBrowser/CResourceBrowser.cpp \
|
||||
CEditorApplication.cpp
|
||||
|
||||
# UI Files
|
||||
FORMS += \
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef IEDITOR
|
||||
#define IEDITOR
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "CEditorApplication.h"
|
||||
|
||||
class IEditor : public QMainWindow
|
||||
{
|
||||
public:
|
||||
IEditor(QWidget *pParent)
|
||||
: QMainWindow(pParent)
|
||||
{
|
||||
gpEdApp->AddEditor(this);
|
||||
}
|
||||
|
||||
virtual void EditorTick(float /*DeltaTime*/) { }
|
||||
virtual CBasicViewport* Viewport() const { return nullptr; }
|
||||
};
|
||||
|
||||
#endif // IEDITOR
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
#include <QMouseEvent>
|
||||
|
||||
INodeEditor::INodeEditor(QWidget *pParent)
|
||||
: QMainWindow(pParent)
|
||||
: IEditor(pParent)
|
||||
, mPickMode(false)
|
||||
, mpSelection(new CNodeSelection)
|
||||
, mSelectionLocked(false)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef INODEEDITOR_H
|
||||
#define INODEEDITOR_H
|
||||
|
||||
#include "IEditor.h"
|
||||
#include "CGizmo.h"
|
||||
#include "CNodeSelection.h"
|
||||
#include <Math/ETransformSpace.h>
|
||||
|
@ -13,7 +14,7 @@
|
|||
#include <QList>
|
||||
#include <QUndoStack>
|
||||
|
||||
class INodeEditor : public QMainWindow
|
||||
class INodeEditor : public IEditor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <assimp/postprocess.h>
|
||||
|
||||
CModelEditorWindow::CModelEditorWindow(QWidget *pParent)
|
||||
: QMainWindow(pParent)
|
||||
: IEditor(pParent)
|
||||
, ui(new Ui::CModelEditorWindow)
|
||||
, mpScene(new CScene())
|
||||
, mpCurrentMat(nullptr)
|
||||
|
@ -54,10 +54,6 @@ CModelEditorWindow::CModelEditorWindow(QWidget *pParent)
|
|||
ui->PassTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
||||
ui->ClearColorPicker->SetColor(QColor(76, 76, 76, 255));
|
||||
|
||||
// Viewport Signal/Slot setup
|
||||
connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(RefreshViewport()));
|
||||
mRefreshTimer.start(0);
|
||||
|
||||
// Editor UI Signal/Slot setup
|
||||
ui->SetSelectionComboBox->setProperty ("ModelEditorWidgetType", eSetSelectComboBox);
|
||||
ui->MatSelectionComboBox->setProperty ("ModelEditorWidgetType", eMatSelectComboBox);
|
||||
|
@ -895,3 +891,8 @@ void CModelEditorWindow::closeEvent(QCloseEvent*)
|
|||
{
|
||||
emit Closed();
|
||||
}
|
||||
|
||||
CModelEditorViewport* CModelEditorWindow::Viewport() const
|
||||
{
|
||||
return ui->Viewport;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef CMODELEDITORWINDOW_H
|
||||
#define CMODELEDITORWINDOW_H
|
||||
|
||||
#include "IEditor.h"
|
||||
#include "CModelEditorViewport.h"
|
||||
#include <Core/GameProject/CResourceStore.h>
|
||||
#include <Core/Render/CRenderer.h>
|
||||
|
@ -16,7 +17,7 @@ namespace Ui {
|
|||
class CModelEditorWindow;
|
||||
}
|
||||
|
||||
class CModelEditorWindow : public QMainWindow
|
||||
class CModelEditorWindow : public IEditor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -28,13 +29,13 @@ class CModelEditorWindow : public QMainWindow
|
|||
CMaterial *mpCurrentMat;
|
||||
CMaterialPass *mpCurrentPass;
|
||||
bool mIgnoreSignals;
|
||||
QTimer mRefreshTimer;
|
||||
|
||||
public:
|
||||
explicit CModelEditorWindow(QWidget *pParent = 0);
|
||||
~CModelEditorWindow();
|
||||
void SetActiveModel(CModel *pModel);
|
||||
void closeEvent(QCloseEvent *pEvent);
|
||||
CModelEditorViewport* Viewport() const;
|
||||
|
||||
public slots:
|
||||
void RefreshViewport();
|
||||
|
|
|
@ -46,10 +46,6 @@ CWorldEditor::CWorldEditor(QWidget *parent)
|
|||
|
||||
mpSelection->SetAllowedNodeTypes(eScriptNode | eLightNode);
|
||||
|
||||
// Start refresh timer
|
||||
connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(RefreshViewport()));
|
||||
mRefreshTimer.start(0);
|
||||
|
||||
// Initialize splitter
|
||||
QList<int> SplitterSizes;
|
||||
SplitterSizes << width() * 0.775 << width() * 0.225;
|
||||
|
@ -912,7 +908,7 @@ void CWorldEditor::UpdateCameraOrbit()
|
|||
if (!mpSelection->IsEmpty())
|
||||
pCamera->SetOrbit(mpSelection->Bounds());
|
||||
else if (mpArea)
|
||||
pCamera->SetOrbit(mpArea->AABox(), 1.5f);
|
||||
pCamera->SetOrbit(mpArea->AABox(), 1.2f);
|
||||
}
|
||||
|
||||
void CWorldEditor::OnCameraSpeedChange(double Speed)
|
||||
|
|
|
@ -37,7 +37,6 @@ class CWorldEditor : public INodeEditor
|
|||
|
||||
TResPtr<CWorld> mpWorld;
|
||||
TResPtr<CGameArea> mpArea;
|
||||
QTimer mRefreshTimer;
|
||||
|
||||
CLinkDialog *mpLinkDialog;
|
||||
CPoiMapEditDialog *mpPoiDialog;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "CStartWindow.h"
|
||||
#include "CEditorApplication.h"
|
||||
#include "CProjectOverviewDialog.h"
|
||||
#include <Common/Log.h>
|
||||
#include <Core/Resource/Factory/CTemplateLoader.h>
|
||||
|
@ -24,7 +24,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
// Create application
|
||||
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
||||
QApplication App(argc, argv);
|
||||
CEditorApplication App(argc, argv);
|
||||
App.setWindowIcon(QIcon(":/icons/AppIcon.ico"));
|
||||
|
||||
// Init log
|
||||
|
|
Loading…
Reference in New Issue