Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
oe::scene::loader::Gltf Class Reference

Loader to load Khronos glTF assets. More...

#include <OxygenEngine/scene/loader/gltf.h>

+ Inheritance diagram for oe::scene::loader::Gltf:

Classes

struct  GltfSceneData
 
struct  GltfTextureList
 Load the glTF asset into a scene (a new root node will be created) More...
 

Public Types

using MeshFlags = uint8_t
 

Public Member Functions

 Gltf (const std::string &filename)
 Load a glTF asset from a file.
 
GltfSceneData convertSceneData (oe::scene::NodePtr root_node, uint16_t id_scene=0) const
 Convert the glTF asset into scene data under the specified node.
 
GltfTextureList convertTextures (render::TextureManager &texture_manager, std::string_view prefix) const
 Load model textures.
 
void setMaterialFiller (std::function< void(const GltfPbrMaterial &gltf_material, Material &oe_material)> material_filler)
 Apply application specific properties on the materials.
 
std::vector< MaterialconvertMaterials (GltfTextureList textures) const
 Convert and return materials.
 
Material generateDefaultMaterial () const
 Generate a default material suitable for glTF rendering.
 

Protected Member Functions

void _custom_load (const std::string &filename)
 

Protected Attributes

std::function< void(const GltfPbrMaterial &, Material &)> _material_filler = {}
 std::list<std::pair<oe::scene::Mesh, int32_t>> _primitives;
 
tinygltf::TinyGLTF * _loader
 
tinygltf::Model * _model
 
std::function< void(const std::string &extension, NodePtr root_node, const nlohmann::json &extension_data, const bool pre_load)> _custom_asset_extension_handler = {}
 
std::function< void(const std::string &extension, NodePtr node, const nlohmann::json &extension_data)> _custom_node_extension_handler = {}
 
std::function< void(const std::string &extension, Material &material, const nlohmann::json &extension_data)> _custom_material_extension_handler = {}
 

Detailed Description

Loader to load Khronos glTF assets.

Example

// Prepare the loader
oe::scene::loader::Gltf gltf_model = {filename};
// Load assets textures with the specified texture_manager
gltf_model.convertTextures(my_texture_manager);
// (optional) Add any custom handlers if you want to customize how the asset is imported
// Here are some examples:
{
// Set a custom material converter
gltf_model.setMaterialFiller(my_gltf_material_filler);
// Customize how the material is applied on nodes
gltf_model.setNodeMaterialModifier(my_gltf_node_material_modifier);
}
// Finally, we can import the glTF asset hierarchy into the scene and retrieve its root node
oe::scene::Node& imported_node = gltf_model.addIntoSceneManager(my_scene_manager);
Scene node.
Definition node.h:30
Loader to load Khronos glTF assets.
Definition gltf.h:98
GltfTextureList convertTextures(render::TextureManager &texture_manager, std::string_view prefix) const
Load model textures.
void setMaterialFiller(std::function< void(const GltfPbrMaterial &gltf_material, Material &oe_material)> material_filler)
Apply application specific properties on the materials.
Definition gltf.h:208

The loader will automatically handle the following glTF extensions:

Note
If you want to handle additional / custom extensions, take a look at GltfWithExtensions

Constructor & Destructor Documentation

◆ Gltf()

oe::scene::loader::Gltf::Gltf ( const std::string &  filename)

Load a glTF asset from a file.

Parameters
filenamepath to the glTF asset

Member Function Documentation

◆ convertMaterials()

std::vector< Material > oe::scene::loader::Gltf::convertMaterials ( GltfTextureList  textures) const

Convert and return materials.

Note
if you need to add custom properties, you can use setCustomMaterialFiller()
Returns
Generated and converted materials

◆ convertSceneData()

GltfSceneData oe::scene::loader::Gltf::convertSceneData ( oe::scene::NodePtr  root_node,
uint16_t  id_scene = 0 
) const

Convert the glTF asset into scene data under the specified node.

Parameters
root_nodeAsset's root nodes will be imported as children of this node
id_sceneglTF scene to load
Returns
Converted glTF scene

◆ convertTextures()

GltfTextureList oe::scene::loader::Gltf::convertTextures ( render::TextureManager texture_manager,
std::string_view  prefix 
) const

Load model textures.

prefix can be anything you want, but it must be unique for gltf asset (ie. if you load the same asset multiple times, the prefix should be the same)

Will generate textures named prefix_X and prefix_RMA_Y|Z in the Texture manager

  • X is the texture id / position (in glTF data)
  • Y, Z are occlusion and roughness textures ids / position (in glTF data) used to generate the RouMetAo texture
Parameters
texture_manager
prefixTexture prefix in the texture manager
Returns
a list of loaded textures: keys are id and values are the name + pointer to the texture (owned by the Texture manager)

The documentation for this class was generated from the following file: