-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
layerOffset.h
167 lines (130 loc) · 4.6 KB
/
layerOffset.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
// Copyright 2016 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://openusd.org/license.
//
#ifndef PXR_USD_SDF_LAYER_OFFSET_H
#define PXR_USD_SDF_LAYER_OFFSET_H
/// \file sdf/layerOffset.h
#include "pxr/pxr.h"
#include "pxr/usd/sdf/api.h"
#include <iosfwd>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
class SdfTimeCode;
/// \class SdfLayerOffset
///
/// Represents a time offset and scale between layers.
///
/// The SdfLayerOffset class is an affine transform, providing both a scale and
/// a translate. It supports vector algebra semantics for composing
/// SdfLayerOffsets together via multiplication. The SdfLayerOffset class is
/// unitless: it does not refer to seconds or frames.
///
/// For example, suppose layer A uses layer B, with an offset of X:
/// when bringing animation from B into A, you first apply the scale of X, and
/// then the offset. Suppose you have a scale of 2 and an offset of 24:
/// first multiply B's frame numbers by 2, and then add 24. The animation from
/// B as seen in A will take twice as long and start 24 frames later.
///
/// Offsets are typically used in either sublayers or prim references. For more
/// information, see the SetSubLayerOffset() method of the SdfLayer class (the
/// subLayerOffsets property in Python), as well as the SetReference() and
/// GetReferenceLayerOffset() methods (the latter is the referenceLayerOffset
/// property in Python) of the SdfPrimSpec class.
///
class SdfLayerOffset
{
public:
/// \name Constructors
/// @{
/// Constructs a new SdfLayerOffset instance.
SDF_API
explicit SdfLayerOffset(double offset = 0.0, double scale = 1.0);
/// @}
/// \name Accessors
/// @{
/// Returns the time offset.
double GetOffset() const { return _offset; }
/// Returns the time scale factor.
double GetScale() const { return _scale; }
/// Sets the time offset.
void SetOffset(double newOffset) { _offset = newOffset; }
/// Sets the time scale factor.
void SetScale(double newScale) { _scale = newScale; }
/// Returns \c true if this is an identity transformation, with
/// an offset of 0.0 and a scale of 1.0.
SDF_API
bool IsIdentity() const;
/// Returns \c true if this offset is valid, i.e. both the offset and
/// scale are finite (not infinite or NaN). Note that a valid layer
/// offset's inverse may be invalid.
SDF_API
bool IsValid() const;
/// Gets the inverse offset, which performs the opposite transformation.
SDF_API
SdfLayerOffset GetInverse() const;
/// \name Hashing
/// @{
/// Returns hash for this offset.
SDF_API
size_t GetHash() const;
/// Hash functor for hash maps and sets.
struct Hash {
size_t operator()(const SdfLayerOffset &offset) const {
return offset.GetHash();
}
};
friend inline size_t hash_value(const SdfLayerOffset &offset) {
return offset.GetHash();
}
/// @}
/// \name Operators
/// @{
/// Returns whether the offsets are equal.
SDF_API
bool operator==(const SdfLayerOffset &rhs) const;
/// \sa SdfLayerOffset::operator==
bool operator!=(const SdfLayerOffset &rhs) const {
return !(*this == rhs);
}
/// Returns whether this offset is less than another. The meaning
/// of less than is somewhat arbitrary.
SDF_API
bool operator<(const SdfLayerOffset &rhs) const;
/// \sa SdfLayerOffset::operator<
bool operator>(const SdfLayerOffset& rhs) const {
return rhs < *this;
}
/// \sa SdfLayerOffset::operator<
bool operator>=(const SdfLayerOffset& rhs) const {
return !(*this < rhs);
}
/// \sa SdfLayerOffset::operator<
bool operator<=(const SdfLayerOffset& rhs) const {
return !(*this > rhs);
}
/// Composes this with the offset \e rhs, such that the resulting
/// offset is equivalent to first applying \e rhs and then \e *this.
SDF_API
SdfLayerOffset operator*(const SdfLayerOffset &rhs) const;
/// Applies the offset to the given value.
SDF_API
double operator*(double rhs) const;
/// Applies the offset to the given value.
SDF_API
SdfTimeCode operator*(const SdfTimeCode &rhs) const;
/// @}
private:
double _offset;
double _scale;
};
typedef std::vector<SdfLayerOffset> SdfLayerOffsetVector;
///
/// Writes the string representation of \a SdfLayerOffset to \a out.
SDF_API
std::ostream & operator<<( std::ostream &out,
const SdfLayerOffset &layerOffset );
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_SDF_LAYER_OFFSET_H