diff --git a/modules/asset_loader/include/vkcv/asset/asset_loader.hpp b/modules/asset_loader/include/vkcv/asset/asset_loader.hpp index ad35d772449f740271657f38f31c8275f3bc099d..f788403425cf22e409e20b77b2febc21bb6ec604 100644 --- a/modules/asset_loader/include/vkcv/asset/asset_loader.hpp +++ b/modules/asset_loader/include/vkcv/asset/asset_loader.hpp @@ -254,17 +254,21 @@ int loadScene(const std::filesystem::path &path, Scene &scene); int probeScene(const std::filesystem::path &path, Scene &scene); /** - * This function loads a single mesh from the given file into the given Scene. - * TODO document whather this function extends or overwrites the given scene - * The names of meshes can be obtained by calling probeScene() and iterating - * through the array of meshes from the probed scene. + * This function loads a single mesh from the given file and adds it to the + * given scene. The scene must already be initialized (via probeScene()). + * The mesh_index refers to the Scenes meshes array and identifies the mesh to + * load. To find the mesh you want, iterate over the probed scene and check the + * meshes details (eg. name). * Besides the mesh, this function will also add any associated data to the * Scene struct such as Materials and Textures required by the Mesh. * * @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(const std::filesystem::path &path, const std::string &name, Scene &scene); +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) { struct TextureData { diff --git a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp index a948de079692d8ca9ba3b545045eeadc5248b486..8bf97754f382db63dbe5e5945504a7abdfb28fce 100644 --- a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp +++ b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp @@ -460,7 +460,7 @@ int createVertexGroups(fx::gltf::Mesh const& objectMesh, std::vector<uint8_t> indexBufferData = {}; const fx::gltf::Accessor& indexAccessor = sceneObjects.accessors[objectPrimitive.indices]; int indexBufferURI; - if (objectPrimitive.indices >= 0 && !probe) { // if there is no index buffer, -1 is returned from fx-gltf + if (objectPrimitive.indices >= 0) { // if there is no index buffer, -1 is returned from fx-gltf const fx::gltf::BufferView& indexBufferView = sceneObjects.bufferViews[indexAccessor.bufferView]; const fx::gltf::Buffer& indexBuffer = sceneObjects.buffers[indexBufferView.buffer]; if (known_uris.count(indexBuffer.uri)) { @@ -471,7 +471,7 @@ int createVertexGroups(fx::gltf::Mesh const& objectMesh, } indexBufferData.resize(indexBufferView.byteLength); - { + if (!probe) { const size_t off = indexBufferView.byteOffset; const void* const ptr = ((char*)indexBuffer.data.data()) + off; if (!memcpy(indexBufferData.data(), ptr, indexBufferView.byteLength)) { @@ -818,6 +818,20 @@ int probeScene(const std::filesystem::path& path, Scene& scene) { } +int loadMesh(Scene &scene, const int idx) +{ + if (idx < 0 || (size_t)idx >= scene.meshes.size()) { + vkcv_log(LogLevel::ERROR, "mesh index out of range: %d", idx); + return ASSET_ERROR; + } + Mesh &mesh = scene.meshes[idx]; + + // TODO go through all vertex groups of the mesh and load the + // associated materials and index/vertex buffers + return ASSET_SUCCESS; +} + + int loadMesh(const std::filesystem::path &path, const std::string &name, Scene &scene) { fx::gltf::Document sceneObjects;