Remove large model resources from the build.

+ Remove Qtk::Skybox dependency on Qt resources.
This commit is contained in:
2025-03-15 14:24:25 -04:00
parent 8d60355ccf
commit 4a1050e02f
87 changed files with 92 additions and 526338 deletions

View File

@@ -9,14 +9,30 @@
# Qtk Application
################################################################################
set(QTK_GUI_SOURCES
qtkmainwindow.cpp qtkmainwindow.h qtkmainwindow.ui
qtkscene.cpp qtkscene.h
main.cpp
)
# Build without the example scene if QTK_GUI_SCENE is unset.
if (QTK_GUI_SCENE)
set(QTK_GUI_SOURCES
qtkmainwindow.cpp qtkmainwindow.h qtkmainwindow.ui
# This scene will clone a git repository for required 3D models.
qtkscene.cpp qtkscene.h
main.cpp
)
else()
# The scene will use a default skybox with no models or examples.
# Models can be added by click-and-dragging an .obj into the scene.
set(QTK_GUI_SOURCES
qtkmainwindow.cpp qtkmainwindow.h qtkmainwindow.ui
main.cpp
)
endif()
qt_add_executable(qtk_gui ${QTK_GUI_SOURCES})
target_link_libraries(qtk_gui PRIVATE qtk_plugin_library)
if (QTK_GUI_SCENE)
target_compile_definitions(qtk_gui PUBLIC QTK_GUI_SCENE)
endif()
if (WIN32)
set_target_properties(qtk_gui PROPERTIES WIN32_EXECUTABLE TRUE)
elseif(APPLE)

View File

@@ -24,7 +24,11 @@ int main(int argc, char * argv[])
// NOTE: We set the scene here and not in QtkMainWindow to detach the scene
// from the QtkWidget plugin (qtk_plugin_library build target).
// Once we can save / load scenes, this call, and QtkScene, can be removed.
#ifdef QTK_GUI_SCENE
window->setScene(new QtkScene);
#else
window->setScene(new EmptyScene);
#endif
window->show();

View File

@@ -49,7 +49,17 @@ namespace Ui
*/
class EmptyScene : public Qtk::Scene
{
void init() override { setSceneName("Empty Scene"); }
void init() override
{
setSkybox(new Qtk::Skybox(":/textures/skybox/right.png",
":/textures/skybox/top.png",
":/textures/skybox/front.png",
":/textures/skybox/left.png",
":/textures/skybox/bottom.png",
":/textures/skybox/back.png",
"Skybox"));
setSceneName("Empty Scene");
}
};
/**
@@ -97,7 +107,7 @@ class MainWindow : public QMainWindow
Qtk::QtkWidget * getQtkWidget(const QString & name);
/**
* @param scene The new scene to view.
* @param scene The new scene to view.
*/
void setScene(Qtk::Scene * scene);

View File

@@ -6,6 +6,10 @@
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################*/
#include <QCoreApplication>
#include <QDir>
#include <QProcess>
#include "qtkscene.h"
using namespace Qtk;
@@ -35,8 +39,38 @@ QtkScene::~QtkScene()
void QtkScene::init()
{
// Clone qtk-resources if it doesn't already exist.
QDir repoDir("resources/");
if (!repoDir.exists()) {
qDebug() << "Cloning qtk-resources repository to '"
<< repoDir.absolutePath() << "'...";
// Run git clone
QProcess gitProcess;
gitProcess.setWorkingDirectory(QCoreApplication::applicationDirPath());
gitProcess.start("git",
{"clone",
"https://git.shaunreed.com/shaunrd0/qtk-resources.git",
repoDir.absolutePath()});
// Wait indefinitely for the process to complete
gitProcess.waitForFinished(-1);
// Check the result
if (gitProcess.exitCode() == 0) {
qDebug() << "Repository cloned successfully.";
} else {
qDebug() << "Git clone failed:" << gitProcess.readAllStandardError();
}
}
// Add a skybox to the scene using default cube map images and settings.
setSkybox(new Qtk::Skybox("Skybox"));
setSkybox(new Qtk::Skybox(":/textures/skybox/right.png",
":/textures/skybox/top.png",
":/textures/skybox/front.png",
":/textures/skybox/left.png",
":/textures/skybox/bottom.png",
":/textures/skybox/back.png",
"Skybox"));
/* Create a red cube with a mini master chief on top. */
auto myCube = new MeshRenderer("My cube", Cube(Qtk::QTK_DRAW_ELEMENTS));
@@ -44,8 +78,7 @@ void QtkScene::init()
myCube->getTransform().setTranslation(5.0f, 0.0f, 0.0f);
addObject(myCube);
auto mySpartan =
new Model("My spartan", ":/models/models/spartan/spartan.obj");
auto mySpartan = new Model("My spartan", QTK_SPARTAN);
mySpartan->getTransform().setTranslation(5.0f, 0.5f, 0.0f);
mySpartan->getTransform().setScale(0.5f);
addObject(mySpartan);
@@ -82,31 +115,27 @@ void QtkScene::init()
//
// 3D Model loading
auto model = addObject(
new Qtk::Model("backpack", ":/models/models/backpack/backpack.obj"));
auto model = addObject(new Qtk::Model("backpack", QTK_BACKPACK));
// Sometimes model textures need flipped in certain directions
model->flipTexture("diffuse.jpg", false, true);
model->getTransform().setTranslation(0.0f, 0.0f, -10.0f);
model = addObject(new Qtk::Model("bird", ":/models/models/bird/bird.obj"));
model = addObject(new Qtk::Model("bird", QTK_BIRD));
model->getTransform().setTranslation(2.0f, 2.0f, -10.0f);
// Sometimes the models are very large
model->getTransform().scale(0.0025f);
model->getTransform().rotate(-110.0f, 0.0f, 1.0f, 0.0f);
model = addObject(
new Qtk::Model("alien", ":/models/models/alien-hominid/alien.obj"));
model = addObject(new Qtk::Model("alien", QTK_ALIEN));
model->getTransform().setTranslation(2.0f, -1.0f, -5.0f);
model->getTransform().scale(0.15f);
model = addObject(
new Qtk::Model("My scythe", ":/models/models/scythe/scythe.obj"));
model = addObject(new Qtk::Model("My scythe", QTK_SCYTHE));
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);
model = addObject(
new Qtk::Model("masterChief", ":/models/models/spartan/spartan.obj"));
model = addObject(new Qtk::Model("masterChief", QTK_SPARTAN));
model->getTransform().setTranslation(-1.5f, 0.5f, -2.0f);
@@ -232,7 +261,7 @@ void QtkScene::init()
/* Test alien Model with phong lighting and specular mapping. */
model = addObject(new Qtk::Model("alienTest",
":/models/models/alien-hominid/alien.obj",
QTK_ALIEN,
":/shaders/model-phong.vert",
":/shaders/model-phong.frag"));
model->getTransform().setTranslation(3.0f, -1.0f, 10.0f);
@@ -259,7 +288,7 @@ void QtkScene::init()
/* Test spartan Model with phong lighting, specular and normal mapping. */
model = addObject(new Qtk::Model("spartanTest",
":/models/models/spartan/spartan.obj",
QTK_SPARTAN,
":/shaders/model-phong.vert",
":/shaders/model-phong.frag"));
model->getTransform().setTranslation(0.0f, -1.0f, 10.0f);

View File

@@ -11,6 +11,12 @@
#include <qtk/scene.h>
#define QTK_SPARTAN "resources/models/spartan/spartan.obj"
#define QTK_BACKPACK "resources/models/backpack/backpack.obj"
#define QTK_BIRD "resources/models/bird/bird.obj"
#define QTK_ALIEN "resources/models/alien-hominid/alien.obj"
#define QTK_SCYTHE "resources/models/scythe/scythe.obj"
/**
* Example scene using QtkWidget to render 3D models and simple geometry within
* QtOpenGLWidgets. This scene also shows some examples of using GLSL shaders to