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:
[legend]
Collaboration diagram for oe::scene::loader::Gltf:
[legend]

Public Member Functions

 Gltf (const std::string &filename, const bool is_binary)
 Load a glTF asset from a file.
 
oe::scene::NodeaddIntoSceneManager (oe::scene::Manager &scene_manager, uint16_t id_scene=0)
 Load the glTF asset into a scene (under a new root node)
 
oe::scene::NodeaddIntoSceneManager (oe::scene::Manager &scene_manager, oe::scene::Node &root_node, uint16_t id_scene=0)
 Load the glTF asset into a scene (using a specified node as root node)
 
void convertTextures (render::TextureManager &)
 Load model textures.
 
void setMaterialFiller (std::function< void(const PbrMaterial &gltf_material, Material &oe_material)>)
 Apply application specific properties on the materials.
 
void setNodeMaterialModifier (std::function< void(Node &node, Material &node_material)>)
 Apply application specific properties on the material that will be applied to a node.
 
std::vector< MaterialgetMaterials ()
 Convert and return materials.
 

Protected Member Functions

void _custom_load (const std::string &filename, const bool is_binary)
 

Protected Attributes

std::vector< std::shared_ptr< oe::scene::Node > > _scenes
 
std::unordered_map< uint32_t, std::list< std::pair< std::shared_ptr< oe::scene::Mesh >, int32_t > > > _meshes
 std::list<std::pair<oe::scene::Mesh, int32_t>> _primitives;
 
std::unordered_map< uint32_t, std::list< std::pair< std::shared_ptr< oe::scene::SkinnedMesh >, int32_t > > > _skinned_meshes
 
std::unordered_map< oe::scene::SkinnedMeshNode *, uint32_t > _skinned_nodes_skins
 
std::vector< std::shared_ptr< oe::render::Texture > > _textures
 
std::function< void(const PbrMaterial &, Material &)> _material_filler = {}
 
std::function< void(Node &node, Material &node_material)> _node_material_modifier = {}
 
oe::scene::Material _default_material
 
std::unique_ptr< tinygltf::TinyGLTF > _loader
 
std::unique_ptr< tinygltf::Model > _model
 
std::function< void(const std::string &extension, Node &root_node, const nlohmann::json &extension_data, const bool pre_load)> _custom_asset_extension_handler = {}
 
std::function< void(const std::string &extension, Node &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, is_binary};
// 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);
Definition node.h:31
Loader to load Khronos glTF assets.
Definition gltf.h:67
void setNodeMaterialModifier(std::function< void(Node &node, Material &node_material)>)
Apply application specific properties on the material that will be applied to a node.
oe::scene::Node & addIntoSceneManager(oe::scene::Manager &scene_manager, uint16_t id_scene=0)
Load the glTF asset into a scene (under a new root node)
void setMaterialFiller(std::function< void(const PbrMaterial &gltf_material, Material &oe_material)>)
Apply application specific properties on the materials.
void convertTextures(render::TextureManager &)
Load model textures.

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,
const bool  is_binary 
)

Load a glTF asset from a file.

Parameters
filenamepath to the glTF asset
is_binarydoes the file should be loaded as a binary file ot text file (ie. true for a .glb, false for a .gltf)

Member Function Documentation

◆ addIntoSceneManager() [1/2]

oe::scene::Node & oe::scene::loader::Gltf::addIntoSceneManager ( oe::scene::Manager scene_manager,
oe::scene::Node root_node,
uint16_t  id_scene = 0 
)

Load the glTF asset into a scene (using a specified node as root node)

Parameters
scene_managerThe scene manager
root_nodeAsset's root nodes will be imported as children of this node
id_sceneglTF scene to load
Returns
a reference to the node containing the glTF scene imported in the oe::scene::Manager

◆ addIntoSceneManager() [2/2]

oe::scene::Node & oe::scene::loader::Gltf::addIntoSceneManager ( oe::scene::Manager scene_manager,
uint16_t  id_scene = 0 
)

Load the glTF asset into a scene (under a new root node)

Parameters
scene_managerThe scene manager
id_sceneglTF scene to load
Returns
a reference to the node containing the glTF scene imported in the oe::scene::Manager

◆ getMaterials()

std::vector< Material > oe::scene::loader::Gltf::getMaterials ( )

Convert and return materials.

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

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