WIP
This commit is contained in:
@@ -13,14 +13,14 @@ install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
||||
COMPONENT libqtk
|
||||
COMPONENT qtk_library
|
||||
DESTINATION lib/cmake/${PROJECT_NAME}
|
||||
)
|
||||
install(
|
||||
EXPORT qtk_export
|
||||
FILE ${PROJECT_NAME}Targets.cmake
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
COMPONENT libqtk
|
||||
COMPONENT qtk_library
|
||||
DESTINATION lib/cmake/${PROJECT_NAME}
|
||||
)
|
||||
# System install for qtk_library
|
||||
@@ -28,7 +28,7 @@ install(
|
||||
TARGETS qtk_library
|
||||
# Associate qtk_library target with qtk-export
|
||||
EXPORT qtk_export
|
||||
COMPONENT libqtk
|
||||
COMPONENT qtk_library
|
||||
FILE_SET HEADERS DESTINATION include
|
||||
INCLUDES DESTINATION include
|
||||
LIBRARY DESTINATION lib
|
||||
@@ -37,32 +37,32 @@ install(
|
||||
)
|
||||
|
||||
# Qtk Application
|
||||
if(QTK_BUILD_GUI OR QTK_INSTALL_PLUGINS)
|
||||
if(QTK_GUI OR QTK_PLUGINS)
|
||||
add_subdirectory(app)
|
||||
endif()
|
||||
|
||||
if(QTK_INSTALL_PLUGINS)
|
||||
if(QTK_PLUGINS)
|
||||
# Optionally install custom Qtk plugins for Qt Designer.
|
||||
install(
|
||||
TARGETS qtk_library qtk_plugin_library
|
||||
COMPONENT collection
|
||||
COMPONENT qtk_plugins
|
||||
LIBRARY DESTINATION "${QTK_PLUGIN_LIBRARY_DIR}"
|
||||
ARCHIVE DESTINATION "${QTK_PLUGIN_LIBRARY_DIR}"
|
||||
RUNTIME DESTINATION "${QTK_PLUGIN_LIBRARY_DIR}"
|
||||
)
|
||||
install(
|
||||
TARGETS qtk_collection
|
||||
COMPONENT collection
|
||||
TARGETS qtk_plugins
|
||||
COMPONENT qtk_plugins
|
||||
LIBRARY DESTINATION "${QTK_PLUGIN_INSTALL_DIR}"
|
||||
ARCHIVE DESTINATION "${QTK_PLUGIN_INSTALL_DIR}"
|
||||
RUNTIME DESTINATION "${QTK_PLUGIN_INSTALL_DIR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(QTK_BUILD_GUI)
|
||||
if(QTK_GUI)
|
||||
install(
|
||||
TARGETS qtk_app
|
||||
COMPONENT qtk
|
||||
TARGETS qtk_gui
|
||||
COMPONENT qtk_gui
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib/static
|
||||
@@ -70,11 +70,11 @@ if(QTK_BUILD_GUI)
|
||||
)
|
||||
|
||||
qt_generate_deploy_app_script(
|
||||
TARGET qtk_app
|
||||
TARGET qtk_gui
|
||||
OUTPUT_SCRIPT QTK_DEPLOY_SCRIPT
|
||||
NO_UNSUPPORTED_PLATFORM_ERROR
|
||||
)
|
||||
install(SCRIPT ${QTK_DEPLOY_SCRIPT} COMPONENT qtk)
|
||||
install(SCRIPT ${QTK_DEPLOY_SCRIPT} COMPONENT qtk_gui)
|
||||
|
||||
if(WIN32)
|
||||
if(MSVC AND TARGET Qt6::qmake)
|
||||
@@ -87,7 +87,7 @@ if(QTK_BUILD_GUI)
|
||||
)
|
||||
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_gui.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")
|
||||
@@ -124,7 +124,7 @@ set(CPACK_THREADS 0)
|
||||
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Qtk")
|
||||
|
||||
# Remove any assimp components if defined by submodule.
|
||||
if (QTK_UPDATE_SUBMODULES)
|
||||
if (QTK_SUBMODULES)
|
||||
get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS)
|
||||
list(FILTER CPACK_COMPONENTS_ALL EXCLUDE REGEX .*assimp.*)
|
||||
list(REMOVE_ITEM CPACK_COMPONENTS_ALL Unspecified)
|
||||
@@ -136,7 +136,7 @@ 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_gui.exe'"
|
||||
)
|
||||
set(
|
||||
CPACK_NSIS_DELETE_ICONS_EXTRA
|
||||
@@ -152,7 +152,7 @@ set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
|
||||
|
||||
# OSX
|
||||
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_gui>/Info.plist)
|
||||
set(CPACK_BUNDLE_ICON ${QTK_OSX_ICONS})
|
||||
|
||||
# Platform defaults for source bundles.
|
||||
|
||||
@@ -33,32 +33,32 @@ target_sources(
|
||||
target_link_libraries(qtk_plugin_library PUBLIC Qt6::UiPlugin qtk_library)
|
||||
|
||||
################################################################################
|
||||
# Qtk Widget Collection Plugin
|
||||
# Qtk Widget Plugins
|
||||
################################################################################
|
||||
# Create a Qt Designer plugin for a collection of widgets from our library.
|
||||
qt_add_plugin(qtk_collection SHARED)
|
||||
qt_add_plugin(qtk_plugins SHARED)
|
||||
target_sources(
|
||||
qtk_collection PRIVATE
|
||||
qtk_plugins PRIVATE
|
||||
widgetplugincollection.cpp widgetplugincollection.h
|
||||
widgetplugin.cpp widgetplugin.h
|
||||
)
|
||||
target_link_libraries(qtk_collection PUBLIC qtk_plugin_library)
|
||||
target_link_libraries(qtk_plugins PUBLIC qtk_plugin_library)
|
||||
|
||||
################################################################################
|
||||
# Final Qtk Application
|
||||
################################################################################
|
||||
|
||||
set(
|
||||
QTK_APP_SOURCES
|
||||
QTK_GUI_SOURCES
|
||||
qtkscene.cpp qtkscene.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_executable(qtk_app ${QTK_APP_SOURCES})
|
||||
target_link_libraries(qtk_app PRIVATE qtk_plugin_library)
|
||||
qt_add_executable(qtk_gui ${QTK_GUI_SOURCES})
|
||||
target_link_libraries(qtk_gui PRIVATE qtk_plugin_library)
|
||||
|
||||
set_target_properties(
|
||||
qtk_app PROPERTIES
|
||||
qtk_gui PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
MACOSX_BUNDLE_BUNDLE_NAME Qtk
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef QTK_RESOURCES_H_IN_H
|
||||
#define QTK_RESOURCES_H_IN_H
|
||||
|
||||
// Not currently in use, but will be in the future.
|
||||
|
||||
#endif // QTK_RESOURCES_H_IN_H
|
||||
@@ -68,7 +68,7 @@ target_link_libraries(
|
||||
Qt6::Core Qt6::OpenGLWidgets Qt6::Widgets
|
||||
)
|
||||
|
||||
if(QTK_UPDATE_SUBMODULES OR NOT ASSIMP_NEW_INTERFACE)
|
||||
if(QTK_SUBMODULES OR NOT ASSIMP_NEW_INTERFACE)
|
||||
target_link_libraries(qtk_library PUBLIC assimp)
|
||||
elseif(ASSIMP_NEW_INTERFACE)
|
||||
target_link_libraries(qtk_library PUBLIC assimp::assimp)
|
||||
|
||||
317
src/qtk/model.h
317
src/qtk/model.h
@@ -27,177 +27,184 @@ namespace Qtk {
|
||||
* Top-level object that represents 3D models stored within a scene.
|
||||
*/
|
||||
class QTKAPI Model : public Object {
|
||||
public:
|
||||
/*************************************************************************
|
||||
* Typedefs
|
||||
************************************************************************/
|
||||
public:
|
||||
/*************************************************************************
|
||||
* Typedefs
|
||||
************************************************************************/
|
||||
|
||||
/** ModelManager typedef that will manage global model access. */
|
||||
typedef QHash<QString, Model *> ModelManager;
|
||||
/** ModelManager typedef that will manage global model access. */
|
||||
typedef QHash<QString, Model *> ModelManager;
|
||||
|
||||
/*************************************************************************
|
||||
* Constructors, Destructors
|
||||
************************************************************************/
|
||||
/*************************************************************************
|
||||
* Constructors, Destructors
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* Constructs a Model
|
||||
* If no shaders are provided we will use default shaders.
|
||||
*
|
||||
* @param name Name to use for the Model's objectName.
|
||||
* @param path Path to the model to load for construction.
|
||||
* @param vertexShader Optional path to custom vertex shader.
|
||||
* @param fragmentShader Optional path to custom fragment shader.
|
||||
*/
|
||||
inline Model(
|
||||
const char * name, const char * path,
|
||||
const char * vertexShader = ":/shaders/model-basic.vert",
|
||||
const char * fragmentShader = ":/shaders/model-basic.frag") :
|
||||
Object(name, QTK_MODEL),
|
||||
mModelPath(path), mVertexShader(vertexShader),
|
||||
mFragmentShader(fragmentShader) {
|
||||
loadModel(mModelPath);
|
||||
/**
|
||||
* Constructs a Model
|
||||
* If no shaders are provided we will use default shaders.
|
||||
*
|
||||
* @param name Name to use for the Model's objectName.
|
||||
* @param path Path to the model to load for construction.
|
||||
* @param vertexShader Optional path to custom vertex shader.
|
||||
* @param fragmentShader Optional path to custom fragment shader.
|
||||
*/
|
||||
inline Model(
|
||||
const char *name, const char *path,
|
||||
const char *vertexShader = ":/shaders/model-basic.vert",
|
||||
const char *fragmentShader = ":/shaders/model-basic.frag") :
|
||||
Object(name, QTK_MODEL),
|
||||
mModelPath(path), mVertexShader(vertexShader),
|
||||
mFragmentShader(fragmentShader) {
|
||||
loadModel(mModelPath);
|
||||
}
|
||||
|
||||
inline Model(
|
||||
std::string name, std::string path,
|
||||
std::string vertexShader = ":/shaders/model-basic.vert",
|
||||
std::string fragmentShader = ":/shaders/model-basic.frag") :
|
||||
Model(name.c_str(), path.c_str(), vertexShader.c_str(),
|
||||
fragmentShader.c_str()) {}
|
||||
|
||||
inline ~Model() override { mManager.remove(getName().c_str()); }
|
||||
|
||||
/*************************************************************************
|
||||
* Public Methods
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws the model using attached shader program.
|
||||
*/
|
||||
void draw();
|
||||
|
||||
/**
|
||||
* Draws the model using a custom shader program.
|
||||
*
|
||||
* @param shader Shader program to use to draw the model.
|
||||
*/
|
||||
void draw(QOpenGLShaderProgram &shader);
|
||||
|
||||
/**
|
||||
* Flip a texture associated with this model
|
||||
*
|
||||
* @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 flipY Flip the texture along the Y axis
|
||||
*/
|
||||
void flipTexture(
|
||||
const std::string &fileName, bool flipX = false, bool flipY = true);
|
||||
|
||||
/*************************************************************************
|
||||
* Setters
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets a uniform value for each ModelMesh within this Model.
|
||||
*
|
||||
* @tparam T The type of the value we are settings
|
||||
* @param location The uniform location
|
||||
* @param value The value to assign to the uniform
|
||||
*/
|
||||
template<typename T>
|
||||
inline void setUniform(const char *location, T value) {
|
||||
for (auto &mesh: mMeshes) {
|
||||
mesh.mProgram->bind();
|
||||
mesh.mProgram->setUniformValue(location, value);
|
||||
mesh.mProgram->release();
|
||||
}
|
||||
}
|
||||
|
||||
inline ~Model() override { mManager.remove(getName().c_str()); }
|
||||
/*************************************************************************
|
||||
* Accessors
|
||||
************************************************************************/
|
||||
|
||||
/*************************************************************************
|
||||
* Public Methods
|
||||
************************************************************************/
|
||||
/**
|
||||
* Accessor function for retrieving a ModelMesh globally.
|
||||
* The mesh is retrieved from the mManager private member.
|
||||
*
|
||||
* @param name The name of the model to load as it was constructed.
|
||||
* @return Pointer to the model stored within the scene.
|
||||
*/
|
||||
[[nodiscard]] static Model *getInstance(const char *name);
|
||||
|
||||
/**
|
||||
* Draws the model using attached shader program.
|
||||
*/
|
||||
void draw();
|
||||
/**
|
||||
* @return Transform3D attached to this Model.
|
||||
*/
|
||||
inline Transform3D &getTransform() { return mTransform; }
|
||||
|
||||
/**
|
||||
* Draws the model using a custom shader program.
|
||||
*
|
||||
* @param shader Shader program to use to draw the model.
|
||||
*/
|
||||
void draw(QOpenGLShaderProgram & shader);
|
||||
private:
|
||||
/*************************************************************************
|
||||
* Private Methods
|
||||
************************************************************************/
|
||||
|
||||
/**
|
||||
* Flip a texture associated with this model
|
||||
*
|
||||
* @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 flipY Flip the texture along the Y axis
|
||||
*/
|
||||
void flipTexture(
|
||||
const std::string & fileName, bool flipX = false, bool flipY = true);
|
||||
/**
|
||||
* Loads a model in .obj, .fbx, .gltf, and other formats.
|
||||
* For a full list of formats see assimp documentation:
|
||||
* https://github.com/assimp/assimp/blob/master/doc/Fileformats.md
|
||||
*
|
||||
* Large models should not be loaded into Qt resource system.
|
||||
* Instead pass an *absolute* path to this function.
|
||||
* Relative paths will break if Qtk is executed from different locations.
|
||||
*
|
||||
* @param path Absolute path to a model in .obj or another format accepted
|
||||
* by assimp.
|
||||
*/
|
||||
void loadModel(const std::string &path);
|
||||
|
||||
/*************************************************************************
|
||||
* Setters
|
||||
************************************************************************/
|
||||
/**
|
||||
* Process a node in the model's geometry using Assimp.
|
||||
*
|
||||
* @param node The Assimp node to process.
|
||||
* @param scene The Assimp scene for the loaded model.
|
||||
*/
|
||||
void processNode(aiNode *node, const aiScene *scene);
|
||||
|
||||
/**
|
||||
* Sets a uniform value for each ModelMesh within this Model.
|
||||
*
|
||||
* @tparam T The type of the value we are settings
|
||||
* @param location The uniform location
|
||||
* @param value The value to assign to the uniform
|
||||
*/
|
||||
template <typename T>
|
||||
inline void setUniform(const char * location, T value) {
|
||||
for(auto & mesh : mMeshes) {
|
||||
mesh.mProgram->bind();
|
||||
mesh.mProgram->setUniformValue(location, value);
|
||||
mesh.mProgram->release();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Process a mesh within a node using Assimp.
|
||||
*
|
||||
* @param mesh The Assimp mesh to process.
|
||||
* @param scene The Assimp scene for the loaded model.
|
||||
* @return
|
||||
*/
|
||||
ModelMesh processMesh(aiMesh *mesh, const aiScene *scene);
|
||||
|
||||
/*************************************************************************
|
||||
* Accessors
|
||||
************************************************************************/
|
||||
/**
|
||||
* Load a collection of material texture using Assimp.
|
||||
* This function loads diffuse, specular, and narmal material textures.
|
||||
* A Mesh may have many of any or all of the texture types above.
|
||||
* Models can have many Meshes attached.
|
||||
* This function returns all textures for a single Mesh within a Model.
|
||||
*
|
||||
* @param mat Loaded Assimp material.
|
||||
* @param type Type of the material.
|
||||
* @param typeName Texture type name in string format.
|
||||
* @return Collection of all textures for a single ModelMesh.
|
||||
*/
|
||||
ModelMesh::Textures loadMaterialTextures(
|
||||
aiMaterial *mat, aiTextureType type, const std::string &typeName);
|
||||
|
||||
/**
|
||||
* Accessor function for retrieving a ModelMesh globally.
|
||||
* The mesh is retrieved from the mManager private member.
|
||||
*
|
||||
* @param name The name of the model to load as it was constructed.
|
||||
* @return Pointer to the model stored within the scene.
|
||||
*/
|
||||
[[nodiscard]] static Model * getInstance(const char * name);
|
||||
/**
|
||||
* Sorts each mesh in the Model based on distance from the camera.
|
||||
* This is for efficient drawing in OpenGL by preventing the drawing of
|
||||
* objects not visible due to being partially or entirely behind another
|
||||
* object.
|
||||
*/
|
||||
void sortModelMeshes();
|
||||
|
||||
/**
|
||||
* @return Transform3D attached to this Model.
|
||||
*/
|
||||
inline Transform3D & getTransform() { return mTransform; }
|
||||
/*************************************************************************
|
||||
* Private Members
|
||||
************************************************************************/
|
||||
|
||||
private:
|
||||
/*************************************************************************
|
||||
* Private Methods
|
||||
************************************************************************/
|
||||
/** Static QHash used to store and access models globally. */
|
||||
static ModelManager mManager;
|
||||
|
||||
/**
|
||||
* Loads a model in .obj, .fbx, .gltf, and other formats.
|
||||
* For a full list of formats see assimp documentation:
|
||||
* https://github.com/assimp/assimp/blob/master/doc/Fileformats.md
|
||||
*
|
||||
* Large models should not be loaded into Qt resource system.
|
||||
* Instead pass an *absolute* path to this function.
|
||||
* Relative paths will break if Qtk is executed from different locations.
|
||||
*
|
||||
* @param path Absolute path to a model in .obj or another format accepted
|
||||
* by assimp.
|
||||
*/
|
||||
void loadModel(const std::string & path);
|
||||
|
||||
/**
|
||||
* Process a node in the model's geometry using Assimp.
|
||||
*
|
||||
* @param node The Assimp node to process.
|
||||
* @param scene The Assimp scene for the loaded model.
|
||||
*/
|
||||
void processNode(aiNode * node, const aiScene * scene);
|
||||
|
||||
/**
|
||||
* Process a mesh within a node using Assimp.
|
||||
*
|
||||
* @param mesh The Assimp mesh to process.
|
||||
* @param scene The Assimp scene for the loaded model.
|
||||
* @return
|
||||
*/
|
||||
ModelMesh processMesh(aiMesh * mesh, const aiScene * scene);
|
||||
|
||||
/**
|
||||
* Load a collection of material texture using Assimp.
|
||||
* This function loads diffuse, specular, and narmal material textures.
|
||||
* A Mesh may have many of any or all of the texture types above.
|
||||
* Models can have many Meshes attached.
|
||||
* This function returns all textures for a single Mesh within a Model.
|
||||
*
|
||||
* @param mat Loaded Assimp material.
|
||||
* @param type Type of the material.
|
||||
* @param typeName Texture type name in string format.
|
||||
* @return Collection of all textures for a single ModelMesh.
|
||||
*/
|
||||
ModelMesh::Textures loadMaterialTextures(
|
||||
aiMaterial * mat, aiTextureType type, const std::string & typeName);
|
||||
|
||||
/**
|
||||
* Sorts each mesh in the Model based on distance from the camera.
|
||||
* This is for efficient drawing in OpenGL by preventing the drawing of
|
||||
* objects not visible due to being partially or entirely behind another
|
||||
* object.
|
||||
*/
|
||||
void sortModelMeshes();
|
||||
|
||||
/*************************************************************************
|
||||
* Private Members
|
||||
************************************************************************/
|
||||
|
||||
/** Static QHash used to store and access models globally. */
|
||||
static ModelManager mManager;
|
||||
|
||||
/** Container to store N loaded textures for this model. */
|
||||
ModelMesh::Textures mTexturesLoaded {};
|
||||
/** Container to store N loaded meshes for this model. */
|
||||
std::vector<ModelMesh> mMeshes {};
|
||||
/** 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;
|
||||
/** Container to store N loaded textures for this model. */
|
||||
ModelMesh::Textures mTexturesLoaded{};
|
||||
/** Container to store N loaded meshes for this model. */
|
||||
std::vector<ModelMesh> mMeshes{};
|
||||
/** 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;
|
||||
};
|
||||
} // namespace Qtk
|
||||
|
||||
|
||||
Reference in New Issue
Block a user