mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-21 18:59:12 +00:00
Split off lots of editor functionality into new abstract INodeEditor class and viewport functionality into CBasicViewport class; added viewport subclasses and undo/redo system in the World Editor
This commit is contained in:
95
UI/CModelEditorViewport.cpp
Normal file
95
UI/CModelEditorViewport.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#include "CModelEditorViewport.h"
|
||||
#include <Core/CDrawUtil.h>
|
||||
|
||||
CModelEditorViewport::CModelEditorViewport(QWidget *pParent)
|
||||
: CBasicViewport(pParent),
|
||||
mMode(eDrawMesh),
|
||||
mpActiveMaterial(nullptr),
|
||||
mpModelNode(nullptr)
|
||||
{
|
||||
mpRenderer = new CRenderer();
|
||||
mpRenderer->SetViewportSize(width(), height());
|
||||
mpRenderer->SetClearColor(CColor::skBlack);
|
||||
mpRenderer->ToggleGrid(true);
|
||||
}
|
||||
|
||||
CModelEditorViewport::~CModelEditorViewport()
|
||||
{
|
||||
delete mpRenderer;
|
||||
}
|
||||
|
||||
void CModelEditorViewport::SetNode(CModelNode *pNode)
|
||||
{
|
||||
mpModelNode = pNode;
|
||||
}
|
||||
|
||||
void CModelEditorViewport::SetActiveMaterial(CMaterial *pMat)
|
||||
{
|
||||
mpActiveMaterial = pMat;
|
||||
}
|
||||
|
||||
void CModelEditorViewport::SetDrawMode(EDrawMode mode)
|
||||
{
|
||||
mMode = mode;
|
||||
}
|
||||
|
||||
void CModelEditorViewport::SetClearColor(CColor color)
|
||||
{
|
||||
mpRenderer->SetClearColor(color);
|
||||
}
|
||||
|
||||
void CModelEditorViewport::Paint()
|
||||
{
|
||||
mpRenderer->BeginFrame();
|
||||
mCamera.LoadMatrices();
|
||||
|
||||
if (!mpModelNode->Model())
|
||||
CDrawUtil::DrawGrid();
|
||||
|
||||
else if (mMode == eDrawMesh)
|
||||
{
|
||||
CDrawUtil::DrawGrid();
|
||||
mpModelNode->AddToRenderer(mpRenderer);
|
||||
mpRenderer->RenderBuckets(mCamera);
|
||||
}
|
||||
|
||||
else if (mMode == eDrawSphere)
|
||||
{
|
||||
if (!mpActiveMaterial) return;
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
CGraphics::sVertexBlock.COLOR0_Amb = CGraphics::skDefaultAmbientColor.ToVector4f();
|
||||
CGraphics::sMVPBlock.ModelMatrix = CMatrix4f::skIdentity;
|
||||
CGraphics::UpdateMVPBlock();
|
||||
CGraphics::SetDefaultLighting();
|
||||
CGraphics::UpdateLightBlock(); // Note: vertex block is updated by the material
|
||||
mpActiveMaterial->SetCurrent(eEnableUVScroll | eEnableBackfaceCull | eEnableOccluders);
|
||||
|
||||
CDrawUtil::DrawSphere(true);
|
||||
}
|
||||
|
||||
else if (mMode == eDrawSquare)
|
||||
{
|
||||
if (!mpActiveMaterial) return;
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
CGraphics::SetDefaultLighting();
|
||||
CGraphics::UpdateLightBlock();
|
||||
CGraphics::sVertexBlock.COLOR0_Amb = CGraphics::skDefaultAmbientColor.ToVector4f();
|
||||
|
||||
CGraphics::sMVPBlock.ModelMatrix = CMatrix4f::skIdentity;
|
||||
CGraphics::sMVPBlock.ViewMatrix = CMatrix4f::skIdentity;
|
||||
CGraphics::sMVPBlock.ProjectionMatrix = CMatrix4f::skIdentity;
|
||||
CGraphics::UpdateMVPBlock();
|
||||
|
||||
mpActiveMaterial->SetCurrent(eEnableUVScroll | eEnableOccluders);
|
||||
CDrawUtil::DrawSquare();
|
||||
}
|
||||
|
||||
mpRenderer->EndFrame();
|
||||
}
|
||||
|
||||
void CModelEditorViewport::OnResize()
|
||||
{
|
||||
mpRenderer->SetViewportSize(width(), height());
|
||||
}
|
||||
Reference in New Issue
Block a user