Avara3D 0.2.0
C++ API reference
GlTFImporter.h
1//
2// GlTFImporter.h
3// avara3d
4//
5// Created by Morgan Davis on 1/30/24.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_SCENE_IMPORTER_GLTFIMPORTER_H
10#define AVARA3D_SCENE_IMPORTER_GLTFIMPORTER_H
11
12#include <cstddef>
13#include <filesystem>
14#include <map>
15#include <memory>
16
17#include <fastgltf/types.hpp>
18
19#include "a3d/scene/Scene.h"
20
21namespace a3d {
22
23 class Camera;
24 class Color;
25 class Image;
26 class Light;
27 class Material;
28 class Mesh;
29 class MeshElement;
30 class Node;
31 class Sampler;
32 class Texture;
33
34 class GlTFImporter {
35
36 public:
37 // [Internal Lifecycle Functions]
38
39 explicit GlTFImporter(const std::filesystem::path& path,
41
42 // [Internal Member Functions]
43
44 std::unique_ptr<Scene> scene();
45 std::shared_ptr<Mesh> firstMesh();
46
47 const std::filesystem::path& path() const;
48 Scene::ImportOptions options() const;
49
50 private:
51 // [Private Member Functions]
52
53 bool parse();
54 void visitGlTFNode(fastgltf::Asset& asset, fastgltf::Node& node, Node* parent);
55 std::shared_ptr<Mesh> meshFromGlTFNode(fastgltf::Asset& asset, fastgltf::Node& node);
56 std::shared_ptr<Mesh> meshFromGlTFMeshIndex(fastgltf::Asset& asset, std::size_t meshIndex);
57 std::unique_ptr<MeshElement> meshElementFromGlTFPrimitive(fastgltf::Asset& asset,
58 fastgltf::Primitive& primitive);
59 std::shared_ptr<Material> materialFromGlTFPrimitive(fastgltf::Asset& asset,
60 fastgltf::Primitive& primitive);
61 std::shared_ptr<Texture> textureFromGlTFTextureIndex(fastgltf::Asset& asset, std::size_t textureIndex);
62
63 std::shared_ptr<Sampler> samplerFromGlTFTexture(fastgltf::Asset& asset, fastgltf::Texture& texture);
64 std::shared_ptr<Image> imageFromGlTFTexture(fastgltf::Asset& asset, fastgltf::Texture& texture);
65 std::shared_ptr<Light> lightFromGlTFNode(fastgltf::Asset& asset, fastgltf::Node& node);
66 std::shared_ptr<Camera> cameraFromGlTFNode(fastgltf::Asset& asset, fastgltf::Node& node);
67
68 // [Private Member Variables]
69
70 bool _parsed;
71 fastgltf::Asset _asset;
72 std::unique_ptr<Scene> _scene;
73 std::filesystem::path _path;
74 Scene::ImportOptions _options;
75 std::map<std::size_t, std::shared_ptr<Camera>> _cameras;
76 std::map<std::size_t, std::shared_ptr<Mesh>> _meshes;
77 std::map<std::size_t, std::shared_ptr<Image>> _images;
78 std::map<std::size_t, std::shared_ptr<Light>> _lights;
79 std::map<std::size_t, std::shared_ptr<Material>> _materials;
80 std::map<std::size_t, std::shared_ptr<Texture>> _textures;
81 std::map<std::size_t, std::shared_ptr<Sampler>> _samplers;
82 };
83
84}
85
86#endif // AVARA3D_SCENE_IMPORTER_GLTFIMPORTER_H
ImportOptions
Selects which resource categories are imported by FromFile().
Definition: Scene.h:50
@ ImportAll
Import all supported resource categories.