Compare commits
No commits in common. "e6bcd131b7ef26b6d900d266eefc11029e4b3103" and "0dcb6d337bcfa75a4ccee1cbf3f31eb563d8774f" have entirely different histories.
e6bcd131b7
...
0dcb6d337b
|
@ -74,7 +74,7 @@ We can install this library on a system path or a custom path and then set `CMAK
|
|||
Below is an example of installing on a system path.
|
||||
|
||||
```bash
|
||||
cmake -S qtk/ -B qtk/build/ -DCMAKE_PREFIX_PATH=$HOME/Qt/6.5.0/gcc_64 -DQTK_INSTALL_GUI=OFF -DQTK_INSTALL_PLUGINS=OFF -DQTK_DEBUG=OFF
|
||||
cmake -S qtk/ -B qtk/build/ -DCMAKE_PREFIX_PATH=$HOME/Qt/6.5.0/gcc_64 -DQTK_INSTALL_GUI=OFF -DQTK_INSTALL_PLUGINS=OFF
|
||||
cmake --build qtk/build/ -j $(nproc --ignore=2)
|
||||
sudo cmake --install . --prefix=/usr/local
|
||||
-- Install configuration: "Release"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/QtkTargets.cmake")
|
||||
|
||||
set_and_check(QTK_EXECUTABLE "${PACKAGE_PREFIX_DIR}/bin/qtk_app")
|
||||
set_and_check(QTK_EXECUTABLE "${PACKAGE_PREFIX_DIR}/bin/qtk_main")
|
||||
set_and_check(QTK_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
|
||||
set_and_check(QTK_LIBRARIES "${PACKAGE_PREFIX_DIR}/lib")
|
||||
|
||||
|
|
|
@ -65,6 +65,6 @@ set(
|
|||
examplewidget.cpp examplewidget.h
|
||||
)
|
||||
|
||||
add_executable(example_app ${EXAMPLE_SOURCES})
|
||||
target_link_libraries(example_app PUBLIC Qt6::Widgets Qt6::OpenGLWidgets Qt6::Core)
|
||||
target_link_libraries(example_app PUBLIC Qtk::qtk_library)
|
||||
add_executable(example ${EXAMPLE_SOURCES})
|
||||
target_link_libraries(example PUBLIC Qt6::Widgets Qt6::OpenGLWidgets Qt6::Core)
|
||||
target_link_libraries(example PUBLIC Qtk::qtk_library)
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
|
||||
This is an example application that is using the Qtk API to create custom Qt
|
||||
OpenGL widgets. This is very similar to `QtkWidget` in the Qtk desktop
|
||||
application source code, but could be modified for different uses if needed.
|
||||
|
||||
There are no camera controls supported in this example. The camera is fixed.
|
||||
If these controls are desired, they can be implemented by the client.
|
||||
application, but could be modified for different uses if needed.
|
||||
|
||||
You can import your own models within `examplescene.cpp`, inside the
|
||||
`ExampleScene::init()` function. Rotations and translations
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
using namespace Qtk;
|
||||
|
||||
ExampleScene::ExampleScene(Qtk::Scene * scene) : Qtk::SceneInterface(scene) {
|
||||
ExampleScene::ExampleScene() {
|
||||
setSceneName("Example Scene");
|
||||
getCamera().getTransform().setTranslation(-8.0f, 0.0f, 10.0f);
|
||||
getCamera().getTransform().setRotation(-5.0f, 0.0f, 1.0f, 0.0f);
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
#include <qtk/scene.h>
|
||||
|
||||
class ExampleScene : public Qtk::SceneInterface {
|
||||
class ExampleScene : public Qtk::Scene {
|
||||
public:
|
||||
ExampleScene(Qtk::Scene * scene);
|
||||
ExampleScene();
|
||||
|
||||
~ExampleScene();
|
||||
|
||||
|
|
|
@ -11,12 +11,7 @@
|
|||
#include "examplewidget.h"
|
||||
|
||||
ExampleWidget::ExampleWidget(QWidget * parent) :
|
||||
QOpenGLWidget(parent), mScene(new ExampleScene(new Qtk::SceneEmpty)) {
|
||||
// NOTE: The decorator pattern is used to save / load scenes in Qtk currently.
|
||||
// The initializer above sets mScene to the concrete decorator ExampleScene.
|
||||
// Qtk::SceneEmpty provides an empty scene as the concrete component.
|
||||
// ExampleScene is defined in client source, deriving Qtk::SceneInterface.
|
||||
|
||||
QOpenGLWidget(parent), mScene(new ExampleScene) {
|
||||
QSurfaceFormat format;
|
||||
format.setRenderableType(QSurfaceFormat::OpenGL);
|
||||
format.setProfile(QSurfaceFormat::CoreProfile);
|
||||
|
|
|
@ -32,7 +32,7 @@ class ExampleWidget : public QOpenGLWidget, protected QOpenGLFunctions {
|
|||
void update();
|
||||
|
||||
private:
|
||||
Qtk::Scene * mScene;
|
||||
ExampleScene * mScene;
|
||||
};
|
||||
|
||||
#endif // QTKCLIENT_EXAMPLEWIDGET_H
|
||||
|
|
|
@ -32,7 +32,7 @@ if (QTK_INSTALL_GUI OR QTK_INSTALL_PLUGINS)
|
|||
|
||||
if(QTK_INSTALL_GUI)
|
||||
install(
|
||||
TARGETS qtk_app qtk_library
|
||||
TARGETS qtk_main qtk_library
|
||||
COMPONENT qtk
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION lib
|
||||
|
@ -41,7 +41,7 @@ if (QTK_INSTALL_GUI OR QTK_INSTALL_PLUGINS)
|
|||
)
|
||||
|
||||
qt_generate_deploy_app_script(
|
||||
TARGET qtk_app
|
||||
TARGET qtk_main
|
||||
OUTPUT_SCRIPT QTK_DEPLOY_SCRIPT
|
||||
NO_UNSUPPORTED_PLATFORM_ERROR
|
||||
)
|
||||
|
@ -58,7 +58,7 @@ if (QTK_INSTALL_GUI OR QTK_INSTALL_PLUGINS)
|
|||
)
|
||||
file(TO_NATIVE_PATH "${QT6_INSTALL_PREFIX}/bin" QT6_INSTALL_PREFIX)
|
||||
|
||||
set(VSUSER_FILE "${CMAKE_CURRENT_BINARY_DIR}/qtk_app.vcxproj.user")
|
||||
set(VSUSER_FILE "${CMAKE_CURRENT_BINARY_DIR}/qtk_main.vcxproj.user")
|
||||
file(WRITE ${VSUSER_FILE} "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
||||
file(APPEND ${VSUSER_FILE} "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n")
|
||||
file(APPEND ${VSUSER_FILE} " <PropertyGroup>\n")
|
||||
|
@ -137,11 +137,11 @@ set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
|
|||
# https://nsis.sourceforge.io/Reference/CreateShortCut
|
||||
set(
|
||||
CPACK_NSIS_CREATE_ICONS_EXTRA
|
||||
"CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Qtk.lnk' '$INSTDIR\\\\bin\\\\qtk_app.exe'"
|
||||
"CreateShortCut '$SMPROGRAMS\\$STARTMENU_FOLDER\\Qtk.lnk' '$INSTDIR\\bin\\qtk_main.exe'"
|
||||
)
|
||||
set(
|
||||
CPACK_NSIS_DELETE_ICONS_EXTRA
|
||||
"Delete '$SMPROGRAMS\\\\$START_MENU\\\\Qtk.lnk'"
|
||||
"Delete '$SMPROGRAMS\\$START_MENU\\Qtk.lnk'"
|
||||
)
|
||||
# TODO: Icons for NSIS installer.
|
||||
#set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/resources/icon.png")
|
||||
|
@ -154,8 +154,9 @@ set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
|
|||
#set(CPACK_PACKAGING_INSTALL_PREFIX /usr/local/)
|
||||
|
||||
# OSX
|
||||
# TODO: Fix OSX appbundle error.
|
||||
set(CPACK_BUNDLE_NAME ${PROJECT_NAME})
|
||||
set(CPACK_BUNDLE_PLIST $<TARGET_BUNDLE_CONTENT_DIR:qtk_app>/Info.plist)
|
||||
set(CPACK_BUNDLE_PLIST $<TARGET_BUNDLE_CONTENT_DIR:qtk_main>/Info.plist)
|
||||
set(CPACK_BUNDLE_ICON ${QTK_OSX_ICONS})
|
||||
|
||||
# Platform defaults for source bundles.
|
||||
|
|
|
@ -50,7 +50,7 @@ target_link_libraries(qtk_collection PUBLIC qtk_plugin_library)
|
|||
|
||||
set(
|
||||
QTK_APP_SOURCES
|
||||
qtkscene.cpp qtkscene.h
|
||||
examplescene.cpp examplescene.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
|
@ -61,11 +61,11 @@ configure_file(
|
|||
@ONLY
|
||||
)
|
||||
|
||||
qt_add_executable(qtk_app ${QTK_APP_SOURCES})
|
||||
target_link_libraries(qtk_app PRIVATE qtk_plugin_library)
|
||||
qt_add_executable(qtk_main ${QTK_APP_SOURCES})
|
||||
target_link_libraries(qtk_main PRIVATE qtk_plugin_library)
|
||||
|
||||
set_target_properties(
|
||||
qtk_app PROPERTIES
|
||||
qtk_main PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
MACOSX_BUNDLE_BUNDLE_NAME Qtk
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################*/
|
||||
|
||||
#include "qtkscene.h"
|
||||
#include "examplescene.h"
|
||||
#include "resources.h"
|
||||
|
||||
using namespace Qtk;
|
||||
|
@ -15,14 +15,13 @@ using namespace Qtk;
|
|||
* Constructors, Destructors
|
||||
******************************************************************************/
|
||||
|
||||
QtkScene::QtkScene(Qtk::Scene * scene) :
|
||||
Qtk::SceneInterface(scene) {
|
||||
setSceneName("Qtk Scene");
|
||||
ExampleScene::ExampleScene() {
|
||||
setSceneName("Example Scene");
|
||||
getCamera().getTransform().setTranslation(0.0f, 0.0f, 20.0f);
|
||||
getCamera().getTransform().setRotation(-5.0f, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
QtkScene::~QtkScene() {
|
||||
ExampleScene::~ExampleScene() {
|
||||
delete mTestPhong;
|
||||
delete mTestSpecular;
|
||||
delete mTestDiffuse;
|
||||
|
@ -33,7 +32,7 @@ QtkScene::~QtkScene() {
|
|||
* Public Member Functions
|
||||
******************************************************************************/
|
||||
|
||||
void QtkScene::init() {
|
||||
void ExampleScene::init() {
|
||||
// Add a skybox to the scene using default cube map images and settings.
|
||||
setSkybox(new Qtk::Skybox("Skybox"));
|
||||
|
||||
|
@ -98,7 +97,7 @@ void QtkScene::init() {
|
|||
model->getTransform().scale(0.15f);
|
||||
|
||||
model =
|
||||
addObject(new Qtk::Model("My scythe", ":/models/models/scythe/scythe.obj"));
|
||||
addObject(new Qtk::Model("scythe", ":/models/models/scythe/scythe.obj"));
|
||||
model->getTransform().setTranslation(-6.0f, 0.0f, -10.0f);
|
||||
model->getTransform().rotate(-90.0f, 1.0f, 0.0f, 0.0f);
|
||||
model->getTransform().rotate(90.0f, 0.0f, 1.0f, 0.0f);
|
||||
|
@ -388,11 +387,19 @@ void QtkScene::init() {
|
|||
mesh->reallocateTexCoords(mesh->getTexCoords());
|
||||
}
|
||||
|
||||
void QtkScene::draw() {
|
||||
void ExampleScene::draw() {
|
||||
// WARNING: We must call the base class draw() function first.
|
||||
// + This will handle rendering core scene components like the Skybox.
|
||||
Scene::draw();
|
||||
|
||||
for(const auto & model : getModels()) {
|
||||
model->draw();
|
||||
}
|
||||
|
||||
for(const auto & mesh : getMeshes()) {
|
||||
mesh->draw();
|
||||
}
|
||||
|
||||
mTestPhong->bindShaders();
|
||||
mTestPhong->setUniform(
|
||||
"uModelInverseTransposed",
|
||||
|
@ -402,14 +409,14 @@ void QtkScene::draw() {
|
|||
MeshRenderer::getInstance("phongLight")->getTransform().getTranslation());
|
||||
mTestPhong->setUniform(
|
||||
"uCameraPosition",
|
||||
QtkScene::getCamera().getTransform().getTranslation());
|
||||
ExampleScene::getCamera().getTransform().getTranslation());
|
||||
mTestPhong->releaseShaders();
|
||||
mTestPhong->draw();
|
||||
|
||||
mTestAmbient->bindShaders();
|
||||
mTestAmbient->setUniform(
|
||||
"uCameraPosition",
|
||||
QtkScene::getCamera().getTransform().getTranslation());
|
||||
ExampleScene::getCamera().getTransform().getTranslation());
|
||||
mTestAmbient->releaseShaders();
|
||||
mTestAmbient->draw();
|
||||
|
||||
|
@ -423,7 +430,7 @@ void QtkScene::draw() {
|
|||
.getTranslation());
|
||||
mTestDiffuse->setUniform(
|
||||
"uCameraPosition",
|
||||
QtkScene::getCamera().getTransform().getTranslation());
|
||||
ExampleScene::getCamera().getTransform().getTranslation());
|
||||
mTestDiffuse->releaseShaders();
|
||||
mTestDiffuse->draw();
|
||||
|
||||
|
@ -437,12 +444,12 @@ void QtkScene::draw() {
|
|||
.getTranslation());
|
||||
mTestSpecular->setUniform(
|
||||
"uCameraPosition",
|
||||
QtkScene::getCamera().getTransform().getTranslation());
|
||||
ExampleScene::getCamera().getTransform().getTranslation());
|
||||
mTestSpecular->releaseShaders();
|
||||
mTestSpecular->draw();
|
||||
}
|
||||
|
||||
void QtkScene::update() {
|
||||
void ExampleScene::update() {
|
||||
auto mySpartan = Model::getInstance("My spartan");
|
||||
mySpartan->getTransform().rotate(0.75f, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
|
@ -456,12 +463,12 @@ void QtkScene::update() {
|
|||
alien->setUniform("uLight.position", position);
|
||||
alien->setUniform(
|
||||
"uCameraPosition",
|
||||
QtkScene::getCamera().getTransform().getTranslation());
|
||||
ExampleScene::getCamera().getTransform().getTranslation());
|
||||
auto posMatrix = alien->getTransform().toMatrix();
|
||||
alien->setUniform("uMVP.normalMatrix", posMatrix.normalMatrix());
|
||||
alien->setUniform("uMVP.model", posMatrix);
|
||||
alien->setUniform("uMVP.view", QtkScene::getCamera().toMatrix());
|
||||
alien->setUniform("uMVP.projection", QtkScene::getProjectionMatrix());
|
||||
alien->setUniform("uMVP.view", ExampleScene::getCamera().toMatrix());
|
||||
alien->setUniform("uMVP.projection", ExampleScene::getProjectionMatrix());
|
||||
alien->getTransform().rotate(0.75f, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
position = MeshRenderer::getInstance("spartanTestLight")
|
||||
|
@ -471,12 +478,12 @@ void QtkScene::update() {
|
|||
spartan->setUniform("uLight.position", position);
|
||||
spartan->setUniform(
|
||||
"uCameraPosition",
|
||||
QtkScene::getCamera().getTransform().getTranslation());
|
||||
ExampleScene::getCamera().getTransform().getTranslation());
|
||||
posMatrix = spartan->getTransform().toMatrix();
|
||||
spartan->setUniform("uMVP.normalMatrix", posMatrix.normalMatrix());
|
||||
spartan->setUniform("uMVP.model", posMatrix);
|
||||
spartan->setUniform("uMVP.view", QtkScene::getCamera().toMatrix());
|
||||
spartan->setUniform("uMVP.projection", QtkScene::getProjectionMatrix());
|
||||
spartan->setUniform("uMVP.view", ExampleScene::getCamera().toMatrix());
|
||||
spartan->setUniform("uMVP.projection", ExampleScene::getProjectionMatrix());
|
||||
spartan->getTransform().rotate(0.75f, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
auto phong = MeshRenderer::getInstance("testPhong");
|
||||
|
@ -487,12 +494,12 @@ void QtkScene::update() {
|
|||
phong->setUniform("uLight.position", position);
|
||||
phong->setUniform(
|
||||
"uCameraPosition",
|
||||
QtkScene::getCamera().getTransform().getTranslation());
|
||||
ExampleScene::getCamera().getTransform().getTranslation());
|
||||
posMatrix = phong->getTransform().toMatrix();
|
||||
phong->setUniform("uMVP.normalMatrix", posMatrix.normalMatrix());
|
||||
phong->setUniform("uMVP.model", posMatrix);
|
||||
phong->setUniform("uMVP.view", QtkScene::getCamera().toMatrix());
|
||||
phong->setUniform("uMVP.projection", QtkScene::getProjectionMatrix());
|
||||
phong->setUniform("uMVP.view", ExampleScene::getCamera().toMatrix());
|
||||
phong->setUniform("uMVP.projection", ExampleScene::getProjectionMatrix());
|
||||
phong->releaseShaders();
|
||||
|
||||
// Rotate lighting example cubes
|
|
@ -29,15 +29,15 @@
|
|||
*
|
||||
* To create your own Scene from scratch see Qtk::Scene.
|
||||
*/
|
||||
class QtkScene : public Qtk::SceneInterface {
|
||||
class ExampleScene : public Qtk::Scene {
|
||||
public:
|
||||
/***************************************************************************
|
||||
* Contructors / Destructors
|
||||
**************************************************************************/
|
||||
|
||||
QtkScene(Qtk::Scene * scene);
|
||||
ExampleScene();
|
||||
|
||||
~QtkScene();
|
||||
~ExampleScene();
|
||||
|
||||
/***************************************************************************
|
||||
* Inherited Public Overrides
|
|
@ -9,7 +9,6 @@
|
|||
#include <QApplication>
|
||||
|
||||
#include "qtkmainwindow.h"
|
||||
#include "qtkscene.h"
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
Q_INIT_RESOURCE(resources);
|
||||
|
@ -17,12 +16,7 @@ int main(int argc, char * argv[]) {
|
|||
QApplication a(argc, argv);
|
||||
|
||||
auto window = MainWindow::getMainWindow();
|
||||
|
||||
// Qtk currently uses the decorator pattern to save / load scenes.
|
||||
// This is a temporary solution and will be improved in the future.
|
||||
auto emptyScene = new Qtk::SceneEmpty;
|
||||
window->getQtkWidget()->setScene(new QtkScene(emptyScene));
|
||||
|
||||
window->show();
|
||||
|
||||
return QApplication::exec();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
##############################################################################*/
|
||||
|
||||
#include "qtkmainwindow.h"
|
||||
#include "qtkscene.h"
|
||||
#include "examplescene.h"
|
||||
#include "ui_qtkmainwindow.h"
|
||||
|
||||
MainWindow * MainWindow::mainWindow_ = Q_NULLPTR;
|
||||
|
@ -27,7 +27,7 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) {
|
|||
// Initialize static container for all active QtkWidgets
|
||||
auto qtkWidgets = findChildren<Qtk::QtkWidget *>();
|
||||
for(auto & qtkWidget : qtkWidgets) {
|
||||
qtkWidget->setScene(new Qtk::SceneEmpty);
|
||||
qtkWidget->setScene(new ExampleScene);
|
||||
views_.emplace(qtkWidget->getScene()->getSceneName(), qtkWidget);
|
||||
ui_->menuView->addAction(qtkWidget->getActionToggleConsole());
|
||||
connect(
|
||||
|
@ -60,13 +60,6 @@ MainWindow * MainWindow::getMainWindow() {
|
|||
return mainWindow_;
|
||||
}
|
||||
|
||||
Qtk::QtkWidget * MainWindow::getQtkWidget(int64_t index) {
|
||||
if(views_.size() <= index) {
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
return views_.begin(index)->second;
|
||||
}
|
||||
|
||||
Qtk::QtkWidget * MainWindow::getQtkWidget(const QString & name) {
|
||||
if(!views_.count(name)) {
|
||||
return Q_NULLPTR;
|
||||
|
@ -76,5 +69,5 @@ Qtk::QtkWidget * MainWindow::getQtkWidget(const QString & name) {
|
|||
|
||||
void MainWindow::refreshScene(QString sceneName) {
|
||||
// TODO: Select TreeView using sceneName>
|
||||
ui_->qtk__TreeView->updateView(getQtkWidget()->getScene());
|
||||
ui_->qtk__TreeView->updateView(getQtkWidget(sceneName)->getScene());
|
||||
}
|
||||
|
|
|
@ -53,8 +53,6 @@ class MainWindow : public QMainWindow {
|
|||
*/
|
||||
static MainWindow * getMainWindow();
|
||||
|
||||
Qtk::QtkWidget * getQtkWidget(int64_t index = 0);
|
||||
|
||||
/**
|
||||
* Accessor for retrieving a QtkWidget by it's objectName.
|
||||
* This function will not construct a new QtkWidget if none is found.
|
||||
|
|
|
@ -108,13 +108,7 @@ void QtkWidget::paintGL() {
|
|||
}
|
||||
|
||||
void QtkWidget::setScene(Qtk::Scene * scene) {
|
||||
if (mScene != Q_NULLPTR) {
|
||||
delete mScene;
|
||||
connect(
|
||||
scene, &Qtk::Scene::sceneUpdated, MainWindow::getMainWindow(),
|
||||
&MainWindow::refreshScene);
|
||||
}
|
||||
|
||||
delete mScene;
|
||||
mScene = scene;
|
||||
if(mScene != Q_NULLPTR) {
|
||||
mConsole->setTitle(mScene->getSceneName());
|
||||
|
|
|
@ -100,13 +100,6 @@ namespace Qtk {
|
|||
*/
|
||||
inline Qtk::Scene * getScene() { return mScene; }
|
||||
|
||||
/**
|
||||
* @return Pointer to the QOpenGLDebugLogger attached to this widget.
|
||||
*/
|
||||
inline QOpenGLDebugLogger * getOpenGLDebugLogger() {
|
||||
return mDebugLogger;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Setters
|
||||
************************************************************************/
|
||||
|
|
|
@ -37,7 +37,7 @@ void Qtk::TreeView::updateView(const Qtk::Scene * scene) {
|
|||
mSceneName = scene->getSceneName();
|
||||
auto objects = scene->getObjects();
|
||||
for(const auto & object : objects) {
|
||||
auto item = new QTreeWidgetItem(QStringList(QString(object->getName().c_str())));
|
||||
auto item = new QTreeWidgetItem(QStringList(QString(object->getName())));
|
||||
ui->treeWidget->insertTopLevelItem(0, item);
|
||||
}
|
||||
}
|
||||
|
@ -45,13 +45,9 @@ void Qtk::TreeView::updateView(const Qtk::Scene * scene) {
|
|||
void Qtk::TreeView::itemFocus(QTreeWidgetItem * item, int column) {
|
||||
QString name = item->text(column);
|
||||
auto scene =
|
||||
MainWindow::getMainWindow()->getQtkWidget()->getScene();
|
||||
MainWindow::getMainWindow()->getQtkWidget(mSceneName)->getScene();
|
||||
auto & transform = scene->getCamera().getTransform();
|
||||
auto object = scene->getObject(name);
|
||||
if (object == Q_NULLPTR) {
|
||||
qDebug() << "Attempt to get non-existing object with name '" << name
|
||||
<< "'\n";
|
||||
}
|
||||
Transform3D * objectTransform;
|
||||
if(object->getType() == Object::QTK_MESH) {
|
||||
objectTransform = &dynamic_cast<MeshRenderer *>(object)->getTransform();
|
||||
|
|
|
@ -38,7 +38,7 @@ MeshRenderer::MeshRenderer(const char * name, const ShapeBase & shape) :
|
|||
}
|
||||
|
||||
MeshRenderer::~MeshRenderer() {
|
||||
sInstances.remove(mName.c_str());
|
||||
sInstances.remove(mName);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
|
|
|
@ -96,7 +96,7 @@ void Model::loadModel(const std::string & path) {
|
|||
sortModelMeshes();
|
||||
|
||||
// Object finished loading, insert it into ModelManager
|
||||
mManager.insert(getName().c_str(), this);
|
||||
mManager.insert(getName(), this);
|
||||
}
|
||||
|
||||
void Model::processNode(aiNode * node, const aiScene * scene) {
|
||||
|
@ -200,7 +200,7 @@ ModelMesh Model::processMesh(aiMesh * mesh, const aiScene * scene) {
|
|||
textures.insert(textures.end(), normalMaps.begin(), normalMaps.end());
|
||||
}
|
||||
|
||||
return {vertices, indices, textures, mVertexShader.c_str(), mFragmentShader.c_str()};
|
||||
return {vertices, indices, textures, mVertexShader, mFragmentShader};
|
||||
}
|
||||
|
||||
ModelMesh::Textures Model::loadMaterialTextures(
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace Qtk {
|
|||
loadModel(mModelPath);
|
||||
}
|
||||
|
||||
inline ~Model() override { mManager.remove(getName().c_str()); }
|
||||
inline ~Model() override { mManager.remove(getName()); }
|
||||
|
||||
/*************************************************************************
|
||||
* Public Methods
|
||||
|
@ -197,7 +197,7 @@ namespace Qtk {
|
|||
/** The directory this model and it's textures are stored. */
|
||||
std::string mDirectory {};
|
||||
/** File names for shaders and 3D model on disk. */
|
||||
std::string mVertexShader, mFragmentShader, mModelPath;
|
||||
const char *mVertexShader, *mFragmentShader, *mModelPath;
|
||||
};
|
||||
} // namespace Qtk
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ void ModelMesh::initMesh(const char * vert, const char * frag) {
|
|||
initializeOpenGLFunctions();
|
||||
|
||||
// Create VAO, VBO, EBO
|
||||
bool status = mVAO->create();
|
||||
mVAO->create();
|
||||
mVBO->create();
|
||||
mEBO->create();
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace Qtk {
|
|||
return mShape.mVertices;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline std::string getName() const { return mName; }
|
||||
[[nodiscard]] inline const char * getName() const { return mName; }
|
||||
|
||||
[[nodiscard]] inline const Type & getType() const { return mType; }
|
||||
|
||||
|
@ -160,7 +160,7 @@ namespace Qtk {
|
|||
Transform3D mTransform;
|
||||
Shape mShape;
|
||||
Texture mTexture;
|
||||
std::string mName;
|
||||
const char * mName;
|
||||
bool mBound;
|
||||
Type mType = QTK_OBJECT;
|
||||
};
|
||||
|
|
|
@ -37,23 +37,6 @@ Scene::~Scene() {
|
|||
* Public Methods
|
||||
******************************************************************************/
|
||||
|
||||
void Scene::draw() {
|
||||
if(!mInit) {
|
||||
initializeOpenGLFunctions();
|
||||
init();
|
||||
mInit = true;
|
||||
}
|
||||
if(mSkybox != Q_NULLPTR) {
|
||||
mSkybox->draw();
|
||||
}
|
||||
for(auto & model : mModels) {
|
||||
model->draw();
|
||||
}
|
||||
for(const auto & mesh : mMeshes) {
|
||||
mesh->draw();
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Object *> Scene::getObjects() const {
|
||||
// All scene objects must inherit from Qtk::Object.
|
||||
std::vector<Object *> objects(mMeshes.begin(), mMeshes.end());
|
||||
|
@ -68,7 +51,7 @@ std::vector<Object *> Scene::getObjects() const {
|
|||
|
||||
Object * Scene::getObject(const QString & name) {
|
||||
for(auto object : getObjects()) {
|
||||
if(object->getName() == name.toStdString()) {
|
||||
if(object->getName() == name) {
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
@ -91,3 +74,24 @@ template <> Model * Scene::addObject(Model * object) {
|
|||
sceneUpdated(mSceneName);
|
||||
return object;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Private Methods
|
||||
******************************************************************************/
|
||||
|
||||
void Scene::privateDraw() {
|
||||
if(!mInit) {
|
||||
initializeOpenGLFunctions();
|
||||
init();
|
||||
mInit = true;
|
||||
}
|
||||
if(mSkybox != Q_NULLPTR) {
|
||||
mSkybox->draw();
|
||||
}
|
||||
for(auto & model : mModels) {
|
||||
model->draw();
|
||||
}
|
||||
for(const auto & mesh : mMeshes) {
|
||||
mesh->draw();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#define QTK_SCENE_H
|
||||
|
||||
#include <QMatrix4x4>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "camera3d.h"
|
||||
|
@ -66,7 +65,7 @@ namespace Qtk {
|
|||
*
|
||||
* This function is only called when the widget is redrawn.
|
||||
*/
|
||||
virtual void draw();
|
||||
virtual void draw() { privateDraw(); };
|
||||
|
||||
/**
|
||||
* Function called to update the QOpenGLWidget. Does not trigger a redraw.
|
||||
|
@ -166,7 +165,6 @@ namespace Qtk {
|
|||
*/
|
||||
inline void setSceneName(QString name) { mSceneName = std::move(name); }
|
||||
|
||||
std::vector<Model *> mModels {};
|
||||
signals:
|
||||
/**
|
||||
* Signal thrown when the scene is modified by adding or removing objects.
|
||||
|
@ -177,6 +175,16 @@ namespace Qtk {
|
|||
void sceneUpdated(QString sceneName);
|
||||
|
||||
private:
|
||||
/*************************************************************************
|
||||
* Private Methods
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* Handles drawing members encapsulated by this base class.
|
||||
* Child classes do not need to draw these objects manually.
|
||||
*/
|
||||
void privateDraw();
|
||||
|
||||
/*************************************************************************
|
||||
* Private Members
|
||||
************************************************************************/
|
||||
|
@ -191,33 +199,8 @@ namespace Qtk {
|
|||
/* MeshRenderers used simple geometry. */
|
||||
std::vector<MeshRenderer *> mMeshes {};
|
||||
/* Models used for storing 3D models in the scene. */
|
||||
std::vector<Model *> mModels {};
|
||||
};
|
||||
|
||||
class SceneEmpty : public Scene {
|
||||
public:
|
||||
void init() override {
|
||||
setSceneName("Empty Scene");
|
||||
}
|
||||
|
||||
void draw() override { Scene::draw(); }
|
||||
|
||||
void update() override { Scene::update(); }
|
||||
};
|
||||
|
||||
class SceneInterface : public Scene {
|
||||
public:
|
||||
explicit SceneInterface(Scene * scene) : mScene(scene) {}
|
||||
|
||||
void init() override { mScene->init(); }
|
||||
|
||||
void draw() override { mScene->draw(); }
|
||||
|
||||
void update() override { mScene->update(); }
|
||||
|
||||
protected:
|
||||
Scene * mScene;
|
||||
};
|
||||
|
||||
} // namespace Qtk
|
||||
|
||||
#endif // QTK_SCENE_H
|
||||
|
|
Loading…
Reference in New Issue