Skip to content
Snippets Groups Projects
Verified Commit 28dd92fc authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Merge branch '26-asset-loading' of...

Merge branch '26-asset-loading' of gitlab.uni-koblenz.de:vulkan2021/vkcv-framework into 26-asset-loading

Signed-off-by: default avatarTobias Frisch <tfrisch@uni-koblenz.de>
parents fa1d7162 413f343e
No related branches found
No related tags found
1 merge request!19Resolve "Asset Loading"
Pipeline #24971 failed
......@@ -52,6 +52,7 @@ typedef struct {
// TODO not yet needed for the first (unlit) triangle
} Material;
/* This struct describes one vertex attribute of a vertex buffer. */
typedef struct {
PrimitiveType type; // POSITION, NORMAL, ...
uint32_t offset; // offset in bytes
......@@ -61,10 +62,25 @@ typedef struct {
uint8_t componentCount; // eg. 3 for vec3
} VertexAttribute;
/* This struct represents one (possibly the only) part of a mesh. There is
* always one vertexBuffer and zero or one indexBuffer (indexed rendering is
* common but not always used). If there is no indexBuffer, this is indicated
* by indexBuffer.data being NULL.
* Each vertex buffer can have one or more vertex attributes.
* Note that the indexBuffer and vertexBuffer might be pointing to the same
* block of memory.
*
* TODO For now, the caller of loadMesh() has to free this memory when they are
* done, but since this is not generally good practice in C++, this behaviour
* will likely be changed later. */
typedef struct {
enum PrimitiveMode mode; // draw as points, lines or triangle?
size_t numIndices, numVertices;
uint32_t *indexBuffer; // array of indices for indexed rendering
struct {
void *data; // binary data of the index buffer
size_t byteLength; // length of the index buffer
uint32_t byteOffset; // offset into the buffer in bytes
} indexBuffer;
struct {
void *data; // the binary data of the buffer
size_t byteLength; // the length of the entire buffer in bytes
......@@ -75,7 +91,8 @@ typedef struct {
uint8_t materialIndex; // index to one of the meshes materials
} VertexGroup;
/* This struct represents a single mesh loaded from a glTF file. */
/* This struct represents a single mesh loaded from a glTF file. It consists of
* at least one VertexVroup and any number of Materials. */
typedef struct {
std::string name;
std::vector<VertexGroup> vertexGroups;
......
......@@ -6,20 +6,40 @@
namespace vkcv::asset {
int loadMesh(const std::string &path, Mesh &mesh) {
std::vector<uint8_t> v;
// TODO load the gltf file using the library, return 0 if there is an
// error.
// If the library throws excaptions, catch them and maybe print an
// error, but do not pass on the exception to the caller!
// Looking at the example code of fx-gltf I would assume that
// fx::gltf::LoadFromText(); is a good starting point.
if (fx::base64::TryDecode(path, v)) {
for (auto& ve : v) {
std::cout << ve << " ";
}
std::cout << std::endl;
} else {
std::cerr << "Schade!" << std::endl;
}
// TODO Verify that all required information can be found in the
// struct/class returned by fx-gltf (eg. check if there is exactly one
// mesh and that it has at least 3 vertices or something like that) and
// return 0 if something is missing.
// The important thing here is that we don't create an incomplete mesh
// because we start copying data before making sure all the required
// data is available.
// TODO
return -1;
// TODO Fill the output argument 'mesh' with the data from the loaded
// glTF file.
// Look at the structs 'Mesh', 'VertexGroup' and 'VertexAttribute'
// defined in asset_loader.hpp and compare it to the glTF cheat sheet:
// https://raw.githubusercontent.com/KhronosGroup/glTF/master/specification/2.0/figures/gltfOverview-2.0.0b.png
//
// If the fx::gltf::Document struct/class from the fx-gltf library
// don't really match our structs, we may need to re-think how our
// structs are defined (they are only based on the glTF specification).
//
// In the first iteration our goal is to simply load the vertices of a
// mesh without textures and materials. (Maybe start with our triangle
// since that does not have textures)
// Once this works, we can add support for materials/textures, but I
// wouldn't include this feature until loading of vertices+indices is
// proven to work
// Finally return 1 to signal that all is fine
return 1;
}
}
......@@ -6,7 +6,7 @@ int main(int argc, const char** argv) {
int result = vkcv::asset::loadMesh("test.gltf", mesh);
if (result == 0) {
if (result == 1) {
std::cout << "Mesh loading successful!" << std::endl;
} else {
std::cout << "Mesh loading failed: " << result << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment