drag-and-drop #14

Merged
shaunrd0 merged 45 commits from drag-and-drop into master 2023-12-27 19:36:48 +00:00
5 changed files with 164 additions and 163 deletions
Showing only changes of commit b0e123e6dd - Show all commits

View File

@ -8,7 +8,7 @@ on:
jobs: jobs:
Qtk: Qtk:
env: env:
CONFIG: -DQTK_SUBMODULES=ON -DQTK_DEBUG=OFF -DQTK_CCACHE=OFF -DQTK_GUI=ON -DQTK_LIBRARY=ON -DQTK_PLUGINS=OFF -DQTK_EXAMPLE=ON CONFIG: -DQTK_SUBMODULES=ON -DQTK_DEBUG=OFF -DQTK_CCACHE=OFF -DQTK_GUI=ON -DQTK_PLUGINS=OFF -DQTK_EXAMPLE=ON
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
@ -138,7 +138,7 @@ jobs:
Qtk-Library: Qtk-Library:
env: env:
CONFIG: -DQTK_SUBMODULES=ON -DQTK_DEBUG=OFF -DQTK_CCACHE=OFF -DQTK_GUI=OFF -DQTK_LIBRARY=ON -DQTK_PLUGINS=OFF -DQTK_EXAMPLE=OFF CONFIG: -DQTK_SUBMODULES=ON -DQTK_DEBUG=OFF -DQTK_CCACHE=OFF -DQTK_GUI=OFF -DQTK_PLUGINS=OFF -DQTK_EXAMPLE=OFF
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
@ -176,7 +176,7 @@ jobs:
- name: Build Qtk Library (Windows) - name: Build Qtk Library (Windows)
if: matrix.os == 'windows-latest' if: matrix.os == 'windows-latest'
shell: bash shell: bash
run: cmake --build build/ --config Release run: cmake --build build/ --config Release --target qtk_library
# OSX / Linux # OSX / Linux
@ -254,7 +254,7 @@ jobs:
Qtk-Plugins: Qtk-Plugins:
env: env:
CONFIG: -DQTK_SUBMODULES=ON -DQTK_DEBUG=OFF -DQTK_CCACHE=OFF -DQTK_GUI=OFF -DQTK_LIBRARY=OFF -DQTK_PLUGINS=ON -DQTK_EXAMPLE=OFF CONFIG: -DQTK_SUBMODULES=ON -DQTK_DEBUG=OFF -DQTK_CCACHE=OFF -DQTK_GUI=OFF -DQTK_PLUGINS=ON -DQTK_EXAMPLE=OFF
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:

View File

@ -21,8 +21,8 @@ jobs:
- name: Build Qtk - name: Build Qtk
run: | run: |
cmake -B build -DQTK_UPDATE_SUBMODULES=OFF -DQTK_ENABLE_CCACHE=OFF cmake -B build -DQTK_SUBMODULES=OFF -DQTK_CCACHE=OFF -DQTK_PLUGINS=OFF -DQTK_GUI=ON
cmake --build build cmake --build build --target qtk_gui -- -j $(nproc)
- uses: cpp-linter/cpp-linter-action@v2 - uses: cpp-linter/cpp-linter-action@v2
id: linter id: linter

View File

@ -241,7 +241,7 @@ Last we need to run `clang-format`, this can be done with the command directly.
This will reformat all the code in the repository. This will reformat all the code in the repository.
```bash ```bash
clang-format -i --style=file:.clang-format src/*.cpp src/*.h app/*.cpp app/*.h clang-format -i --style=file:.clang-format src/app/*.cpp src/app/*.h src/qtk/*.cpp src/qtk/*.h example-app/*.cpp example-app/*.h
``` ```
`clang-format` can be run with git integration (or CLion if you prefer). `clang-format` can be run with git integration (or CLion if you prefer).

View File

@ -11,7 +11,7 @@
using namespace Qtk; using namespace Qtk;
ExampleScene::ExampleScene(Qtk::Scene *scene) : Qtk::SceneInterface(scene) { ExampleScene::ExampleScene(Qtk::Scene * scene) : Qtk::SceneInterface(scene) {
setSceneName("Example Scene"); setSceneName("Example Scene");
getCamera().getTransform().setTranslation(-8.0f, 0.0f, 10.0f); getCamera().getTransform().setTranslation(-8.0f, 0.0f, 10.0f);
getCamera().getTransform().setRotation(-5.0f, 0.0f, 1.0f, 0.0f); getCamera().getTransform().setRotation(-5.0f, 0.0f, 1.0f, 0.0f);
@ -24,8 +24,8 @@ void ExampleScene::init() {
setSkybox(skybox); setSkybox(skybox);
auto spartan = new Model( auto spartan = new Model(
"spartan", std::string(QTK_EXAMPLE_SOURCE_DIR) + "spartan", std::string(QTK_EXAMPLE_SOURCE_DIR)
"/../resources/models/spartan/spartan.obj"); + "/../resources/models/spartan/spartan.obj");
addObject(spartan); addObject(spartan);
spartan->getTransform().setTranslation(-4.0f, 0.0f, 0.0f); spartan->getTransform().setTranslation(-4.0f, 0.0f, 0.0f);

View File

@ -27,184 +27,185 @@ namespace Qtk {
* Top-level object that represents 3D models stored within a scene. * Top-level object that represents 3D models stored within a scene.
*/ */
class QTKAPI Model : public Object { class QTKAPI Model : public Object {
public: public:
/************************************************************************* /*************************************************************************
* Typedefs * Typedefs
************************************************************************/ ************************************************************************/
/** ModelManager typedef that will manage global model access. */ /** ModelManager typedef that will manage global model access. */
typedef QHash<QString, Model *> ModelManager; typedef QHash<QString, Model *> ModelManager;
/************************************************************************* /*************************************************************************
* Constructors, Destructors * Constructors, Destructors
************************************************************************/ ************************************************************************/
/** /**
* Constructs a Model * Constructs a Model
* If no shaders are provided we will use default shaders. * If no shaders are provided we will use default shaders.
* *
* @param name Name to use for the Model's objectName. * @param name Name to use for the Model's objectName.
* @param path Path to the model to load for construction. * @param path Path to the model to load for construction.
* @param vertexShader Optional path to custom vertex shader. * @param vertexShader Optional path to custom vertex shader.
* @param fragmentShader Optional path to custom fragment shader. * @param fragmentShader Optional path to custom fragment shader.
*/ */
inline Model( inline Model(
const char *name, const char *path, const char * name, const char * path,
const char *vertexShader = ":/shaders/model-basic.vert", const char * vertexShader = ":/shaders/model-basic.vert",
const char *fragmentShader = ":/shaders/model-basic.frag") : const char * fragmentShader = ":/shaders/model-basic.frag") :
Object(name, QTK_MODEL), Object(name, QTK_MODEL),
mModelPath(path), mVertexShader(vertexShader), mModelPath(path), mVertexShader(vertexShader),
mFragmentShader(fragmentShader) { mFragmentShader(fragmentShader) {
loadModel(mModelPath); loadModel(mModelPath);
} }
inline Model( inline Model(
std::string name, std::string path, std::string name, std::string path,
std::string vertexShader = ":/shaders/model-basic.vert", std::string vertexShader = ":/shaders/model-basic.vert",
std::string fragmentShader = ":/shaders/model-basic.frag") : std::string fragmentShader = ":/shaders/model-basic.frag") :
Model(name.c_str(), path.c_str(), vertexShader.c_str(), Model(
name.c_str(), path.c_str(), vertexShader.c_str(),
fragmentShader.c_str()) {} fragmentShader.c_str()) {}
inline ~Model() override { mManager.remove(getName().c_str()); } inline ~Model() override { mManager.remove(getName().c_str()); }
/************************************************************************* /*************************************************************************
* Public Methods * Public Methods
************************************************************************/ ************************************************************************/
/** /**
* Draws the model using attached shader program. * Draws the model using attached shader program.
*/ */
void draw(); void draw();
/** /**
* Draws the model using a custom shader program. * Draws the model using a custom shader program.
* *
* @param shader Shader program to use to draw the model. * @param shader Shader program to use to draw the model.
*/ */
void draw(QOpenGLShaderProgram &shader); void draw(QOpenGLShaderProgram & shader);
/** /**
* Flip a texture associated with this model * Flip a texture associated with this model
* *
* @param fileName The name of the texture to flip as it is stored on disk * @param fileName The name of the texture to flip as it is stored on disk
* @param flipX Flip the texture along the X axis * @param flipX Flip the texture along the X axis
* @param flipY Flip the texture along the Y axis * @param flipY Flip the texture along the Y axis
*/ */
void flipTexture( void flipTexture(
const std::string &fileName, bool flipX = false, bool flipY = true); const std::string & fileName, bool flipX = false, bool flipY = true);
/************************************************************************* /*************************************************************************
* Setters * Setters
************************************************************************/ ************************************************************************/
/** /**
* Sets a uniform value for each ModelMesh within this Model. * Sets a uniform value for each ModelMesh within this Model.
* *
* @tparam T The type of the value we are settings * @tparam T The type of the value we are settings
* @param location The uniform location * @param location The uniform location
* @param value The value to assign to the uniform * @param value The value to assign to the uniform
*/ */
template<typename T> template <typename T>
inline void setUniform(const char *location, T value) { inline void setUniform(const char * location, T value) {
for (auto &mesh: mMeshes) { for(auto & mesh : mMeshes) {
mesh.mProgram->bind(); mesh.mProgram->bind();
mesh.mProgram->setUniformValue(location, value); mesh.mProgram->setUniformValue(location, value);
mesh.mProgram->release(); mesh.mProgram->release();
}
} }
}
/************************************************************************* /*************************************************************************
* Accessors * Accessors
************************************************************************/ ************************************************************************/
/** /**
* Accessor function for retrieving a ModelMesh globally. * Accessor function for retrieving a ModelMesh globally.
* The mesh is retrieved from the mManager private member. * The mesh is retrieved from the mManager private member.
* *
* @param name The name of the model to load as it was constructed. * @param name The name of the model to load as it was constructed.
* @return Pointer to the model stored within the scene. * @return Pointer to the model stored within the scene.
*/ */
[[nodiscard]] static Model *getInstance(const char *name); [[nodiscard]] static Model * getInstance(const char * name);
/** /**
* @return Transform3D attached to this Model. * @return Transform3D attached to this Model.
*/ */
inline Transform3D &getTransform() { return mTransform; } inline Transform3D & getTransform() { return mTransform; }
private: private:
/************************************************************************* /*************************************************************************
* Private Methods * Private Methods
************************************************************************/ ************************************************************************/
/** /**
* Loads a model in .obj, .fbx, .gltf, and other formats. * Loads a model in .obj, .fbx, .gltf, and other formats.
* For a full list of formats see assimp documentation: * For a full list of formats see assimp documentation:
* https://github.com/assimp/assimp/blob/master/doc/Fileformats.md * https://github.com/assimp/assimp/blob/master/doc/Fileformats.md
* *
* Large models should not be loaded into Qt resource system. * Large models should not be loaded into Qt resource system.
* Instead pass an *absolute* path to this function. * Instead pass an *absolute* path to this function.
* Relative paths will break if Qtk is executed from different locations. * Relative paths will break if Qtk is executed from different locations.
* *
* @param path Absolute path to a model in .obj or another format accepted * @param path Absolute path to a model in .obj or another format accepted
* by assimp. * by assimp.
*/ */
void loadModel(const std::string &path); void loadModel(const std::string & path);
/** /**
* Process a node in the model's geometry using Assimp. * Process a node in the model's geometry using Assimp.
* *
* @param node The Assimp node to process. * @param node The Assimp node to process.
* @param scene The Assimp scene for the loaded model. * @param scene The Assimp scene for the loaded model.
*/ */
void processNode(aiNode *node, const aiScene *scene); void processNode(aiNode * node, const aiScene * scene);
/** /**
* Process a mesh within a node using Assimp. * Process a mesh within a node using Assimp.
* *
* @param mesh The Assimp mesh to process. * @param mesh The Assimp mesh to process.
* @param scene The Assimp scene for the loaded model. * @param scene The Assimp scene for the loaded model.
* @return * @return
*/ */
ModelMesh processMesh(aiMesh *mesh, const aiScene *scene); ModelMesh processMesh(aiMesh * mesh, const aiScene * scene);
/** /**
* Load a collection of material texture using Assimp. * Load a collection of material texture using Assimp.
* This function loads diffuse, specular, and narmal material textures. * This function loads diffuse, specular, and narmal material textures.
* A Mesh may have many of any or all of the texture types above. * A Mesh may have many of any or all of the texture types above.
* Models can have many Meshes attached. * Models can have many Meshes attached.
* This function returns all textures for a single Mesh within a Model. * This function returns all textures for a single Mesh within a Model.
* *
* @param mat Loaded Assimp material. * @param mat Loaded Assimp material.
* @param type Type of the material. * @param type Type of the material.
* @param typeName Texture type name in string format. * @param typeName Texture type name in string format.
* @return Collection of all textures for a single ModelMesh. * @return Collection of all textures for a single ModelMesh.
*/ */
ModelMesh::Textures loadMaterialTextures( ModelMesh::Textures loadMaterialTextures(
aiMaterial *mat, aiTextureType type, const std::string &typeName); aiMaterial * mat, aiTextureType type, const std::string & typeName);
/** /**
* Sorts each mesh in the Model based on distance from the camera. * Sorts each mesh in the Model based on distance from the camera.
* This is for efficient drawing in OpenGL by preventing the drawing of * This is for efficient drawing in OpenGL by preventing the drawing of
* objects not visible due to being partially or entirely behind another * objects not visible due to being partially or entirely behind another
* object. * object.
*/ */
void sortModelMeshes(); void sortModelMeshes();
/************************************************************************* /*************************************************************************
* Private Members * Private Members
************************************************************************/ ************************************************************************/
/** Static QHash used to store and access models globally. */ /** Static QHash used to store and access models globally. */
static ModelManager mManager; static ModelManager mManager;
/** Container to store N loaded textures for this model. */ /** Container to store N loaded textures for this model. */
ModelMesh::Textures mTexturesLoaded{}; ModelMesh::Textures mTexturesLoaded {};
/** Container to store N loaded meshes for this model. */ /** Container to store N loaded meshes for this model. */
std::vector<ModelMesh> mMeshes{}; std::vector<ModelMesh> mMeshes {};
/** The directory this model and it's textures are stored. */ /** The directory this model and it's textures are stored. */
std::string mDirectory{}; std::string mDirectory {};
/** File names for shaders and 3D model on disk. */ /** File names for shaders and 3D model on disk. */
std::string mVertexShader, mFragmentShader, mModelPath; std::string mVertexShader, mFragmentShader, mModelPath;
}; };
} // namespace Qtk } // namespace Qtk