diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c5e5a68..1435b963 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,4 +47,5 @@ configure_file(cmake/path.hpp.in ${TAIXUENGINE_ROOT_DIR}/engine/src/common/base/ add_subdirectory(engine) add_subdirectory(docs) -add_subdirectory(tests) \ No newline at end of file +add_subdirectory(tests) +add_subdirectory(tools) \ No newline at end of file diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 331da80d..71200467 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -81,10 +81,12 @@ set(glslangValidator_executable ${Vulkan_GLSLANG_VALIDATOR_EXECUTABLE}) set(SHADER_COMPILE_TARGET TaixuShaderCompile) set(COMMON_COMPILE_TARGET TaixuCommonLib) +set(SCRIPT_COMPILE_TARGET TaixuScriptLib) add_subdirectory(shaders) # editor and runtime add_subdirectory(src/editor) add_subdirectory(src/common) -add_subdirectory(src/runtime) \ No newline at end of file +add_subdirectory(src/runtime) +add_subdirectory(src/script) \ No newline at end of file diff --git a/engine/src/common/base/macro.hpp b/engine/src/common/base/macro.hpp index 046fc4ec..b76ff7ec 100644 --- a/engine/src/common/base/macro.hpp +++ b/engine/src/common/base/macro.hpp @@ -87,7 +87,7 @@ namespace taixu { /** * @brief Define Opengl version */ -constexpr std::string_view OPENGL_VERSION = "#version 460"; +constexpr std::string_view OPENGL_VERSION = "#version 410"; /** * @brief Define Opengl major version */ @@ -95,7 +95,7 @@ constexpr std::int32_t OPENGL_MAJOR_VERSION = 4; /** * @brief Define Opengl minor version */ -constexpr std::int32_t OPENGL_MINOR_VERSION = 6; +constexpr std::int32_t OPENGL_MINOR_VERSION = 1; /** * @brief status enum diff --git a/engine/src/editor/main.cpp b/engine/src/editor/main.cpp index 09a6c3e3..7919af73 100644 --- a/engine/src/editor/main.cpp +++ b/engine/src/editor/main.cpp @@ -9,17 +9,6 @@ #include "ui/main_window/main_window.hpp" -/** - * @brief initWindow spdlog config - */ -void initSpdlog() { -#ifndef NDEBUG - spdlog::set_level(spdlog::level::debug);// Set global log level to debug -#else - spdlog::set_level(spdlog::level::info);// Set global log level to info -#endif -} - /** * @brief Main window width */ @@ -38,10 +27,8 @@ int main(int argc, char* argv[]) { // avoid c-style array std::vector const args(argv, argv + argc); - initSpdlog(); - taixu::Engine* engine_ptr = &taixu::Engine::getInstance(); - engine_ptr->loadParams(args); + taixu::Engine::loadParams(args); spdlog::info("start init the application!"); diff --git a/engine/src/runtime/engine.cpp b/engine/src/runtime/engine.cpp index 883f83fe..92341586 100644 --- a/engine/src/runtime/engine.cpp +++ b/engine/src/runtime/engine.cpp @@ -4,6 +4,8 @@ #include #include "engine_args.hpp" +#include "resource/converted_data/project.hpp" +#include "resource/manager/project_manager.hpp" #include #include #include @@ -33,9 +35,8 @@ void Engine::init(std::unique_ptr context, } _renderer->init(); - _project_manager = std::make_unique(); - _asset_manager = std::make_unique(); - _scene_manager = std::make_unique(); + _asset_manager = std::make_unique(); + _scene_manager = std::make_unique(); _renderer->set_default_texture( _asset_manager->loadTexture(".", "assets/texture/rgba1111.png") @@ -71,20 +72,32 @@ void Engine::destroy() { this->_window_ptr->destroy(); } AbstractRenderer* Engine::getRenderer() const { return _renderer.get(); } -Status Engine::loadProject(const std::string_view& path) { - spdlog::info("Loading project: {}", path); - Status const status = _project_manager->openProject(path); - if (Status::OK != status) { - spdlog::error("Failed to load project: {}", - magic_enum::enum_name(status)); - return status; +void Engine::loadProject(const std::filesystem::path& path) { + spdlog::info("Loading project: {}", path.generic_string()); + std::optional tpj{std::nullopt}; + try { + tpj = openProject(path); + } catch (std::exception& e) { + spdlog::error("Failed to load project: {}", e.what()); + return; } - - return Status::OK; + glfwSetWindowTitle(this->_context_ptr->_window, + fmt::format("{} - {} - {}", this->_context_ptr->_title, + tpj.value().manifest.name, + tpj.value().current_path.generic_string()) + .c_str()); + this->_opened_project = std::move(tpj); } -Project* Engine::getOpenedProject() const { - return this->_project_manager->getCurrentProject(); +/** + * @brief 获取打开的项目文件 + * @return + */ +Project const* Engine::getOpenedProject() const { + if (this->_opened_project.has_value()) { + return &this->_opened_project.value(); + } + return nullptr; } Scene* Engine::getScene() const { return _current_scene; } diff --git a/engine/src/runtime/engine.hpp b/engine/src/runtime/engine.hpp index f0aaac47..85733e98 100644 --- a/engine/src/runtime/engine.hpp +++ b/engine/src/runtime/engine.hpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -23,21 +24,27 @@ class Engine final : public PublicSingleton { private: std::unique_ptr _renderer{nullptr}; std::unique_ptr _asset_manager{nullptr}; - std::unique_ptr _project_manager{nullptr}; std::unique_ptr _scene_manager{nullptr}; + std::unique_ptr _context_ptr{nullptr}; std::unique_ptr _window_ptr{nullptr}; - Scene* _current_scene{nullptr}; + + std::optional _opened_project{std::nullopt}; + Scene* _current_scene{nullptr}; /** * @brief editor state */ EngineState _state{EngineState::EDITORMODE}; + /** + * @brief engine clock + */ Clock _clock{}; +private: void update(); public: @@ -50,11 +57,11 @@ class Engine final : public PublicSingleton { void destroy(); - Status loadProject(std::string_view const& path); + void loadProject(std::filesystem::path const& path); [[nodiscard]] AbstractRenderer* getRenderer() const; - [[nodiscard]] Project* getOpenedProject() const; + [[nodiscard]] Project const* getOpenedProject() const; [[nodiscard]] Scene* getScene() const; diff --git a/engine/src/runtime/engine_args.hpp b/engine/src/runtime/engine_args.hpp index de023cc0..d22c4e8e 100644 --- a/engine/src/runtime/engine_args.hpp +++ b/engine/src/runtime/engine_args.hpp @@ -5,6 +5,7 @@ #ifndef TAIXUENGINE_RUNTIME_ENGINE_ARGS_HPP #define TAIXUENGINE_RUNTIME_ENGINE_ARGS_HPP +#include "spdlog/common.h" #include #include #include @@ -65,6 +66,10 @@ class EngineArgs : public PublicSingleton { #ifdef NDEBUG this->_is_debug = false; + spdlog::set_level(spdlog::level::info);// Set global log level to debug +#else + this->_is_debug = true; + spdlog::set_level(spdlog::level::debug);// Set global log level to info #endif } }; diff --git a/engine/src/runtime/resource/converted_data/project.hpp b/engine/src/runtime/resource/converted_data/project.hpp new file mode 100644 index 00000000..ceab9ed4 --- /dev/null +++ b/engine/src/runtime/resource/converted_data/project.hpp @@ -0,0 +1,24 @@ +// +// Created by xmmmmmovo on 2023/7/23. +// + +#ifndef ENGINE_SRC_RUNTIME_RESOURCE_CONVERTED_DATA_PROJECT_HPP +#define ENGINE_SRC_RUNTIME_RESOURCE_CONVERTED_DATA_PROJECT_HPP + +#include "runtime/resource/converted_data/world.hpp" +#include "runtime/resource/json/manifest_json.hpp" +#include +#include +#include + +namespace taixu { + +struct Project { + std::filesystem::path current_path; + Manifest manifest; + std::vector worlds; +}; + +}// namespace taixu + +#endif// ENGINE_SRC_RUNTIME_RESOURCE_CONVERTED_DATA_PROJECT_HPP diff --git a/engine/src/runtime/resource/converted_data/world.hpp b/engine/src/runtime/resource/converted_data/world.hpp new file mode 100644 index 00000000..c5dc517d --- /dev/null +++ b/engine/src/runtime/resource/converted_data/world.hpp @@ -0,0 +1,14 @@ +// +// Created by xmmmmmovo on 2023/7/23. +// + +#ifndef ENGINE_SRC_RUNTIME_RESOURCE_CONVERTED_DATA_WORLD_HPP +#define ENGINE_SRC_RUNTIME_RESOURCE_CONVERTED_DATA_WORLD_HPP + +namespace taixu { + +struct World {}; + +}// namespace taixu + +#endif// ENGINE_SRC_RUNTIME_RESOURCE_CONVERTED_DATA_WORLD_HPP diff --git a/engine/src/runtime/resource/json/project_json.hpp b/engine/src/runtime/resource/json/manifest_json.hpp similarity index 100% rename from engine/src/runtime/resource/json/project_json.hpp rename to engine/src/runtime/resource/json/manifest_json.hpp diff --git a/engine/src/runtime/resource/json/serializable.hpp b/engine/src/runtime/resource/json/serializable.hpp index a775ad51..6c05d260 100644 --- a/engine/src/runtime/resource/json/serializable.hpp +++ b/engine/src/runtime/resource/json/serializable.hpp @@ -2,8 +2,8 @@ // Created by xmmmmmovo on 2023/2/26. // -#ifndef TAIXUENGINE_JSONABLE_HPP -#define TAIXUENGINE_JSONABLE_HPP +#ifndef TAIXUENGINE_SRC_RUNTIME_RESOURCE_SERIALIZABLE_HPP +#define TAIXUENGINE_SRC_RUNTIME_RESOURCE_SERIALIZABLE_HPP #include @@ -18,4 +18,4 @@ class ISerializableList : refl::attr::usage::field {}; }// namespace taixu -#endif// TAIXUENGINE_JSONABLE_HPP +#endif// TAIXUENGINE_SRC_RUNTIME_RESOURCE_SERIALIZABLE_HPP diff --git a/engine/src/runtime/resource/json/world_json.hpp b/engine/src/runtime/resource/json/world_json.hpp new file mode 100644 index 00000000..07ff3ecd --- /dev/null +++ b/engine/src/runtime/resource/json/world_json.hpp @@ -0,0 +1,43 @@ +// +// Created by xmmmmmovo on 2023/7/23. +// + +#ifndef ENGINE_SRC_RUNTIME_RESOURCE_JSON_WORLD_JSON_HPP +#define ENGINE_SRC_RUNTIME_RESOURCE_JSON_WORLD_JSON_HPP + +#include + +#include + +#include "serializable.hpp" + +namespace taixu { + +struct World { + struct Level { + std::string level_name{}; + std::string level_path{}; + }; + + struct Global { + std::string render{}; + }; + + std::string name{}; + Global global{}; + std::vector levels{}; +}; + +}// namespace taixu + +REFL_AUTO(type(taixu::World), field(name, taixu::ISerializableStr()), + field(global, taixu::ISerializableObject()), + field(levels, taixu::ISerializableList())) + +REFL_AUTO(type(taixu::World::Level), + field(level_name, taixu::ISerializableStr()), + field(level_path, taixu::ISerializableStr())) + +REFL_AUTO(type(taixu::World::Global), field(render, taixu::ISerializableStr())) + +#endif// ENGINE_SRC_RUNTIME_RESOURCE_JSON_WORLD_JSON_HPP diff --git a/engine/src/runtime/resource/manager/asset_manager.cpp b/engine/src/runtime/resource/manager/asset_manager.cpp index 0a9c3eb0..238a1b07 100644 --- a/engine/src/runtime/resource/manager/asset_manager.cpp +++ b/engine/src/runtime/resource/manager/asset_manager.cpp @@ -7,7 +7,6 @@ #include #include "asset_manager.hpp" -#include #include #include #include @@ -235,8 +234,8 @@ Model* AssetManager::loadModel(std::filesystem::path const& root_path, return nullptr; } - if (_models.count(full_path.generic_string())) { - return &_models[full_path.generic_string()]; + if (_models.count(full_path.generic_string().data())) { + return &_models[full_path.generic_string().data()]; } Model ret_model{}; @@ -261,8 +260,8 @@ Model* AssetManager::loadModel(std::filesystem::path const& root_path, processMaterial(scene, root_path, ret_model); processNode(scene->mRootNode, scene, ret_model); - auto [model_ref, was_ins] = - _models.insert({full_path.generic_string(), std::move(ret_model)}); + auto [model_ref, was_ins] = _models.insert( + {full_path.generic_string().data(), std::move(ret_model)}); return &model_ref->second; @@ -279,12 +278,12 @@ AssetManager::loadTexture(std::filesystem::path const& root_path, return nullptr; } - if (_textures.count(full_path.generic_string())) { - return &_textures[full_path.generic_string()]; + if (_textures.count(full_path.generic_string().data())) { + return &_textures[full_path.generic_string().data()]; } auto [tex_ref, was_ins] = _textures.insert( - {full_path.generic_string(), + {full_path.generic_string().data(), transferCPUTextureToGPU(root_path, relative_path, type)}); return &tex_ref->second; } diff --git a/engine/src/runtime/resource/manager/asset_manager.hpp b/engine/src/runtime/resource/manager/asset_manager.hpp index 75e39143..48416bf0 100644 --- a/engine/src/runtime/resource/manager/asset_manager.hpp +++ b/engine/src/runtime/resource/manager/asset_manager.hpp @@ -19,7 +19,6 @@ #include "glm/gtc/type_ptr.hpp" #include -#include #include #include #include @@ -28,15 +27,13 @@ namespace taixu { class AssetManager final { private: - std::unordered_map _textures{}; - std::unordered_map _models{}; - std::unordered_map _fbx_files{}; + std::unordered_map _textures{}; + std::unordered_map _models{}; static Mesh processMesh(aiMesh* mesh); void processNode(aiNode* node, aiScene const* scene, Model& model); - void processNode(aiNode* node, aiScene const* scene, Model& model, - FBXData* fbx); + void processMaterial(aiScene const* scene, std::filesystem::path const& root_path, Model& model); @@ -63,14 +60,9 @@ class AssetManager final { std::filesystem::path const& relative_path, std::function const& callback); - // for animation - FBXData* loadFBX(std::filesystem::path const& root_path, - std::filesystem::path const& relative_path); - void reset() { _textures.clear(); _models.clear(); - _fbx_files.clear(); } }; }// namespace taixu diff --git a/engine/src/runtime/resource/manager/project_manager.cpp b/engine/src/runtime/resource/manager/project_manager.cpp index b7d84f2f..8dba24b2 100644 --- a/engine/src/runtime/resource/manager/project_manager.cpp +++ b/engine/src/runtime/resource/manager/project_manager.cpp @@ -6,53 +6,49 @@ #include -#include +#include "runtime/resource/converted_data/project.hpp" +#include "runtime/resource/json/manifest_json.hpp" #include "spdlog/spdlog.h" +#include +#include +#include +#include namespace taixu { -Status ProjectManager::openProject(std::string_view const& path) { +std::optional openProject(std::filesystem::path const& path) { // If the project is not loaded, load it from the JSON file - std::filesystem::path manifest_path = path; - manifest_path /= "manifest.json"; - std::ifstream file(manifest_path.c_str()); + std::filesystem::path manifest_path = path / "manifest.json"; + std::ifstream const file((path / "manifest.json").generic_string()); if (!file.is_open()) { - std::cerr << "Failed to open project file " << path << "\n"; - return Status::NO_SUCH_FILE_FAILED; + spdlog::error("Failed to open project file {}", path.generic_string()); + return std::nullopt; } - std::string name; - - // Create a new project object and add it to the vector of projects - opened_project = std::make_unique(Project{name}); - - current_path = manifest_path.parent_path(); - - return Status::OK; + Project project; + project.current_path = path; + project.manifest = loadFromJsonFile(manifest_path); + return project; } -Status ProjectManager::createProject(std::string const& path, - std::string const& name) { - if (opened_project) { opened_project = nullptr; } - return Status::OK; +std::optional createProject(std::filesystem::path const& path, + std::string const& name, + std::string const& author, + std::string const& description) { + Project project; + project.current_path = path; + project.manifest = Manifest(); + project.manifest.name = name; + project.manifest.author = + author.empty() ? "noname" : author;// TODO: get current user name + project.manifest.description = description; + project.manifest.version = "0.0.1"; + + return project; } -Status ProjectManager::saveAsProject(const std::string& path) { - if (opened_project == nullptr) { - spdlog::error("current have no project opening, error"); - return Status::NO_OPEN_PROJECT; - } +Status saveAsProject(const std::filesystem::path& path) { return Status::OK; } - return Status::OK; -} - -Status ProjectManager::saveProject() { - if (opened_project == nullptr) { - spdlog::error("current have no project opening, error"); - return Status::NO_OPEN_PROJECT; - } - - return Status::OK; -} +Status saveProject() { return Status::OK; } }// namespace taixu \ No newline at end of file diff --git a/engine/src/runtime/resource/manager/project_manager.hpp b/engine/src/runtime/resource/manager/project_manager.hpp index b5add467..b7a77ea7 100644 --- a/engine/src/runtime/resource/manager/project_manager.hpp +++ b/engine/src/runtime/resource/manager/project_manager.hpp @@ -4,49 +4,32 @@ #ifndef TAIXUENGINE_PROJECT_MANAGER_HPP #define TAIXUENGINE_PROJECT_MANAGER_HPP +#include #include +#include #include #include #include +#include "runtime/resource/converted_data/project.hpp" + #include namespace taixu { -struct Project { -public: - //name of project - std::string_view name; -}; - -class ProjectManager { -private: - // current project - std::unique_ptr opened_project{nullptr}; - //file path of project - std::filesystem::path current_path; - -public: - ProjectManager() = default; - - Status openProject(std::string_view const &path); - - Status createProject(std::string const &path, std::string const &name); +std::optional openProject(std::filesystem::path const& path); - Status saveProject(); +std::optional createProject(std::filesystem::path const& path, + std::string const& name, + std::string const& author, + std::string const& description); - Status saveAsProject(std::string const &path); +Status saveProject(); - [[nodiscard]] inline Project *getCurrentProject() const { - return opened_project.get(); - } +Status saveAsProject(std::filesystem::path const& path); - [[nodiscard]] inline std::filesystem::path getCurrentPath() const { - return current_path; - } -}; }// namespace taixu -#endif//TAIXUENGINE_PROJECT_MANAGER_HPP +#endif// TAIXUENGINE_PROJECT_MANAGER_HPP diff --git a/engine/src/runtime/resource/raw_data/asset_data.hpp b/engine/src/runtime/resource/raw_data/asset_data.hpp index 7b225eb4..011efcc1 100644 --- a/engine/src/runtime/resource/raw_data/asset_data.hpp +++ b/engine/src/runtime/resource/raw_data/asset_data.hpp @@ -11,10 +11,10 @@ namespace taixu { -struct BaseAssetData { +struct AbstractAssetData { std::filesystem::path file_path; }; }// namespace taixu -#endif//TAIXUENGINE_ASSET_DATA_HPP +#endif// TAIXUENGINE_ASSET_DATA_HPP diff --git a/engine/src/runtime/resource/raw_data/bone.hpp b/engine/src/runtime/resource/raw_data/bone.hpp deleted file mode 100644 index 88d61ad2..00000000 --- a/engine/src/runtime/resource/raw_data/bone.hpp +++ /dev/null @@ -1,168 +0,0 @@ -#ifndef TAIXUENGINE_BONE_HPP -#define TAIXUENGINE_BONE_HPP - -#include "glm/glm.hpp" -#include "glm/gtc/quaternion.hpp" -namespace taixu { -#define MAX_BONE_INFLUENCE 4 -struct KeyPosition { - glm::vec3 position; - float timeStamp; -}; - -struct KeyRotation { - glm::quat orientation; - float timeStamp; -}; - -struct KeyScale { - glm::vec3 scale; - float timeStamp; -}; - -struct BoneInfo { - /*id is index in finalBoneMatrices*/ - int id; - - /*offset matrix transforms vertex from model space to bone space*/ - glm::mat4 offset; -}; - -struct VertexRelateBoneInfo { - int related_bones[MAX_BONE_INFLUENCE]; - float related_bones_weights[MAX_BONE_INFLUENCE]; -}; - -struct AssimpNodeData { - glm::mat4 transformation; - std::string name; - int childrenCount; - std::vector children; -}; - -class Bone { -public: - std::vector m_Positions; - std::vector m_Rotations; - std::vector m_Scales; - int m_NumPositions; - int m_NumRotations; - int m_NumScalings; - - glm::mat4 m_LocalTransform; - std::string m_Name; - int m_ID; - - Bone() = default; - /*interpolates b/w positions,rotations & scaling keys based on the curren time of - the animation and prepares the local transformation matrix by combining all keys - tranformations*/ - void Update(float animationTime) { - glm::mat4 translation = InterpolatePosition(animationTime); - glm::mat4 rotation = InterpolateRotation(animationTime); - glm::mat4 scale = InterpolateScaling(animationTime); - m_LocalTransform = translation * rotation * scale; - } - - glm::mat4 GetLocalTransform() { return m_LocalTransform; } - std::string GetBoneName() const { return m_Name; } - int GetBoneID() { return m_ID; } - - - /* Gets the current index on mKeyPositions to interpolate to based on - the current animation time*/ - int GetPositionIndex(float animationTime) { - for (int index = 0; index < m_NumPositions - 1; ++index) { - if (animationTime < m_Positions[index + 1].timeStamp) return index; - } - assert(0); - return -1; - } - - /* Gets the current index on mKeyRotations to interpolate to based on the - current animation time*/ - int GetRotationIndex(float animationTime) { - for (int index = 0; index < m_NumRotations - 1; ++index) { - if (animationTime < m_Rotations[index + 1].timeStamp) return index; - } - assert(0); - return -1; - } - - /* Gets the current index on mKeyScalings to interpolate to based on the - current animation time */ - int GetScaleIndex(float animationTime) { - for (int index = 0; index < m_NumScalings - 1; ++index) { - if (animationTime < m_Scales[index + 1].timeStamp) return index; - } - assert(0); - return -1; - } - -private: - /* Gets normalized value for Lerp & Slerp*/ - float GetScaleFactor(float lastTimeStamp, float nextTimeStamp, - float animationTime) { - float scaleFactor = 0.0f; - float midWayLength = animationTime - lastTimeStamp; - float framesDiff = nextTimeStamp - lastTimeStamp; - scaleFactor = midWayLength / framesDiff; - return scaleFactor; - } - - /*figures out which position keys to interpolate b/w and performs the interpolation - and returns the translation matrix*/ - glm::mat4 InterpolatePosition(float animationTime) { - if (1 == m_NumPositions) - return glm::translate(glm::mat4(1.0f), m_Positions[0].position); - - int p0Index = GetPositionIndex(animationTime); - int p1Index = p0Index + 1; - float scaleFactor = - GetScaleFactor(m_Positions[p0Index].timeStamp, - m_Positions[p1Index].timeStamp, animationTime); - glm::vec3 finalPosition = - glm::mix(m_Positions[p0Index].position, - m_Positions[p1Index].position, scaleFactor); - return glm::translate(glm::mat4(1.0f), finalPosition); - } - - /*figures out which rotations keys to interpolate b/w and performs the interpolation - and returns the rotation matrix*/ - glm::mat4 InterpolateRotation(float animationTime) { - if (1 == m_NumRotations) { - auto rotation = glm::normalize(m_Rotations[0].orientation); - return glm::mat4(rotation); - } - - int p0Index = GetRotationIndex(animationTime); - int p1Index = p0Index + 1; - float scaleFactor = - GetScaleFactor(m_Rotations[p0Index].timeStamp, - m_Rotations[p1Index].timeStamp, animationTime); - glm::quat finalRotation = - glm::slerp(m_Rotations[p0Index].orientation, - m_Rotations[p1Index].orientation, scaleFactor); - finalRotation = glm::normalize(finalRotation); - return glm::mat4(finalRotation); - } - - /*figures out which scaling keys to interpolate b/w and performs the interpolation - and returns the scale matrix*/ - glm::mat4 InterpolateScaling(float animationTime) { - if (1 == m_NumScalings) - return glm::scale(glm::mat4(1.0f), m_Scales[0].scale); - - int p0Index = GetScaleIndex(animationTime); - int p1Index = p0Index + 1; - float scaleFactor = - GetScaleFactor(m_Scales[p0Index].timeStamp, - m_Scales[p1Index].timeStamp, animationTime); - glm::vec3 finalScale = glm::mix(m_Scales[p0Index].scale, - m_Scales[p1Index].scale, scaleFactor); - return glm::scale(glm::mat4(1.0f), finalScale); - } -}; - -}// namespace taixu -#endif /* TAIXUENGINE_BONE_HPP */ diff --git a/engine/src/runtime/resource/raw_data/fbx_data.hpp b/engine/src/runtime/resource/raw_data/fbx_data.hpp deleted file mode 100644 index 031a5e25..00000000 --- a/engine/src/runtime/resource/raw_data/fbx_data.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef TAIXUENGINE_FBXHELPER_HPP -#define TAIXUENGINE_FBXHELPER_HPP - -#include "bone.hpp" -#include "model.hpp" -#include -namespace taixu { - -class FBXData : public BaseAssetData { -public: - Model *model; - std::map m_BoneInfoMap; - int m_BoneCounter{0}; - - float m_Duration; - int m_TicksPerSecond; - std::vector skeleton; - - AssimpNodeData m_RootNode; - - bool hasAnimation{false}; - void bindSkinedMesh(Model *m) { model = m; } - - Bone *FindBone(const std::string &name) { - auto iter = std::find_if( - skeleton.begin(), skeleton.end(), - [&](const Bone &Bone) { return Bone.GetBoneName() == name; }); - if (iter == skeleton.end()) { - return nullptr; - } else { - return &(*iter); - } - } - - [[nodiscard]] float GetTicksPerSecond() const { return m_TicksPerSecond; } - - [[nodiscard]] float GetDuration() const { return m_Duration; } -}; - -}// namespace taixu - - -#endif /* TAIXUENGINE_FBXHELPER_HPP */ diff --git a/engine/src/runtime/resource/raw_data/mesh.hpp b/engine/src/runtime/resource/raw_data/mesh.hpp index a5da3f5d..9a57a43c 100644 --- a/engine/src/runtime/resource/raw_data/mesh.hpp +++ b/engine/src/runtime/resource/raw_data/mesh.hpp @@ -12,10 +12,9 @@ #include #include "asset_data.hpp" -#include #include "material.hpp" -#include -#include "bone.hpp" +#include "runtime/management/graphics/render/vertex_array.hpp" +#include "runtime/platform/opengl/ogl_vertex_array.hpp" namespace taixu { struct MeshGPU final { @@ -36,67 +35,9 @@ struct Mesh final { std::vector indices; std::optional material_id{std::nullopt}; - - std::vector related_bones_id; - - std::vector related_bones_weights; }; -inline MeshGPU transferCPUMesh2GPU(Mesh const &mesh) { - MeshGPU mesh_gpu{}; - - if (EngineArgs::getInstance().api() == GraphicsAPI::OPENGL) { - auto vao = std::make_unique(); - - vao->bind(); - vao->addVBO(OGLVertexBuffer{mesh.vertices.size(), - &mesh.vertices.front(), GL_STATIC_DRAW, 3},GL_FLOAT); - - if (!mesh.normals.empty()) { - vao->addVBO(OGLVertexBuffer{mesh.normals.size(), - &mesh.normals.front(), GL_STATIC_DRAW, - 3},GL_FLOAT); - } - - if (!mesh.tex_coords.empty()) { - vao->addVBO(OGLVertexBuffer{mesh.tex_coords.size(), - &mesh.tex_coords.front(), - GL_STATIC_DRAW, 2},GL_FLOAT); - } - - if (!mesh.tangents.empty()) { - vao->addVBO(OGLVertexBuffer{mesh.tangents.size(), - &mesh.tangents.front(), GL_STATIC_DRAW, - 3},GL_FLOAT); - vao->addVBO(OGLVertexBuffer{mesh.bitangents.size(), - &mesh.bitangents.front(), - GL_STATIC_DRAW, 3},GL_FLOAT); - } - - if (!mesh.related_bones_id.empty()) { - vao->addVBO(OGLVertexBuffer{mesh.related_bones_id.size(), - &mesh.related_bones_id.front(), GL_STATIC_DRAW, - 4},GL_INT); - - vao->addVBO(OGLVertexBuffer{mesh.related_bones_weights.size(), - &mesh.related_bones_weights.front(), GL_STATIC_DRAW, - 4},GL_FLOAT); - } - - vao->setEBO(OGLElementBuffer{mesh.indices.size(), &mesh.indices.front(), - GL_STATIC_DRAW}); - - vao->unbind(); - mesh_gpu.vao = std::move(vao); - } - - mesh_gpu.index_count = mesh.indices.size(); - mesh_gpu.mat_index = mesh.material_id; - - return mesh_gpu; -} - }// namespace taixu -#endif//TAIXUENGINE_MESH_HPP +#endif// TAIXUENGINE_MESH_HPP diff --git a/engine/src/runtime/resource/raw_data/model.hpp b/engine/src/runtime/resource/raw_data/model.hpp index f691a63c..abb0f064 100644 --- a/engine/src/runtime/resource/raw_data/model.hpp +++ b/engine/src/runtime/resource/raw_data/model.hpp @@ -17,24 +17,13 @@ struct ModelGPU final { std::vector meshes{}; }; -struct Model final : public BaseAssetData { +struct Model final : public AbstractAssetData { std::vector meshes; std::vector materials; std::optional gpu_data{std::nullopt}; }; -inline void transferCPUModelToGPU(Model *model) { - ModelGPU ret{}; - - ret.meshes.reserve(model->meshes.size()); - for (auto const &mesh : model->meshes) { - ret.meshes.push_back(transferCPUMesh2GPU(mesh)); - } - - model->gpu_data = std::move(ret); -} - }// namespace taixu -#endif//TAIXUENGINE_RESOURCE_RAW_DATA_MODEL_HPP +#endif// TAIXUENGINE_RESOURCE_RAW_DATA_MODEL_HPP diff --git a/engine/src/runtime/resource/raw_data/texture.hpp b/engine/src/runtime/resource/raw_data/texture.hpp index 1cb6fd36..9ab3c5e5 100644 --- a/engine/src/runtime/resource/raw_data/texture.hpp +++ b/engine/src/runtime/resource/raw_data/texture.hpp @@ -9,6 +9,7 @@ #include #include "asset_data.hpp" +#include "runtime/engine_args.hpp" #include #include #include @@ -74,7 +75,7 @@ inline TextureType textureTypeFromAssimpType(aiTextureType aitype) { } } -struct Texture2DAsset final : public BaseAssetData { +struct Texture2DAsset final : public AbstractAssetData { TextureType type{TextureType::COMMON}; std::unique_ptr texture{nullptr}; }; @@ -88,6 +89,7 @@ transferCPUTextureToGPU(std::filesystem::path const &asset_path, texture.type = type; texture.file_path = relative_path; + if (EngineArgs::getInstance().api() == GraphicsAPI::OPENGL) { texture.texture = std::make_unique( fromRelativePath(asset_path, relative_path)); diff --git a/engine/src/script/CMakeLists.txt b/engine/src/script/CMakeLists.txt new file mode 100644 index 00000000..d9583b7c --- /dev/null +++ b/engine/src/script/CMakeLists.txt @@ -0,0 +1 @@ +set(TARGET_NAME ${SCRIPT_COMPILE_TARGET}) \ No newline at end of file diff --git a/engine/src/script/lua/bind.lua b/engine/src/script/lua/bind.lua new file mode 100644 index 00000000..1c5bd6c7 --- /dev/null +++ b/engine/src/script/lua/bind.lua @@ -0,0 +1,3 @@ +function main() + print("Hello World!") +end \ No newline at end of file diff --git a/example_proj/gameplay/world/.keep b/example_proj/gameplay/world/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/example_proj/gameplay/taixuworld.json b/example_proj/gameplay/world/taixuworld.json similarity index 88% rename from example_proj/gameplay/taixuworld.json rename to example_proj/gameplay/world/taixuworld.json index 85a5a808..56ab4195 100644 --- a/example_proj/gameplay/taixuworld.json +++ b/example_proj/gameplay/world/taixuworld.json @@ -1,5 +1,5 @@ { - "name": "mainworld", + "name": "main world", "global": { "render": "gameplay/global/render.global.json" }, diff --git a/tests/MoveResources.cmake b/tests/MoveResources.cmake deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/unit_tests/json_tests.cpp b/tests/unit_tests/json_tests.cpp index fefb2ea5..b1a14658 100644 --- a/tests/unit_tests/json_tests.cpp +++ b/tests/unit_tests/json_tests.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include "lib/logger.hpp" diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 00000000..70c042b8 --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.20) + +project(TaixuEngineTools LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_C_STANDARD 11) + +# ---- Options ---- + +# ---- Dependencies ---- + +include(../cmake/CPM.cmake) + +file(GLOB_RECURSE model_converter_source CONFIGURE_DEPENDS + "model_converter/*.cpp" "model_converter/*.hpp") + +add_executable(ModelConverterTool ${model_converter_source}) + +target_link_libraries(ModelConverterTool PRIVATE TaixuRuntime) \ No newline at end of file diff --git a/tools/model_converter/main.cpp b/tools/model_converter/main.cpp new file mode 100644 index 00000000..37df6fa7 --- /dev/null +++ b/tools/model_converter/main.cpp @@ -0,0 +1,6 @@ +// +// Created by xmmmmmovo on 2023/7/24. +// +#include + +int main(int argc, char* argv[]) { return 0; } \ No newline at end of file