Polished collision editor UI a bit
This commit is contained in:
parent
0827c05802
commit
3507be8e42
|
@ -1 +1 @@
|
||||||
Subproject commit fe3ccf42b71382683f976bb0509a8e68578e1deb
|
Subproject commit 685830ad4aa398baee88df2f010ef94f5915c03d
|
|
@ -380,7 +380,8 @@ SOURCES += \
|
||||||
Resource/Scan/CScan.cpp \
|
Resource/Scan/CScan.cpp \
|
||||||
Resource/Cooker/CScanCooker.cpp \
|
Resource/Cooker/CScanCooker.cpp \
|
||||||
NCoreTests.cpp \
|
NCoreTests.cpp \
|
||||||
Resource/Collision/CCollisionRenderData.cpp
|
Resource/Collision/CCollisionRenderData.cpp \
|
||||||
|
Resource/Collision/CCollidableOBBTree.cpp
|
||||||
|
|
||||||
# Codegen
|
# Codegen
|
||||||
CODEGEN_DIR = $$EXTERNALS_DIR/CodeGen
|
CODEGEN_DIR = $$EXTERNALS_DIR/CodeGen
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "CCollidableOBBTree.h"
|
||||||
|
|
||||||
|
void CCollidableOBBTree::BuildRenderData()
|
||||||
|
{
|
||||||
|
if (!mRenderData.IsBuilt())
|
||||||
|
{
|
||||||
|
mRenderData.BuildRenderData(mIndexData);
|
||||||
|
mRenderData.BuildBoundingHierarchyRenderData(mpOBBTree.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCollidableOBBTree::BuildOBBTree()
|
||||||
|
{
|
||||||
|
}
|
|
@ -11,14 +11,9 @@ class CCollidableOBBTree : public CCollisionMesh
|
||||||
std::unique_ptr<SOBBTreeNode> mpOBBTree;
|
std::unique_ptr<SOBBTreeNode> mpOBBTree;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void BuildRenderData() override
|
virtual void BuildRenderData() override;
|
||||||
{
|
|
||||||
if (!mRenderData.IsBuilt())
|
void BuildOBBTree();
|
||||||
{
|
|
||||||
mRenderData.BuildRenderData(mIndexData);
|
|
||||||
mRenderData.BuildBoundingHierarchyRenderData(mpOBBTree.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Accessors */
|
/** Accessors */
|
||||||
inline SOBBTreeNode* GetOBBTree() const
|
inline SOBBTreeNode* GetOBBTree() const
|
||||||
|
|
|
@ -134,7 +134,7 @@ void CCollisionRenderData::BuildBoundingHierarchyRenderData(const SOBBTreeNode*
|
||||||
mBoundingIndexBuffer.SetPrimitiveType(GL_LINES);
|
mBoundingIndexBuffer.SetPrimitiveType(GL_LINES);
|
||||||
|
|
||||||
// Iterate through the OBB tree, building a list of nodes as we go.
|
// 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
|
// 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.
|
// subset of the bounding hierarchy based on a max depth level.
|
||||||
std::vector<const SOBBTreeNode*> TreeNodes;
|
std::vector<const SOBBTreeNode*> TreeNodes;
|
||||||
|
@ -199,7 +199,7 @@ void CCollisionRenderData::BuildBoundingHierarchyRenderData(const SOBBTreeNode*
|
||||||
2, 6,
|
2, 6,
|
||||||
3, 7
|
3, 7
|
||||||
};
|
};
|
||||||
uint FirstIndex = mBoundingIndexBuffer.GetSize();
|
uint FirstIndex = mBoundingVertexBuffer.Size() - 8;
|
||||||
for (uint i=0; i<24; i++)
|
for (uint i=0; i<24; i++)
|
||||||
{
|
{
|
||||||
mBoundingIndexBuffer.AddIndex(skUnitCubeWireIndices[i] + FirstIndex);
|
mBoundingIndexBuffer.AddIndex(skUnitCubeWireIndices[i] + FirstIndex);
|
||||||
|
@ -261,3 +261,8 @@ void CCollisionRenderData::RenderBoundingHierarchy(int MaxDepthLevel /*= -1*/)
|
||||||
mBoundingIndexBuffer.DrawElements(FirstIndex, NumIndices);
|
mBoundingIndexBuffer.DrawElements(FirstIndex, NumIndices);
|
||||||
mBoundingVertexBuffer.Unbind();
|
mBoundingVertexBuffer.Unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CCollisionRenderData::MaxBoundingHierarchyDepth() const
|
||||||
|
{
|
||||||
|
return mBoundingHierarchyBuilt ? mBoundingDepthOffsets.size()-1 : 0;
|
||||||
|
}
|
||||||
|
|
|
@ -49,10 +49,10 @@ public:
|
||||||
/** Render */
|
/** Render */
|
||||||
void Render(bool Wireframe, int MaterialIndex = -1);
|
void Render(bool Wireframe, int MaterialIndex = -1);
|
||||||
void RenderBoundingHierarchy(int MaxDepthLevel = -1);
|
void RenderBoundingHierarchy(int MaxDepthLevel = -1);
|
||||||
|
int MaxBoundingHierarchyDepth() const;
|
||||||
|
|
||||||
/** Accessors */
|
/** Accessors */
|
||||||
inline bool IsBuilt() const { return mBuilt; }
|
inline bool IsBuilt() const { return mBuilt; }
|
||||||
inline int MaxBoundingHierarchyDepth() const { return mBoundingHierarchyBuilt ? mBoundingDepthOffsets.size() - 1 : 0; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CCOLLISIONRENDERDATA_H
|
#endif // CCOLLISIONRENDERDATA_H
|
||||||
|
|
|
@ -128,5 +128,14 @@ void CCollisionNode::SetCollision(CCollisionMeshGroup *pCollision)
|
||||||
if (mpCollision)
|
if (mpCollision)
|
||||||
{
|
{
|
||||||
mpCollision->BuildRenderData();
|
mpCollision->BuildRenderData();
|
||||||
|
|
||||||
|
// Update bounds
|
||||||
|
mLocalAABox = CAABox::skInfinite;
|
||||||
|
|
||||||
|
for (uint MeshIdx = 0; MeshIdx < pCollision->NumMeshes(); MeshIdx++)
|
||||||
|
{
|
||||||
|
CCollisionMesh* pMesh = pCollision->MeshByIndex(MeshIdx);
|
||||||
|
mLocalAABox.ExpandBounds(pMesh->Bounds());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
#include "CCollisionEditor.h"
|
#include "CCollisionEditor.h"
|
||||||
#include "ui_CCollisionEditor.h"
|
#include "ui_CCollisionEditor.h"
|
||||||
|
#include "Editor/UICommon.h"
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QSlider>
|
||||||
|
#include <QSpacerItem>
|
||||||
|
|
||||||
CCollisionEditor::CCollisionEditor(CCollisionMeshGroup* pCollisionMesh, QWidget* pParent /*= 0*/)
|
CCollisionEditor::CCollisionEditor(CCollisionMeshGroup* pCollisionMesh, QWidget* pParent /*= 0*/)
|
||||||
: IEditor(pParent)
|
: IEditor(pParent)
|
||||||
|
@ -18,11 +23,66 @@ CCollisionEditor::CCollisionEditor(CCollisionMeshGroup* pCollisionMesh, QWidget*
|
||||||
CCamera& rCamera = mpUI->Viewport->Camera();
|
CCamera& rCamera = mpUI->Viewport->Camera();
|
||||||
rCamera.SetMoveSpeed(0.5f);
|
rCamera.SetMoveSpeed(0.5f);
|
||||||
rCamera.SetPitch(-0.3f);
|
rCamera.SetPitch(-0.3f);
|
||||||
// rCamera.SetMoveMode(ECameraMoveMode::Orbit);
|
rCamera.SetMoveMode(ECameraMoveMode::Orbit);
|
||||||
// rCamera.SetOrbit(
|
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
|
CCollisionEditorViewport* CCollisionEditor::Viewport() const
|
||||||
{
|
{
|
||||||
return mpUI->Viewport;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,11 @@ public:
|
||||||
/** Constructor/destructor */
|
/** Constructor/destructor */
|
||||||
explicit CCollisionEditor(CCollisionMeshGroup* pCollisionMesh, QWidget* pParent = 0);
|
explicit CCollisionEditor(CCollisionMeshGroup* pCollisionMesh, QWidget* pParent = 0);
|
||||||
virtual CCollisionEditorViewport* Viewport() const override;
|
virtual CCollisionEditorViewport* Viewport() const override;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void OnGridToggled(bool Enabled);
|
||||||
|
void OnOrbitToggled(bool Enabled);
|
||||||
|
void OnOBBTreeDepthChanged(int NewValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CCOLLISIONEDITOR_H
|
#endif // CCOLLISIONEDITOR_H
|
||||||
|
|
|
@ -20,7 +20,64 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</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>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
@ -30,6 +87,8 @@
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources>
|
||||||
|
<include location="../Icons.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
CCollisionEditorViewport::CCollisionEditorViewport(QWidget* pParent /*= 0*/)
|
CCollisionEditorViewport::CCollisionEditorViewport(QWidget* pParent /*= 0*/)
|
||||||
: CBasicViewport(pParent)
|
: CBasicViewport(pParent)
|
||||||
|
, mGridEnabled(true)
|
||||||
{
|
{
|
||||||
mpRenderer = std::make_unique<CRenderer>();
|
mpRenderer = std::make_unique<CRenderer>();
|
||||||
mpRenderer->SetViewportSize(width(), height());
|
mpRenderer->SetViewportSize(width(), height());
|
||||||
|
@ -13,13 +14,8 @@ CCollisionEditorViewport::CCollisionEditorViewport(QWidget* pParent /*= 0*/)
|
||||||
mViewInfo.pRenderer = mpRenderer.get();
|
mViewInfo.pRenderer = mpRenderer.get();
|
||||||
mViewInfo.pScene = nullptr;
|
mViewInfo.pScene = nullptr;
|
||||||
mViewInfo.GameMode = false;
|
mViewInfo.GameMode = false;
|
||||||
mViewInfo.CollisionSettings.DrawBoundingHierarchy = true;
|
mViewInfo.CollisionSettings.DrawBoundingHierarchy = false;
|
||||||
}
|
mViewInfo.CollisionSettings.BoundingHierarchyRenderDepth = 0;
|
||||||
|
|
||||||
/** Update the collision node to render in the scene */
|
|
||||||
void CCollisionEditorViewport::SetNode(CCollisionNode* pNode)
|
|
||||||
{
|
|
||||||
mpCollisionNode = pNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** CBasicViewport interface */
|
/** CBasicViewport interface */
|
||||||
|
@ -27,7 +23,7 @@ void CCollisionEditorViewport::Paint()
|
||||||
{
|
{
|
||||||
mpRenderer->BeginFrame();
|
mpRenderer->BeginFrame();
|
||||||
mCamera.LoadMatrices();
|
mCamera.LoadMatrices();
|
||||||
//mGrid.AddToRenderer(mpRenderer.get(), mViewInfo);
|
if (mGridEnabled) mGrid.AddToRenderer(mpRenderer.get(), mViewInfo);
|
||||||
|
|
||||||
if (mpCollisionNode)
|
if (mpCollisionNode)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,17 +14,24 @@ class CCollisionEditorViewport : public CBasicViewport
|
||||||
std::unique_ptr<CRenderer> mpRenderer;
|
std::unique_ptr<CRenderer> mpRenderer;
|
||||||
CCollisionNode* mpCollisionNode;
|
CCollisionNode* mpCollisionNode;
|
||||||
CGridRenderable mGrid;
|
CGridRenderable mGrid;
|
||||||
|
bool mGridEnabled;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
CCollisionEditorViewport(QWidget* pParent = 0);
|
CCollisionEditorViewport(QWidget* pParent = 0);
|
||||||
|
|
||||||
/** Update the collision node to render in the scene */
|
|
||||||
void SetNode(CCollisionNode* pNode);
|
|
||||||
|
|
||||||
/** CBasicViewport interface */
|
/** CBasicViewport interface */
|
||||||
virtual void Paint() override;
|
virtual void Paint() override;
|
||||||
virtual void OnResize() 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
|
#endif // CCOLLISIONEDITORVIEWPORT_H
|
||||||
|
|
Loading…
Reference in New Issue