-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGltfModelFactory.h
More file actions
105 lines (76 loc) · 2.65 KB
/
GltfModelFactory.h
File metadata and controls
105 lines (76 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#pragma once
#include<iostream>
#include"GltfModel.h"
#include"MaterialBuilder.h"
#include"GpuBufferFactory.h"
#include"DescriptorSetFactory.h"
#include"DescriptorSetLayoutFactory.h"
class GltfModelFactory
{
private:
std::shared_ptr<GpuBufferFactory> bufferFactory;
std::shared_ptr<DescriptorSetLayoutFactory> layoutFactory;
std::shared_ptr<DescriptorSetFactory> descriptorSetFactory;
//マテリアルを読み込みする
std::shared_ptr<MaterialBuilder> materialBuilder;
//テクスチャを作成
std::shared_ptr<TextureFactory> textureFactory;
//ロードしたgltfモデルを保存するマップ
std::unordered_map<size_t, std::shared_ptr<GltfModel>> modelStorage;
//コライダー用のAABBの座標を求める
glm::vec3 minPos;
glm::vec3 maxPos;
//モデル全体の頂点数とインデックス数
int vertexNum;
int indexNum;
//ファイルパスからハッシュ値を計算する
size_t hashFilePath(const std::string& filePath)
{
std::hash<std::string> hasher;
return hasher(filePath);
}
//gltfモデルのノードを再帰的に読み込む
void loadNode(std::shared_ptr<GltfModel> model, const int nodeIndex, const tinygltf::Model& gltfModel);
void loadNode(size_t& offset, int parentIndex, std::shared_ptr<GltfModel> model
, const int nodeIndex, const tinygltf::Model& gltfModel);
//gltfモデルのメッシュを読み込む
void loadMesh(const tinygltf::Node& gltfNode, const tinygltf::Model& gltfModel
, Mesh& mesh, std::shared_ptr<GltfModel> model, int meshIndex);
//プリミティブの読み取り
void loadPrimitive(Mesh& mesh, int& indexStart
, tinygltf::Primitive glPrimitive, tinygltf::Model glModel, std::shared_ptr<GltfModel> model);
//アニメーションを読み込む
void loadAnimations(std::shared_ptr<GltfModel> model, const tinygltf::Model& gltfModel);
//スキンを読み込む
void loadSkin(std::shared_ptr<GltfModel> model, tinygltf::Model gltfModel);
//スキンを設定する
void setSkin(std::shared_ptr<GltfModel> model);
//マテリアルを読み込む
void loadMaterial(std::shared_ptr<GltfModel> model, tinygltf::Model& gltfModel);
public:
GltfModelFactory(std::shared_ptr<MaterialBuilder> builder
, std::shared_ptr<TextureFactory> texture, std::shared_ptr<GpuBufferFactory> bf
, std::shared_ptr<DescriptorSetLayoutFactory> layout, std::shared_ptr<DescriptorSetFactory> desc)
{
materialBuilder = builder;
textureFactory = texture;
bufferFactory = bf;
layoutFactory = layout;
descriptorSetFactory = desc;
}
~GltfModelFactory()
{
#ifdef _DEBUG
std::cout << "GltfModelFactory :: デストラクタ" << std::endl;
#endif
}
size_t Load(const std::string& filePath);
std::shared_ptr<GltfModel> GetModel(size_t hash)
{
if (modelStorage.find(hash) != modelStorage.end())
{
return modelStorage[hash];
}
return nullptr;
}
};