Code cleanup and simplification
This commit is contained in:
parent
b13ed52213
commit
1158cb2232
1 changed files with 33 additions and 41 deletions
|
|
@ -534,27 +534,24 @@ void VulkanglTFModel::updateAnimation(float deltaTime)
|
|||
animation.currentTime -= animation.end;
|
||||
}
|
||||
|
||||
bool updated = false;
|
||||
for (auto &channel : animation.channels)
|
||||
{
|
||||
AnimationSampler &sampler = animation.samplers[channel.samplerIndex];
|
||||
if (sampler.inputs.size() > sampler.outputsVec4.size())
|
||||
for (size_t i = 0; i < sampler.inputs.size() - 1; i++)
|
||||
{
|
||||
if (sampler.interpolation != "LINEAR")
|
||||
{
|
||||
std::cout << "This sample only supports linear interpolations\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sampler.inputs.size() - 1; i++)
|
||||
{
|
||||
// Get the input keyframe values for the current time stamp
|
||||
if ((animation.currentTime >= sampler.inputs[i]) && (animation.currentTime <= sampler.inputs[i + 1]))
|
||||
{
|
||||
float u = std::max(0.0f, animation.currentTime - sampler.inputs[i]) / (sampler.inputs[i + 1] - sampler.inputs[i]);
|
||||
if (u <= 1.0f)
|
||||
{
|
||||
float a = (animation.currentTime - sampler.inputs[i]) / (sampler.inputs[i + 1] - sampler.inputs[i]);
|
||||
if (channel.path == "translation")
|
||||
{
|
||||
glm::vec4 trans = glm::mix(sampler.outputsVec4[i], sampler.outputsVec4[i + 1], u);
|
||||
channel.node->translation = glm::vec3(trans);
|
||||
updated = true;
|
||||
channel.node->translation = glm::mix(sampler.outputsVec4[i], sampler.outputsVec4[i + 1], a);
|
||||
}
|
||||
if (channel.path == "rotation")
|
||||
{
|
||||
|
|
@ -563,32 +560,27 @@ void VulkanglTFModel::updateAnimation(float deltaTime)
|
|||
q1.y = sampler.outputsVec4[i].y;
|
||||
q1.z = sampler.outputsVec4[i].z;
|
||||
q1.w = sampler.outputsVec4[i].w;
|
||||
|
||||
glm::quat q2;
|
||||
q2.x = sampler.outputsVec4[i + 1].x;
|
||||
q2.y = sampler.outputsVec4[i + 1].y;
|
||||
q2.z = sampler.outputsVec4[i + 1].z;
|
||||
q2.w = sampler.outputsVec4[i + 1].w;
|
||||
channel.node->rotation = glm::normalize(glm::slerp(q1, q2, u));
|
||||
updated = true;
|
||||
|
||||
channel.node->rotation = glm::normalize(glm::slerp(q1, q2, a));
|
||||
}
|
||||
if (channel.path == "scale")
|
||||
{
|
||||
glm::vec4 trans = glm::mix(sampler.outputsVec4[i], sampler.outputsVec4[i + 1], u);
|
||||
channel.node->scale = glm::vec3(trans);
|
||||
updated = true;
|
||||
channel.node->scale = glm::mix(sampler.outputsVec4[i], sampler.outputsVec4[i + 1], a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (updated)
|
||||
{
|
||||
for (auto &node : nodes)
|
||||
{
|
||||
updateJoints(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
glTF rendering functions
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue