Loading...
Searching...
No Matches
spline_KeyFrames.h
1//
2// Copyright 2023 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24
25#ifndef PXR_BASE_TS_SPLINE_KEY_FRAMES_H
26#define PXR_BASE_TS_SPLINE_KEY_FRAMES_H
27
28#include "pxr/pxr.h"
29#include "pxr/base/ts/keyFrame.h"
30#include "pxr/base/ts/keyFrameMap.h"
31#include "pxr/base/ts/loopParams.h"
32#include "pxr/base/ts/types.h"
33#include "pxr/base/vt/value.h"
34
35#include <vector>
36#include <map>
37#include <typeinfo>
38
39PXR_NAMESPACE_OPEN_SCOPE
40
50{
51public:
54
60 TsKeyFrameMap const *keyFrames = NULL);
61
64 const TsKeyFrameMap & GetKeyFrames() const;
65
68
74 void SwapKeyFrames(std::vector<TsKeyFrame>* keyFrames);
75
78 *intervalAffected=NULL );
79
81 void RemoveKeyFrame( TsTime t, GfInterval
82 *intervalAffected=NULL );
83
85 void Clear();
86
89
91 const TsLoopParams &GetLoopParams() const;
92
94 void SetLoopParams(const TsLoopParams &loopParams);
95
97 const TsExtrapolationPair &GetExtrapolation() const;
98
100 void SetExtrapolation(const TsExtrapolationPair &extrapolation);
101
102 bool operator==(const TsSpline_KeyFrames &rhs) const;
103
104 // Bakes looped key frames out and turns looping off.
105 void BakeSplineLoops();
106
107private:
108 typedef std::pair<TsKeyFrameMap::iterator,
109 TsKeyFrameMap::iterator> _KeyFrameRange;
110
111 // Get a pointer to the keyframes that lets us change them
112 TsKeyFrameMap *_GetKeyFramesMutable();
113
114 // Returns the time interval affected by an edit to a keyframe at
115 // the given time.
116 GfInterval _GetTimeInterval( TsTime time );
117
118 // Copy the normal to the looped and then unroll the master keys
119 void _SetLoopedFromNormal();
120
121 // Copy the master, prepeat and repeated intervals from the looped keys to
122 // the normal keys
123 void _SetNormalFromLooped();
124
125 // Unroll the master interval of the looped keys to itself; clears the
126 // entire unrolled region first
127 void _UnrollMaster();
128
129 void _UnrollKeyFrames(TsKeyFrameMap *keyFrames,
130 const TsLoopParams &params);
131
132 // Unroll the given range of _loopedKeyFrames. If times is given, return
133 // the times that were written. Does not clear the unrolled region before
134 // writing.
135 void _UnrollKeyFrameRange(TsKeyFrameMap *keyFrames,
136 const TsKeyFrameMap::iterator &k0,
137 const TsKeyFrameMap::iterator &k1,
138 const TsLoopParams &params,
139 std::vector<TsTime> *times = NULL);
140
141 // Returns the range of keyframes including time as non-const iterators.
142 // If there is a keyframe at \p time then this is the keyframe before the
143 // keyframe at \p time to the keyframe after that one. If there isn't a
144 // keyframe at \p time then it's the closest keyframes before and after \p
145 // time.
146 _KeyFrameRange _GetKeyFrameRange( TsTime time );
147
148 // Returns the range of keyframes including the time interval as non-const
149 // iterators. These are the key frames from the key frame before (not at)
150 // \p leftTime to the key frame after (not at) \p rightTime.
151 _KeyFrameRange _GetKeyFrameRange( TsTime leftTime, TsTime rightTime );
152
153 // Returns the time interval that will be changed by removing a key frame
154 // at the given \p time.
155 GfInterval _FindRemoveKeyFrameChangedInterval(TsTime time);
156
157 // Returns the time interval that will be changed by setting the given
158 // \p keyFrame on the spline.
159 GfInterval _FindSetKeyFrameChangedInterval(const TsKeyFrame &keyFrame);
160
161 // Determine the effective extrapolation for \p keyframe on \p side
162 TsExtrapolationType _GetEffectiveExtrapolationType(
163 const TsKeyFrame &keyFrame,
164 const TsSide &side) const;
165
167 void _LoopParamsChanged(bool loopingChanged, bool valueOffsetChanged,
168 bool domainChanged);
169
170private:
171 friend class TsKeyFrameEvalUtil;
172 friend class TsSpline;
173
174 TsExtrapolationPair _extrapolation;
175 TsLoopParams _loopParams;
176 TsKeyFrameMap _normalKeyFrames;
177 TsKeyFrameMap _loopedKeyFrames;
178};
179
180PXR_NAMESPACE_CLOSE_SCOPE
181
182#endif
A basic mathematical interval class.
Definition: interval.h:50
Specifies the value of an TsSpline object at a particular point in time.
Definition: keyFrame.h:67
An ordered sequence of keyframes with STL-compliant API for finding, inserting, and erasing keyframes...
Definition: keyFrameMap.h:50
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:68