Loading...
Searching...
No Matches
spline_KeyFrames.h
1//
2// Copyright 2023 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7
8#ifndef PXR_BASE_TS_SPLINE_KEY_FRAMES_H
9#define PXR_BASE_TS_SPLINE_KEY_FRAMES_H
10
11#include "pxr/pxr.h"
12#include "pxr/base/ts/keyFrame.h"
13#include "pxr/base/ts/keyFrameMap.h"
14#include "pxr/base/ts/loopParams.h"
15#include "pxr/base/ts/types.h"
16#include "pxr/base/vt/value.h"
17
18#include <vector>
19#include <map>
20#include <typeinfo>
21
22PXR_NAMESPACE_OPEN_SCOPE
23
33{
34public:
37
43 TsKeyFrameMap const *keyFrames = NULL);
44
47 const TsKeyFrameMap & GetKeyFrames() const;
48
51
57 void SwapKeyFrames(std::vector<TsKeyFrame>* keyFrames);
58
61 *intervalAffected=NULL );
62
64 void RemoveKeyFrame( TsTime t, GfInterval
65 *intervalAffected=NULL );
66
68 void Clear();
69
72
74 const TsLoopParams &GetLoopParams() const;
75
77 void SetLoopParams(const TsLoopParams &loopParams);
78
80 const TsExtrapolationPair &GetExtrapolation() const;
81
83 void SetExtrapolation(const TsExtrapolationPair &extrapolation);
84
85 bool operator==(const TsSpline_KeyFrames &rhs) const;
86
87 // Bakes looped key frames out and turns looping off.
88 void BakeSplineLoops();
89
90private:
91 typedef std::pair<TsKeyFrameMap::iterator,
92 TsKeyFrameMap::iterator> _KeyFrameRange;
93
94 // Get a pointer to the keyframes that lets us change them
95 TsKeyFrameMap *_GetKeyFramesMutable();
96
97 // Returns the time interval affected by an edit to a keyframe at
98 // the given time.
99 GfInterval _GetTimeInterval( TsTime time );
100
101 // Copy the normal to the looped and then unroll the master keys
102 void _SetLoopedFromNormal();
103
104 // Copy the master, prepeat and repeated intervals from the looped keys to
105 // the normal keys
106 void _SetNormalFromLooped();
107
108 // Unroll the master interval of the looped keys to itself; clears the
109 // entire unrolled region first
110 void _UnrollMaster();
111
112 void _UnrollKeyFrames(TsKeyFrameMap *keyFrames,
113 const TsLoopParams &params);
114
115 // Unroll the given range of _loopedKeyFrames. If times is given, return
116 // the times that were written. Does not clear the unrolled region before
117 // writing.
118 void _UnrollKeyFrameRange(TsKeyFrameMap *keyFrames,
119 const TsKeyFrameMap::iterator &k0,
120 const TsKeyFrameMap::iterator &k1,
121 const TsLoopParams &params,
122 std::vector<TsTime> *times = NULL);
123
124 // Returns the range of keyframes including time as non-const iterators.
125 // If there is a keyframe at \p time then this is the keyframe before the
126 // keyframe at \p time to the keyframe after that one. If there isn't a
127 // keyframe at \p time then it's the closest keyframes before and after \p
128 // time.
129 _KeyFrameRange _GetKeyFrameRange( TsTime time );
130
131 // Returns the range of keyframes including the time interval as non-const
132 // iterators. These are the key frames from the key frame before (not at)
133 // \p leftTime to the key frame after (not at) \p rightTime.
134 _KeyFrameRange _GetKeyFrameRange( TsTime leftTime, TsTime rightTime );
135
136 // Returns the time interval that will be changed by removing a key frame
137 // at the given \p time.
138 GfInterval _FindRemoveKeyFrameChangedInterval(TsTime time);
139
140 // Returns the time interval that will be changed by setting the given
141 // \p keyFrame on the spline.
142 GfInterval _FindSetKeyFrameChangedInterval(const TsKeyFrame &keyFrame);
143
144 // Determine the effective extrapolation for \p keyframe on \p side
145 TsExtrapolationType _GetEffectiveExtrapolationType(
146 const TsKeyFrame &keyFrame,
147 const TsSide &side) const;
148
150 void _LoopParamsChanged(bool loopingChanged, bool valueOffsetChanged,
151 bool domainChanged);
152
153private:
154 friend class TsKeyFrameEvalUtil;
155 friend class TsSpline;
156
157 TsExtrapolationPair _extrapolation;
158 TsLoopParams _loopParams;
159 TsKeyFrameMap _normalKeyFrames;
160 TsKeyFrameMap _loopedKeyFrames;
161};
162
163PXR_NAMESPACE_CLOSE_SCOPE
164
165#endif
A basic mathematical interval class.
Definition: interval.h:33
Specifies the value of an TsSpline object at a particular point in time.
Definition: keyFrame.h:50
An ordered sequence of keyframes with STL-compliant API for finding, inserting, and erasing keyframes...
Definition: keyFrameMap.h:33
Maintains the keyframes for a spline.
void SetExtrapolation(const TsExtrapolationPair &extrapolation)
Sets the left and right extrapolation.
void SetKeyFrames(const TsKeyFrameMap &)
If looping, just writes to the non unrolled intervals.
const TsExtrapolationPair & GetExtrapolation() const
Get the left and right extrapolation.
TsSpline_KeyFrames(TsSpline_KeyFrames const &other, TsKeyFrameMap const *keyFrames=NULL)
Generalized copy constructor.
void SwapKeyFrames(std::vector< TsKeyFrame > *keyFrames)
Replaces the key frames of this spline with keyFrames, and replaces the contents of keyFrames with th...
const TsKeyFrameMap & GetNormalKeyFrames() const
Gets the underlying normal keys.
void Clear()
Clears both maps.
const TsKeyFrameMap & GetKeyFrames() const
Gets the looped or unlooped keys, according to whether the spline is looping.
const TsLoopParams & GetLoopParams() const
Get the loop parameters.
void SetLoopParams(const TsLoopParams &loopParams)
Sets the loop parameters.
void RemoveKeyFrame(TsTime t, GfInterval *intervalAffected=NULL)
If looping, just affects the non unrolled intervals.
void SetKeyFrame(TsKeyFrame kf, GfInterval *intervalAffected=NULL)
If looping, just writes to the non unrolled intervals.
Represents a spline value object.
Definition: spline.h:51