Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_modelconverter.hpp
Go to the documentation of this file.
1#pragma once
2#include "../bench/foray_hostbenchmark.hpp"
3#include "../scene/foray_animation.hpp"
4#include "../scene/foray_geo.hpp"
5#include "../scene/foray_scene.hpp"
6#include "../scene/foray_scene_declares.hpp"
7#include "../osi/foray_env.hpp"
8#include <map>
9#include <set>
10#include <tinygltf/tiny_gltf.h>
11
12namespace foray::gltf {
13
16 {
17 using SceneSelectFunctionPointer = std::function<int32_t(tinygltf::Model&)>;
18
32 bool FlipY = false;
33 };
34
37 {
38 public:
39 explicit ModelConverter(scene::Scene* scene);
40
45 void LoadGltfModel(osi::Utf8Path utf8Path, core::Context* context = nullptr, const ModelConverterOptions& options = ModelConverterOptions());
46
47 FORAY_GETTER_V(Scene)
48
49 FORAY_GETTER_CR(Benchmark)
50
51 protected:
53
54 // Tinygltf stuff
55
56 tinygltf::Model mGltfModel = {};
57 tinygltf::Scene* mGltfScene = nullptr;
58
59 // Temporary structures
60
62
64
65 std::vector<scene::Vertex>* mVertexBuffer = nullptr;
66 std::vector<uint32_t>* mIndexBuffer = nullptr;
67
70 {
72 std::vector<scene::Node*> Nodes;
76 std::vector<scene::Mesh*> Meshes;
81
83
84 // Result structures
85
86 scene::Scene* mScene = nullptr;
87
92
93 static void sTranslateSampler(const tinygltf::Sampler& tinygltfSampler, VkSamplerCreateInfo& outsamplerCI, bool& generateMipMaps);
94
95 void RecursivelyTranslateNodes(int32_t currentIndex, scene::Node* parent = nullptr);
96
97 // void LoadMesh
98
100 const std::vector<double>& matrix,
101 const std::vector<double>& translation,
102 const std::vector<double>& rotation,
103 const std::vector<double>& scale);
104
106 void PushGltfMeshToBuffers(const tinygltf::Mesh& mesh, std::vector<scene::Primitive>& outprimitives);
107
112 const tinygltf::Animation& gltfAnimation,
113 int32_t samplerIndex,
114 const std::map<std::string_view, scene::EAnimationInterpolation>& interpolationMap,
115 std::map<int, int>& samplerIndexMap);
116
117 void TranslateLight(scene::ncomp::PunctualLight* component, const tinygltf::Light& light);
118
119 void TranslateCamera(scene::ncomp::Camera* component, const tinygltf::Camera& camera);
120
122
124
125 void Reset();
126 };
127} // namespace foray::gltf
Simple types for supressing automatic definition of duplicating move constructors & operator.
Definition foray_basics.hpp:19
A host (CPU time) benchmark based on std::chrono::high_resolution_clock. Timestamps are recorded in m...
Definition foray_hostbenchmark.hpp:8
Type which reads glTF files and merges a scene of the file into the scene graph.
Definition foray_modelconverter.hpp:37
bench::HostBenchmark mBenchmark
Definition foray_modelconverter.hpp:91
void RecursivelyTranslateNodes(int32_t currentIndex, scene::Node *parent=nullptr)
std::vector< scene::Vertex > * mVertexBuffer
Definition foray_modelconverter.hpp:65
scene::gcomp::MaterialManager & mMaterialBuffer
Definition foray_modelconverter.hpp:88
int32_t mNextMeshInstanceIndex
Definition foray_modelconverter.hpp:82
void PushGltfMeshToBuffers(const tinygltf::Mesh &mesh, std::vector< scene::Primitive > &outprimitives)
static void sTranslateSampler(const tinygltf::Sampler &tinygltfSampler, VkSamplerCreateInfo &outsamplerCI, bool &generateMipMaps)
struct foray::gltf::ModelConverter::IndexBindings mIndexBindings
tinygltf::Scene * mGltfScene
Definition foray_modelconverter.hpp:57
scene::gcomp::GeometryStore & mGeo
Definition foray_modelconverter.hpp:89
void TranslateCamera(scene::ncomp::Camera *component, const tinygltf::Camera &camera)
void TranslateAnimationSampler(scene::Animation &animation, const tinygltf::Animation &gltfAnimation, int32_t samplerIndex, const std::map< std::string_view, scene::EAnimationInterpolation > &interpolationMap, std::map< int, int > &samplerIndexMap)
osi::Utf8Path mUtf8Dir
Definition foray_modelconverter.hpp:63
tinygltf::Model mGltfModel
Definition foray_modelconverter.hpp:56
void InitTransformFromGltf(scene::ncomp::Transform *transform, const std::vector< double > &matrix, const std::vector< double > &translation, const std::vector< double > &rotation, const std::vector< double > &scale)
ModelConverterOptions mOptions
Definition foray_modelconverter.hpp:61
ModelConverter(scene::Scene *scene)
void LoadGltfModel(osi::Utf8Path utf8Path, core::Context *context=nullptr, const ModelConverterOptions &options=ModelConverterOptions())
Loads glTF model and integrates it into the scene set in constructor.
std::vector< uint32_t > * mIndexBuffer
Definition foray_modelconverter.hpp:66
void TranslateLight(scene::ncomp::PunctualLight *component, const tinygltf::Light &light)
scene::gcomp::TextureManager & mTextures
Definition foray_modelconverter.hpp:90
core::Context * mContext
Definition foray_modelconverter.hpp:52
scene::Scene * mScene
Definition foray_modelconverter.hpp:86
Utf8 encoded path wrapper.
Definition foray_env.hpp:28
Represents an animation, defined by atleast one channel affecting one node property each.
Definition foray_animation.hpp:94
A scene node. Extends the registry with hierarchical information.
Definition foray_node.hpp:8
Provides registries and methods as the anchor of a component based scene.
Definition foray_scene.hpp:17
Stores all geometry in a single set of index and vertex buffers.
Definition foray_geometrymanager.hpp:12
Manages a device local storage buffer providing material information for rendering.
Definition foray_materialmanager.hpp:10
Manages textures and samplers.
Definition foray_texturemanager.hpp:10
Defines a camera with projection matrix.
Definition foray_camera.hpp:10
Defines a simple punctual light (directional or point)
Definition foray_punctuallight.hpp:10
Defines a nodes transform relative to its parent (or world origin, if no parent is set)
Definition foray_transform.hpp:9
#define FORAY_GETTER_V(member)
Return value.
Definition foray_basics.hpp:39
#define FORAY_GETTER_CR(member)
Return constant reference.
Definition foray_basics.hpp:60
Definition foray_modelconverter.hpp:12
Non owning context object.
Definition foray_context.hpp:16
Options for converting glTF models to the integrated scene graph (foray::scene::Scene)
Definition foray_modelconverter.hpp:16
SceneSelectFunctionPointer SceneSelect
A model can define multiple scenes. Index 0 is selected automatically, set this function pointer to o...
Definition foray_modelconverter.hpp:20
bool FlipY
Flip the model in the Y direction on loading (experimental)
Definition foray_modelconverter.hpp:32
std::function< int32_t(tinygltf::Model &)> SceneSelectFunctionPointer
Definition foray_modelconverter.hpp:17
Variables which determine how to map gltf-model indices to scene indices/pointers.
Definition foray_modelconverter.hpp:70
size_t IndexBufferStart
Definition foray_modelconverter.hpp:79
std::vector< scene::Node * > Nodes
Offset for translating gltfModel node index -> scene node buffer index.
Definition foray_modelconverter.hpp:72
int32_t TextureBufferOffset
Vector mapping gltfModel texture index to ManagedImage*.
Definition foray_modelconverter.hpp:78
int32_t MaterialBufferOffset
Offset for translating gltfModel material index -> scene material buffer index.
Definition foray_modelconverter.hpp:74
std::vector< scene::Mesh * > Meshes
Vector mapping gltfModel mesh index to Mesh*.
Definition foray_modelconverter.hpp:76