Skip to content

Commit f3f6bc2

Browse files
gitamohrpixar-oss
authored andcommitted
usd: Time-varying composing value types implementation.
(Internal change: 2393523)
1 parent 1015a55 commit f3f6bc2

23 files changed

Lines changed: 2663 additions & 1375 deletions

pxr/exec/esf/attributeQuery.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ESF_API_TYPE EsfAttributeQueryInterface :
119119
/// introducing Usd as a dependency.
120120
///
121121
class EsfAttributeQuery
122-
: public EsfFixedSizePolymorphicHolder<EsfAttributeQueryInterface, 160>
122+
: public EsfFixedSizePolymorphicHolder<EsfAttributeQueryInterface, 168>
123123
{
124124
public:
125125
using EsfFixedSizePolymorphicHolder::EsfFixedSizePolymorphicHolder;

pxr/usd/usd/attribute.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ UsdAttribute::GetBracketingTimeSamples(double desiredTime,
102102
bool* hasTimeSamples) const
103103
{
104104
return _GetStage()->_GetBracketingTimeSamples(
105-
*this, desiredTime, /*requireAuthored*/ false,
106-
lower, upper, hasTimeSamples);
105+
*this, desiredTime, lower, upper, hasTimeSamples);
107106
}
108107

109108
bool
@@ -211,7 +210,8 @@ template <typename T>
211210
bool
212211
UsdAttribute::_Get(T* value, UsdTimeCode time) const
213212
{
214-
return _GetStage()->_GetValue(time, *this, value);
213+
SdfAbstractDataTypedValue<T> av(value);
214+
return _GetStage()->_GetValue(time, *this, &av);
215215
}
216216

217217
bool

pxr/usd/usd/attribute.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,17 @@ class UsdAttribute : public UsdProperty {
497497
UsdResolveInfo
498498
GetResolveInfo(UsdTimeCode time) const;
499499

500-
/// Perform value resolution to determine the source of the resolved
501-
/// value of this attribute at any non-default time.
500+
/// Perform value resolution to determine the proximal source of the
501+
/// resolved value of this attribute at any non-default time.
502502
///
503-
/// Often (i.e. unless the attribute is affected by
504-
/// \ref Usd_Page_ValueClips "Value Clips") the source of the resolved value
503+
/// Often (i.e. unless the attribute is affected by \ref Usd_Page_ValueClips
504+
/// "Value Clips" or the authored values are composing value types like
505+
/// VtArrayEdits or SdfPathExpressions) the source of the resolved value
505506
/// does not vary over time. See UsdAttributeQuery as an example that takes
506-
/// advantage of this quality of value resolution.
507+
/// advantage of this quality of value resolution. Call the
508+
/// GetResolveInfo() overload that takes a `time` to get a more complete
509+
/// picture, and see UsdResolveInfo::GetSource() for more information.
510+
///
507511
USD_API
508512
UsdResolveInfo
509513
GetResolveInfo() const;

pxr/usd/usd/attributeQuery.cpp

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ USD_API
131131
bool
132132
UsdAttributeQuery::_Get(T* value, UsdTimeCode time) const
133133
{
134+
SdfAbstractDataTypedValue<T> result(value);
135+
134136
// If the requested time is default but the resolved value source is time
135137
// varying, then the stored resolve info won't give us the correct value
136138
// for default time. In this case we have to get the resolve info at default
@@ -148,24 +150,46 @@ UsdAttributeQuery::_Get(T* value, UsdTimeCode time) const
148150
_attr, &defaultResolveInfo, &defaultTime);
149151
}
150152
return _attr._GetStage()->_GetValueFromResolveInfo(
151-
defaultResolveInfo, defaultTime, _attr, value);
153+
defaultResolveInfo, defaultTime, _attr, &result);
152154
}
153155

154156
return _attr._GetStage()->_GetValueFromResolveInfo(
155-
_resolveInfo, time, _attr, value);
157+
_resolveInfo, time, _attr, &result, _resolveTarget.get());
156158
}
157159

158160
bool
159161
UsdAttributeQuery::Get(VtValue* value, UsdTimeCode time) const
160162
{
161-
return _Get(value, time);
163+
// If the requested time is default but the resolved value source is time
164+
// varying, then the stored resolve info won't give us the correct value
165+
// for default time. In this case we have to get the resolve info at default
166+
// time and query the value from that.
167+
if (time.IsDefault() &&
168+
_resolveInfo.ValueSourceMightBeTimeVarying()) {
169+
170+
static const UsdTimeCode defaultTime = UsdTimeCode::Default();
171+
UsdResolveInfo defaultResolveInfo;
172+
if (_resolveTarget && TF_VERIFY(!_resolveTarget->IsNull())) {
173+
_attr._GetStage()->_GetResolveInfoWithResolveTarget(
174+
_attr, *_resolveTarget, &defaultResolveInfo, &defaultTime);
175+
} else {
176+
_attr._GetStage()->_GetResolveInfo(
177+
_attr, &defaultResolveInfo, &defaultTime);
178+
}
179+
return _attr._GetStage()->_GetValueFromResolveInfo(
180+
defaultResolveInfo, defaultTime, _attr, value);
181+
}
182+
183+
return _attr._GetStage()->_GetValueFromResolveInfo(
184+
_resolveInfo, time, _attr, value, _resolveTarget.get());
162185
}
163186

164187
bool
165188
UsdAttributeQuery::GetTimeSamples(std::vector<double>* times) const
166189
{
167-
return _attr._GetStage()->_GetTimeSamplesInIntervalFromResolveInfo(
168-
_resolveInfo, _attr, GfInterval::GetFullInterval(), times);
190+
return _attr._GetStage()->_GetTimeSamplesInInterval(
191+
_attr, GfInterval::GetFullInterval(), times,
192+
&_resolveInfo, _resolveTarget.get());
169193
}
170194

171195
TsSpline
@@ -194,8 +218,9 @@ bool
194218
UsdAttributeQuery::GetTimeSamplesInInterval(const GfInterval& interval,
195219
std::vector<double>* times) const
196220
{
197-
return _attr._GetStage()->_GetTimeSamplesInIntervalFromResolveInfo(
198-
_resolveInfo, _attr, interval, times);
221+
return _attr._GetStage()->
222+
_GetTimeSamplesInInterval(_attr, interval, times,
223+
&_resolveInfo, _resolveTarget.get());
199224
}
200225

201226
/* static */
@@ -237,9 +262,9 @@ UsdAttributeQuery::GetUnionedTimeSamplesInInterval(
237262

238263
// This will work even if the attributes belong to different
239264
// USD stages.
240-
success = attr.GetStage()->_GetTimeSamplesInIntervalFromResolveInfo(
241-
attrQuery._resolveInfo, attr, interval, &attrSampleTimes)
242-
&& success;
265+
success = attr.GetStage()->_GetTimeSamplesInInterval(
266+
attr, interval, &attrSampleTimes, &attrQuery._resolveInfo,
267+
attrQuery._resolveTarget.get()) && success;
243268

244269
// Merge attrSamplesTimes into the times vector.
245270
Usd_MergeTimeSamples(times, attrSampleTimes, &tempUnionSampleTimes);
@@ -251,8 +276,8 @@ UsdAttributeQuery::GetUnionedTimeSamplesInInterval(
251276
size_t
252277
UsdAttributeQuery::GetNumTimeSamples() const
253278
{
254-
return _attr._GetStage()->_GetNumTimeSamplesFromResolveInfo(
255-
_resolveInfo, _attr);
279+
return _attr._GetStage()->_GetNumTimeSamples(
280+
_attr, &_resolveInfo, _resolveTarget.get());
256281
}
257282

258283
bool
@@ -261,9 +286,9 @@ UsdAttributeQuery::GetBracketingTimeSamples(double desiredTime,
261286
double* upper,
262287
bool* hasTimeSamples) const
263288
{
264-
return _attr._GetStage()->_GetBracketingTimeSamplesFromResolveInfo(
265-
_resolveInfo, _attr, desiredTime, /* authoredOnly */ false,
266-
lower, upper, hasTimeSamples);
289+
return _attr._GetStage()->_GetBracketingTimeSamples(
290+
_attr, desiredTime, lower, upper, hasTimeSamples,
291+
&_resolveInfo, _resolveTarget.get());
267292
}
268293

269294
bool
@@ -305,8 +330,8 @@ UsdAttributeQuery::GetFallbackValue(VtValue* value) const
305330
bool
306331
UsdAttributeQuery::ValueMightBeTimeVarying() const
307332
{
308-
return _attr._GetStage()->_ValueMightBeTimeVaryingFromResolveInfo(
309-
_resolveInfo, _attr);
333+
return _attr._GetStage()->
334+
_ValueMightBeTimeVaryingFromResolveInfo(_resolveInfo, _attr);
310335
}
311336

312337
ARCH_PRAGMA_PUSH

pxr/usd/usd/clip.cpp

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "pxr/base/gf/interval.h"
2727
#include "pxr/base/tf/preprocessorUtilsLite.h"
2828
#include "pxr/base/tf/stringUtils.h"
29+
#include "pxr/base/vt/array.h"
30+
#include "pxr/base/vt/arrayEdit.h"
2931

3032
#include <optional>
3133
#include <ostream>
@@ -809,6 +811,18 @@ _ConvertValueForTime(const Usd_Clip::ExternalTime &extTime,
809811
}
810812
}
811813

814+
// Similarly we convert arrayEdits of SdfTimeCodes.
815+
inline
816+
void
817+
_ConvertValueForTime(const Usd_Clip::ExternalTime &extTime,
818+
const Usd_Clip::InternalTime &intTime,
819+
VtArrayEdit<SdfTimeCode> *value)
820+
{
821+
for (SdfTimeCode &tc: value->GetMutableLiterals()) {
822+
_ConvertValueForTime(extTime, intTime, &tc);
823+
}
824+
}
825+
812826
// Helpers for accessing the typed value from type erased values, needed for
813827
// converting SdfTimeCodes.
814828
template <class T>
@@ -854,6 +868,11 @@ _ConvertTypeErasedValueForTime(const Usd_Clip::ExternalTime &extTime,
854868
_UncheckedSwap(value, rawVal);
855869
_ConvertValueForTime(extTime, intTime, &rawVal);
856870
_UncheckedSwap(value, rawVal);
871+
} else if (_IsHolding<VtArrayEdit<SdfTimeCode>>(*value)) {
872+
VtArrayEdit<SdfTimeCode> rawVal;
873+
_UncheckedSwap(value, rawVal);
874+
_ConvertValueForTime(extTime, intTime, &rawVal);
875+
_UncheckedSwap(value, rawVal);
857876
}
858877
}
859878

@@ -887,28 +906,44 @@ template <class T>
887906
static bool
888907
_Interpolate(
889908
const SdfLayerRefPtr& clip, const SdfPath &clipPath,
890-
Usd_Clip::InternalTime clipTime, Usd_InterpolatorBase* interpolator,
909+
Usd_Clip::InternalTime clipTime, Usd_Interpolator const & interpolator,
891910
T* value)
892911
{
893912
double lowerInClip, upperInClip;
894913
if (clip->GetBracketingTimeSamplesForPath(
895914
clipPath, clipTime, &lowerInClip, &upperInClip)) {
896-
897-
return Usd_GetOrInterpolateValue(
898-
clip, clipPath, clipTime, lowerInClip, upperInClip,
899-
interpolator, value);
915+
916+
Usd_InterpolationSampleSeries samples;
917+
if (interpolator.GetInterpolatingSamples(
918+
clip, clipPath, clipTime,
919+
lowerInClip, upperInClip, &samples)) {
920+
Usd_Interpolate(&samples, clipTime);
921+
Usd_SetValue(value, samples[0].value);
922+
return true;
923+
}
924+
return false;
900925
}
901926

902927
return false;
903928
}
904929

905930
}; // End anonymous namespace
906931

932+
const std::type_info &
933+
Usd_Clip::QueryTimeSampleTypeid(const SdfPath &path, UsdTimeCode time) const
934+
{
935+
const SdfPath clipPath = _TranslatePathToClip(path);
936+
const InternalTime clipTime = _TranslateTimeToInternal(time);
937+
const SdfLayerRefPtr& clip = _GetLayerForClip();
938+
939+
return clip->QueryTimeSampleTypeid(clipPath, clipTime);
940+
}
941+
907942
template <class T>
908943
bool
909944
Usd_Clip::QueryTimeSample(
910945
const SdfPath& path, UsdTimeCode time,
911-
Usd_InterpolatorBase* interpolator, T* value) const
946+
Usd_Interpolator const & interpolator, T* value) const
912947
{
913948
const SdfPath clipPath = _TranslatePathToClip(path);
914949
const InternalTime clipTime = _TranslateTimeToInternal(time);
@@ -929,24 +964,24 @@ Usd_Clip::QueryTimeSample(
929964
#define _INSTANTIATE_QUERY_TIME_SAMPLE(unused, elem) \
930965
template bool Usd_Clip::QueryTimeSample( \
931966
const SdfPath&, UsdTimeCode, \
932-
Usd_InterpolatorBase*, \
967+
Usd_Interpolator const &, \
933968
SDF_VALUE_CPP_TYPE(elem)*) const; \
934969
template bool Usd_Clip::QueryTimeSample( \
935970
const SdfPath&, UsdTimeCode, \
936-
Usd_InterpolatorBase*, \
971+
Usd_Interpolator const &, \
937972
SDF_VALUE_CPP_ARRAY_TYPE(elem)*) const;
938973

939974
TF_PP_SEQ_FOR_EACH(_INSTANTIATE_QUERY_TIME_SAMPLE, ~, SDF_VALUE_TYPES)
940975
#undef _INSTANTIATE_QUERY_TIME_SAMPLE
941976

942977
template bool Usd_Clip::QueryTimeSample(
943978
const SdfPath&, UsdTimeCode,
944-
Usd_InterpolatorBase*,
979+
Usd_Interpolator const &,
945980
SdfAbstractDataValue*) const;
946981

947982
template bool Usd_Clip::QueryTimeSample(
948983
const SdfPath&, UsdTimeCode,
949-
Usd_InterpolatorBase*,
984+
Usd_Interpolator const &,
950985
VtValue*) const;
951986

952987
PXR_NAMESPACE_CLOSE_SCOPE

pxr/usd/usd/clip.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PXR_NAMESPACE_OPEN_SCOPE
2424

2525
TF_DECLARE_WEAK_PTRS(PcpLayerStack);
2626

27-
class Usd_InterpolatorBase;
27+
class Usd_Interpolator;
2828
class UsdTimeCode;
2929

3030
/// Returns true if the given scene description metadata \p fieldName is
@@ -151,7 +151,12 @@ struct Usd_Clip
151151
template <class T>
152152
bool QueryTimeSample(
153153
const SdfPath& path, UsdTimeCode time,
154-
Usd_InterpolatorBase* interpolator, T* value) const;
154+
Usd_Interpolator const &interpolator, T* value) const;
155+
156+
/// If there is a time sample for \p path at \p time, return its value's
157+
/// typeid(), otherwise return typeid(void).
158+
const std::type_info &QueryTimeSampleTypeid(
159+
const SdfPath &path, UsdTimeCode time) const;
155160

156161
/// Return true if this clip has authored time samples for the attribute
157162
/// corresponding to the given \p path. Clips may add time sample times

pxr/usd/usd/clipSet.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ Usd_ClipSet::_ClipContributesValue(
478478
}
479479

480480
// Use the clip if a default value specified in the manifest.
481-
if (Usd_HasDefault<int>(manifestClip, path, nullptr)
481+
if (Usd_HasDefault<VtValue>(manifestClip, path, nullptr)
482482
!= Usd_DefaultValueResult::None) {
483483
return true;
484484
}
@@ -707,6 +707,24 @@ Usd_ClipSet::GetTimeSamplesInInterval(
707707
return timeSamples;
708708
}
709709

710+
const std::type_info &
711+
Usd_ClipSet::QueryTimeSampleTypeid(const SdfPath &path, UsdTimeCode time) const
712+
{
713+
const Usd_ClipRefPtr& clip =
714+
GetActiveClip(time, false /*timeHasJumpDiscontinuity*/);
715+
716+
// First query the clip for time sample typeid at the specified time.
717+
const std::type_info &type = clip->QueryTimeSampleTypeid(path, time);
718+
if (type != typeid(void)) {
719+
return type;
720+
}
721+
722+
// If no value exists in the clip, get the default value from the manifest.
723+
const std::type_info *typePtr = &typeid(void);
724+
Usd_HasDefault<VtValue>(manifestClip, path, nullptr, &typePtr);
725+
return *typePtr;
726+
}
727+
710728
size_t
711729
Usd_ClipSet::_FindClipIndexForTime(double time) const
712730
{

pxr/usd/usd/clipSet.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,12 @@ class Usd_ClipSet
135135
template <class T>
136136
bool QueryTimeSample(
137137
const SdfPath& path, UsdTimeCode time,
138-
Usd_InterpolatorBase* interpolator, T* value) const;
138+
Usd_Interpolator const &interpolator, T* value) const;
139+
140+
/// If there is a time sample for \p path at \p time, return its value's
141+
/// typeid(), otherwise return typeid(void).
142+
const std::type_info &QueryTimeSampleTypeid(
143+
const SdfPath& path, UsdTimeCode time) const;
139144

140145
/// Query time samples for an attribute at \p path at pre-time \p time if
141146
/// samples represent a jump discontinuity.
@@ -146,7 +151,7 @@ class Usd_ClipSet
146151
template <class T>
147152
bool QueryPreTimeSampleWithJumpDiscontinuity(
148153
const SdfPath& path, UsdTimeCode time,
149-
Usd_InterpolatorBase* interpolator, T* value) const;
154+
Usd_Interpolator const &interpolator, T* value) const;
150155

151156
std::string name;
152157
PcpLayerStackPtr sourceLayerStack;
@@ -186,7 +191,7 @@ template <class T>
186191
inline bool
187192
Usd_ClipSet::QueryTimeSample(
188193
const SdfPath& path, UsdTimeCode time,
189-
Usd_InterpolatorBase* interpolator, T* value) const
194+
Usd_Interpolator const &interpolator, T* value) const
190195
{
191196
const Usd_ClipRefPtr& clip =
192197
GetActiveClip(time, false /*timeHasJumpDiscontinuity*/);
@@ -207,7 +212,7 @@ template <class T>
207212
inline bool
208213
Usd_ClipSet::QueryPreTimeSampleWithJumpDiscontinuity(
209214
const SdfPath& path, UsdTimeCode time,
210-
Usd_InterpolatorBase* interpolator, T* value) const
215+
Usd_Interpolator const &interpolator, T* value) const
211216
{
212217
if (!time.IsPreTime()) {
213218
return false;
@@ -234,7 +239,7 @@ template <class T>
234239
inline bool
235240
Usd_QueryTimeSample(
236241
const Usd_ClipSetRefPtr& clipSet, const SdfPath& path,
237-
double time, Usd_InterpolatorBase* interpolator, T* result)
242+
double time, Usd_Interpolator const &interpolator, T* result)
238243
{
239244
return clipSet->QueryTimeSample(path, time, interpolator, result);
240245
}

0 commit comments

Comments
 (0)