Skip to content

Commit ad61d67

Browse files
committed
Improve usage of fastgltf & use fmt::print
1 parent 06df175 commit ad61d67

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

chapter-3/vk_loader.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ std::optional<std::vector<std::shared_ptr<MeshAsset>>> loadGltfMeshes(VulkanEngi
2020
data.loadFromFile(filePath);
2121

2222
constexpr auto gltfOptions = fastgltf::Options::LoadGLBBuffers
23-
| fastgltf::Options::LoadExternalBuffers;
23+
| fastgltf::Options::LoadExternalBuffers
24+
| fastgltf::Options::GenerateMeshIndices;
2425

2526
fastgltf::Asset gltf;
2627
fastgltf::Parser parser {};
@@ -29,7 +30,7 @@ std::optional<std::vector<std::shared_ptr<MeshAsset>>> loadGltfMeshes(VulkanEngi
2930
if (load) {
3031
gltf = std::move(load.get());
3132
} else {
32-
fmt::print("Failed to load glTF: {} \n", fastgltf::to_underlying(load.error()));
33+
fmt::print("Failed to load glTF: {} \n", fastgltf::getErrorMessage(load.error()));
3334
return {};
3435
}
3536
//< openmesh
@@ -40,7 +41,7 @@ std::optional<std::vector<std::shared_ptr<MeshAsset>>> loadGltfMeshes(VulkanEngi
4041
// often
4142
std::vector<uint32_t> indices;
4243
std::vector<Vertex> vertices;
43-
for (fastgltf::Mesh& mesh : gltf.meshes) {
44+
for (const fastgltf::Mesh& mesh : gltf.meshes) {
4445
MeshAsset newmesh;
4546

4647
newmesh.name = mesh.name;

chapter-4/vk_loader.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ std::optional<std::vector<std::shared_ptr<MeshAsset>>> loadGltfMeshes(VulkanEngi
2020
data.loadFromFile(filePath);
2121

2222
constexpr auto gltfOptions = fastgltf::Options::LoadGLBBuffers
23-
| fastgltf::Options::LoadExternalBuffers;
23+
| fastgltf::Options::LoadExternalBuffers
24+
| fastgltf::Options::GenerateMeshIndices;
2425

2526
fastgltf::Asset gltf;
2627
fastgltf::Parser parser {};
@@ -29,7 +30,7 @@ std::optional<std::vector<std::shared_ptr<MeshAsset>>> loadGltfMeshes(VulkanEngi
2930
if (load) {
3031
gltf = std::move(load.get());
3132
} else {
32-
fmt::print("Failed to load glTF: {} \n", fastgltf::to_underlying(load.error()));
33+
fmt::print("Failed to load glTF: {} \n", fastgltf::getErrorMessage(load.error()));
3334
return {};
3435
}
3536
//< openmesh
@@ -40,7 +41,7 @@ std::optional<std::vector<std::shared_ptr<MeshAsset>>> loadGltfMeshes(VulkanEngi
4041
// often
4142
std::vector<uint32_t> indices;
4243
std::vector<Vertex> vertices;
43-
for (fastgltf::Mesh& mesh : gltf.meshes) {
44+
for (const fastgltf::Mesh& mesh : gltf.meshes) {
4445
MeshAsset newmesh;
4546

4647
newmesh.name = mesh.name;

chapter-5/vk_loader.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ std::optional<std::shared_ptr<LoadedGLTF>> loadGltf(VulkanEngine* engine, std::s
137137

138138
fastgltf::Parser parser {};
139139

140-
constexpr auto gltfOptions = fastgltf::Options::DontRequireValidAssetMember | fastgltf::Options::AllowDouble | fastgltf::Options::LoadGLBBuffers | fastgltf::Options::LoadExternalBuffers;
140+
constexpr auto gltfOptions = fastgltf::Options::DontRequireValidAssetMember
141+
| fastgltf::Options::AllowDouble
142+
| fastgltf::Options::LoadGLBBuffers
143+
| fastgltf::Options::LoadExternalBuffers
144+
| fastgltf::Options::GenerateMeshIndices;
141145
// fastgltf::Options::LoadExternalImages;
142146

143147
fastgltf::GltfDataBuffer data;
@@ -153,15 +157,15 @@ std::optional<std::shared_ptr<LoadedGLTF>> loadGltf(VulkanEngine* engine, std::s
153157
if (load) {
154158
gltf = std::move(load.get());
155159
} else {
156-
std::cerr << "Failed to load glTF: " << fastgltf::to_underlying(load.error()) << std::endl;
160+
fmt::print("Failed to load glTF: {}", fastgltf::getErrorMessage(load.error()));
157161
return {};
158162
}
159163
} else if (type == fastgltf::GltfType::GLB) {
160164
auto load = parser.loadBinaryGLTF(&data, path.parent_path(), gltfOptions);
161165
if (load) {
162166
gltf = std::move(load.get());
163167
} else {
164-
std::cerr << "Failed to load glTF: " << fastgltf::to_underlying(load.error()) << std::endl;
168+
fmt::print("Failed to load glTF: {}", fastgltf::getErrorMessage(load.error()));
165169
return {};
166170
}
167171
} else {
@@ -180,7 +184,7 @@ std::optional<std::shared_ptr<LoadedGLTF>> loadGltf(VulkanEngine* engine, std::s
180184
//> load_samplers
181185

182186
// load samplers
183-
for (fastgltf::Sampler& sampler : gltf.samplers) {
187+
for (const fastgltf::Sampler& sampler : gltf.samplers) {
184188

185189
VkSamplerCreateInfo sampl = { .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .pNext = nullptr};
186190
sampl.maxLod = VK_LOD_CLAMP_NONE;
@@ -364,7 +368,7 @@ std::optional<std::shared_ptr<LoadedGLTF>> loadGltf(VulkanEngine* engine, std::s
364368

365369
glm::vec3 minpos = vertices[initial_vtx].position;
366370
glm::vec3 maxpos = vertices[initial_vtx].position;
367-
for (int i = initial_vtx; i < vertices.size(); i++) {
371+
for (size_t i = initial_vtx; i < vertices.size(); i++) {
368372
minpos = glm::min(minpos, vertices[i].position);
369373
maxpos = glm::max(maxpos, vertices[i].position);
370374
}

meshbaker/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void output_meshes(std::filesystem::path target_file, std::filesystem::path sour
6767
gltf = std::move(load.get());
6868
}
6969
else {
70-
std::cerr << "Failed to load glTF: " << fastgltf::to_underlying(load.error()) << std::endl;
70+
std::cerr << "Failed to load glTF: " << fastgltf::getErrorMessage(load.error()) << std::endl;
7171
}
7272
}
7373
else if (type == fastgltf::GltfType::GLB) {
@@ -76,7 +76,7 @@ void output_meshes(std::filesystem::path target_file, std::filesystem::path sour
7676
gltf = std::move(load.get());
7777
}
7878
else {
79-
std::cerr << "Failed to load glTF: " << fastgltf::to_underlying(load.error()) << std::endl;
79+
std::cerr << "Failed to load glTF: " << fastgltf::getErrorMessage(load.error()) << std::endl;
8080
}
8181
}
8282
else {

0 commit comments

Comments
 (0)