diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2021-08-15 23:17:06 +0200 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2021-08-15 23:17:06 +0200 |
| commit | e1cbdd1d61ffb04ae156fe67923ec5e0871021f1 (patch) | |
| tree | 438b6aa8bcbd5d2a00a10b2805bf0d45ea82f5c9 /src/scene.cpp | |
| parent | 8c1e26e552556e36a5c1fecd9558d9ab9dd3d454 (diff) | |
Improve gltf loading
Diffstat (limited to 'src/scene.cpp')
| -rw-r--r-- | src/scene.cpp | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/scene.cpp b/src/scene.cpp index 73c73e5..15cea11 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -1,6 +1,7 @@ #include "scene.hpp"
#include <filesystem>
+#include <queue>
#include "utils.hpp"
#include "gltf.hpp"
@@ -69,23 +70,42 @@ scene::scene(camera cam, uint32_t width, uint32_t height)
:meta(cam, width, height){
+ // auto bistro_interior_path = std::filesystem::path("../models/BistroInterior");
+ // auto bistro_interior_filename = std::string("BistroInterior.gltf");
+ // auto root_node = gltf::load(bistro_interior_path, bistro_interior_filename);
+
auto sponza_path = std::filesystem::path("../models/sponza");
auto sponza_filename = std::string("Sponza.gltf");
- auto mesh = gltf::load(sponza_path, sponza_filename);
+ auto root_node = gltf::load(sponza_path, sponza_filename);
+
+ std::queue<node> nodes_to_load {};
+ nodes_to_load.push(root_node);
+
+ while(nodes_to_load.size() != 0) {
+ auto &node = nodes_to_load.front();
- auto node = mesh.nodes[0];
- for (auto& mesh_part: node) {
- for (size_t i = 0; i < mesh_part.indices.size(); i += 3) {
- auto i1 = mesh_part.indices[i];
- auto i2 = mesh_part.indices[i + 1];
- auto i3 = mesh_part.indices[i + 2];
+ if (node.mesh) {
+ auto &mesh = node.mesh.value();
+ for (auto& mesh_part: mesh.parts) {
+ for (size_t i = 0; i < mesh_part.indices.size(); i += 3) {
+ auto i1 = mesh_part.indices[i];
+ auto i2 = mesh_part.indices[i + 1];
+ auto i3 = mesh_part.indices[i + 2];
- auto v1 = vertex { .position = mesh_part.positions[i1] };
- auto v2 = vertex { .position = mesh_part.positions[i2] };
- auto v3 = vertex { .position = mesh_part.positions[i3] };
+ auto v1 = vertex { .position = mesh_part.positions[i1] };
+ auto v2 = vertex { .position = mesh_part.positions[i2] };
+ auto v3 = vertex { .position = mesh_part.positions[i3] };
- triangles.emplace_back(v1, v2, v3);
+ triangles.emplace_back(v1, v2, v3);
+ }
+ }
}
+
+ for (auto &node: node.children) {
+ nodes_to_load.push(node);
+ }
+
+ nodes_to_load.pop();
}
// random_scene();
|
