From 27461174676ca5ef7972f325f12707abe98c0c9b Mon Sep 17 00:00:00 2001 From: spiffmon Date: Sat, 22 Jul 2017 01:41:44 -0700 Subject: [PATCH] Fixes issue where UsdGeomPrimvar::IsIndexed() doesn't work for index attrs with only authored timeSamples. We now have UsdResolveInfo for answering "has value" questions without actually needing to read in an attribute value (in theory, though actually pulling off that optimization will require some SdfAbstractData API work, to allow USD to query a value's type, which in crate and other formats can be discovered without actually reading in the full value). Fixes #238 (Internal change: 1767403) --- pxr/usd/lib/usdGeom/primvar.cpp | 8 +++++--- pxr/usd/lib/usdGeom/testenv/testUsdGeomPrimvar.py | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pxr/usd/lib/usdGeom/primvar.cpp b/pxr/usd/lib/usdGeom/primvar.cpp index f013f439de..5d091b1e61 100644 --- a/pxr/usd/lib/usdGeom/primvar.cpp +++ b/pxr/usd/lib/usdGeom/primvar.cpp @@ -251,9 +251,11 @@ UsdGeomPrimvar::GetIndices(VtIntArray *indices, bool UsdGeomPrimvar::IsIndexed() const { - // XXX update this to api that can directly see if an attribute is blocked. - VtIntArray dummy; - return _GetIndicesAttr(/*create*/ false).Get(&dummy); + UsdResolveInfo valueSource = _GetIndicesAttr(/*create*/ false). + GetResolveInfo(UsdTimeCode::EarliestTime()); + + return (valueSource.HasAuthoredValueOpinion() && + !valueSource.ValueIsBlocked()); } bool diff --git a/pxr/usd/lib/usdGeom/testenv/testUsdGeomPrimvar.py b/pxr/usd/lib/usdGeom/testenv/testUsdGeomPrimvar.py index 7356f70a3c..b4f1b9652e 100644 --- a/pxr/usd/lib/usdGeom/testenv/testUsdGeomPrimvar.py +++ b/pxr/usd/lib/usdGeom/testenv/testUsdGeomPrimvar.py @@ -183,6 +183,15 @@ def test_PrimvarAPI(self): self.assertTrue(len(u1.ComputeFlattened(2.0)) == 0) self.assertNotEqual(u1.ComputeFlattened(2.0), u1.Get(2.0)) + # Ensure that primvars with indices only authored at timeSamples + # (i.e. no default) are recognized as such. Manual name-munging + # necessitated by UsdGeomPrimvar's lack of API for accessing + # the indices attribute directly! + u1Indices = p.GetAttribute(u1.GetName() + ":indices") + self.assertTrue(u1Indices) + u1Indices.ClearDefault() + self.assertTrue(u1.IsIndexed()) + # Finally, ensure the values returned by GetDeclarationInfo # (on new Primvar objects, to test the GprimSchema API) # is identical to the individual queries, and matches what we set above