Hymn to Beauty
C++ 3D Engine
GLTFImporter.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5#include <json/json.h>
7#include <glm/glm.hpp>
8
9class Entity;
10
12
16 public:
18
22 void Import(const std::string& path, const std::string& filename);
23
24 private:
25 struct Buffer {
26 uint32_t length;
27 char* data;
28 };
29
30 struct BufferView {
31 uint32_t buffer;
32 uint32_t offset;
33 uint32_t length;
35 };
36
37 struct Accessor {
38 uint32_t bufferView;
39 uint32_t byteOffset;
40 uint32_t count;
41 enum ComponentType { BYTE = 5120, UNSIGNED_BYTE, SHORT, UNSIGNED_SHORT, UNSIGNED_INT = 5125, FLOAT } componentType;
42 enum class Type { SCALAR, VEC2, VEC3, VEC4 } type;
43 glm::vec3 min;
44 glm::vec3 max;
45 };
46
47 struct Primitive {
48 uint32_t vertexCount;
49 uint32_t indexCount;
51 uint32_t* indices;
52 glm::vec3 min;
53 glm::vec3 max;
54 uint32_t material;
55 };
56
57 struct Texture {
58 uint32_t image;
59 };
60
61 struct Material {
62 uint32_t albedoTexture;
63 uint32_t roughnessMetallicTexture;
64 uint32_t normalTexture;
65 };
66
67 struct GLTF {
68 Json::Value root;
69 std::vector<Buffer> buffers;
70 std::vector<BufferView> bufferViews;
71 std::vector<Accessor> accessors;
72 std::vector<std::string> meshes;
73 std::vector<std::string> images;
74 std::vector<Texture> textures;
75 std::vector<Material> materials;
76 };
77
78 void ReadBuffers(const std::string& path, GLTF& gltf);
79 void ReadBufferViews(GLTF& gltf);
80 void ReadAccessors(GLTF& gltf);
81 void ReadImages(const std::string& path, GLTF& gltf);
82 void ReadTextures(GLTF& gltf);
83 void ReadMaterials(GLTF& gltf);
84 void LoadMeshes(const std::string& path, const std::string& filename, GLTF& gltf);
85 Primitive LoadPrimitive(const GLTF& gltf, const Json::Value& primitive);
86 void SavePrimitive(const Primitive& primitive, const std::string& filename);
87 void LoadScenes(const std::string& path, const std::string& filename, GLTF& gltf);
88 void LoadNode(GLTF& gltf, Entity* parent, uint32_t index);
89};
Entity containing various components.
Definition: Entity.hpp:16
Converts GLTF models to internal format.
Definition: GLTFImporter.hpp:15
void Import(const std::string &path, const std::string &filename)
Import a GLTF model.
Definition: GLTFImporter.cpp:16
Vertex type used for static meshes.
Definition: StaticVertex.hpp:13