Skip to content

Commit

Permalink
Merge pull request #76 from dgelessus/preview_more_scene_objects
Browse files Browse the repository at this point in the history
Allow previewing non-drawable scene objects with drawable children
  • Loading branch information
zrax authored Mar 1, 2024
2 parents 9ce55a6 + 936dd0d commit 228f0e5
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 3 deletions.
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
16 changes: 16 additions & 0 deletions src/PrpShop/PRP/Render/QPlasmaRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,22 @@ void QPlasmaRender::mouseReleaseEvent(QMouseEvent* evt)
}
}

void QPlasmaRender::addObject(plKey obj)
{
fObjects[obj] = ObjectInfo();

plSceneObject* sceneObj = GET_KEY_OBJECT(obj, plSceneObject);
plCoordinateInterface* coord = GET_KEY_OBJECT(sceneObj->getCoordInterface(), plCoordinateInterface);
if (coord == nullptr) {
return;
}
for (auto childKey : coord->getChildren()) {
if (childKey->getType() == kSceneObject) {
addObject(std::move(childKey));
}
}
}

void QPlasmaRender::setView(const hsVector3& view, float angle)
{
fViewPos = view;
Expand Down
2 changes: 1 addition & 1 deletion src/PrpShop/PRP/Render/QPlasmaRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class QPlasmaRender : public QOpenGLWidget
QSize minimumSizeHint() const override { return QSize(50, 50); }
QSize sizeHint() const override { return QSize(400, 400); }

void addObject(plKey obj) { fObjects[obj] = ObjectInfo(); }
void addObject(plKey obj);
void setView(const hsVector3& view, float angle = 0.0f);
void center(plKey obj, bool world);
void build(NavigationMode navMode, DrawMode drawMode);
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 = nullptr);
};

#endif
34 changes: 32 additions & 2 deletions src/PrpShop/QPlasmaUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <algorithm>
#include "QPlasmaUtils.h"
#include <ResManager/pdUnifiedTypeMap.h>
#include <PRP/plSceneNode.h>
#include <PRP/Object/plCoordinateInterface.h>
#include <PRP/Object/plSceneObject.h>

bool s_showTypeIDs = false;
Expand Down Expand Up @@ -613,6 +615,25 @@ bool pqIsValidKOType(short objType)
return std::find(valid_types.begin(), valid_types.end(), objType) != valid_types.end();
}

static bool pqCanPreviewSceneObject(plSceneObject* sceneObj)
{
if (sceneObj->getDrawInterface().Exists()) {
return true;
}

plCoordinateInterface* coord = GET_KEY_OBJECT(sceneObj->getCoordInterface(), plCoordinateInterface);
if (coord == nullptr) {
return false;
}
for (const auto& childKey : coord->getChildren()) {
plSceneObject* child = GET_KEY_OBJECT(childKey, plSceneObject);
if (child != nullptr && pqCanPreviewSceneObject(child)) {
return true;
}
}
return false;
}

bool pqCanPreviewType(plCreatable* pCre)
{
short type = pCre->ClassIndex();
Expand All @@ -622,9 +643,18 @@ 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 != nullptr && pqCanPreviewSceneObject(so)) {
return true;
}
}
return false;
} else if (type == kSceneObject) {
plSceneObject* tmp = plSceneObject::Convert(pCre);
return tmp->getDrawInterface().Exists();
return pqCanPreviewSceneObject(tmp);
}

for (size_t i=0; i<s_numTypes; i++) {
Expand Down

0 comments on commit 228f0e5

Please sign in to comment.