VkCV Framework  0.0.1
CV Vulkan framework
vkcv::asset Namespace Reference

Classes

struct  Material
 
struct  Mesh
 
struct  Sampler
 
struct  Scene
 
struct  Texture
 
struct  TextureData
 
struct  VertexAttribute
 
struct  VertexGroup
 

Enumerations

enum  PrimitiveMode : uint8_t {
  POINTS =0, LINES, LINELOOP, LINESTRIP,
  TRIANGLES, TRIANGLESTRIP, TRIANGLEFAN
}
 
enum  IndexType : uint8_t { UNDEFINED =0, UINT8 =1, UINT16 =2, UINT32 =3 }
 
enum  PBRTextureTarget {
  baseColor =1, metalRough =2, normal =4, occlusion =8,
  emissive =16
}
 
enum  PrimitiveType : uint32_t {
  UNDEFINED = 0, POSITION = 1, NORMAL = 2, TEXCOORD_0 = 3,
  TEXCOORD_1 = 4, TANGENT = 5
}
 
enum  ComponentType : uint16_t {
  NONE = 0, INT8 = 5120, UINT8 = 5121, INT16 = 5122,
  UINT16 = 5123, UINT32 = 5125, FLOAT32 = 5126
}
 

Functions

bool materialHasTexture (const Material *const m, const PBRTextureTarget t)
 
int loadScene (const std::string &path, Scene &scene)
 
TextureData loadTexture (const std::filesystem::path &path)
 
uint8_t convertTypeToInt (const fx::gltf::Accessor::Type type)
 
void print_what (const std::exception &e, const std::string &path)
 
enum IndexType getIndexType (const enum fx::gltf::Accessor::ComponentType &t)
 
std::array< float, 16 > computeModelMatrix (std::array< float, 3 > translation, std::array< float, 3 > scale, std::array< float, 4 > rotation, std::array< float, 16 > matrix)
 

Detailed Description

LOADING MESHES The description of meshes is a hierarchy of structures with the Mesh at the top.

Each Mesh has an array of one or more vertex groups (called "primitives" in 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 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 interpreted and which material from the Scenes materials array should be used for the surface of the vertices. As a bonus there is also the axis aligned bounding box of the vertices.

The vertex buffer is presented as a single block of binary data with a given length in bytes. The layout of the vertex buffer is described by an array of VertexAttribute structs that define the type of attribute, the offset, length and stride in bytes and number and type of components of the attribute. These values can directly be given to vulkan when describing the content of vertex buffers.

Enumeration Type Documentation

◆ ComponentType

enum vkcv::asset::ComponentType : uint16_t
strong

These integer values are used the same way in OpenGL, Vulkan and glTF. This enum is not needed for translation, it's only for the programmers convenience (easier to read in if/switch statements etc). While this enum exists in (almost) the same definition in the fx-gltf library, we want to avoid exposing that dependency, thus it is re-defined here.

◆ IndexType

enum vkcv::asset::IndexType : uint8_t
strong

The indices in the index buffer can be of different bit width.

◆ PBRTextureTarget

Flags for the bit-mask in the Material struct. To check if a material has a certain texture target, you can use the hasTexture() function below, passing the material struct and the enum.

◆ PrimitiveMode

enum vkcv::asset::PrimitiveMode : uint8_t
strong

This enum matches modes in fx-gltf, the library returns a standard mode (TRIANGLES) if no mode is given in the file.

◆ PrimitiveType

enum vkcv::asset::PrimitiveType : uint32_t
strong

With these enums, 0 is reserved to signal uninitialized or invalid data.

Function Documentation

◆ computeModelMatrix()

std::array<float, 16> vkcv::asset::computeModelMatrix ( std::array< float, 3 >  translation,
std::array< float, 3 >  scale,
std::array< float, 4 >  rotation,
std::array< float, 16 >  matrix 
)

This function computes the modelMatrix out of the data given in the gltf file. It also checks, whether a modelMatrix was given.

Parameters
translationpossible translation vector (default 0,0,0)
scalepossible scale vector (default 1,1,1)
rotationpossible rotation, given in quaternion (default 0,0,0,1)
matrixpossible modelmatrix (default identity)
Returns
model Matrix as an array of floats

◆ convertTypeToInt()

uint8_t vkcv::asset::convertTypeToInt ( const fx::gltf::Accessor::Type  type)

convert the accessor type from the fx-gltf library to an unsigned int

Parameters
type
Returns
unsigned integer representation

◆ getIndexType()

enum IndexType vkcv::asset::getIndexType ( const enum fx::gltf::Accessor::ComponentType &  t)

Translate the component type used in the index accessor of fx-gltf to our enum for index type. The reason we have defined an incompatible enum that needs translation is that only a subset of component types is valid for indices and we want to catch these incompatibilities here.

◆ loadScene()

int vkcv::asset::loadScene ( const std::string &  path,
Scene scene 
)

Load every mesh from the glTF file, as well as materials and textures.

Parameters
pathmust be the path to a glTF or glb file.
sceneis a reference to a Scene struct that will be filled with the content of the glTF file being loaded.

References print_what().

Here is the call graph for this function:

◆ materialHasTexture()

bool vkcv::asset::materialHasTexture ( const Material *const  m,
const PBRTextureTarget  t 
)

To signal that a certain texture target is active in a Material struct, its bit is set in the textureMask. You can use this function to check that: Material mat = ...; if (materialHasTexture(&mat, baseColor)) {...}

◆ print_what()

void vkcv::asset::print_what ( const std::exception &  e,
const std::string &  path 
)

This function unrolls nested exceptions via recursion and prints them

Parameters
eerror code
pathpath to file that is responsible for error

Referenced by loadScene().

Here is the caller graph for this function: