From dc6de38b468c953654e6762643ed7ba2766e523c Mon Sep 17 00:00:00 2001 From: brige Date: Tue, 11 Nov 2025 21:35:15 +0800 Subject: [PATCH] modify pathcomponts --- src/entities/PathComponent.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/entities/PathComponent.cpp b/src/entities/PathComponent.cpp index 2d6f25c8..40b2b5a6 100644 --- a/src/entities/PathComponent.cpp +++ b/src/entities/PathComponent.cpp @@ -17,7 +17,7 @@ PathComponent::PathComponent(SceneComponent* parent) : SceneComponent(parent) { animationPath_ = new osg::AnimationPath(); - animationPath_->setLoopMode(osg::AnimationPath::SWING); + animationPath_->setLoopMode(osg::AnimationPath::NO_LOOPING); } PathComponent::~PathComponent() { @@ -70,16 +70,18 @@ void PathComponent::Begin() { if (hasPathTimes) { const auto& times = transformPath_->GetTimes(); if (timeStep_->HasManualRange()) { - // 将路径文件时间列线性映射到用户指定的手动区间,保证相对时间关系不变 - double srcMin = times.front(); - double srcMax = times.back(); + // 使用文件时间为主:仅截取手动范围内的原始时间点 double dstMin = timeStep_->GetManualStart(); double dstMax = timeStep_->GetManualEnd(); - double srcSpan = std::max(1e-9, srcMax - srcMin); mappedSteps.reserve(times.size()); for (double t : times) { - double alpha = (t - srcMin) / srcSpan; - mappedSteps.push_back(dstMin + alpha * (dstMax - dstMin)); + if (t >= dstMin && t <= dstMax) { + mappedSteps.push_back(t); + } + } + // 若截取后为空,回退为原始时间列,避免动画路径为空 + if (mappedSteps.empty()) { + mappedSteps = times; } } else { mappedSteps = times;