Scene loading

Loading a complex scene like the iconic Sponza scene can be done via the scene module from the VkCV framework. For this you only need to provide the path of your scene of choice as GLTF file. In this example the file is placed relative to the projects directory inside an "assets" subfolder.

Because you want to load data from host (the CPU) memory into GPU memory, you likely need transfer queues. In case of the scene module this is definitely required. So don't forget to add the fitting vk::QueueFlagBits::eTransfer flag to your core instance creation.

Notice that GLTF files do not necessarily contain all data of its scene but link to this data (in form of binary files for the meshes and images for the used textures) via relative paths. So make sure that all required files can be found at the location you want to load the scene from.

#include <vkcv/scene/Scene.hpp>
vkcv::scene::Scene scene = vkcv::scene::Scene::load(
  core, // core instance
  
  // Relative or absolute path to the specified GLTF file
  std::filesystem::path("assets/Sponza/Sponza.gltf"),
  
  // list of vertex attribute types
  {
    vkcv::asset::PrimitiveType::POSITION,
    vkcv::asset::PrimitiveType::NORMAL,
    vkcv::asset::PrimitiveType::TEXCOORD_0
  }
);

The list of vertex attribute types being passed to the vkcv::scene::Scene::load() function will define the order of the vertex buffer bindings for each mesh in the loaded scene. This order is required to match the vertex layout of the graphics pipeline in a later step for proper rendering.

Technically a GLTF file might contains more vertex attributes than the requested ones during the loading process (in this example: position, normal and uv texture coordinates). This is not an issue. But if you request any attribute that is not defined in the loaded file, a warning is triggered.

Previous

Next

Popular posts from this blog

Introduction

Application development

First setup