add zasset

This commit is contained in:
ouczbs 2024-03-03 23:33:13 +08:00
parent e48d175b76
commit f6e3b52dca
17 changed files with 234 additions and 4 deletions

5
engine/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.associations": {
"vector": "cpp"
}
}

98
engine/3rdparty/assimp/xmake.lua vendored Normal file
View File

@ -0,0 +1,98 @@
package("assimp")
set_homepage("https://assimp.org")
set_description("Portable Open-Source library to import various well-known 3D model formats in a uniform manner")
set_license("BSD-3-Clause")
set_urls("https://github.com/assimp/assimp/archive/$(version).zip",
"https://github.com/assimp/assimp.git")
add_versions("v5.2.5", "5384877d53be7b5bbf50c26ab3f054bec91b3df8614372dcd7240f44f61c509b")
if not is_host("windows") then
add_extsources("pkgconfig::assimp")
end
if is_plat("mingw") and is_subhost("msys") then
add_extsources("pacman::assimp")
elseif is_plat("linux") then
add_extsources("pacman::assimp", "apt::libassimp-dev")
elseif is_plat("macosx") then
add_extsources("brew::assimp")
end
add_configs("build_tools", {description = "Build the supplementary tools for Assimp.", default = false, type = "boolean"})
add_configs("double_precision", {description = "Enable double precision processing.", default = false, type = "boolean"})
add_configs("no_export", {description = "Disable Assimp's export functionality (reduces library size).", default = false, type = "boolean"})
add_configs("android_jniiosysystem", {description = "Enable Android JNI IOSystem support.", default = false, type = "boolean"})
add_configs("asan", {description = "Enable AddressSanitizer.", default = false, type = "boolean"})
add_configs("ubsan", {description = "Enable Undefined Behavior sanitizer.", default = false, type = "boolean"})
add_deps("cmake", "zlib")
if is_plat("windows") then
add_syslinks("advapi32")
end
on_load(function (package)
if not package:gitref() and package:version():le("5.1.0") then
package:add("deps", "irrxml")
end
if package:is_plat("linux", "macosx") and package:config("shared") then
package:add("links", "assimp" .. (package:is_debug() and "d" or ""))
end
end)
on_install(function (package)
local configs = {"-DASSIMP_BUILD_SAMPLES=OFF",
"-DASSIMP_BUILD_TESTS=OFF",
"-DASSIMP_BUILD_DOCS=OFF",
"-DASSIMP_BUILD_FRAMEWORK=OFF",
"-DASSIMP_INSTALL_PDB=ON",
"-DASSIMP_INJECT_DEBUG_POSTFIX=ON",
"-DASSIMP_BUILD_ZLIB=OFF",
"-DSYSTEM_IRRXML=ON",
"-DASSIMP_WARNINGS_AS_ERRORS=OFF"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
local function add_config_arg(config_name, cmake_name)
table.insert(configs, "-D" .. cmake_name .. "=" .. (package:config(config_name) and "ON" or "OFF"))
end
add_config_arg("shared", "BUILD_SHARED_LIBS")
add_config_arg("double_precision", "ASSIMP_DOUBLE_PRECISION")
add_config_arg("no_export", "ASSIMP_NO_EXPORT")
add_config_arg("asan", "ASSIMP_ASAN")
add_config_arg("ubsan", "ASSIMP_UBSAN")
if package:is_plat("android") then
add_config_arg("android_jniiosysystem", "ASSIMP_ANDROID_JNIIOSYSTEM")
end
if package:is_plat("windows", "linux", "macosx", "mingw") then
add_config_arg("build_tools", "ASSIMP_BUILD_ASSIMP_TOOLS")
else
table.insert(configs, "-DASSIMP_BUILD_ASSIMP_TOOLS=OFF")
end
if not package:gitref() and package:version():lt("v5.2.4") then
-- ASSIMP_WARNINGS_AS_ERRORS is not supported before v5.2.4
if package:is_plat("windows") then
io.replace("code/CMakeLists.txt", "TARGET_COMPILE_OPTIONS(assimp PRIVATE /W4 /WX)", "", {plain = true})
else
io.replace("code/CMakeLists.txt", "TARGET_COMPILE_OPTIONS(assimp PRIVATE -Werror)", "", {plain = true})
end
end
if package:is_plat("mingw") and package:version():lt("v5.1.5") then
-- CMAKE_COMPILER_IS_MINGW has been removed: https://github.com/assimp/assimp/pull/4311
io.replace("CMakeLists.txt", "CMAKE_COMPILER_IS_MINGW", "MINGW", {plain = true})
end
import("package.tools.cmake").install(package, configs)
-- copy pdb
if package:is_plat("windows") then
if package:config("shared") then
os.trycp(path.join(package:buildir(), "bin", "**.pdb"), package:installdir("bin"))
else
os.trycp(path.join(package:buildir(), "lib", "**.pdb"), package:installdir("lib"))
end
end
end)

33
engine/3rdparty/zasset/include/asset.h vendored Normal file
View File

@ -0,0 +1,33 @@
#include <cstdint>
#include <string>
namespace engineapi
{
class Asset {
public:
enum {
ASSET_NONE,
ASSET_SHARED_TYPE,
ASSET_COPY_TYPE,
ASSET_ASYNC_TYPE,
ASSET_LOADED_TYPE,
ASSET_NUM,
};
protected:
uint32_t mFlags;
std::string mName;
public:
Asset(std::string& name, uint32_t flags):mName(name),mFlags(flags) {};
virtual void onLoadFinished() { mFlags |= ASSET_LOADED_TYPE; };
virtual void SyncLoad() {};
public:
inline bool IsShared() {
return mFlags & ASSET_SHARED_TYPE;
}
inline bool IsCopyed() {
return mFlags & ASSET_COPY_TYPE;
}
inline bool IsAsync() {
return mFlags & ASSET_ASYNC_TYPE;
}
};
}

View File

@ -0,0 +1,54 @@
#pragma once
#include <filesystem>
#include <fstream>
#include <functional>
#include <sstream>
#include <string>
#include <map>
#include "asset.h"
namespace engineapi
{
class AssetManager
{
public:
struct AssetWrap {
Asset& asset;
uint32_t count;
AssetWrap(Asset& asset): asset(asset),count(0) {
}
};
private:
std::map<const std::string, AssetWrap> mAssetMap;
public:
template<typename TAsset>
TAsset* LoadAsset(const std::string& asset_url,uint32_t flags)
{
std::filesystem::path asset_path = getFullPath(asset_url);
auto it = mAssetMap.find(asset_path.string());
if (it != mAssetMap.end()) {
if (it->second.asset.IsShared()) {
return &(it->second.asset);
}
if (it->second.asset.IsCopyed()) {
TAsset* asset = new TAsset(asset_path.string(), flags);
*asset = it->second.asset;
return asset;
}
}
TAsset* asset = new TAsset(asset_path.string(), flags);
if (asset->IsShared() || asset->IsCopyed()) {
mAssetMap.emplace(asset_path.string(), *asset);
}
if (asset->IsAsync()) {
//todo: AsyncLoad
asset->SyncLoad();
}
else {
asset->SyncLoad();
}
return asset;
}
std::filesystem::path getFullPath(const std::string& relative_path) const;
};
}

5
engine/3rdparty/zasset/src/asset.cpp vendored Normal file
View File

@ -0,0 +1,5 @@
#include "asset.h"
namespace engineapi
{
}

View File

@ -0,0 +1,6 @@
#include "asset_manager.h"
std::filesystem::path engineapi::AssetManager::getFullPath(const std::string& relative_path) const
{
return std::filesystem::path(relative_path);
}

7
engine/3rdparty/zasset/xmake.lua vendored Normal file
View File

@ -0,0 +1,7 @@
set_languages("cxx20")
target("zasset")
set_kind("static")
add_includedirs("include", {public = true})
add_deps("zlog",{public = true})
add_files("src/*.cpp")
add_headerfiles("include/*.h")

View File

@ -0,0 +1,12 @@
#include "mesh.h"
#include "assimp/Importer.hpp"
#include "assimp/scene.h"
#include "assimp/postprocess.h"
namespace vulkanapi {
void Mesh::SyncLoad()
{
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(mName, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_CalcTangentSpace);
}
}

View File

@ -0,0 +1,10 @@
#pragma once
#include "asset.h"
#include "../vulkan.h"
namespace vulkanapi {
class Mesh : public engineapi::Asset{
public:
void SyncLoad()override;
};
};

View File

@ -13,7 +13,7 @@ int main(int argc, char** argv)
auto vulkan = vulkanapi::Backend(name);
auto wnd = vulkanapi::Window(vulkan, 3, 640, 720, name);
auto gbuffer = vulkanapi::GeometryBuffer(vulkan.GetDevice(), 3, 640, 720);
auto forardpass = vulkanapi::ForwardPass(vulkan.GetDevice(), gbuffer);
auto forwardpass = vulkanapi::ForwardPass(vulkan.GetDevice(), gbuffer);
while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}

View File

@ -1,11 +1,11 @@
includes("3rdparty/xmake.lua")
--includes("test/**xmake.lua")
add_requires("assimp")
target("zengine")
set_kind("binary")
set_rundir(".")
add_deps("zcoro","zlog")
add_packages("vulkansdk","tinyobjloader","glm")
add_deps("zcoro","zlog","zasset")
add_packages("vulkansdk","tinyobjloader","glm","assimp")
add_includedirs("src")
add_syslinks("user32")
add_files("src/*.cpp", "src/**.cpp")