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

[#63] Define new Scene struct and re-define Mesh.

This commit has breaking changes to the API header of the asset_loader,
meaning things will not compile until the implementation in
asset_loader.cpp is adjusted.
parent 75896e06
No related branches found
No related tags found
1 merge request!51Resolve "Laden mehrer Meshes mit Materials und Textures"
Pipeline #25439 failed
...@@ -25,12 +25,13 @@ ...@@ -25,12 +25,13 @@
* top. * top.
* *
* Each Mesh has an array of one or more vertex groups (called "primitives" in * Each Mesh has an array of one or more vertex groups (called "primitives" in
* glTF parlance) and an array of zero or more Materials. * glTF parlance). Specifically, it has an array of indices into an array of
* vertex groups defined by the Scene struct.
* *
* Each vertex group describes a part of the meshes vertices by defining how * Each vertex group describes a part of the meshes vertices by defining how
* they should be rendered (as points, lines, triangles), how many indices and * they should be rendered (as points, lines, triangles), how many indices and
* vertices there are, how the content of the vertex buffer is to be * vertices there are, how the content of the vertex buffer is to be
* interpreted and which material from the Meshes materials array should be * interpreted and which material from the Scenes materials array should be
* used for the surface of the vertices. * used for the surface of the vertices.
* As a bonus there is also the axis aligned bounding box of the vertices. * As a bonus there is also the axis aligned bounding box of the vertices.
* *
...@@ -76,7 +77,7 @@ typedef struct { ...@@ -76,7 +77,7 @@ typedef struct {
} Sampler; } Sampler;
typedef struct { typedef struct {
uint8_t sampler; // index into the Meshes samplers array int sampler; // index into the sampler array of the Scene
uint8_t channels; // number of channels uint8_t channels; // number of channels
uint16_t w, h; // width and height of the texture uint16_t w, h; // width and height of the texture
std::vector<uint8_t> data; // binary data of the decoded texture std::vector<uint8_t> data; // binary data of the decoded texture
...@@ -89,9 +90,9 @@ typedef struct { ...@@ -89,9 +90,9 @@ typedef struct {
* each of the texture targets in the Material struct and a VertexAttribute of * each of the texture targets in the Material struct and a VertexAttribute of
* a VertexBuffer that defines the UV coordinates for that texture. */ * a VertexBuffer that defines the UV coordinates for that texture. */
typedef struct { typedef struct {
uint8_t textureMask; // bit mask with active texture targets uint16_t textureMask; // bit mask with active texture targets
// Indices into the Mesh.textures array // Indices into the Mesh.textures array
uint8_t baseColor, metalRough, normal, occlusion, emissive; int baseColor, metalRough, normal, occlusion, emissive;
// Scaling factors for each texture target // Scaling factors for each texture target
struct { float r, g, b, a; } baseColorFactor; struct { float r, g, b, a; } baseColorFactor;
float metallicFactor, roughnessFactor; float metallicFactor, roughnessFactor;
...@@ -118,19 +119,30 @@ typedef struct { ...@@ -118,19 +119,30 @@ typedef struct {
} vertexBuffer; } vertexBuffer;
struct { float x, y, z; } min; // bounding box lower left struct { float x, y, z; } min; // bounding box lower left
struct { float x, y, z; } max; // bounding box upper right struct { float x, y, z; } max; // bounding box upper right
uint8_t materialIndex; // index to one of the meshes materials int materialIndex; // index to one of the materials
} VertexGroup; } VertexGroup;
/* This struct represents a single mesh loaded from a glTF file. It consists of /* This struct represents a single mesh as it was loaded from a glTF file. It
* at least one VertexVroup and any number of Materials. */ * consists of at least one VertexGroup, which then references other resources
* such as Materials. */
typedef struct { typedef struct {
std::string name; std::string name;
std::vector<int> vertexGroups;
} Mesh;
/* The scene struct is simply a collection of objects in the scene as well as
* the resources used by those objects.
* For now the only type of object are the meshes and they are represented in a
* flat array.
* Note that parent-child relations are not yet possible. */
typedef struct {
std::vector<Mesh> meshes;
std::vector<VertexGroup> vertexGroups; std::vector<VertexGroup> vertexGroups;
std::vector<Material> materials; std::vector<Material> materials;
std::vector<Texture> textures; std::vector<Texture> textures;
std::vector<Sampler> samplers; std::vector<Sampler> samplers;
} Mesh; } Scene;
/** /**
* In its first iteration the asset loader module will only allow loading * In its first iteration the asset loader module will only allow loading
...@@ -143,5 +155,9 @@ typedef struct { ...@@ -143,5 +155,9 @@ typedef struct {
* */ * */
int loadMesh(const std::string &path, Mesh &mesh); int loadMesh(const std::string &path, Mesh &mesh);
// TODO Either replace loadMesh with this new function loadScene, or implement
// loadScene as a second function besides loadMesh...
int loadScene(const std::string &path, Scene &scene);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment