From a526e7456c07f1f5728902c55bab1245cf5daec7 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sun, 24 Oct 2021 23:23:02 +0200 Subject: [PATCH] Allow previewing non-drawable scene objects with drawable children --- src/PrpShop/PRP/Render/QPlasmaRender.cpp | 15 +++++++++++++++ src/PrpShop/PRP/Render/QPlasmaRender.h | 2 +- src/PrpShop/QPlasmaUtils.cpp | 22 +++++++++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/PrpShop/PRP/Render/QPlasmaRender.cpp b/src/PrpShop/PRP/Render/QPlasmaRender.cpp index ad43646..27488cc 100644 --- a/src/PrpShop/PRP/Render/QPlasmaRender.cpp +++ b/src/PrpShop/PRP/Render/QPlasmaRender.cpp @@ -227,6 +227,21 @@ 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 == NULL) { + return; + } + for (auto it = coord->getChildren().begin(); it != coord->getChildren().end(); it++) { + if ((*it)->getType() == kSceneObject) { + addObject(*it); + } + } +} + void QPlasmaRender::setView(const hsVector3& view, float angle) { fViewPos = view; diff --git a/src/PrpShop/PRP/Render/QPlasmaRender.h b/src/PrpShop/PRP/Render/QPlasmaRender.h index d067861..7186358 100644 --- a/src/PrpShop/PRP/Render/QPlasmaRender.h +++ b/src/PrpShop/PRP/Render/QPlasmaRender.h @@ -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); diff --git a/src/PrpShop/QPlasmaUtils.cpp b/src/PrpShop/QPlasmaUtils.cpp index 4835782..cf2c49c 100644 --- a/src/PrpShop/QPlasmaUtils.cpp +++ b/src/PrpShop/QPlasmaUtils.cpp @@ -17,6 +17,7 @@ #include #include "QPlasmaUtils.h" #include +#include #include bool s_showTypeIDs = false; @@ -613,6 +614,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 == NULL) { + return false; + } + for (auto it = coord->getChildren().begin(); it != coord->getChildren().end(); it++) { + plSceneObject* child = GET_KEY_OBJECT((*it), plSceneObject); + if (child != NULL && pqCanPreviewSceneObject(child)) { + return true; + } + } + return false; +} + bool pqCanPreviewType(plCreatable* pCre) { short type = pCre->ClassIndex(); @@ -624,7 +644,7 @@ bool pqCanPreviewType(plCreatable* pCre) if (type == kSceneObject) { plSceneObject* tmp = plSceneObject::Convert(pCre); - return tmp->getDrawInterface().Exists(); + return pqCanPreviewSceneObject(tmp); } for (size_t i=0; i