Magnum::Trade::TinyGltfImporter class

TinyGltf importer plugin.

Imports glTF and binary glTF using the TinyGLTF library.

This plugin depends on the Trade library and is built if WITH_TINYGLTFIMPORTER is enabled when building Magnum Plugins. To use as a dynamic plugin, you need to load the "TinyGltfImporter" plugin from MAGNUM_PLUGINS_IMPORTER_DIR. To use as a static plugin or as a dependency of another plugin with CMake, you need to request the TinyGltfImporter component of the MagnumPlugins package and link to the MagnumPlugins::TinyGltfImporter target. See Downloading and building plugins, Plugin usage with CMake and Loading and using plugins for more information.

This plugin provides GltfImporter and GlbImporter plugins.

Behavior and limitations

The plugin supports Feature::OpenData and Feature::FileCallback features. The tiny_gltf library loads everything during initial import, meaning all external file loading callbacks are called with ImporterFileCallbackPolicy::LoadTemporary and the resources can be safely freed right after the openData() / openFile() function exits.

Import of skeleton, skin and morph data is not supported at the moment.

Animation import

  • At the moment, only constant and linear animation interpolation can be imported
  • Skinning and morph targets are not supported
  • Animation tracks are always imported with Animation::Extrapolation::Constant, because glTF doesn't support anything else

Object import

Light import

  • Light properties besides light type are not imported.
  • Light intensity is not yet supported due to glTF extension draft state.

Mesh import

  • Only the first mesh of a multi-primitive mesh is imported.
  • Meshes with interleaved vertex data/buffer views are not supported.

Material import

  • Subset of all material specs is currently imported as Trade::PhongMaterialData
  • Ambient color is always 0x000000_rgbf (never a texture)
  • For the Metallic/Roughness material spec (in core, default):
    • The baseColorTexture field is used for diffuse texture, if present. Otherwise, baseColorFactor is used for diffuse color, if present. Otherwise, 0xffffff_rgbf is used.
    • Specular color is always 0xffffff_rgbf (never a texture)
    • Shininess is always 1.0f
  • For the Specular/Glossiness material spec (KHR_materials_pbrSpecularGlossiness extension):
    • The diffuseTexture field is used for diffuse texture, if present. Otherwise, diffuseFactor is used for diffuse color, if present. Otherwise, 0xffffff_rgbf is used.
    • The specularGlossinessTexture field is used for a specular texture, if present (note that only the RGB channels should be used and the alpha channel — containing glossiness — should be ignored). Otherwise, specularFactor is used for specular color, if present. Otherwise, 0xffffff_rgbf is used.
    • Shininess is always 1.0f
  • For the Blinn/Phong material spec (draft KHR_materials_cmnBlinnPhong extension):
    • The diffuseTexture field is used for diffuse texture, if present. Otherwise, diffuseFactor is used for diffuse color, if present. Otherwise, 0xffffff_rgbf is used.
    • The specularShininessTexture field is used for specular texture, if present (note that only the RGB channels should be used and the alpha channel — containing snininess — should be ignored). Otherwise, specularFactor is used for diffuse color, if present. Otherwise, 0xffffff_rgbf is used.
    • The snininessFactor field is used for snininess, if present. Otherwise 1.0f is used.

Texture import

Access to internal importer state

Access to the underlying TinyGLTF structures it is provided through importer-specific data accessors:

The TinyGLTF header is installed alsongside the plugin and accessible like this:

#include <MagnumExternal/TinyGLTF/tiny_gltf.h>

Base classes

class AbstractImporter
Base for importer plugins.

Constructors, destructors, conversion operators

TinyGltfImporter() explicit
Default constructor.
TinyGltfImporter(PluginManager::Manager<AbstractImporter>& manager) explicit
Constructor.
TinyGltfImporter(PluginManager::AbstractManager& manager, const std::string& plugin) explicit
Plugin manager constructor.

Public functions

auto importerState() const -> const tinygltf::Model*
Importer state.

Private functions

auto doFeatures() const override -> Features virtual
Implementation for features()
auto doIsOpened() const override -> bool virtual
Implementation for isOpened()
void doOpenData(Containers::ArrayView<const char> data) override virtual
Implementation for openData()
void doOpenFile(const std::string& filename) override virtual
Implementation for openFile()
void doClose() override virtual
Implementation for close()
auto doAnimationCount() const override -> UnsignedInt virtual
Implementation for animationCount()
auto doAnimationName(UnsignedInt id) override -> std::string virtual
Implementation for animationName()
auto doAnimationForName(const std::string& name) override -> Int virtual
Implementation for animationForName()
auto doAnimation(UnsignedInt id) override -> Containers::Optional<AnimationData> virtual
Implementation for animation()
auto doCamera(UnsignedInt id) override -> Containers::Optional<CameraData> virtual
Implementation for camera()
auto doCameraForName(const std::string& name) override -> Int virtual
Implementation for cameraForName()
auto doCameraName(const UnsignedInt id) override -> std::string virtual
Implementation for cameraName()
auto doCameraCount() const override -> UnsignedInt virtual
Implementation for cameraCount()
auto doLight(UnsignedInt id) override -> Containers::Optional<LightData> virtual
Implementation for light()
auto doLightForName(const std::string& name) override -> Int virtual
Implementation for lightForName()
auto doLightName(const UnsignedInt id) override -> std::string virtual
Implementation for lightName()
auto doLightCount() const override -> UnsignedInt virtual
Implementation for lightCount()
auto doDefaultScene() override -> Int virtual
Implementation for defaultScene()
auto doScene(UnsignedInt id) override -> Containers::Optional<SceneData> virtual
Implementation for scene()
auto doSceneForName(const std::string& name) override -> Int virtual
Implementation for sceneForName()
auto doSceneName(const UnsignedInt id) override -> std::string virtual
Implementation for sceneName()
auto doSceneCount() const override -> UnsignedInt virtual
Implementation for sceneCount()
auto doObject3DCount() const override -> UnsignedInt virtual
Implementation for object3DCount()
auto doObject3DForName(const std::string& name) override -> Int virtual
Implementation for object3DForName()
auto doObject3DName(UnsignedInt id) override -> std::string virtual
Implementation for object3DName()
auto doObject3D(UnsignedInt id) override -> std::unique_ptr<ObjectData3D> virtual
Implementation for object3D()
auto doMesh3DCount() const override -> UnsignedInt virtual
Implementation for mesh3DCount()
auto doMesh3DForName(const std::string& name) override -> Int virtual
Implementation for mesh3DForName()
auto doMesh3DName(const UnsignedInt id) override -> std::string virtual
Implementation for mesh3DName()
auto doMesh3D(const UnsignedInt id) override -> Containers::Optional<MeshData3D> virtual
Implementation for mesh3D()
auto doMaterialCount() const override -> UnsignedInt virtual
Implementation for materialCount()
auto doMaterialForName(const std::string& name) override -> Int virtual
Implementation for materialForName()
auto doMaterialName(const UnsignedInt id) override -> std::string virtual
Implementation for materialName()
auto doMaterial(const UnsignedInt id) override -> std::unique_ptr<AbstractMaterialData> virtual
Implementation for material()
auto doTextureCount() const override -> UnsignedInt virtual
Implementation for textureCount()
auto doTextureForName(const std::string& name) override -> Int virtual
Implementation for textureForName()
auto doTextureName(const UnsignedInt id) override -> std::string virtual
Implementation for textureName()
auto doTexture(const UnsignedInt id) override -> Containers::Optional<TextureData> virtual
Implementation for texture()
auto doImage2DCount() const override -> UnsignedInt virtual
Implementation for image2DCount()
auto doImage2DForName(const std::string& name) override -> Int virtual
Implementation for image2DForName()
auto doImage2DName(const UnsignedInt id) override -> std::string virtual
Implementation for image2DName()
auto doImage2D(const UnsignedInt id) override -> Containers::Optional<ImageData2D> virtual
Implementation for image2D()
auto doImporterState() const override -> const void* virtual
Implementation for importerState()

Function documentation

Magnum::Trade::TinyGltfImporter::TinyGltfImporter() explicit

Default constructor.

In case you want to open images, use TinyGltfImporter(PluginManager::Manager<AbstractImporter>&) instead.

Magnum::Trade::TinyGltfImporter::TinyGltfImporter(PluginManager::Manager<AbstractImporter>& manager) explicit

Constructor.

The plugin needs access to plugin manager for importing images.

const tinygltf::Model* Magnum::Trade::TinyGltfImporter::importerState() const

Importer state.

See class documentation for more information.

void Magnum::Trade::TinyGltfImporter::doOpenFile(const std::string& filename) override virtual private

Implementation for openFile()

If Feature::OpenData is supported, default implementation opens the file and calls doOpenData() with its contents. It is allowed to call this function from your doOpenFile() implementation.

UnsignedInt Magnum::Trade::TinyGltfImporter::doAnimationCount() const override virtual private

Implementation for animationCount()

Default implementation returns 0.

std::string Magnum::Trade::TinyGltfImporter::doAnimationName(UnsignedInt id) override virtual private

Implementation for animationName()

Default implementation returns empty string.

Int Magnum::Trade::TinyGltfImporter::doAnimationForName(const std::string& name) override virtual private

Implementation for animationForName()

Default implementation returns -1.

Int Magnum::Trade::TinyGltfImporter::doCameraForName(const std::string& name) override virtual private

Implementation for cameraForName()

Default implementation returns -1.

std::string Magnum::Trade::TinyGltfImporter::doCameraName(const UnsignedInt id) override virtual private

Implementation for cameraName()

Default implementation returns empty string.

UnsignedInt Magnum::Trade::TinyGltfImporter::doCameraCount() const override virtual private

Implementation for cameraCount()

Default implementation returns 0.

Int Magnum::Trade::TinyGltfImporter::doLightForName(const std::string& name) override virtual private

Implementation for lightForName()

Default implementation returns -1.

std::string Magnum::Trade::TinyGltfImporter::doLightName(const UnsignedInt id) override virtual private

Implementation for lightName()

Default implementation returns empty string.

UnsignedInt Magnum::Trade::TinyGltfImporter::doLightCount() const override virtual private

Implementation for lightCount()

Default implementation returns 0.

Int Magnum::Trade::TinyGltfImporter::doDefaultScene() override virtual private

Implementation for defaultScene()

Default implementation returns -1.

Int Magnum::Trade::TinyGltfImporter::doSceneForName(const std::string& name) override virtual private

Implementation for sceneForName()

Default implementation returns -1.

std::string Magnum::Trade::TinyGltfImporter::doSceneName(const UnsignedInt id) override virtual private

Implementation for sceneName()

Default implementation returns empty string.

UnsignedInt Magnum::Trade::TinyGltfImporter::doSceneCount() const override virtual private

Implementation for sceneCount()

Default implementation returns 0.

UnsignedInt Magnum::Trade::TinyGltfImporter::doObject3DCount() const override virtual private

Implementation for object3DCount()

Default implementation returns 0.

Int Magnum::Trade::TinyGltfImporter::doObject3DForName(const std::string& name) override virtual private

Implementation for object3DForName()

Default implementation returns -1.

std::string Magnum::Trade::TinyGltfImporter::doObject3DName(UnsignedInt id) override virtual private

Implementation for object3DName()

Default implementation returns empty string.

UnsignedInt Magnum::Trade::TinyGltfImporter::doMesh3DCount() const override virtual private

Implementation for mesh3DCount()

Default implementation returns 0.

Int Magnum::Trade::TinyGltfImporter::doMesh3DForName(const std::string& name) override virtual private

Implementation for mesh3DForName()

Default implementation returns -1.

std::string Magnum::Trade::TinyGltfImporter::doMesh3DName(const UnsignedInt id) override virtual private

Implementation for mesh3DName()

Default implementation returns empty string.

UnsignedInt Magnum::Trade::TinyGltfImporter::doMaterialCount() const override virtual private

Implementation for materialCount()

Default implementation returns 0.

Int Magnum::Trade::TinyGltfImporter::doMaterialForName(const std::string& name) override virtual private

Implementation for materialForName()

Default implementation returns -1.

std::string Magnum::Trade::TinyGltfImporter::doMaterialName(const UnsignedInt id) override virtual private

Implementation for materialName()

Default implementation returns empty string.

UnsignedInt Magnum::Trade::TinyGltfImporter::doTextureCount() const override virtual private

Implementation for textureCount()

Default implementation returns 0.

Int Magnum::Trade::TinyGltfImporter::doTextureForName(const std::string& name) override virtual private

Implementation for textureForName()

Default implementation returns -1.

std::string Magnum::Trade::TinyGltfImporter::doTextureName(const UnsignedInt id) override virtual private

Implementation for textureName()

Default implementation returns empty string.

UnsignedInt Magnum::Trade::TinyGltfImporter::doImage2DCount() const override virtual private

Implementation for image2DCount()

Default implementation returns 0.

Int Magnum::Trade::TinyGltfImporter::doImage2DForName(const std::string& name) override virtual private

Implementation for image2DForName()

Default implementation returns -1.

std::string Magnum::Trade::TinyGltfImporter::doImage2DName(const UnsignedInt id) override virtual private

Implementation for image2DName()

Default implementation returns empty string.