3D Preview - Leo's fixes and formatting

This commit is contained in:
Trevor SANDY 2020-10-07 10:08:58 +02:00
parent a239e504ec
commit 506b7a175f
2 changed files with 75 additions and 88 deletions

View file

@ -13,8 +13,8 @@
lcPreviewWidget* gPreviewWidget; lcPreviewWidget* gPreviewWidget;
lcPreviewDockWidget::lcPreviewDockWidget(QMainWindow *parent) lcPreviewDockWidget::lcPreviewDockWidget(QMainWindow* Parent)
:QMainWindow(parent) : QMainWindow(Parent)
{ {
Preview = new lcPreviewWidget(); Preview = new lcPreviewWidget();
ViewWidget = new lcQGLWidget(nullptr, Preview, true/*IsView*/, true/*IsPreview*/); ViewWidget = new lcQGLWidget(nullptr, Preview, true/*IsView*/, true/*IsPreview*/);
@ -23,14 +23,15 @@ lcPreviewDockWidget::lcPreviewDockWidget(QMainWindow *parent)
ToolBar = addToolBar(tr("PreviewDescription")); ToolBar = addToolBar(tr("PreviewDescription"));
ToolBar->setObjectName("PreviewDescription"); ToolBar->setObjectName("PreviewDescription");
ToolBar->setMovable(false); ToolBar->setMovable(false);
Label = new QLabel(""); Label = new QLabel(QString());
ToolBar->addWidget(Label); ToolBar->addWidget(Label);
} }
bool lcPreviewDockWidget::SetCurrentPiece(const QString &PartType, int ColorCode) bool lcPreviewDockWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
{ {
Label->setText("Loading..."); Label->setText("Loading...");
if (Preview->SetCurrentPiece(PartType, ColorCode)) { if (Preview->SetCurrentPiece(PartType, ColorCode))
{
Label->setText(Preview->GetDescription()); Label->setText(Preview->GetDescription());
return true; return true;
} }
@ -40,13 +41,12 @@ bool lcPreviewDockWidget::SetCurrentPiece(const QString &PartType, int ColorCode
void lcPreviewDockWidget::ClearPreview() void lcPreviewDockWidget::ClearPreview()
{ {
Preview->ClearPreview(); Preview->ClearPreview();
Label->setText(""); Label->setText(QString());
} }
lcPreviewWidget::lcPreviewWidget() lcPreviewWidget::lcPreviewWidget()
: mLoader(new Project(true/*IsPreview*/)), : mLoader(new Project(true/*IsPreview*/)),
mViewSphere(this/*Preview*/), mViewSphere(this/*Preview*/)
mIsPart(false)
{ {
mTool = LC_TOOL_SELECT; mTool = LC_TOOL_SELECT;
mTrackTool = LC_TRACKTOOL_NONE; mTrackTool = LC_TRACKTOOL_NONE;
@ -64,22 +64,16 @@ lcPreviewWidget::~lcPreviewWidget()
if (mCamera && mCamera->IsSimple()) if (mCamera && mCamera->IsSimple())
delete mCamera; delete mCamera;
if (mIsPart) { delete mLoader;
lcPiecesLibrary* Library = lcGetPiecesLibrary();
for (lcPiece* Piece : mModel->GetPieces())
{
PieceInfo *Info = Piece->mPieceInfo;
Library->ReleasePieceInfo(Info);
}
}
} }
bool lcPreviewWidget::SetCurrentPiece(const QString &PartType, int ColorCode) bool lcPreviewWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
{ {
lcPiecesLibrary *Library = lcGetPiecesLibrary(); lcPiecesLibrary* Library = lcGetPiecesLibrary();
PieceInfo* Info = Library->FindPiece(PartType.toLatin1().constData(), nullptr, false, false); PieceInfo* Info = Library->FindPiece(PartType.toLatin1().constData(), nullptr, false, false);
if (Info) {
mIsPart = true; if (Info)
{
mDescription = Info->m_strDescription; mDescription = Info->m_strDescription;
lcModel* ActiveModel = GetActiveModel(); lcModel* ActiveModel = GetActiveModel();
@ -89,27 +83,22 @@ bool lcPreviewWidget::SetCurrentPiece(const QString &PartType, int ColorCode)
Library->LoadPieceInfo(Info, false, true); Library->LoadPieceInfo(Info, false, true);
Library->WaitForLoadQueue(); Library->WaitForLoadQueue();
float* Matrix = lcMatrix44Identity();; lcStep CurrentStep = 1;
lcMatrix44 Transform(lcVector4( Matrix[0], Matrix[2], -Matrix[1], 0.0f), lcVector4(Matrix[8], Matrix[10], -Matrix[9], 0.0f),
lcVector4(-Matrix[4], -Matrix[6], Matrix[5], 0.0f), lcVector4(Matrix[12], Matrix[14], -Matrix[13], 1.0f));
int CurrentStep = 1;
lcPiece* Piece = new lcPiece(nullptr); lcPiece* Piece = new lcPiece(nullptr);
Piece->SetPieceInfo(Info, PartType, false); Piece->SetPieceInfo(Info, PartType, false);
Piece->Initialize(Transform, CurrentStep); Piece->Initialize(lcMatrix44Identity(), CurrentStep);
Piece->SetColorCode(ColorCode); Piece->SetColorCode(ColorCode);
ActiveModel->SetPreviewPiece(Piece); ActiveModel->SetPreviewPiece(Piece);
}
else
{
QString ModelPath = QString("%1/%2").arg(QDir::currentPath()).arg(PartType);
Piece = nullptr; if (!mLoader->Load(ModelPath))
} else { {
QString ModelPath = QString("%1/%2") QMessageBox::warning(nullptr, QMessageBox::tr("Error"), QMessageBox::tr("Failed to load '%1'.").arg(ModelPath));
.arg(QDir::currentPath())
.arg(PartType);
if (!mLoader->Load(ModelPath)) {
QMessageBox::critical(nullptr, QMessageBox::tr("Error"), QMessageBox::tr("Failed to load '%1'.").arg(ModelPath));
return false; return false;
} }
@ -121,6 +110,7 @@ bool lcPreviewWidget::SetCurrentPiece(const QString &PartType, int ColorCode)
else else
mDescription = PartType; mDescription = PartType;
} }
ZoomExtents(); ZoomExtents();
return true; return true;
@ -158,7 +148,8 @@ lcModel* lcPreviewWidget::GetActiveModel() const
void lcPreviewWidget::ZoomExtents() void lcPreviewWidget::ZoomExtents()
{ {
lcModel* ActiveModel = GetActiveModel(); lcModel* ActiveModel = GetActiveModel();
if (ActiveModel) { if (ActiveModel)
{
ActiveModel->ZoomExtents(mCamera, float(mWidth) / float(mHeight)); ActiveModel->ZoomExtents(mCamera, float(mWidth) / float(mHeight));
Redraw(); Redraw();
} }
@ -231,7 +222,7 @@ void lcPreviewWidget::DrawViewport()
void lcPreviewWidget::DrawAxes() void lcPreviewWidget::DrawAxes()
{ {
// glClear(GL_DEPTH_BUFFER_BIT); // glClear(GL_DEPTH_BUFFER_BIT);
const float Verts[28 * 3] = const float Verts[28 * 3] =
{ {
@ -281,14 +272,14 @@ void lcPreviewWidget::DrawAxes()
glEnable(GL_BLEND); glEnable(GL_BLEND);
float TextBuffer[6 * 5 * 3]; float TextBuffer[6 * 5 * 3];
/*** Native viewer camera globe mod, switch Y and Z axis with -Y(LC -Z) in the up direction ***/ /*** Native viewer camera globe mod, switch Y and Z axis with -Y(LC -Z) in the up direction ***/
lcVector3 PosX = lcMul30(lcVector3(25.0f, 0.0f, 0.0f), WorldViewMatrix); lcVector3 PosX = lcMul30(lcVector3(25.0f, 0.0f, 0.0f), WorldViewMatrix);
gTexFont.GetGlyphTriangles(PosX.x, PosX.y, PosX.z, 'X', TextBuffer); gTexFont.GetGlyphTriangles(PosX.x, PosX.y, PosX.z, 'X', TextBuffer);
lcVector3 PosY = lcMul30(lcVector3(0.0f, 25.0f, 0.0f), WorldViewMatrix); lcVector3 PosY = lcMul30(lcVector3(0.0f, 25.0f, 0.0f), WorldViewMatrix);
gTexFont.GetGlyphTriangles(PosY.x, PosY.y, PosY.z, 'Z', TextBuffer + 5 * 6); gTexFont.GetGlyphTriangles(PosY.x, PosY.y, PosY.z, 'Z', TextBuffer + 5 * 6);
lcVector3 PosZ = lcMul30(lcVector3(0.0f, 0.0f, 25.0f), WorldViewMatrix); lcVector3 PosZ = lcMul30(lcVector3(0.0f, 0.0f, 25.0f), WorldViewMatrix);
gTexFont.GetGlyphTriangles(PosZ.x, PosZ.y, PosZ.z, 'Y', TextBuffer + 5 * 6 * 2); gTexFont.GetGlyphTriangles(PosZ.x, PosZ.y, PosZ.z, 'Y', TextBuffer + 5 * 6 * 2);
/*** Camera globe mod end ***/ /*** Camera globe mod end ***/
mContext->SetVertexBufferPointer(TextBuffer); mContext->SetVertexBufferPointer(TextBuffer);
mContext->SetVertexFormat(0, 3, 0, 2, 0, false); mContext->SetVertexFormat(0, 3, 0, 2, 0, false);

View file

@ -1,5 +1,4 @@
#ifndef PREVIEWWIDGET_H #pragma once
#define PREVIEWWIDGET_H
#include <QMainWindow> #include <QMainWindow>
#include <QString> #include <QString>
@ -134,12 +133,9 @@ protected:
QString mDescription; QString mDescription;
bool mIsPart;
bool mTrackUpdated; bool mTrackUpdated;
int mMouseDownX; int mMouseDownX;
int mMouseDownY; int mMouseDownY;
}; };
extern class lcPreviewWidget* gPreviewWidget; extern lcPreviewWidget* gPreviewWidget;
#endif // PREVIEWWIDGET_H