Parse textures in gltf_parser
This commit is contained in:
parent
f3700dc4b8
commit
514f4006ef
2 changed files with 28 additions and 4 deletions
|
|
@ -34,7 +34,13 @@ namespace psemek::gfx
|
||||||
|
|
||||||
struct material
|
struct material
|
||||||
{
|
{
|
||||||
color_4f albedo;
|
std::optional<color_4f> albedo;
|
||||||
|
std::optional<std::size_t> texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct texture
|
||||||
|
{
|
||||||
|
std::string uri;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct accessor
|
struct accessor
|
||||||
|
|
@ -62,6 +68,7 @@ namespace psemek::gfx
|
||||||
std::vector<node> nodes;
|
std::vector<node> nodes;
|
||||||
std::vector<mesh> meshes;
|
std::vector<mesh> meshes;
|
||||||
std::vector<material> materials;
|
std::vector<material> materials;
|
||||||
|
std::vector<texture> textures;
|
||||||
std::vector<accessor> accessors;
|
std::vector<accessor> accessors;
|
||||||
std::vector<buffer_view> buffer_views;
|
std::vector<buffer_view> buffer_views;
|
||||||
std::vector<buffer> buffers;
|
std::vector<buffer> buffers;
|
||||||
|
|
|
||||||
|
|
@ -102,9 +102,26 @@ namespace psemek::gfx
|
||||||
{
|
{
|
||||||
auto & target = result.materials.emplace_back();
|
auto & target = result.materials.emplace_back();
|
||||||
|
|
||||||
auto const & color = material["pbrMetallicRoughness"]["baseColorFactor"].GetArray();
|
auto const & pbr = material["pbrMetallicRoughness"];
|
||||||
|
|
||||||
|
if (pbr.HasMember("baseColorFactor"))
|
||||||
|
{
|
||||||
|
auto const & color = pbr["baseColorFactor"].GetArray();
|
||||||
|
gfx::color_4f & target_color = target.albedo.emplace();
|
||||||
for (std::size_t i = 0; i < 4; ++i)
|
for (std::size_t i = 0; i < 4; ++i)
|
||||||
target.albedo[i] = color[i].GetFloat();
|
target_color[i] = color[i].GetFloat();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pbr.HasMember("baseColorTexture"))
|
||||||
|
{
|
||||||
|
target.texture = document["textures"].GetArray()[pbr["baseColorTexture"]["index"].GetUint64()]["source"].GetInt64();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto const & image : document["images"].GetArray())
|
||||||
|
{
|
||||||
|
auto & target = result.textures.emplace_back();
|
||||||
|
target.uri = image["uri"].GetString();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto const & accessor : document["accessors"].GetArray())
|
for (auto const & accessor : document["accessors"].GetArray())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue