Polished collision editor UI a bit

This commit is contained in:
Aruki 2019-02-18 03:59:19 -07:00
parent 0827c05802
commit 3507be8e42
12 changed files with 179 additions and 28 deletions

2
externals/LibCommon vendored

@ -1 +1 @@
Subproject commit fe3ccf42b71382683f976bb0509a8e68578e1deb
Subproject commit 685830ad4aa398baee88df2f010ef94f5915c03d

View File

@ -380,7 +380,8 @@ SOURCES += \
Resource/Scan/CScan.cpp \
Resource/Cooker/CScanCooker.cpp \
NCoreTests.cpp \
Resource/Collision/CCollisionRenderData.cpp
Resource/Collision/CCollisionRenderData.cpp \
Resource/Collision/CCollidableOBBTree.cpp
# Codegen
CODEGEN_DIR = $$EXTERNALS_DIR/CodeGen

View File

@ -0,0 +1,14 @@
#include "CCollidableOBBTree.h"
void CCollidableOBBTree::BuildRenderData()
{
if (!mRenderData.IsBuilt())
{
mRenderData.BuildRenderData(mIndexData);
mRenderData.BuildBoundingHierarchyRenderData(mpOBBTree.get());
}
}
void CCollidableOBBTree::BuildOBBTree()
{
}

View File

@ -11,14 +11,9 @@ class CCollidableOBBTree : public CCollisionMesh
std::unique_ptr<SOBBTreeNode> mpOBBTree;
public:
virtual void BuildRenderData() override
{
if (!mRenderData.IsBuilt())
{
mRenderData.BuildRenderData(mIndexData);
mRenderData.BuildBoundingHierarchyRenderData(mpOBBTree.get());
}
}
virtual void BuildRenderData() override;
void BuildOBBTree();
/** Accessors */
inline SOBBTreeNode* GetOBBTree() const

View File

@ -134,7 +134,7 @@ void CCollisionRenderData::BuildBoundingHierarchyRenderData(const SOBBTreeNode*
mBoundingIndexBuffer.SetPrimitiveType(GL_LINES);
// Iterate through the OBB tree, building a list of nodes as we go.
// We iterate through this using a breadth-first search in order to group together
// We iterate through this using a breadth-first traversal in order to group together
// OBBs in the same depth level in the index buffer. This allows us to render a
// subset of the bounding hierarchy based on a max depth level.
std::vector<const SOBBTreeNode*> TreeNodes;
@ -199,7 +199,7 @@ void CCollisionRenderData::BuildBoundingHierarchyRenderData(const SOBBTreeNode*
2, 6,
3, 7
};
uint FirstIndex = mBoundingIndexBuffer.GetSize();
uint FirstIndex = mBoundingVertexBuffer.Size() - 8;
for (uint i=0; i<24; i++)
{
mBoundingIndexBuffer.AddIndex(skUnitCubeWireIndices[i] + FirstIndex);
@ -261,3 +261,8 @@ void CCollisionRenderData::RenderBoundingHierarchy(int MaxDepthLevel /*= -1*/)
mBoundingIndexBuffer.DrawElements(FirstIndex, NumIndices);
mBoundingVertexBuffer.Unbind();
}
int CCollisionRenderData::MaxBoundingHierarchyDepth() const
{
return mBoundingHierarchyBuilt ? mBoundingDepthOffsets.size()-1 : 0;
}

View File

@ -49,10 +49,10 @@ public:
/** Render */
void Render(bool Wireframe, int MaterialIndex = -1);
void RenderBoundingHierarchy(int MaxDepthLevel = -1);
int MaxBoundingHierarchyDepth() const;
/** Accessors */
inline bool IsBuilt() const { return mBuilt; }
inline int MaxBoundingHierarchyDepth() const { return mBoundingHierarchyBuilt ? mBoundingDepthOffsets.size() - 1 : 0; }
};
#endif // CCOLLISIONRENDERDATA_H

View File

@ -128,5 +128,14 @@ void CCollisionNode::SetCollision(CCollisionMeshGroup *pCollision)
if (mpCollision)
{
mpCollision->BuildRenderData();
// Update bounds
mLocalAABox = CAABox::skInfinite;
for (uint MeshIdx = 0; MeshIdx < pCollision->NumMeshes(); MeshIdx++)
{
CCollisionMesh* pMesh = pCollision->MeshByIndex(MeshIdx);
mLocalAABox.ExpandBounds(pMesh->Bounds());
}
}
}

View File

@ -1,5 +1,10 @@
#include "CCollisionEditor.h"
#include "ui_CCollisionEditor.h"
#include "Editor/UICommon.h"
#include <QLabel>
#include <QSlider>
#include <QSpacerItem>
CCollisionEditor::CCollisionEditor(CCollisionMeshGroup* pCollisionMesh, QWidget* pParent /*= 0*/)
: IEditor(pParent)
@ -18,11 +23,66 @@ CCollisionEditor::CCollisionEditor(CCollisionMeshGroup* pCollisionMesh, QWidget*
CCamera& rCamera = mpUI->Viewport->Camera();
rCamera.SetMoveSpeed(0.5f);
rCamera.SetPitch(-0.3f);
// rCamera.SetMoveMode(ECameraMoveMode::Orbit);
// rCamera.SetOrbit(
rCamera.SetMoveMode(ECameraMoveMode::Orbit);
rCamera.SetOrbit(mpCollisionNode->AABox(), 4.f);
// Add depth widgets to the toolbar
mpUI->ToolBar->addSeparator();
mpUI->ToolBar->addWidget( new QLabel("OBBTree: ", this) );
int MaxDepth = 0;
for (uint MeshIdx = 0; MeshIdx < pCollisionMesh->NumMeshes(); MeshIdx++)
{
CCollisionMesh* pMesh = pCollisionMesh->MeshByIndex(MeshIdx);
int MeshDepth = pMesh->GetRenderData().MaxBoundingHierarchyDepth();
MaxDepth = Math::Max(MeshDepth, MaxDepth);
}
QSlider* pOBBTreeSlider = new QSlider(this);
pOBBTreeSlider->setMinimum(0);
pOBBTreeSlider->setMaximum(MaxDepth);
pOBBTreeSlider->setOrientation(Qt::Horizontal);
pOBBTreeSlider->setMaximumWidth(100);
connect(pOBBTreeSlider, SIGNAL(valueChanged(int)),
this, SLOT(OnOBBTreeDepthChanged(int)));
mpUI->ToolBar->addWidget(pOBBTreeSlider);
QWidget* pSpacerWidget = new QWidget(this);
pSpacerWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
mpUI->ToolBar->addWidget(pSpacerWidget);
// Connections
connect(mpUI->ActionToggleGrid, SIGNAL(toggled(bool)),
this, SLOT(OnGridToggled(bool)));
connect(mpUI->ActionToggleOrbit, SIGNAL(toggled(bool)),
this, SLOT(OnOrbitToggled(bool)));
// Update window title
QString WindowTitle = "%APP_FULL_NAME% - Collision Editor - %1[*]";
WindowTitle = WindowTitle.arg( TO_QSTRING(mpCollisionMesh->Entry()->CookedAssetPath(true).GetFileName()) );
SET_WINDOWTITLE_APPVARS(WindowTitle);
}
CCollisionEditorViewport* CCollisionEditor::Viewport() const
{
return mpUI->Viewport;
}
void CCollisionEditor::OnGridToggled(bool Enabled)
{
mpUI->Viewport->SetGridEnabled(Enabled);
}
void CCollisionEditor::OnOrbitToggled(bool Enabled)
{
CCamera& Camera = mpUI->Viewport->Camera();
Camera.SetMoveMode( Enabled ? ECameraMoveMode::Orbit : ECameraMoveMode::Free );
}
void CCollisionEditor::OnOBBTreeDepthChanged(int NewValue)
{
mpUI->Viewport->SetOBBTreeDepth(NewValue);
}

View File

@ -29,6 +29,11 @@ public:
/** Constructor/destructor */
explicit CCollisionEditor(CCollisionMeshGroup* pCollisionMesh, QWidget* pParent = 0);
virtual CCollisionEditorViewport* Viewport() const override;
public slots:
void OnGridToggled(bool Enabled);
void OnOrbitToggled(bool Enabled);
void OnOBBTreeDepthChanged(int NewValue);
};
#endif // CCOLLISIONEDITOR_H

View File

@ -20,7 +20,64 @@
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="ToolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="ActionToggleGrid"/>
<addaction name="ActionToggleOrbit"/>
</widget>
<action name="ActionToggleGrid">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../Icons.qrc">
<normaloff>:/icons/Grid_32px.png</normaloff>:/icons/Grid_32px.png</iconset>
</property>
<property name="text">
<string>Toggle Grid</string>
</property>
<property name="shortcut">
<string>G</string>
</property>
</action>
<action name="ActionToggleOrbit">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../Icons.qrc">
<normaloff>:/icons/OrbitCamera_32px.png</normaloff>:/icons/OrbitCamera_32px.png</iconset>
</property>
<property name="text">
<string>Toggle Orbit</string>
</property>
<property name="toolTip">
<string>Toggle Orbit</string>
</property>
<property name="shortcut">
<string>Z</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
@ -30,6 +87,8 @@
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="../Icons.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -3,6 +3,7 @@
/** Constructor */
CCollisionEditorViewport::CCollisionEditorViewport(QWidget* pParent /*= 0*/)
: CBasicViewport(pParent)
, mGridEnabled(true)
{
mpRenderer = std::make_unique<CRenderer>();
mpRenderer->SetViewportSize(width(), height());
@ -13,13 +14,8 @@ CCollisionEditorViewport::CCollisionEditorViewport(QWidget* pParent /*= 0*/)
mViewInfo.pRenderer = mpRenderer.get();
mViewInfo.pScene = nullptr;
mViewInfo.GameMode = false;
mViewInfo.CollisionSettings.DrawBoundingHierarchy = true;
}
/** Update the collision node to render in the scene */
void CCollisionEditorViewport::SetNode(CCollisionNode* pNode)
{
mpCollisionNode = pNode;
mViewInfo.CollisionSettings.DrawBoundingHierarchy = false;
mViewInfo.CollisionSettings.BoundingHierarchyRenderDepth = 0;
}
/** CBasicViewport interface */
@ -27,7 +23,7 @@ void CCollisionEditorViewport::Paint()
{
mpRenderer->BeginFrame();
mCamera.LoadMatrices();
//mGrid.AddToRenderer(mpRenderer.get(), mViewInfo);
if (mGridEnabled) mGrid.AddToRenderer(mpRenderer.get(), mViewInfo);
if (mpCollisionNode)
{

View File

@ -14,17 +14,24 @@ class CCollisionEditorViewport : public CBasicViewport
std::unique_ptr<CRenderer> mpRenderer;
CCollisionNode* mpCollisionNode;
CGridRenderable mGrid;
bool mGridEnabled;
public:
/** Constructor */
CCollisionEditorViewport(QWidget* pParent = 0);
/** Update the collision node to render in the scene */
void SetNode(CCollisionNode* pNode);
/** CBasicViewport interface */
virtual void Paint() override;
virtual void OnResize() override;
/** Accessors */
inline void SetNode(CCollisionNode* pNode) { mpCollisionNode = pNode; }
inline void SetGridEnabled(bool Enabled) { mGridEnabled = Enabled; }
inline void SetOBBTreeDepth(int Depth)
{
mViewInfo.CollisionSettings.DrawBoundingHierarchy = (Depth > 0);
mViewInfo.CollisionSettings.BoundingHierarchyRenderDepth = Depth;
}
};
#endif // CCOLLISIONEDITORVIEWPORT_H