gr2: align curve sampling with Granny 2.11 (loop window, cubic, degree 0)

- Curve::eval rebuilds the B-spline window like ConstructBSplineBuffers:
  clamped ends repeat the endpoint; underflow/overflow looping takes knots
  from the other end (+-duration, skipping the duplicated last knot); equal
  trailing knots get +1e-5.
- Degree 3 (CubicCoefficients) supported; degrees 0..3 share one path.
- Degree 0 takes the control of the first knot > t (SampleBSpline0 = pi[0]);
  DaKeyframes32f curves are marked keyframed and keep frame trunc(t/dt).
- Loop flags threaded through BoneTrack::sample, Animation::sample_local and
  sample_pose; control_loop_state() mirrors GetControlLoopState.
- Gr2ModelInstance::SetAnimationLoop(); animated attachments (fmod) loop.
- Quaternion continuity stays on for every span (Granny: buffer path only).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 13:39:33 +09:00
co-authored by Claude Opus 5.5
parent 86759bb726
commit de8fa40098
7 changed files with 252 additions and 82 deletions
+9 -1
View File
@@ -164,6 +164,13 @@ float Gr2ModelInstance::GetAnimationDuration() const {
return 0.0f;
}
void Gr2ModelInstance::SetAnimationLoop(bool underflow_loop, bool overflow_loop) {
if (underflow_loop == m_loopUnderflow && overflow_loop == m_loopOverflow) return;
m_loopUnderflow = underflow_loop;
m_loopOverflow = overflow_loop;
m_poseValid = false;
}
void Gr2ModelInstance::EvaluatePose(float time) const {
if (!m_file || m_file->file_info().skeletons.empty()) return;
const auto& sk = m_file->file_info().skeletons[0];
@@ -186,7 +193,7 @@ void Gr2ModelInstance::EvaluatePose(float time) const {
m_localPose.resize(sk.bones.size());
for (size_t i=0; i<sk.bones.size(); ++i) m_localPose[i]=sk.bones[i].local_transform;
if (keyTime >= 0) {
anim->sample_local(time, m_trackPose);
anim->sample_local(time, m_trackPose, m_loopUnderflow, m_loopOverflow);
for (size_t i=0; i<m_trackPose.size() && i<m_trackBones.size(); ++i)
if (m_trackBones[i]>=0) m_localPose[m_trackBones[i]]=m_trackPose[i];
}
@@ -723,6 +730,7 @@ std::vector<Gr2MeshDraw> Gr2ModelInstance::BuildDrawCommands(float animation_tim
if (am.animated && animation_time >= 0.0f) {
float duration = am.model->GetAnimationDuration();
attach_time = duration > 0.0f ? std::fmod(animation_time, duration) : 0.0f;
am.model->SetAnimationLoop(true, true); // fmod 回绕 = 无限循环
}
auto attach_draws = am.model->BuildDrawCommands(attach_time, nullptr, hardwareSkinning);
for (auto& ad : attach_draws) {