Skip to content

Commit

Permalink
Add scene node previewer
Browse files Browse the repository at this point in the history
  • Loading branch information
dgelessus committed Mar 1, 2024
1 parent 577cf95 commit f718963
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/PrpShop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ set(PrpShop_Headers
PRP/Surface/QLayerSDLAnimation.h
PRP/Surface/QMaterial.h
PRP/Surface/QMipmap.h
PRP/Render/QSceneNode_Preview.h
PRP/Render/QSceneObj_Preview.h
PRP/Render/QPlasmaRender.h
)
Expand Down Expand Up @@ -131,6 +132,7 @@ set(PrpShop_Sources
PRP/Surface/QMaterial.cpp
PRP/Surface/QMipmap.cpp
PRP/Render/QPlasmaRender.cpp
PRP/Render/QSceneNode_Preview.cpp
PRP/Render/QSceneObj_Preview.cpp
PRP/Render/QTrackball.cpp
)
Expand Down
3 changes: 3 additions & 0 deletions src/PrpShop/PRP/QCreatable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void QCreatable::closeEvent(QCloseEvent*)
#include "PRP/Surface/QLayerSDLAnimation.h"
#include "PRP/Surface/QMaterial.h"
#include "PRP/Surface/QMipmap.h"
#include "PRP/Render/QSceneNode_Preview.h"
#include "PRP/Render/QSceneObj_Preview.h"

QCreatable* pqMakeCreatableForm(plCreatable* pCre, QWidget* parent, int forceType)
Expand Down Expand Up @@ -285,6 +286,8 @@ QCreatable* pqMakeCreatableForm(plCreatable* pCre, QWidget* parent, int forceTyp
// Preview meta-types
case kPreviewMipmap:
return new QMipmap_Preview(pCre, parent);
case kPreviewSceneNode:
return new QSceneNode_Preview(pCre, parent);
case kPreviewSceneObject:
return new QSceneObj_Preview(pCre, parent);

Expand Down
53 changes: 53 additions & 0 deletions src/PrpShop/PRP/Render/QSceneNode_Preview.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* This file is part of PlasmaShop.
*
* PlasmaShop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlasmaShop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PlasmaShop. If not, see <http://www.gnu.org/licenses/>.
*/

#include "QSceneNode_Preview.h"

#include <PRP/plSceneNode.h>
#include <PRP/Object/plSceneObject.h>
#include <QToolBar>
#include <QGridLayout>

QSceneNode_Preview::QSceneNode_Preview(plCreatable* pCre, QWidget* parent)
: QCreatable(pCre, kPreviewSceneNode, parent)
{
plSceneNode* obj = plSceneNode::Convert(fCreatable);
fRender = new QPlasmaRender(this);
bool centered = false;
for (const auto& soKey : obj->getSceneObjects()) {
if (soKey->getType() == kSceneObject) {
fRender->addObject(soKey);
if (!centered) {
fRender->center(soKey, false);
centered = true;
}
}
}
fRender->build(QPlasmaRender::kNavModel, QPlasmaRender::kDrawTextured);
QSizePolicy renderPolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
fRender->setSizePolicy(renderPolicy);

QToolBar* viewToolbar = new QToolBar(tr("View"), this);
viewToolbar->setFloatable(false);
QActionGroup* viewActions = fRender->createViewActions();
viewToolbar->addActions(viewActions->actions());

QGridLayout* layout = new QGridLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setVerticalSpacing(0);
layout->addWidget(viewToolbar, 0, 0);
layout->addWidget(fRender, 1, 0);
}
34 changes: 34 additions & 0 deletions src/PrpShop/PRP/Render/QSceneNode_Preview.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* This file is part of PlasmaShop.
*
* PlasmaShop is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlasmaShop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PlasmaShop. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _QSCENENODE_PREVIEW_H
#define _QSCENENODE_PREVIEW_H

#include "PRP/QCreatable.h"
#include "QPlasmaRender.h"

class QSceneNode_Preview : public QCreatable
{
Q_OBJECT

protected:
QPlasmaRender* fRender;

public:
QSceneNode_Preview(plCreatable* pCre, QWidget* parent = NULL);
};

#endif
12 changes: 11 additions & 1 deletion src/PrpShop/QPlasmaUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <algorithm>
#include "QPlasmaUtils.h"
#include <ResManager/pdUnifiedTypeMap.h>
#include <PRP/plSceneNode.h>
#include <PRP/Object/plCoordinateInterface.h>
#include <PRP/Object/plSceneObject.h>

Expand Down Expand Up @@ -642,7 +643,16 @@ bool pqCanPreviewType(plCreatable* pCre)
};
static size_t s_numTypes = sizeof(s_typeList) / sizeof(s_typeList[0]);

if (type == kSceneObject) {
if (type == kSceneNode) {
plSceneNode* tmp = plSceneNode::Convert(pCre);
for (const auto& soKey : tmp->getSceneObjects()) {
plSceneObject* so = GET_KEY_OBJECT(soKey, plSceneObject);
if (so != NULL && pqCanPreviewSceneObject(so)) {
return true;
}
}
return false;
} else if (type == kSceneObject) {
plSceneObject* tmp = plSceneObject::Convert(pCre);
return pqCanPreviewSceneObject(tmp);
}
Expand Down

0 comments on commit f718963

Please sign in to comment.