Support embedded textures in glTF

This commit is contained in:
Nikita Lisitsa 2024-08-26 23:42:29 +03:00
parent 954068ba3a
commit 2bd4e5790b
3 changed files with 16 additions and 4 deletions

View file

@ -73,7 +73,8 @@ namespace psemek::gfx
struct texture struct texture
{ {
std::string uri; std::optional<std::string> uri;
std::optional<std::size_t> buffer_view;
}; };
struct skin struct skin

View file

@ -95,9 +95,17 @@ namespace psemek::gfx
for (auto const & texture : asset.textures) for (auto const & texture : asset.textures)
{ {
auto data = uri_loader(texture.uri);
auto & target = textures_.emplace_back(); auto & target = textures_.emplace_back();
target.load_srgb(gfx::read_image<gfx::color_rgba>(io::memory_istream(data.string_view())));
if (texture.uri)
{
auto data = uri_loader(*texture.uri);
target.load_srgb(gfx::read_image<gfx::color_rgba>(io::memory_istream(data.string_view())));
}
else
{
target.load_srgb(gfx::pixmap_rgba({2, 2}, gfx::color_rgba{255, 0, 255, 255}));
}
target.linear_mipmap_filter(); target.linear_mipmap_filter();
target.anisotropy(); target.anisotropy();
target.generate_mipmap(); target.generate_mipmap();

View file

@ -293,7 +293,10 @@ namespace psemek::gfx
if (document.HasMember("images")) for (auto const & image : document["images"].GetArray()) if (document.HasMember("images")) for (auto const & image : document["images"].GetArray())
{ {
auto & target = result.textures.emplace_back(); auto & target = result.textures.emplace_back();
target.uri = image["uri"].GetString(); if (image.HasMember("uri"))
target.uri = image["uri"].GetString();
if (image.HasMember("bufferView"))
target.buffer_view = image["bufferView"].GetUint64();
} }
if (document.HasMember("skins")) for (auto const & skin : document["skins"].GetArray()) if (document.HasMember("skins")) for (auto const & skin : document["skins"].GetArray())