Added a basic UI to change collision render settings, added the ability to color collision based on the surface type

This commit is contained in:
parax0 2016-12-26 23:02:32 -07:00
parent 78baa42bce
commit be40dfdf02
13 changed files with 254 additions and 8 deletions

View File

@ -301,12 +301,22 @@ public:
inline u32 ToInt32(int Base = 16) const inline u32 ToInt32(int Base = 16) const
{ {
return std::stoul(mInternalString, nullptr, Base); try {
return std::stoul(mInternalString, nullptr, Base);
}
catch(...) {
return 0;
}
} }
inline u64 ToInt64(int Base = 16) const inline u64 ToInt64(int Base = 16) const
{ {
return std::stoull(mInternalString, nullptr, Base); try {
return std::stoull(mInternalString, nullptr, Base);
}
catch(...) {
return 0;
}
} }
void ToInt128(CharType* pOut, int Base = 16) const void ToInt128(CharType* pOut, int Base = 16) const
@ -453,6 +463,10 @@ public:
if (HasPrefix) if (HasPrefix)
Str = Str.ChopFront(2); Str = Str.ChopFront(2);
// If the string is empty other than the prefix, then this is not a valid hex string
if (Str.IsEmpty())
return false;
// If we have a variable width then assign the width value to the string size // If we have a variable width then assign the width value to the string size
Width = Str.Size(); Width = Str.Size();
} }

View File

@ -6,6 +6,23 @@
#include <Math/CMatrix4f.h> #include <Math/CMatrix4f.h>
#include <Math/CRay.h> #include <Math/CRay.h>
enum ECollisionDrawMode
{
eCDM_Default,
eCDM_TintSurfaceType
};
struct SCollisionRenderSettings
{
ECollisionDrawMode DrawMode;
u64 HighlightMask;
u64 HideMask;
bool DrawWireframe;
SCollisionRenderSettings()
: DrawMode(eCDM_TintSurfaceType), HighlightMask(0), HideMask(0), DrawWireframe(false) {}
};
struct SViewInfo struct SViewInfo
{ {
class CScene *pScene; class CScene *pScene;
@ -14,6 +31,7 @@ struct SViewInfo
bool GameMode; bool GameMode;
FShowFlags ShowFlags; FShowFlags ShowFlags;
SCollisionRenderSettings CollisionSettings;
CFrustumPlanes ViewFrustum; CFrustumPlanes ViewFrustum;
CMatrix4f RotationOnlyViewMatrix; CMatrix4f RotationOnlyViewMatrix;
}; };

View File

@ -3,6 +3,7 @@
#include "CResource.h" #include "CResource.h"
#include "CCollisionMesh.h" #include "CCollisionMesh.h"
#include "EGame.h"
#include "TResPtr.h" #include "TResPtr.h"
#include <vector> #include <vector>
@ -10,6 +11,7 @@ class CCollisionMeshGroup : public CResource
{ {
DECLARE_RESOURCE_TYPE(eCollisionMeshGroup) DECLARE_RESOURCE_TYPE(eCollisionMeshGroup)
std::vector<CCollisionMesh*> mMeshes; std::vector<CCollisionMesh*> mMeshes;
EGame mGame;
public: public:
CCollisionMeshGroup() {} CCollisionMeshGroup() {}
@ -20,8 +22,11 @@ public:
delete *it; delete *it;
} }
inline EGame Game() const { return mGame; }
inline u32 NumMeshes() const { return mMeshes.size(); } inline u32 NumMeshes() const { return mMeshes.size(); }
inline CCollisionMesh* MeshByIndex(u32 Index) const { return mMeshes[Index]; } inline CCollisionMesh* MeshByIndex(u32 Index) const { return mMeshes[Index]; }
inline void SetGame(EGame Game) { mGame = Game; }
inline void AddMesh(CCollisionMesh *pMesh) { mMeshes.push_back(pMesh); } inline void AddMesh(CCollisionMesh *pMesh) { mMeshes.push_back(pMesh); }
inline void Draw() inline void Draw()

View File

@ -144,6 +144,7 @@ CCollisionMeshGroup* CCollisionLoader::LoadAreaCollision(IInputStream& rMREA)
loader.mVersion = GetFormatVersion(rMREA.ReadLong()); loader.mVersion = GetFormatVersion(rMREA.ReadLong());
loader.mpGroup = new CCollisionMeshGroup; loader.mpGroup = new CCollisionMeshGroup;
loader.mpGroup->SetGame(loader.mVersion);
loader.mpMesh = new CCollisionMesh; loader.mpMesh = new CCollisionMesh;
// Octree - structure is known, but not coding this right now // Octree - structure is known, but not coding this right now
@ -180,6 +181,7 @@ CCollisionMeshGroup* CCollisionLoader::LoadDCLN(IInputStream& rDCLN)
} }
Loader.mVersion = GetFormatVersion(rDCLN.ReadLong()); Loader.mVersion = GetFormatVersion(rDCLN.ReadLong());
Loader.mpGroup->SetGame(Loader.mVersion);
Loader.mpMesh = new CCollisionMesh; Loader.mpMesh = new CCollisionMesh;
Loader.mpMesh->mOctreeLoaded = false; Loader.mpMesh->mOctreeLoaded = false;

View File

@ -45,13 +45,72 @@ void CCollisionNode::Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, ER
for (u32 iMat = 0; iMat < pMesh->NumMaterials(); iMat++) for (u32 iMat = 0; iMat < pMesh->NumMaterials(); iMat++)
{ {
CDrawUtil::UseCollisionShader(BaseTint); SCollisionMaterial& rMat = pMesh->GetMaterial(iMat);
if (rkViewInfo.CollisionSettings.HideMask != 0 && (rMat.RawFlags & rkViewInfo.CollisionSettings.HideMask) == rkViewInfo.CollisionSettings.HideMask)
continue;
CColor Tint = BaseTint;
if (rkViewInfo.CollisionSettings.HighlightMask != 0 && (rMat.RawFlags & rkViewInfo.CollisionSettings.HighlightMask) == rkViewInfo.CollisionSettings.HighlightMask)
Tint *= CColor::skRed;
else if (mpCollision->Game() <= ePrime && rkViewInfo.CollisionSettings.DrawMode == eCDM_TintSurfaceType)
{
// Organic
if (rMat.RawFlags & 0x00800000)
Tint *= CColor::Integral(130, 130, 250); // Purple
// Wood
else if (rMat.RawFlags & 0x00400000)
Tint *= CColor::Integral(190, 140, 105); // Brown
// Sand
else if (rMat.RawFlags & 0x00020000)
Tint *= CColor::Integral(230, 200, 170); // Light Brown
// Shield
else if (rMat.RawFlags & 0x00010000)
Tint *= CColor::Integral(250, 230, 60); // Yellow
// Glass
else if (rMat.RawFlags & 0x00008000)
Tint *= CColor::Integral(20, 255, 190); // Greenish/Bluish
// Snow
else if (rMat.RawFlags & 0x00000800)
Tint *= CColor::Integral(230, 255, 255); // *Very* light blue
// Lava
else if (rMat.RawFlags & 0x00000200)
Tint *= CColor::Integral(200, 30, 30); // Red
// Rock
else if (rMat.RawFlags & 0x00000100)
Tint *= CColor::Integral(150, 130, 120); // Brownish-gray
// Phazon
else if (rMat.RawFlags & 0x00000080)
Tint *= CColor::Integral(0, 128, 255); // Blue
// Metal Grating
else if (rMat.RawFlags & 0x00000040)
Tint *= CColor::Integral(170, 170, 170); // Gray
// Ice
else if (rMat.RawFlags & 0x00000010)
Tint *= CColor::Integral(200, 255, 255); // Light blue
// Grass
else if (rMat.RawFlags & 0x00000008)
Tint *= CColor::Integral(90, 150, 70); // Green
// Metal
else if (rMat.RawFlags & 0x00000004)
Tint *= CColor::Integral(110, 110, 110); // Dark gray
// Stone
else if (rMat.RawFlags & 0x00000002)
Tint *= CColor::Integral(220, 215, 160); // Brown/green ish
}
CDrawUtil::UseCollisionShader(Tint);
pMesh->DrawMaterial(iMat); pMesh->DrawMaterial(iMat);
} }
} }
//CDrawUtil::UseColorShader(CColor::skTransparentBlack); if (rkViewInfo.CollisionSettings.DrawWireframe)
//mpCollision->DrawWireframe(); {
CDrawUtil::UseColorShader(CColor::skTransparentBlack);
mpCollision->DrawWireframe();
}
} }
SRayIntersection CCollisionNode::RayNodeIntersectTest(const CRay& /*rkRay*/, u32 /*AssetID*/, const SViewInfo& /*rkViewInfo*/) SRayIntersection CCollisionNode::RayNodeIntersectTest(const CRay& /*rkRay*/, u32 /*AssetID*/, const SViewInfo& /*rkViewInfo*/)

View File

@ -64,6 +64,7 @@ public:
CVector2f MouseDeviceCoordinates(); CVector2f MouseDeviceCoordinates();
double LastRenderDuration(); double LastRenderDuration();
inline SCollisionRenderSettings& CollisionRenderSettings() { return mViewInfo.CollisionSettings; }
public slots: public slots:
void ProcessInput(); void ProcessInput();
void Render(); void Render();

View File

@ -164,7 +164,8 @@ HEADERS += \
CharacterEditor/CCharacterEditorViewport.h \ CharacterEditor/CCharacterEditorViewport.h \
CGridRenderable.h \ CGridRenderable.h \
CharacterEditor/CSkeletonHierarchyModel.h \ CharacterEditor/CSkeletonHierarchyModel.h \
CLineRenderable.h CLineRenderable.h \
WorldEditor/CCollisionRenderSettingsDialog.h
# Source Files # Source Files
SOURCES += \ SOURCES += \
@ -224,7 +225,8 @@ SOURCES += \
CAboutDialog.cpp \ CAboutDialog.cpp \
CharacterEditor/CCharacterEditor.cpp \ CharacterEditor/CCharacterEditor.cpp \
CharacterEditor/CCharacterEditorViewport.cpp \ CharacterEditor/CCharacterEditorViewport.cpp \
CharacterEditor/CSkeletonHierarchyModel.cpp CharacterEditor/CSkeletonHierarchyModel.cpp \
WorldEditor/CCollisionRenderSettingsDialog.cpp
# UI Files # UI Files
FORMS += \ FORMS += \
@ -245,4 +247,5 @@ FORMS += \
WorldEditor/CSelectInstanceDialog.ui \ WorldEditor/CSelectInstanceDialog.ui \
WorldEditor/CRepackInfoDialog.ui \ WorldEditor/CRepackInfoDialog.ui \
CAboutDialog.ui \ CAboutDialog.ui \
CharacterEditor/CCharacterEditor.ui CharacterEditor/CCharacterEditor.ui \
WorldEditor/CCollisionRenderSettingsDialog.ui

View File

@ -0,0 +1,40 @@
#include "CCollisionRenderSettingsDialog.h"
#include "ui_CCollisionRenderSettingsDialog.h"
#include "CWorldEditor.h"
#include "Editor/UICommon.h"
CCollisionRenderSettingsDialog::CCollisionRenderSettingsDialog(CWorldEditor *pEditor, QWidget *pParent /*= 0*/)
: QDialog(pParent)
, mpEditor(pEditor)
, mpUi(new Ui::CCollisionRenderSettingsDialog)
{
mpUi->setupUi(this);
connect(mpUi->HideMaskLineEdit, SIGNAL(textChanged(QString)), this, SLOT(OnHideMaskChanged(QString)));
connect(mpUi->HighlightMaskLineEdit, SIGNAL(textChanged(QString)), this, SLOT(OnHighlightMaskChanged(QString)));
connect(mpUi->WireframeCheckBox, SIGNAL(toggled(bool)), this, SLOT(OnWireframeToggled(bool)));
}
CCollisionRenderSettingsDialog::~CCollisionRenderSettingsDialog()
{
delete mpUi;
}
void CCollisionRenderSettingsDialog::OnHideMaskChanged(QString NewMask)
{
TString MaskStr = TO_TSTRING(NewMask);
u64 Mask = (MaskStr.IsHexString() ? MaskStr.ToInt64(16) : 0);
mpEditor->Viewport()->CollisionRenderSettings().HideMask = Mask;
}
void CCollisionRenderSettingsDialog::OnHighlightMaskChanged(QString NewMask)
{
TString MaskStr = TO_TSTRING(NewMask);
u64 Mask = (MaskStr.IsHexString() ? MaskStr.ToInt64(16) : 0);
mpEditor->Viewport()->CollisionRenderSettings().HighlightMask = Mask;
}
void CCollisionRenderSettingsDialog::OnWireframeToggled(bool Enable)
{
mpEditor->Viewport()->CollisionRenderSettings().DrawWireframe = Enable;
}

View File

@ -0,0 +1,29 @@
#ifndef CCOLLISIONRENDERSETTINGSDIALOG_H
#define CCOLLISIONRENDERSETTINGSDIALOG_H
#include <QDialog>
class CWorldEditor;
namespace Ui {
class CCollisionRenderSettingsDialog;
}
class CCollisionRenderSettingsDialog : public QDialog
{
Q_OBJECT
Ui::CCollisionRenderSettingsDialog *mpUi;
CWorldEditor *mpEditor;
public:
explicit CCollisionRenderSettingsDialog(CWorldEditor *pEditor, QWidget *pParent = 0);
~CCollisionRenderSettingsDialog();
public slots:
void OnHideMaskChanged(QString NewMask);
void OnHighlightMaskChanged(QString NewMask);
void OnWireframeToggled(bool Enable);
};
#endif // CCOLLISIONRENDERSETTINGSDIALOG_H

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CCollisionRenderSettingsDialog</class>
<widget class="QDialog" name="CCollisionRenderSettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>309</width>
<height>89</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="HideMaskLabel">
<property name="text">
<string>Hide Mask</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="HideMaskLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="HighlightMaskLabel">
<property name="text">
<string>Highlight Mask</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="HighlightMaskLineEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="WireframeLabel">
<property name="text">
<string>Wireframe</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="WireframeCheckBox">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -34,6 +34,7 @@ CWorldEditor::CWorldEditor(QWidget *parent)
, ui(new Ui::CWorldEditor) , ui(new Ui::CWorldEditor)
, mpArea(nullptr) , mpArea(nullptr)
, mpWorld(nullptr) , mpWorld(nullptr)
, mpCollisionDialog(new CCollisionRenderSettingsDialog(this, this))
, mpLinkDialog(new CLinkDialog(this, this)) , mpLinkDialog(new CLinkDialog(this, this))
, mpPoiDialog(nullptr) , mpPoiDialog(nullptr)
, mIsMakingLink(false) , mIsMakingLink(false)
@ -139,6 +140,7 @@ CWorldEditor::CWorldEditor(QWidget *parent)
connect(ui->ActionBloom, SIGNAL(triggered()), this, SLOT(SetBloom())); connect(ui->ActionBloom, SIGNAL(triggered()), this, SLOT(SetBloom()));
connect(ui->ActionIncrementGizmo, SIGNAL(triggered()), this, SLOT(IncrementGizmo())); connect(ui->ActionIncrementGizmo, SIGNAL(triggered()), this, SLOT(IncrementGizmo()));
connect(ui->ActionDecrementGizmo, SIGNAL(triggered()), this, SLOT(DecrementGizmo())); connect(ui->ActionDecrementGizmo, SIGNAL(triggered()), this, SLOT(DecrementGizmo()));
connect(ui->ActionCollisionRenderSettings, SIGNAL(triggered()), this, SLOT(EditCollisionRenderSettings()));
connect(ui->ActionEditLayers, SIGNAL(triggered()), this, SLOT(EditLayers())); connect(ui->ActionEditLayers, SIGNAL(triggered()), this, SLOT(EditLayers()));
connect(ui->ActionEditPoiToWorldMap, SIGNAL(triggered()), this, SLOT(EditPoiToWorldMap())); connect(ui->ActionEditPoiToWorldMap, SIGNAL(triggered()), this, SLOT(EditPoiToWorldMap()));
@ -1104,6 +1106,11 @@ void CWorldEditor::DecrementGizmo()
mGizmo.DecrementSize(); mGizmo.DecrementSize();
} }
void CWorldEditor::EditCollisionRenderSettings()
{
mpCollisionDialog->show();
}
void CWorldEditor::EditLayers() void CWorldEditor::EditLayers()
{ {
// Launch layer editor // Launch layer editor

View File

@ -1,6 +1,7 @@
#ifndef CWORLDEDITOR_H #ifndef CWORLDEDITOR_H
#define CWORLDEDITOR_H #define CWORLDEDITOR_H
#include "CCollisionRenderSettingsDialog.h"
#include "CLinkDialog.h" #include "CLinkDialog.h"
#include "CPoiMapEditDialog.h" #include "CPoiMapEditDialog.h"
#include "Editor/INodeEditor.h" #include "Editor/INodeEditor.h"
@ -39,6 +40,7 @@ class CWorldEditor : public INodeEditor
TResPtr<CGameArea> mpArea; TResPtr<CGameArea> mpArea;
QTimer mRefreshTimer; QTimer mRefreshTimer;
CCollisionRenderSettingsDialog *mpCollisionDialog;
CLinkDialog *mpLinkDialog; CLinkDialog *mpLinkDialog;
CPoiMapEditDialog *mpPoiDialog; CPoiMapEditDialog *mpPoiDialog;
@ -132,6 +134,7 @@ private slots:
void SetBloom(); void SetBloom();
void IncrementGizmo(); void IncrementGizmo();
void DecrementGizmo(); void DecrementGizmo();
void EditCollisionRenderSettings();
void EditLayers(); void EditLayers();
void EditPoiToWorldMap(); void EditPoiToWorldMap();

View File

@ -463,6 +463,7 @@
<addaction name="menuLighting"/> <addaction name="menuLighting"/>
<addaction name="menuBloom"/> <addaction name="menuBloom"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="ActionCollisionRenderSettings"/>
<addaction name="ActionDisableBackfaceCull"/> <addaction name="ActionDisableBackfaceCull"/>
<addaction name="ActionDisableAlpha"/> <addaction name="ActionDisableAlpha"/>
</widget> </widget>
@ -818,6 +819,11 @@
<string>Ctrl+Shift+S</string> <string>Ctrl+Shift+S</string>
</property> </property>
</action> </action>
<action name="ActionCollisionRenderSettings">
<property name="text">
<string>Collision Render Settings</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>