Skip to content

Commit

Permalink
[gltf] minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Jul 30, 2023
1 parent 5cfd682 commit 3100cac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
20 changes: 11 additions & 9 deletions src/tz/io/gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ namespace tz::io
return this->meshes;
}

std::span<const gltf_buffer> gltf::get_buffers() const
{
return this->buffers;
}

std::span<const gltf_image> gltf::get_images() const
{
return this->images;
Expand Down Expand Up @@ -365,10 +370,10 @@ namespace tz::io
}
this->create_scenes();
this->create_nodes();
this->load_resources();
this->create_animations();
this->create_buffers();
this->create_images();
this->create_materials();
this->create_animations();
this->create_views();
this->create_accessors();
this->create_meshes();
Expand Down Expand Up @@ -558,20 +563,17 @@ namespace tz::io
}
}

void gltf::load_resources()
void gltf::create_buffers()
{
TZ_PROFZONE("gltf - load resources", 0xFFFF2222);
// according to spec, top level buffers and images contain lists of 'buffer' and 'image' respectively.
TZ_PROFZONE("gltf - create buffers", 0xFFFF2222);
json buffers = this->data["buffers"];
tz::assert(buffers.is_array() || buffers.is_null());
json images = this->data["images"];
tz::assert(images.is_array() || images.is_null());

if(buffers.is_array())
{
for(auto buf : buffers)
{
this->resources.push_back(this->load_buffer(buf));
this->buffers.push_back(this->load_buffer(buf));
}
}
}
Expand Down Expand Up @@ -898,7 +900,7 @@ namespace tz::io
}
}

gltf_resource gltf::load_buffer(json node)
gltf_buffer gltf::load_buffer(json node)
{
TZ_PROFZONE("gltf - load buffer", 0xFFFF2222);
std::string makeshift_bufname = "buffer" + std::to_string(this->parsed_buf_count);
Expand Down
19 changes: 7 additions & 12 deletions src/tz/io/gltf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ namespace tz::io
}
using json = nlohmann::json;

enum class gltf_resource_type
{
buffer,
image
};

struct gltf_resource
struct gltf_buffer
{
std::string label;
std::span<const std::byte> data;
Expand Down Expand Up @@ -268,6 +262,7 @@ namespace tz::io
static gltf from_file(const char* path);
std::span<const std::byte> view_buffer(gltf_buffer_view view) const;
std::span<const gltf_mesh> get_meshes() const;
std::span<const gltf_buffer> get_buffers() const;
std::span<const gltf_image> get_images() const;
std::span<const gltf_node> get_nodes() const;
std::vector<gltf_node> get_active_nodes() const;
Expand All @@ -279,14 +274,14 @@ namespace tz::io
void parse_chunks(std::string_view chunkdata);
void create_scenes();
void create_nodes();
void load_resources();
void create_animations();
void create_buffers();
void create_images();
void create_materials();
void create_animations();
void create_views();
void create_accessors();
void create_meshes();
gltf_resource load_buffer(json node);
gltf_buffer load_buffer(json node);
gltf_mesh load_mesh(json node);
std::span<const std::byte> get_binary_data(std::size_t offset, std::size_t len) const;

Expand All @@ -296,10 +291,10 @@ namespace tz::io
std::size_t active_scene_id = detail::badzu;
std::vector<gltf_scene> scenes = {};
std::vector<gltf_node> nodes = {};
std::vector<gltf_resource> resources = {};
std::vector<gltf_animation> animations = {};
std::vector<gltf_buffer> buffers = {};
std::vector<gltf_image> images = {};
std::vector<gltf_material> materials = {};
std::vector<gltf_animation> animations = {};
std::vector<gltf_buffer_view> views = {};
std::vector<gltf_accessor> accessors = {};
std::vector<gltf_mesh> meshes = {};
Expand Down

0 comments on commit 3100cac

Please sign in to comment.