Compare commits

...

3 Commits

2 changed files with 13 additions and 7 deletions

View File

@ -17,7 +17,7 @@
PathComponent::PathComponent(SceneComponent* parent) PathComponent::PathComponent(SceneComponent* parent)
: SceneComponent(parent) { : SceneComponent(parent) {
animationPath_ = new osg::AnimationPath(); animationPath_ = new osg::AnimationPath();
animationPath_->setLoopMode(osg::AnimationPath::SWING); animationPath_->setLoopMode(osg::AnimationPath::NO_LOOPING);
} }
PathComponent::~PathComponent() { PathComponent::~PathComponent() {
@ -70,16 +70,18 @@ void PathComponent::Begin() {
if (hasPathTimes) { if (hasPathTimes) {
const auto& times = transformPath_->GetTimes(); const auto& times = transformPath_->GetTimes();
if (timeStep_->HasManualRange()) { if (timeStep_->HasManualRange()) {
// 将路径文件时间列线性映射到用户指定的手动区间,保证相对时间关系不变 // 使用文件时间为主:仅截取手动范围内的原始时间点
double srcMin = times.front();
double srcMax = times.back();
double dstMin = timeStep_->GetManualStart(); double dstMin = timeStep_->GetManualStart();
double dstMax = timeStep_->GetManualEnd(); double dstMax = timeStep_->GetManualEnd();
double srcSpan = std::max(1e-9, srcMax - srcMin);
mappedSteps.reserve(times.size()); mappedSteps.reserve(times.size());
for (double t : times) { for (double t : times) {
double alpha = (t - srcMin) / srcSpan; if (t >= dstMin && t <= dstMax) {
mappedSteps.push_back(dstMin + alpha * (dstMax - dstMin)); mappedSteps.push_back(t);
}
}
// 若截取后为空,回退为原始时间列,避免动画路径为空
if (mappedSteps.empty()) {
mappedSteps = times;
} }
} else { } else {
mappedSteps = times; mappedSteps = times;

View File

@ -118,6 +118,10 @@ void PlayManagerMenu::OnWorkspaceChange(WorkSpace* workSpace) {
} }
workSpace_ = workSpace; workSpace_ = workSpace;
connect(workSpace, &WorkSpace::TimestepChanged, this, &PlayManagerMenu::OnTimestepChanged); connect(workSpace, &WorkSpace::TimestepChanged, this, &PlayManagerMenu::OnTimestepChanged);
// 若当前 workspace 已有 timestep则立即刷新一次 UI
if (auto* timestep = workSpace->GetTimestep()) {
OnTimestepChanged(timestep);
}
} }
void PlayManagerMenu::OnTimestepChanged(Timestep* timestep) { void PlayManagerMenu::OnTimestepChanged(Timestep* timestep) {