Skip to content
Snippets Groups Projects
Commit 77857abc authored by Trevor Hollmann's avatar Trevor Hollmann
Browse files

[#79] Start re-implementing loadMesh.

The new function is not complete, so the old one is still kept around.
parent 3c75a574
No related branches found
No related tags found
1 merge request!69Resolve "Rework Asset Loader API"
Pipeline #26426 failed
......@@ -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 {
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment