From f087c54e8c1fc2263a5ad8b208b3ab4b098bc560 Mon Sep 17 00:00:00 2001 From: Tobias Frisch <tfrisch@uni-koblenz.de> Date: Mon, 19 Jul 2021 18:26:15 +0200 Subject: [PATCH] [#79] Removed old loadMesh() and fixed compile errors Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de> --- .../include/vkcv/asset/asset_loader.hpp | 6 +- .../src/vkcv/asset/asset_loader.cpp | 109 +----------------- 2 files changed, 2 insertions(+), 113 deletions(-) diff --git a/modules/asset_loader/include/vkcv/asset/asset_loader.hpp b/modules/asset_loader/include/vkcv/asset/asset_loader.hpp index f7884034..04f0b39b 100644 --- a/modules/asset_loader/include/vkcv/asset/asset_loader.hpp +++ b/modules/asset_loader/include/vkcv/asset/asset_loader.hpp @@ -265,11 +265,7 @@ int probeScene(const std::filesystem::path &path, Scene &scene); * @param path must be the path to a glTF- or glb-file. * @param scene is the scene struct to which the results will be written. */ -int loadMesh(Scene &scene, const int mesh_index); - -// The old loadMesh-function, to be removed -int loadMesh(const std::filesystem::path &path, const std::string &name, Scene &scene) { - +int loadMesh(Scene &scene, int mesh_index); struct TextureData { int width; diff --git a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp index 8bf97754..f07d4ba7 100644 --- a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp +++ b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp @@ -818,7 +818,7 @@ int probeScene(const std::filesystem::path& path, Scene& scene) { } -int loadMesh(Scene &scene, const int idx) +int loadMesh(Scene &scene, int idx) { if (idx < 0 || (size_t)idx >= scene.meshes.size()) { vkcv_log(LogLevel::ERROR, "mesh index out of range: %d", idx); @@ -831,111 +831,4 @@ int loadMesh(Scene &scene, const int idx) return ASSET_SUCCESS; } - -int loadMesh(const std::filesystem::path &path, const std::string &name, Scene &scene) { - fx::gltf::Document sceneObjects; - - try { - if (path.extension() == ".glb") { - sceneObjects = fx::gltf::LoadFromBinary(path.string()); - } - else { - sceneObjects = fx::gltf::LoadFromText(path.string()); - } - } - catch (const std::system_error& err) { - recurseExceptionPrint(err, path.string()); - return ASSET_ERROR; - } - catch (const std::exception& e) { - recurseExceptionPrint(e, path.string()); - return ASSET_ERROR; - } - auto dir = path.parent_path().string(); - - // file has to contain at least one mesh - if (sceneObjects.meshes.empty()) { - return ASSET_ERROR; - } - - std::vector<Material> materials; - std::vector<Texture> textures; - std::vector<Sampler> samplers; - std::vector<Mesh> meshes; - std::vector<VertexGroup> vertexGroups; - std::vector<std::string> uris; - int groupCount = 0; - int meshIndex = -1; - - for (size_t i = 0; i < sceneObjects.meshes.size(); i++) { - if (sceneObjects.meshes[i].name == name) { - std::vector<int> vertexGroupsIndices; - fx::gltf::Mesh const& objectMesh = sceneObjects.meshes[i]; - - if (createVertexGroups(objectMesh, sceneObjects, - vertexGroups, - vertexGroupsIndices, uris, - groupCount, false) - != ASSET_SUCCESS) { - vkcv_log(LogLevel::ERROR, "Failed to get Vertex Groups!"); - return ASSET_ERROR; - } - - Mesh mesh = {}; - mesh.name = sceneObjects.meshes[i].name; - mesh.vertexGroups = vertexGroupsIndices; - - meshes.push_back(mesh); - meshIndex = i; - break; - } - } - - if (meshes.empty()) { - vkcv_log(LogLevel::ERROR, "No mesh by that name!"); - return ASSET_ERROR; - } - - // This only works if the node has a mesh and it only loads the meshes and ignores cameras and lights - if (sceneObjects.nodes[meshIndex].mesh > -1) { - meshes[sceneObjects.nodes[meshIndex].mesh].modelMatrix = computeModelMatrix( - sceneObjects.nodes[meshIndex].translation, - sceneObjects.nodes[meshIndex].scale, - sceneObjects.nodes[meshIndex].rotation, - sceneObjects.nodes[meshIndex].matrix - ); - } - - if (createTextures(sceneObjects.textures, sceneObjects.images, sceneObjects.buffers, sceneObjects.bufferViews, dir, uris, textures) != ASSET_SUCCESS) { - size_t missing = sceneObjects.textures.size() - textures.size(); - vkcv_log(LogLevel::ERROR, "Failed to get %lu textures from glTF source '%s'", - missing, path.c_str()); - } - - - if (createMaterial(sceneObjects, materials) != ASSET_SUCCESS) { - vkcv_log(LogLevel::ERROR, "Failed to get Materials!"); - return ASSET_ERROR; - } - - samplers.reserve(sceneObjects.samplers.size()); - for (const auto& it : sceneObjects.samplers) { - samplers.push_back({}); - auto& sampler = samplers.back(); - if (translateSampler(it, sampler) != ASSET_SUCCESS) { - return ASSET_ERROR; - } - } - - scene = { - meshes, - vertexGroups, - materials, - textures, - samplers - }; - - return ASSET_SUCCESS; -} - } -- GitLab