Skip to content

Commit

Permalink
[gltf] fixed an issue where animations would never be loaded properly
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Jul 30, 2023
1 parent a7e201c commit 8dbd6a9
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/tz/io/gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,22 +585,20 @@ namespace tz::io
void gltf::create_animations()
{
TZ_PROFZONE("gltf - create animations", 0xFFFF2222);
json anims = this->data["animations"];
tz::assert(anims.is_array() || anims.is_null());
if(anims.is_array())
json janims = this->data["animations"];
tz::assert(janims.is_array() || janims.is_null());
if(janims.is_array())
{
for(auto anim : anims)
for(auto janim : janims)
{
std::string name = "Unnamed";
if(anim["name"].is_string())
auto& anim = this->animations.emplace_back();
if(janim["name"].is_string())
{
name = anim["name"];
anim.name = janim["name"];
}

std::vector<gltf_animation_sampler> samplers;

tz::assert(anim["samplers"].is_array());
for(auto samp : anim["samplers"])
tz::assert(janim["samplers"].is_array());
for(auto samp : janim["samplers"])
{
tz::assert(samp["interpolation"].is_string());
std::string erp = samp["interpolation"];
Expand All @@ -619,20 +617,18 @@ namespace tz::io
}
else
{
tz::error("Unexpected animation sampler key interpolation \"%s\". Should be either \"LINEAR\", \"STEP\", or \"CUBICSPLINE\".", erp.c_str());
tz::error("Unexpected janimation sampler key interpolation \"%s\". Should be either \"LINEAR\", \"STEP\", or \"CUBICSPLINE\".", erp.c_str());
}
samplers.push_back
anim.samplers.push_back
({
.input = samp["input"],
.output = samp["output"],
.interpolation = interp
});
}

std::vector<gltf_animation_channel> channels;

tz::assert(anim["channels"].is_array());
for(auto chan : anim["channels"])
tz::assert(janim["channels"].is_array());
for(auto chan : janim["channels"])
{
auto tar = chan["target"];
tz::assert(tar.is_object());
Expand All @@ -659,7 +655,7 @@ namespace tz::io
{
tz::error("Unexpected animation channel target path \"%s\". Should be either \"translation\", \"rotation\", \"scale\", or \"weights\".", path_str.c_str());
}
channels.push_back
anim.channels.push_back
({
.sampler_id = chan["sampler"],
.target =
Expand Down

0 comments on commit 8dbd6a9

Please sign in to comment.