diff options
author | Mahmoud Badri <mahmoud.badri@qt.io> | 2019-09-05 12:54:23 +0300 |
---|---|---|
committer | Mahmoud Badri <mahmoud.badri@qt.io> | 2019-09-10 11:01:07 +0300 |
commit | 82d35c552c770050f0d248b562f46ac1ecfdaed7 (patch) | |
tree | c755353ffd9850d4c1106e69f5170159f6a97e8b | |
parent | e57b86e0b1fd1ad41a9f0af8449aeeb1be44414e (diff) |
Improve property graph curve fitting
- fit only selected (visible) bezier controls
- fit based on mix/min points on the curve (which is different from
keyframe values)
- fit based on the visible part of the timeline only
- center the curve in the view when its value range is very small
(smaller than the min scale value)
Change-Id: Ibb4d9b15c65937c35ffc20be1218d2cdd3af04b1
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r-- | src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp index 215c4d64..4c8e0752 100644 --- a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp +++ b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp @@ -318,7 +318,7 @@ void RowTimelinePropertyGraph::updateBezierControlValue(TimelineControlType cont if (controlType == TimelineControlType::BezierKeyframe) { float dVal = value - kf.m_value; - for (auto kfHandle : m_selectedBezierKeyframes) { + for (auto kfHandle : qAsConst(m_selectedBezierKeyframes)) { SBezierKeyframe kf_i = get<SBezierKeyframe>(m_animCore->GetKeyframeData(kfHandle)); kf_i.m_value += dVal; kf_i.m_InTangentValue += dVal; @@ -413,18 +413,25 @@ void RowTimelinePropertyGraph::fitGraph() // get min/max keyframes values in the active channels float minVal = FLT_MAX; float maxVal = -FLT_MAX; + + auto ruler = m_rowTimeline->rowTree()->m_scene->ruler(); + int startX = qMax(ruler->viewportX() - int(RULER_EDGE_OFFSET), 0); + int endX = ruler->viewportX() + m_rowTimeline->rowTree()->m_scene->widgetTimeline() + ->viewTimelineContent()->width(); + long startTime = ruler->distanceToTime(startX); + long endTime = ruler->distanceToTime(endX); + for (int i = 0; i < m_activeChannels.size(); ++i) { - Qt3DSDMTimelineKeyframe::TKeyframeHandleList keyframeHandles; - m_animCore->GetKeyframes(m_activeChannels[i], keyframeHandles); - for (auto kfHandle : keyframeHandles) { + auto extrema = m_animCore->getAnimationExtrema(m_activeChannels[i], startTime, endTime); + if (extrema.second < minVal) + minVal = extrema.second; + if (extrema.first > maxVal) + maxVal = extrema.first; + + // for bezier keyframes check selected tangents in/out also + for (auto kfHandle : qAsConst(m_selectedBezierKeyframes)) { TKeyframe keyframeData = m_animCore->GetKeyframeData(kfHandle); - float value = getKeyframeValue(keyframeData); - if (value < minVal) - minVal = value; - if (value > maxVal) - maxVal = value; - // for bezier keyframes compare tangents in/out also if (keyframeData.getType() == qt3dsdm::EAnimationTypeBezier) { long timeIn, timeOut; float valueIn, valueOut; @@ -456,7 +463,12 @@ void RowTimelinePropertyGraph::fitGraph() m_valScale = graphH / (maxVal - minVal); checkValScaleLimits(); - m_graphY = marginT + maxVal * m_valScale; + m_graphY = double(marginT + maxVal * m_valScale); + + // if value range is < min scale, center the range + float rangeH = (maxVal - minVal) * m_valScale; + if (rangeH < graphH) + m_graphY += double(graphH - rangeH) / 2.; m_rowTimeline->update(); } |