From 6e1abd7d7a689e3bff15d7792b99af7b154d1325 Mon Sep 17 00:00:00 2001 From: Mark Tucker Date: Mon, 10 Jan 2022 13:49:21 -0500 Subject: [PATCH 001/285] When using scene index emulation, return after calling AddLegacyPrim when inserting a new Bprim (otherwise it would be created twice). --- pxr/imaging/hd/renderIndex.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/pxr/imaging/hd/renderIndex.cpp b/pxr/imaging/hd/renderIndex.cpp index d4121e66bc..ec26c5bc62 100644 --- a/pxr/imaging/hd/renderIndex.cpp +++ b/pxr/imaging/hd/renderIndex.cpp @@ -608,6 +608,7 @@ HdRenderIndex::InsertBprim(TfToken const& typeId, // the prim information if (_IsEnabledSceneIndexEmulation()) { _emulationSceneIndex->AddLegacyPrim(bprimId, typeId, sceneDelegate); + return; } _InsertBprim(typeId, sceneDelegate, bprimId); From 4ca6de0bed6d3434715291fbcc3c7a1c7fa7f16b Mon Sep 17 00:00:00 2001 From: krickw Date: Thu, 27 Jan 2022 14:09:02 -0500 Subject: [PATCH 002/285] Add GetInstanceIndicesChangeCount to HdChangeTracker to detect changes to instance indexing. --- pxr/imaging/hd/changeTracker.cpp | 15 +++++++++++++++ pxr/imaging/hd/changeTracker.h | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/pxr/imaging/hd/changeTracker.cpp b/pxr/imaging/hd/changeTracker.cpp index 5e42e7c763..e774d69d49 100644 --- a/pxr/imaging/hd/changeTracker.cpp +++ b/pxr/imaging/hd/changeTracker.cpp @@ -60,6 +60,7 @@ HdChangeTracker::HdChangeTracker() , _instancerIndexVersion(1) , _sceneStateVersion(1) , _visChangeCount(1) + , _instanceIndicesChangeCount(1) , _rprimRenderTagVersion(1) , _taskRenderTagsVersion(1) , _emulationSceneIndex(nullptr) @@ -194,6 +195,10 @@ void HdChangeTracker::_MarkRprimDirty(SdfPath const& id, HdDirtyBits bits) ++_visChangeCount; } + if ((bits & DirtyInstanceIndex) != 0) { + ++_instanceIndicesChangeCount; + } + if ((bits & DirtyRenderTag) != 0) { ++_rprimRenderTagVersion; } @@ -527,6 +532,7 @@ HdChangeTracker::_MarkInstancerDirty(SdfPath const& id, HdDirtyBits bits) } if (bits & DirtyInstanceIndex) { toPropagate |= DirtyInstanceIndex; + ++_instanceIndicesChangeCount; } // Now mark any associated rprims or instancers dirty. @@ -1011,6 +1017,9 @@ HdChangeTracker::MarkAllRprimsDirty(HdDirtyBits bits) if ((bits & DirtyVisibility) != 0) { ++_visChangeCount; } + if ((bits & DirtyInstanceIndex) != 0) { + ++_instanceIndicesChangeCount; + } if ((bits & DirtyRenderTag) != 0) { ++_rprimRenderTagVersion; } @@ -1099,6 +1108,12 @@ HdChangeTracker::GetVisibilityChangeCount() const return _visChangeCount; } +unsigned +HdChangeTracker::GetInstanceIndicesChangeCount() const +{ + return _instanceIndicesChangeCount; +} + void HdChangeTracker::AddState(TfToken const& name) { diff --git a/pxr/imaging/hd/changeTracker.h b/pxr/imaging/hd/changeTracker.h index 35c4a76f32..988f8c1323 100644 --- a/pxr/imaging/hd/changeTracker.h +++ b/pxr/imaging/hd/changeTracker.h @@ -479,6 +479,12 @@ class HdChangeTracker HD_API unsigned GetVisibilityChangeCount() const; + /// Returns the number of changes to instance index. This is intended to be used + /// to detect when instance indices changed for *any* Rprim. Use in with + /// GetInstancerIndexVersion() to detect all changes to instance indices. + HD_API + unsigned GetInstanceIndicesChangeCount() const; + /// Returns the current version of varying state. This is used to refresh /// cached DirtyLists unsigned GetVaryingStateVersion() const { @@ -637,6 +643,9 @@ class HdChangeTracker // Used to detect that visibility changed somewhere in the render index. unsigned _visChangeCount; + // Used to detect that instance indices changed somewhere in the render index. + unsigned _instanceIndicesChangeCount; + // Used to detect changes to the render tag opinion of rprims. unsigned _rprimRenderTagVersion; From 6fd316ba456c1e57e6f9fbb9cae1428e7ab417ca Mon Sep 17 00:00:00 2001 From: Zhicheng Ye Date: Thu, 10 Feb 2022 12:02:25 +1100 Subject: [PATCH 003/285] Implement reverse lookup table in instanceAdapter to improve performance of getting proto prim --- pxr/usdImaging/usdImaging/instanceAdapter.cpp | 45 +++++++++++-------- pxr/usdImaging/usdImaging/instanceAdapter.h | 6 +++ 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/pxr/usdImaging/usdImaging/instanceAdapter.cpp b/pxr/usdImaging/usdImaging/instanceAdapter.cpp index 7327b8a46d..4ad8c73076 100644 --- a/pxr/usdImaging/usdImaging/instanceAdapter.cpp +++ b/pxr/usdImaging/usdImaging/instanceAdapter.cpp @@ -334,6 +334,13 @@ UsdImagingInstanceAdapter::_Populate(UsdPrim const& prim, instancerData.childPointInstancers.insert(protoPath); } + // Store cache path and instancer path mapping that + // helps to improve reversing lookup in `_GetProtoPrim()` + const auto& cacheIt = _protoPrimCacheMap.find(protoPath); + if (cacheIt == _protoPrimCacheMap.end()) { + _protoPrimCacheMap[protoPath] = instancerPath; + } + TF_DEBUG(USDIMAGING_INSTANCER).Msg( "[Add Instance NI] <%s> %s (%s), adapter = %s\n", instancerPath.GetText(), protoPath.GetText(), @@ -1355,6 +1362,11 @@ UsdImagingInstanceAdapter::_ResyncPath(SdfPath const& cachePath, } } + // Clear proto prim cache + if (!_protoPrimCacheMap.empty()) { + _protoPrimCacheMap.clear(); + } + // Actually resync everything. for (SdfPath const& instancer : instancersToUnload) { _ResyncInstancer(instancer, index, reload); @@ -2161,25 +2173,20 @@ UsdImagingInstanceAdapter::_GetProtoPrim(SdfPath const& instancerPath, // prim is not nested under the instancer, which causes the // instancerPath to be invalid in this context. // - // Tracking the non-child prims in a separate map would remove the need - // for this loop. - for (auto const& pathInstancerDataPair : _instancerData) { - _InstancerData const& instancer = pathInstancerDataPair.second; - _PrimMap::const_iterator protoIt = - instancer.primMap.find(cachePath); - if (protoIt != instancer.primMap.end()) { - // This is the correct instancer path for this prim. - instancerCachePath = pathInstancerDataPair.first; - materialUsdPath = - pathInstancerDataPair.second.materialUsdPath; - drawMode = - pathInstancerDataPair.second.drawMode; - inheritablePurpose = - pathInstancerDataPair.second.inheritablePurpose; - r = &protoIt->second; - break; - } - } + const auto& cacheIt = _protoPrimCacheMap.find(cachePath); + if (cacheIt != _protoPrimCacheMap.end()) { + const auto& instancerIt = _instancerData.find(cacheIt->second); + if (instancerIt != _instancerData.end()) { + const auto& protoIt = instancerIt->second.primMap.find(cachePath); + if (protoIt != instancerIt->second.primMap.end()) { + instancerCachePath = cacheIt->second; + materialUsdPath = instancerIt->second.materialUsdPath; + drawMode = instancerIt->second.drawMode; + inheritablePurpose = instancerIt->second.inheritablePurpose; + r = &protoIt->second; + } + } + } } if (!r) { diff --git a/pxr/usdImaging/usdImaging/instanceAdapter.h b/pxr/usdImaging/usdImaging/instanceAdapter.h index e76775296a..abe55b4890 100644 --- a/pxr/usdImaging/usdImaging/instanceAdapter.h +++ b/pxr/usdImaging/usdImaging/instanceAdapter.h @@ -621,6 +621,12 @@ class UsdImagingInstanceAdapter : public UsdImagingPrimAdapter typedef TfHashMultiMap _PrototypeToInstancerMap; _PrototypeToInstancerMap _prototypeToInstancerMap; + + // Map from instance cache path to their instancer path. + // Note: this is for reducing proto prim lookup in _GetProtoPrim method. + typedef std::unordered_map + _ProtoPrimCacheMap; + _ProtoPrimCacheMap _protoPrimCacheMap; }; From 38dd0a7debd85d6d1098817b0331ca3ade0c866e Mon Sep 17 00:00:00 2001 From: Alan Blevins Date: Thu, 17 Feb 2022 23:24:20 -0800 Subject: [PATCH 004/285] small fix to GfVec Slerp test --- pxr/base/gf/testenv/testGfVec.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pxr/base/gf/testenv/testGfVec.py b/pxr/base/gf/testenv/testGfVec.py index 2594d64d5e..6c9a831c62 100644 --- a/pxr/base/gf/testenv/testGfVec.py +++ b/pxr/base/gf/testenv/testGfVec.py @@ -504,7 +504,7 @@ def MethodsTest(self, Vec): v3 = Gf.Slerp(0.75, v1, v2) self.assertTrue(Gf.IsClose(v3, Vec(-.70711, 0, -.70711), eps)) v3 = Gf.Slerp(1, v1, v2) - self.assertTrue(Gf.IsClose(v3, v3, eps)) + self.assertTrue(Gf.IsClose(v3, v2, eps)) # test Slerp w/ opposing vectors SetVec( v1, [0,1,0] ) @@ -519,7 +519,7 @@ def MethodsTest(self, Vec): v3 = Gf.Slerp(0.75, v1, v2) self.assertTrue(Gf.IsClose(v3, Vec(0, -.70711, .70711), eps)) v3 = Gf.Slerp(1, v1, v2) - self.assertTrue(Gf.IsClose(v3, v3, eps)) + self.assertTrue(Gf.IsClose(v3, v2, eps)) def test_Types(self): vecTypes = [Gf.Vec2d, From f96b8f37365da1a5657807479dd51d505663ca2e Mon Sep 17 00:00:00 2001 From: Mark Tucker Date: Fri, 18 Feb 2022 22:58:20 -0500 Subject: [PATCH 005/285] Change Usd_Clip to hold a shared pointer to the array of time mappings. Set up this array in Usd_ClipSet where all the Usd_Clip objects are allocated. Prevents N^2 memory usage on the number of time mappings in a clip set. --- pxr/usd/usd/clip.cpp | 100 ++++++++++++---------------------------- pxr/usd/usd/clip.h | 23 ++++++++- pxr/usd/usd/clipSet.cpp | 33 +++++++++++-- 3 files changed, 80 insertions(+), 76 deletions(-) diff --git a/pxr/usd/usd/clip.cpp b/pxr/usd/usd/clip.cpp index 9860158f2d..99c53cf901 100644 --- a/pxr/usd/usd/clip.cpp +++ b/pxr/usd/usd/clip.cpp @@ -69,23 +69,6 @@ UsdGetClipRelatedFields() }; } -struct Usd_SortByExternalTime -{ - bool - operator()(const Usd_Clip::TimeMapping& x, - const Usd_Clip::ExternalTime y) const - { - return x.externalTime < y; - } - - bool - operator()(const Usd_Clip::TimeMapping& x, - const Usd_Clip::TimeMapping& y) const - { - return x.externalTime < y.externalTime; - } -}; - std::ostream& operator<<(std::ostream& out, const Usd_ClipRefPtr& clip) { @@ -118,7 +101,7 @@ Usd_Clip::Usd_Clip( ExternalTime clipAuthoredStartTime, ExternalTime clipStartTime, ExternalTime clipEndTime, - const TimeMappings& timeMapping) + const std::shared_ptr &timeMapping) : sourceLayerStack(clipSourceLayerStack) , sourcePrimPath(clipSourcePrimPath) , sourceLayerIndex(clipSourceLayerIndex) @@ -129,29 +112,6 @@ Usd_Clip::Usd_Clip( , endTime(clipEndTime) , times(timeMapping) { - if (!times.empty()) { - // Maintain the relative order of entries with the same stage time for - // jump discontinuities in case the authored times array was unsorted. - std::stable_sort(times.begin(), times.end(), Usd_SortByExternalTime()); - - // Jump discontinuities are represented by consecutive entries in the - // times array with the same stage time, e.g. (10, 10), (10, 0). - // We represent this internally as (10 - SafeStep(), 10), (10, 0) - // because a lot of the desired behavior just falls out from this - // representation. - for (size_t i = 0; i < times.size() - 1; ++i) { - if (times[i].externalTime == times[i + 1].externalTime) { - times[i].externalTime = - times[i].externalTime - UsdTimeCode::SafeStep(); - times[i].isJumpDiscontinuity = true; - } - } - - // Add sentinel values to the beginning and end for convenience. - times.insert(times.begin(), times.front()); - times.insert(times.end(), times.back()); - } - // For performance reasons, we want to defer the loading of the layer // for this clip until absolutely needed. However, if the layer happens // to already be opened, we can take advantage of that here. @@ -195,8 +155,8 @@ _GetBracketingTimeSegment( } else { *m2 = std::distance(times.begin(), - std::lower_bound(times.begin(), times.end(), - time, Usd_SortByExternalTime())); + std::lower_bound(times.begin(), times.end(), + time, Usd_Clip::Usd_SortByExternalTime())); *m1 = *m2 - 1; } @@ -336,7 +296,7 @@ Usd_Clip::_GetBracketingTimeSamplesForPathFromClipLayer( // s2, since s2 is in the range of (m2, m3), we use those mappings to map // s2 to e2. So, our final answer is (e1, e2). size_t m1, m2; - if (!_GetBracketingTimeSegment(times, time, &m1, &m2)) { + if (!_GetBracketingTimeSegment(*times, time, &m1, &m2)) { *tLower = lowerInClip; *tUpper = upperInClip; return true; @@ -389,11 +349,11 @@ Usd_Clip::_GetBracketingTimeSamplesForPathFromClipLayer( }; for (int i1 = m1, i2 = m2; i1 >= 0 && i2 >= 0; --i1, --i2) { - if (_CanTranslate(times, i1, i2, /*lower=*/true)) { break; } + if (_CanTranslate(*times, i1, i2, /*lower=*/true)) { break; } } - for (size_t i1 = m1, i2 = m2, sz = times.size(); i1 < sz && i2 < sz; ++i1, ++i2) { - if (_CanTranslate(times, i1, i2, /*lower=*/false)) { break; } + for (size_t i1 = m1, i2 = m2, sz = times->size(); i1 < sz && i2 < sz; ++i1, ++i2) { + if (_CanTranslate(*times, i1, i2, /*lower=*/false)) { break; } } if (translatedLower && !translatedUpper) { @@ -414,18 +374,18 @@ Usd_Clip::_GetBracketingTimeSamplesForPathFromClipLayer( // // The 'timingOutsideClip' test case in testUsdModelClips exercises // this behavior. - if (lowerInClip < times.front().internalTime) { - translatedLower.reset(times.front().externalTime); + if (lowerInClip < times->front().internalTime) { + translatedLower.reset(times->front().externalTime); } - else if (lowerInClip > times.back().internalTime) { - translatedLower.reset(times.back().externalTime); + else if (lowerInClip > times->back().internalTime) { + translatedLower.reset(times->back().externalTime); } - if (upperInClip < times.front().internalTime) { - translatedUpper.reset(times.front().externalTime); + if (upperInClip < times->front().internalTime) { + translatedUpper.reset(times->front().externalTime); } - else if (upperInClip > times.back().internalTime) { - translatedUpper.reset(times.back().externalTime); + else if (upperInClip > times->back().internalTime) { + translatedUpper.reset(times->back().externalTime); } } @@ -452,7 +412,7 @@ Usd_Clip::GetBracketingTimeSamplesForPath( // Each external time in the clip times array is considered a time // sample. if (_GetBracketingTimeSamples( - times.cbegin(), times.cend(), time, + times->cbegin(), times->cend(), time, &bracketingTimes[numTimes], &bracketingTimes[numTimes + 1])) { numTimes += 2; } @@ -505,7 +465,7 @@ Usd_Clip::_ListTimeSamplesForPathFromClipLayer( { std::set timeSamplesInClip = _GetLayerForClip()->ListTimeSamplesForPath(_TranslatePathToClip(path)); - if (times.empty()) { + if (times->empty()) { *timeSamples = std::move(timeSamplesInClip); // Filter out all samples that are outside the clip's active range @@ -528,9 +488,9 @@ Usd_Clip::_ListTimeSamplesForPathFromClipLayer( // To deal with this, every internal time sample has to be checked // against the entire mapping function. for (InternalTime t: timeSamplesInClip) { - for (size_t i = 0; i < times.size() - 1; ++i) { - const TimeMapping& m1 = times[i]; - const TimeMapping& m2 = times[i+1]; + for (size_t i = 0; i < times->size() - 1; ++i) { + const TimeMapping& m1 = (*times)[i]; + const TimeMapping& m2 = (*times)[i+1]; // Ignore time mappings whose external time domain does not // intersect the times at which this clip is active. @@ -576,7 +536,7 @@ Usd_Clip::ListTimeSamplesForPath(const SdfPath& path) const // Each entry in the clip's time mapping is considered a time sample, // so add them in here. - for (const TimeMapping& t : times) { + for (const TimeMapping& t : *times) { if (startTime <= t.externalTime && t.externalTime < endTime) { timeSamples.insert(t.externalTime); } @@ -651,12 +611,12 @@ Usd_Clip::InternalTime Usd_Clip::_TranslateTimeToInternal(ExternalTime extTime) const { size_t i1, i2; - if (!_GetBracketingTimeSegment(times, extTime, &i1, &i2)) { + if (!_GetBracketingTimeSegment(*times, extTime, &i1, &i2)) { return extTime; } - const TimeMapping& m1 = times[i1]; - const TimeMapping& m2 = times[i2]; + const TimeMapping& m1 = (*times)[i1]; + const TimeMapping& m2 = (*times)[i2]; // If the time segment ends on the left side of a jump discontinuity // we use the authored external time for the translation. @@ -681,8 +641,8 @@ Usd_Clip::_TranslateTimeToInternal(ExternalTime extTime) const // This avoids all of the issues above and more closely matches the intent // expressed in the authored times metadata. if (m2.isJumpDiscontinuity) { - TF_VERIFY(i2 + 1 < times.size()); - const TimeMapping& m3 = times[i2 + 1]; + TF_VERIFY(i2 + 1 < times->size()); + const TimeMapping& m3 = (*times)[i2 + 1]; return _TranslateTimeToInternalHelper( extTime, m1, TimeMapping(m3.externalTime, m2.internalTime)); } @@ -718,8 +678,8 @@ Usd_Clip::ExternalTime Usd_Clip::_TranslateTimeToExternal( InternalTime intTime, size_t i1, size_t i2) const { - const TimeMapping& m1 = times[i1]; - const TimeMapping& m2 = times[i2]; + const TimeMapping& m1 = (*times)[i1]; + const TimeMapping& m2 = (*times)[i2]; // Clients should never be trying to map an internal time through a jump // discontinuity. @@ -747,8 +707,8 @@ Usd_Clip::_TranslateTimeToExternal( // This avoids all of the issues above and more closely matches the intent // expressed in the authored times metadata. if (m2.isJumpDiscontinuity) { - TF_VERIFY(i2 + 1 < times.size()); - const TimeMapping& m3 = times[i2 + 1]; + TF_VERIFY(i2 + 1 < times->size()); + const TimeMapping& m3 = (*times)[i2 + 1]; return _TranslateTimeToExternalHelper( intTime, m1, TimeMapping(m3.externalTime, m2.internalTime)); } diff --git a/pxr/usd/usd/clip.h b/pxr/usd/usd/clip.h index 9224ebb65c..acdb317fe5 100644 --- a/pxr/usd/usd/clip.h +++ b/pxr/usd/usd/clip.h @@ -105,6 +105,25 @@ struct Usd_Clip typedef std::vector TimeMappings; + /// Structure used to sort TimeMapping objects. Used by both Usd_Clip and + /// Usd_ClipSet. + struct Usd_SortByExternalTime + { + bool + operator()(const Usd_Clip::TimeMapping& x, + const Usd_Clip::ExternalTime y) const + { + return x.externalTime < y; + } + + bool + operator()(const Usd_Clip::TimeMapping& x, + const Usd_Clip::TimeMapping& y) const + { + return x.externalTime < y.externalTime; + } + }; + Usd_Clip(); Usd_Clip( const PcpLayerStackPtr& clipSourceLayerStack, @@ -115,7 +134,7 @@ struct Usd_Clip ExternalTime clipAuthoredStartTime, ExternalTime clipStartTime, ExternalTime clipEndTime, - const TimeMappings& timeMapping); + const std::shared_ptr &timeMapping); bool HasField(const SdfPath& path, const TfToken& field) const; @@ -201,7 +220,7 @@ struct Usd_Clip ExternalTime endTime; /// Mapping of external to internal times. - TimeMappings times; + std::shared_ptr times; private: friend class UsdStage; diff --git a/pxr/usd/usd/clipSet.cpp b/pxr/usd/usd/clipSet.cpp index 93d637d34a..485ca01d42 100644 --- a/pxr/usd/usd/clipSet.cpp +++ b/pxr/usd/usd/clipSet.cpp @@ -351,15 +351,40 @@ Usd_ClipSet::Usd_ClipSet( } // Generate the clip time mapping that applies to all clips. - Usd_Clip::TimeMappings timeMapping; + std::shared_ptr times(new Usd_Clip::TimeMappings()); if (clipDef.clipTimes) { for (const auto& clipTime : *clipDef.clipTimes) { const Usd_Clip::ExternalTime extTime = clipTime[0]; const Usd_Clip::InternalTime intTime = clipTime[1]; - timeMapping.push_back(Usd_Clip::TimeMapping(extTime, intTime)); + times->push_back(Usd_Clip::TimeMapping(extTime, intTime)); } } + if (!times->empty()) { + // Maintain the relative order of entries with the same stage time for + // jump discontinuities in case the authored times array was unsorted. + std::stable_sort(times->begin(), times->end(), + Usd_Clip::Usd_SortByExternalTime()); + + // Jump discontinuities are represented by consecutive entries in the + // times array with the same stage time, e.g. (10, 10), (10, 0). + // We represent this internally as (10 - SafeStep(), 10), (10, 0) + // because a lot of the desired behavior just falls out from this + // representation. + for (size_t i = 0; i < times->size() - 1; ++i) { + if ((*times)[i].externalTime == (*times)[i + 1].externalTime) { + (*times)[i].externalTime = + (*times)[i].externalTime - UsdTimeCode::SafeStep(); + (*times)[i].isJumpDiscontinuity = true; + } + } + + // Add sentinel values to the beginning and end for convenience. + times->insert(times->begin(), times->front()); + times->insert(times->end(), times->back()); + } + + // Build up the final vector of clips. const _TimeToClipMap::const_iterator itBegin = startTimeToClip.begin(); const _TimeToClipMap::const_iterator itEnd = startTimeToClip.end(); @@ -384,7 +409,7 @@ Usd_ClipSet::Usd_ClipSet( /* clipAuthoredStartTime = */ clipEntry.startTime, /* clipStartTime = */ clipStartTime, /* clipEndTime = */ clipEndTime, - /* clipTimes = */ timeMapping)); + /* clipTimes = */ times)); valueClips.push_back(clip); } @@ -416,7 +441,7 @@ Usd_ClipSet::Usd_ClipSet( /* clipAuthoredStartTime= */ Usd_ClipTimesEarliest, /* clipStartTime = */ Usd_ClipTimesEarliest, /* clipEndTime = */ Usd_ClipTimesLatest, - /* clipTimes = */ Usd_Clip::TimeMappings())); + /* clipTimes = */ std::make_shared())); if (generatedManifest) { // If we generated a manifest layer pull on the clip so that it takes From ac3ca253e643a095e0985264238be28b95109a44 Mon Sep 17 00:00:00 2001 From: Jerry Gamache Date: Tue, 14 Dec 2021 16:18:23 -0500 Subject: [PATCH 006/285] Update to MaterialX v1.38.3 - Use CMake config directly from MaterialX install - Update for API and library changes in v1.38.3 - Strenghten NodeDef discovery This is the last update that is not version tagged in the C++ code. Future updates will be bracketed using MATERIALX_MINOR_VERSION defines introduced in v1.38.3. --- BUILDING.md | 6 +- build_scripts/build_usd.py | 35 ++++- cmake/modules/FindMaterialX.cmake | 139 ------------------ pxr/imaging/hdMtlx/CMakeLists.txt | 6 +- pxr/imaging/hdMtlx/hdMtlx.h | 6 +- pxr/imaging/hdSt/CMakeLists.txt | 10 +- pxr/imaging/hdSt/materialXFilter.cpp | 4 +- pxr/imaging/hdSt/materialXShaderGen.cpp | 15 +- pxr/usd/usdMtlx/CMakeLists.txt | 6 +- pxr/usd/usdMtlx/reader.cpp | 19 ++- pxr/usd/usdMtlx/utils.cpp | 2 +- pxr/usdImaging/bin/usdBakeMtlx/CMakeLists.txt | 5 +- .../bin/usdBakeMtlx/bakeMaterialX.h | 6 +- .../plugin/hdPrman/CMakeLists.txt | 10 +- 14 files changed, 90 insertions(+), 179 deletions(-) delete mode 100644 cmake/modules/FindMaterialX.cmake diff --git a/BUILDING.md b/BUILDING.md index d62efeb53b..7105213ff8 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -273,9 +273,9 @@ Linux and MacOS. The additional dependencies that must be supplied when invoking cmake are: -| Dependency Name | Description | -| ------------------ |---------------------------------------- | -| MATERIALX_ROOT | The root path to a MaterialX SDK install.| +| Dependency Name | Description | +| ------------------ |----------------------------------------------------------- | +| MaterialX_DIR | Path to the CMake package config of a MaterialX SDK install.| See [3rd Party Library and Application Versions](VERSIONS.md) for version information. diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py index 7c27a2aa33..80115c9482 100644 --- a/build_scripts/build_usd.py +++ b/build_scripts/build_usd.py @@ -1349,20 +1349,43 @@ def InstallDraco(context, force, buildArgs): ############################################################ # MaterialX -MATERIALX_URL = "https://github.com/materialx/MaterialX/archive/v1.38.0.zip" +MATERIALX_URL = "https://github.com/materialx/MaterialX/archive/v1.38.3.zip" def InstallMaterialX(context, force, buildArgs): with CurrentWorkingDirectory(DownloadURL(MATERIALX_URL, context, force)): - # USD requires MaterialX to be built as a shared library on Linux and MacOS - # Currently MaterialX does not support shared builds on Windows - cmakeOptions = [] - if Linux() or MacOS(): - cmakeOptions += ['-DMATERIALX_BUILD_SHARED_LIBS=ON'] + cmakeOptions = ['-DMATERIALX_BUILD_SHARED_LIBS=ON'] cmakeOptions += buildArgs; + if "v1.38.3.zip" in MATERIALX_URL: + # This will be fixed in v1.38.4: + PatchFile(os.path.join('cmake', 'modules', 'MaterialXConfig.cmake.in'), + [('set_and_check(MATERIALX_PYTHON_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/python")\n', + 'IF (@MATERIALX_BUILD_PYTHON@ AND @MATERIALX_INSTALL_PYTHON@)\n' + ' set_and_check(MATERIALX_PYTHON_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/python")\n' + 'ENDIF()\n')], + multiLineMatches=True) + RunCMake(context, force, cmakeOptions) + if "v1.38.3.zip" in MATERIALX_URL: + # This will be fixed in v1.38.4: + # Post-build fix. Make sure MaterialX config is relocatable: + filename = os.path.join(context.instDir, 'lib', 'cmake', 'MaterialX', 'MaterialXTargets.cmake') + oldLines = open(filename, 'r').readlines() + newLines = [] + for s in oldLines: + if s.startswith('set(_IMPORT_PREFIX '): + pathBegin = s.find(' ') + 1 + pathEnd = s.rfind(')') + s = s[:pathBegin] + '${PACKAGE_PREFIX_DIR}' + s[pathEnd:] + newLines.append(s) + if newLines != oldLines: + PrintInfo("Patching file {filename} (original in {oldFilename})..." + .format(filename=filename, oldFilename=filename + ".old")) + shutil.copy(filename, filename + ".old") + open(filename, 'w').writelines(newLines) + MATERIALX = Dependency("MaterialX", InstallMaterialX, "include/MaterialXCore/Library.h") ############################################################ diff --git a/cmake/modules/FindMaterialX.cmake b/cmake/modules/FindMaterialX.cmake deleted file mode 100644 index 3780834143..0000000000 --- a/cmake/modules/FindMaterialX.cmake +++ /dev/null @@ -1,139 +0,0 @@ -# -# Copyright 2018 Pixar -# -# Licensed under the Apache License, Version 2.0 (the "Apache License") -# with the following modification; you may not use this file except in -# compliance with the Apache License and the following modification to it: -# Section 6. Trademarks. is deleted and replaced with: -# -# 6. Trademarks. This License does not grant permission to use the trade -# names, trademarks, service marks, or product names of the Licensor -# and its affiliates, except as required to comply with Section 4(c) of -# the License and to reproduce the content of the NOTICE file. -# -# You may obtain a copy of the Apache License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the Apache License with the above modification is -# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the Apache License for the specific -# language governing permissions and limitations under the Apache License. -# -# - Find MaterialX Development Kit -# -# Finds an installed MaterialX Development Kit -# -# Variables that will be defined: -# MATERIALX_FOUND Defined if MaterialX has been detected -# MATERIALX_BASE_DIR Path to the root of the MaterialX installation -# MATERIALX_INCLUDE_DIRS Path to the MaterialX include directories -# MATERIALX_LIB_DIRS Path to the MaterialX library directories -# MATERIALX_STDLIB_DIR Path to the MaterialX standard library directory -# MATERIALX_LIBRARIES List of MaterialX libraries - -# -# In: -# MATERIALX_ROOT Path to the root of the MaterialX installation -# MATERIALX_DATA_ROOT Path where MaterialX data files (libraries and -# resources) are installed, if different from -# MATERIALX_ROOT -# -# Out: -# MATERIALX_FOUND -# MATERIALX_INCLUDE_DIRS -# MATERIALX_LIB_DIRS -# MATERIALX_LIBRARIES - -find_path(MATERIALX_BASE_DIR - NAMES - include/MaterialXCore/Library.h - HINTS - "${MATERIALX_ROOT}" - "$ENV{MATERIALX_ROOT}" - ) - -find_path(MATERIALX_INCLUDE_DIRS - MaterialXCore/Library.h - HINTS - "${MATERIALX_ROOT}" - "$ENV{MATERIALX_ROOT}" - "${MATERIALX_BASE_DIR}" - PATH_SUFFIXES - include - DOC - "MaterialX Header Path" -) - -if (WIN32) - set(MATERIALX_CORE_STATIC_LIB_NAME MaterialXCore.lib) - set(MATERIALX_CORE_DYNAMIC_LIB_NAME MaterialXCore.dll) -else() - set(MATERIALX_CORE_STATIC_LIB_NAME libMaterialXCore.a) - if (APPLE) - set(MATERIALX_CORE_DYNAMIC_LIB_NAME libMaterialXCore.dylib) - else() - set(MATERIALX_CORE_DYNAMIC_LIB_NAME libMaterialXCore.so) - endif() -endif() - -find_path(MATERIALX_LIB_DIRS - "${MATERIALX_CORE_STATIC_LIB_NAME}" - "${MATERIALX_CORE_DYNAMIC_LIB_NAME}" - HINTS - "${MATERIALX_ROOT}" - "$ENV{MATERIALX_ROOT}" - "${MATERIALX_BASE_DIR}" - PATH_SUFFIXES - lib - DOC - "MaterialX Library Path" -) - -find_path(MATERIALX_STDLIB_DIR - stdlib/stdlib_defs.mtlx - HINTS - "${MATERIALX_ROOT}" - "$ENV{MATERIALX_ROOT}" - "${MATERIALX_BASE_DIR}" - "${MATERIALX_DATA_ROOT}" - PATH_SUFFIXES - libraries - DOC - "MaterialX Standard Libraries Path" -) - -foreach(MATERIALX_LIB - Core - Format - GenGlsl - GenOsl - GenShader - Render - RenderGlsl - RenderHw - RenderOsl - ) - find_library(MATERIALX_${MATERIALX_LIB}_LIBRARY - MaterialX${MATERIALX_LIB} - HINTS - "${MATERIALX_LIB_DIRS}" - DOC - "MaterialX's ${MATERIALX_LIB} library path" - NO_CMAKE_SYSTEM_PATH - ) - - if (MATERIALX_${MATERIALX_LIB}_LIBRARY) - list(APPEND MATERIALX_LIBRARIES ${MATERIALX_${MATERIALX_LIB}_LIBRARY}) - endif () -endforeach() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(MaterialX - REQUIRED_VARS - MATERIALX_BASE_DIR - MATERIALX_INCLUDE_DIRS - MATERIALX_LIB_DIRS - MATERIALX_STDLIB_DIR -) diff --git a/pxr/imaging/hdMtlx/CMakeLists.txt b/pxr/imaging/hdMtlx/CMakeLists.txt index 37fce0b0a2..1947b42f13 100644 --- a/pxr/imaging/hdMtlx/CMakeLists.txt +++ b/pxr/imaging/hdMtlx/CMakeLists.txt @@ -11,10 +11,8 @@ pxr_library(hdMtlx trace usdMtlx vt - ${MATERIALX_LIBRARIES} - - INCLUDE_DIRS - ${MATERIALX_INCLUDE_DIRS} + MaterialXCore + MaterialXFormat PUBLIC_CLASSES hdMtlx diff --git a/pxr/imaging/hdMtlx/hdMtlx.h b/pxr/imaging/hdMtlx/hdMtlx.h index ca2281f03a..552d039f9d 100644 --- a/pxr/imaging/hdMtlx/hdMtlx.h +++ b/pxr/imaging/hdMtlx/hdMtlx.h @@ -31,11 +31,13 @@ #include #include -namespace MaterialX { +#include + +MATERIALX_NAMESPACE_BEGIN class FileSearchPath; using DocumentPtr = std::shared_ptr; using StringMap = std::unordered_map; -} +MATERIALX_NAMESPACE_END PXR_NAMESPACE_OPEN_SCOPE diff --git a/pxr/imaging/hdSt/CMakeLists.txt b/pxr/imaging/hdSt/CMakeLists.txt index 2fde872ba0..8e40f6bbd0 100644 --- a/pxr/imaging/hdSt/CMakeLists.txt +++ b/pxr/imaging/hdSt/CMakeLists.txt @@ -14,8 +14,14 @@ set(optionalIncludeDirs "") set(optionalPublicClasses "") set(optionalPrivateClasses "") if (${PXR_ENABLE_MATERIALX_SUPPORT}) - list(APPEND optionalLibs ${MATERIALX_LIBRARIES} hdMtlx) - list(APPEND optionalIncludeDirs ${MATERIALX_INCLUDE_DIRS}) + list(APPEND optionalLibs + MaterialXGenShader + MaterialXRender + MaterialXCore + MaterialXFormat + MaterialXGenGlsl + hdMtlx + ) list(APPEND optionalPrivateClasses materialXFilter materialXShaderGen diff --git a/pxr/imaging/hdSt/materialXFilter.cpp b/pxr/imaging/hdSt/materialXFilter.cpp index 7b18ca7fcc..788e774133 100644 --- a/pxr/imaging/hdSt/materialXFilter.cpp +++ b/pxr/imaging/hdSt/materialXFilter.cpp @@ -68,8 +68,8 @@ TF_DEFINE_PRIVATE_TOKENS( static mx::ShaderPtr _GenMaterialXShader(mx::GenContext & mxContext, mx::ElementPtr const& mxElem) { - bool hasTransparency = mx::isTransparentSurface(mxElem, - mxContext.getShaderGenerator()); + bool hasTransparency = mx::isTransparentSurface(mxElem, + mxContext.getShaderGenerator().getTarget()); mx::GenContext materialContext = mxContext; materialContext.getOptions().hwTransparency = hasTransparency; diff --git a/pxr/imaging/hdSt/materialXShaderGen.cpp b/pxr/imaging/hdSt/materialXShaderGen.cpp index c8232bd0b9..85f6eb9531 100644 --- a/pxr/imaging/hdSt/materialXShaderGen.cpp +++ b/pxr/imaging/hdSt/materialXShaderGen.cpp @@ -273,8 +273,8 @@ HdStMaterialXShaderGen::_EmitMxFunctions( mx::ShaderStage& mxStage) const { // Add global constants and type definitions - emitInclude("pbrlib/" + mx::GlslShaderGenerator::TARGET - + "/lib/mx_defines.glsl", mxContext, mxStage); + emitInclude("stdlib/" + mx::GlslShaderGenerator::TARGET + + "/lib/mx_math.glsl", mxContext, mxStage); emitLine("#if NUM_LIGHTS > 0", mxStage, false); emitLine("#define MAX_LIGHT_SOURCES NUM_LIGHTS", mxStage, false); emitLine("#else", mxStage, false); @@ -386,11 +386,6 @@ HdStMaterialXShaderGen::_EmitMxFunctions( _EmitMxInitFunction(vertexData, mxStage); } - // Emit common math functions - emitInclude("pbrlib/" + mx::GlslShaderGenerator::TARGET - + "/lib/mx_math.glsl", mxContext, mxStage); - emitLineBreak(mxStage); - // Emit lighting and shadowing code if (lighting) { emitSpecularEnvironment(mxContext, mxStage); @@ -427,6 +422,9 @@ HdStMaterialXShaderGen::_EmitMxFunctions( emitInclude(ShaderGenerator::T_FILE_TRANSFORM_UV, mxContext, mxStage); } + // Add light sampling functions + emitLightFunctionDefinitions(mxGraph, mxContext, mxStage); + // Add all functions for node implementations emitFunctionDefinitions(mxGraph, mxContext, mxStage); } @@ -448,7 +446,8 @@ HdStMaterialXShaderGen::_EmitMxSurfaceShader( emitLine("mxInit(Peye, Neye)", mxStage); const mx::ShaderGraphOutputSocket* outputSocket = mxGraph.getOutputSocket(); - if (mxGraph.hasClassification(mx::ShaderNode::Classification::CLOSURE)) { + if (mxGraph.hasClassification(mx::ShaderNode::Classification::CLOSURE) && + !mxGraph.hasClassification(mx::ShaderNode::Classification::SHADER)) { // Handle the case where the mxGraph is a direct closure. // We don't support rendering closures without attaching // to a surface shader, so just output black. diff --git a/pxr/usd/usdMtlx/CMakeLists.txt b/pxr/usd/usdMtlx/CMakeLists.txt index c4504abcd2..5d919832bc 100644 --- a/pxr/usd/usdMtlx/CMakeLists.txt +++ b/pxr/usd/usdMtlx/CMakeLists.txt @@ -19,10 +19,8 @@ pxr_library(usdMtlx usdShade usdUI usdUtils - ${MATERIALX_LIBRARIES} - - INCLUDE_DIRS - ${MATERIALX_INCLUDE_DIRS} + MaterialXCore + MaterialXFormat CPPFILES debugCodes.cpp diff --git a/pxr/usd/usdMtlx/reader.cpp b/pxr/usd/usdMtlx/reader.cpp index d99b7d0dbe..c5cbd1793c 100644 --- a/pxr/usd/usdMtlx/reader.cpp +++ b/pxr/usd/usdMtlx/reader.cpp @@ -288,6 +288,7 @@ _FindMatchingNodeDef( const mx::ConstDocumentPtr& mtlxDocument, const mx::ConstInterfaceElementPtr& mtlxInterface, const std::string& family, + const std::string& type, const NdrVersion& version, const std::string& target) { @@ -300,7 +301,11 @@ _FindMatchingNodeDef( } // Filter by types. - if (mtlxInterface && !mtlxInterface->isTypeCompatible(mtlxNodeDef)) { + if (mtlxInterface && !mtlxInterface->hasExactInputMatch(mtlxNodeDef)) { + continue; + } + + if (mtlxNodeDef->getType() != type) { continue; } @@ -347,6 +352,7 @@ _FindMatchingNodeDef( auto nodeDef = _FindMatchingNodeDef(mtlxShaderNode->getDocument(), mtlxInterface, mtlxShaderNode->getCategory(), + mtlxShaderNode->getType(), UsdMtlxGetVersion(mtlxShaderNode), mtlxShaderNode->getTarget()); if (nodeDef) { @@ -355,9 +361,18 @@ _FindMatchingNodeDef( // Get the standard library document and check that. static auto standardLibraryDocument = UsdMtlxGetDocument(""); + + if (mtlxShaderNode->hasNodeDefString()) { + nodeDef = standardLibraryDocument->getNodeDef(mtlxShaderNode->getNodeDefString()); + if (nodeDef) { + return nodeDef; + } + } + return _FindMatchingNodeDef(standardLibraryDocument, mtlxInterface, mtlxShaderNode->getCategory(), + mtlxShaderNode->getType(), UsdMtlxGetVersion(mtlxShaderNode), mtlxShaderNode->getTarget()); } @@ -1316,7 +1331,7 @@ _Context::AddShaderNode(const mx::ConstNodePtr& mtlxShaderNode) // Get the nodeDef for this shaderNode. mx::ConstNodeDefPtr mtlxNodeDef = mtlxShaderNode->getNodeDef(); - if (mtlxShaderNode->getNodeDefString().empty()) { + if (!mtlxNodeDef) { // The shaderNode specified a node instead of a nodeDef. Find // the best matching nodedef since the MaterialX API doesn't. mtlxNodeDef = diff --git a/pxr/usd/usdMtlx/utils.cpp b/pxr/usd/usdMtlx/utils.cpp index 943494e3c1..9701fd710f 100644 --- a/pxr/usd/usdMtlx/utils.cpp +++ b/pxr/usd/usdMtlx/utils.cpp @@ -311,7 +311,7 @@ _ReadFromAsset(mx::DocumentPtr doc, const ArResolvedPath& resolvedPath, newReadOptions); }; - mx::readFromXmlString(doc, s, &readOptions); + mx::readFromXmlString(doc, s, searchPath, &readOptions); } #endif diff --git a/pxr/usdImaging/bin/usdBakeMtlx/CMakeLists.txt b/pxr/usdImaging/bin/usdBakeMtlx/CMakeLists.txt index 2b60220580..96466929a7 100644 --- a/pxr/usdImaging/bin/usdBakeMtlx/CMakeLists.txt +++ b/pxr/usdImaging/bin/usdBakeMtlx/CMakeLists.txt @@ -15,11 +15,12 @@ pxr_library(usdBakeMtlx hd hdMtlx usdImaging - ${MATERIALX_LIBRARIES} + MaterialXCore + MaterialXFormat + MaterialXRenderGlsl INCLUDE_DIRS ${Boost_INCLUDE_DIRS} - ${MATERIALX_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} PUBLIC_CLASSES diff --git a/pxr/usdImaging/bin/usdBakeMtlx/bakeMaterialX.h b/pxr/usdImaging/bin/usdBakeMtlx/bakeMaterialX.h index c14437bf7e..201fb4b419 100644 --- a/pxr/usdImaging/bin/usdBakeMtlx/bakeMaterialX.h +++ b/pxr/usdImaging/bin/usdBakeMtlx/bakeMaterialX.h @@ -30,13 +30,15 @@ #include "pxr/imaging/hd/material.h" #include "pxr/usd/usdShade/material.h" +#include + #include "pxr/base/tf/declarePtrs.h" #include -namespace MaterialX { +MATERIALX_NAMESPACE_BEGIN using FilePathVec = std::vector; class FileSearchPath; -} +MATERIALX_NAMESPACE_END PXR_NAMESPACE_OPEN_SCOPE diff --git a/third_party/renderman-24/plugin/hdPrman/CMakeLists.txt b/third_party/renderman-24/plugin/hdPrman/CMakeLists.txt index 6424e4113d..dee21d5a5f 100644 --- a/third_party/renderman-24/plugin/hdPrman/CMakeLists.txt +++ b/third_party/renderman-24/plugin/hdPrman/CMakeLists.txt @@ -22,8 +22,14 @@ endif() set(optionalIncludeDirs "") set(optionalPublicClasses "") if (${PXR_ENABLE_MATERIALX_SUPPORT}) - list(APPEND optionalLibs ${MATERIALX_LIBRARIES} hdMtlx) - list(APPEND optionalIncludeDirs ${MATERIALX_INCLUDE_DIRS}) + list(APPEND optionalLibs + MaterialXCore + MaterialXFormat + MaterialXGenShader + MaterialXGenOsl + MaterialXRender + hdMtlx + ) list(APPEND optionalPublicClasses matfiltMaterialX) if (${PXR_ENABLE_OSL_SUPPORT}) From 535f6da758795b983c83dd02c5ac024f8e971bbc Mon Sep 17 00:00:00 2001 From: Paul Molodowitch Date: Wed, 24 Nov 2021 13:33:03 -0800 Subject: [PATCH 007/285] better detection of python lib / include dirs in build_usd.py This addresses two issues: - Building using a venv-installed python - The venv-installed pythons would try to pull the libraries from the venv-directory, when they only reside at the "original"\ installed python location - Building with a python that was moved after building on Linux - We experienced issues where the `INCLUDEPY` and `LIBDIR` sysconfig vars were baked at build time. Thus these would no longer be reliable if running a python executable that was moved to a different location after building. Note that or python-2.7, `installed_base` doesn't exist, so we fall back to `base`. This should be fairly backward-compatible, as we check if the dir (for include) or file (for lib) doesn't exist, and try alternate methods if not. --- build_scripts/build_usd.py | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py index 7c27a2aa33..7191d82d7d 100644 --- a/build_scripts/build_usd.py +++ b/build_scripts/build_usd.py @@ -226,20 +226,38 @@ def _GetPythonLibraryFilename(context): pythonLibPath = os.path.join(pythonBaseDir, "lib", _GetPythonLibraryFilename(context)) else: - pythonIncludeDir = sysconfig.get_config_var("INCLUDEPY") - if Windows(): + pythonIncludeDir = sysconfig.get_path("include") + if not pythonIncludeDir or not os.path.isdir(pythonIncludeDir): + # as a backup, and for legacy reasons - not preferred because + # it may be baked at build time + pythonIncludeDir = sysconfig.get_config_var("INCLUDEPY") + + # if in a venv, installed_base will be the "original" python, + # which is where the libs are ("base" will be the venv dir) + pythonBaseDir = sysconfig.get_config_var("installed_base") + if not pythonBaseDir or not os.path.isdir(pythonBaseDir): + # for python-2.7 pythonBaseDir = sysconfig.get_config_var("base") + + if Windows(): pythonLibPath = os.path.join(pythonBaseDir, "libs", _GetPythonLibraryFilename(context)) elif Linux(): - pythonLibDir = sysconfig.get_config_var("LIBDIR") pythonMultiarchSubdir = sysconfig.get_config_var("multiarchsubdir") - if pythonMultiarchSubdir: - pythonLibDir = pythonLibDir + pythonMultiarchSubdir - pythonLibPath = os.path.join(pythonLibDir, - _GetPythonLibraryFilename(context)) + # Try multiple ways to get the python lib dir + for pythonLibDir in (sysconfig.get_config_var("LIBDIR"), + os.path.join(pythonBaseDir, "lib")): + if pythonMultiarchSubdir: + pythonLibPath = \ + os.path.join(pythonLibDir + pythonMultiarchSubdir, + _GetPythonLibraryFilename(context)) + if os.path.isfile(pythonLibPath): + break + pythonLibPath = os.path.join(pythonLibDir, + _GetPythonLibraryFilename(context)) + if os.path.isfile(pythonLibPath): + break elif MacOS(): - pythonBaseDir = sysconfig.get_config_var("base") pythonLibPath = os.path.join(pythonBaseDir, "lib", _GetPythonLibraryFilename(context)) else: From 23ab43d36f2f7dd67809c74a3007f4f0ed0cad53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rob=20Piek=C3=A9?= Date: Mon, 7 Mar 2022 08:41:19 +0000 Subject: [PATCH 008/285] Copying behaviour from `lightAdapter` to consider *all* attributes for setting `DirtyParams` in `TrackVariability` --- pxr/usdImaging/usdImaging/cameraAdapter.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pxr/usdImaging/usdImaging/cameraAdapter.cpp b/pxr/usdImaging/usdImaging/cameraAdapter.cpp index 5c3453f30c..cffa06c8e7 100644 --- a/pxr/usdImaging/usdImaging/cameraAdapter.cpp +++ b/pxr/usdImaging/usdImaging/cameraAdapter.cpp @@ -199,6 +199,24 @@ UsdImagingCameraAdapter::TrackVariability(UsdPrim const& prim, false)) { return; } + + if ((*timeVaryingBits & HdCamera::DirtyParams) != 0) + return; + + // If any other camera attributes are time varying + // we will assume all camera params are time-varying. + const std::vector &attrs = prim.GetAttributes(); + for (UsdAttribute const& attr : attrs) { + // Don't double-count transform attrs. + if (UsdGeomXformable::IsTransformationAffectedByAttrNamed( + attr.GetBaseName())) { + continue; + } + if (attr.GetNumTimeSamples() > 1) { + *timeVaryingBits |= HdCamera::DirtyParams; + break; + } + } } void From 4aca63cd57a9fb8c676ecb5fc10513f759314a75 Mon Sep 17 00:00:00 2001 From: Chris Rydalch Date: Mon, 28 Mar 2022 13:32:23 -0500 Subject: [PATCH 009/285] Adds Plane primitive to UsdGeom. --- pxr/usd/usdGeom/CMakeLists.txt | 2 + pxr/usd/usdGeom/generatedSchema.usda | 127 +++++++ pxr/usd/usdGeom/module.cpp | 1 + pxr/usd/usdGeom/plane.cpp | 353 +++++++++++++++++ pxr/usd/usdGeom/plane.h | 355 ++++++++++++++++++ pxr/usd/usdGeom/plugInfo.json | 11 + pxr/usd/usdGeom/schema.usda | 60 +++ pxr/usd/usdGeom/tokens.cpp | 6 + pxr/usd/usdGeom/tokens.h | 24 +- pxr/usd/usdGeom/wrapPlane.cpp | 208 ++++++++++ pxr/usd/usdGeom/wrapTokens.cpp | 3 + pxr/usdImaging/usdImaging/CMakeLists.txt | 1 + .../usdImaging/implicitSurfaceMeshUtils.cpp | 53 +++ .../usdImaging/implicitSurfaceMeshUtils.h | 27 ++ pxr/usdImaging/usdImaging/planeAdapter.cpp | 161 ++++++++ pxr/usdImaging/usdImaging/planeAdapter.h | 108 ++++++ pxr/usdImaging/usdImaging/plugInfo.json | 7 + 17 files changed, 1501 insertions(+), 6 deletions(-) create mode 100644 pxr/usd/usdGeom/plane.cpp create mode 100644 pxr/usd/usdGeom/plane.h create mode 100644 pxr/usd/usdGeom/wrapPlane.cpp create mode 100644 pxr/usdImaging/usdImaging/planeAdapter.cpp create mode 100644 pxr/usdImaging/usdImaging/planeAdapter.h diff --git a/pxr/usd/usdGeom/CMakeLists.txt b/pxr/usd/usdGeom/CMakeLists.txt index 49e4932347..d39e5949a7 100644 --- a/pxr/usd/usdGeom/CMakeLists.txt +++ b/pxr/usd/usdGeom/CMakeLists.txt @@ -42,6 +42,7 @@ pxr_library(usdGeom motionAPI nurbsCurves nurbsPatch + plane pointBased pointInstancer points @@ -86,6 +87,7 @@ pxr_library(usdGeom wrapMotionAPI.cpp wrapNurbsCurves.cpp wrapNurbsPatch.cpp + wrapPlane.cpp wrapPointBased.cpp wrapPointInstancer.cpp wrapPoints.cpp diff --git a/pxr/usd/usdGeom/generatedSchema.usda b/pxr/usd/usdGeom/generatedSchema.usda index bb1c11220b..30e74b41b9 100644 --- a/pxr/usd/usdGeom/generatedSchema.usda +++ b/pxr/usd/usdGeom/generatedSchema.usda @@ -1342,6 +1342,133 @@ class Cone "Cone" ( ) } +class Plane "Plane" ( + doc = """Defines a primitive plane, centered at the origin, and is defined by + a cardinal axis, width, and length. It is also double-sided. + + The axis of width and length are perpendicular to the plane's axis: + + axis | width | length + ----- | ------ | ------- + X | z-axis | y-axis + Y | x-axis | z-axis + Z | x-axis | y-axis + + """ +) +{ + uniform token axis = "Z" ( + allowedTokens = ["X", "Y", "Z"] + doc = """The axis along which the surface of the plane is aligned. When set + to 'Z' the plane is in the xy-plane; when axis is 'X' the plane is in + the yz-plane, and when axis is 'Y' the plane is in the xz-plane. + + \\sa UsdGeomGprim::GetAxisAttr().""" + ) + uniform bool doubleSided = 1 ( + doc = """Planes are double-sided by default, clients may also supported + single-sided planes. + + \\sa UsdGeomGprim::GetDoubleSidedAttr()""" + ) + float3[] extent = [(-1, -1, 0), (1, 1, 0)] ( + doc = """Extent is re-defined on Plane only to provide a fallback + value. \\sa UsdGeomGprim::GetExtentAttr().""" + ) + double length = 2 ( + doc = """The length of the plane, which aligns to the y-axis when axis is + 'Z' or 'X', or to the z-axis when axis is 'Y'. If you author length + you must also author extent. + + \\sa UsdGeomGprim::GetExtentAttr()""" + ) + uniform token orientation = "rightHanded" ( + allowedTokens = ["rightHanded", "leftHanded"] + doc = """Orientation specifies whether the gprim's surface normal + should be computed using the right hand rule, or the left hand rule. + Please see for a deeper explanation and + generalization of orientation to composed scenes with transformation + hierarchies.""" + ) + color3f[] primvars:displayColor ( + doc = '''It is useful to have an "official" colorSet that can be used + as a display or modeling color, even in the absence of any specified + shader for a gprim. DisplayColor serves this role; because it is a + UsdGeomPrimvar, it can also be used as a gprim override for any shader + that consumes a displayColor parameter.''' + ) + float[] primvars:displayOpacity ( + doc = """Companion to displayColor that specifies opacity, broken + out as an independent attribute rather than an rgba color, both so that + each can be independently overridden, and because shaders rarely consume + rgba parameters.""" + ) + texCoord2d[] primvars:st = [(1, 1), (0, 1), (0, 0), (1, 0)] ( + doc = """The default st coordinates for texture maps. + + \\sa UsdGeomGprim::GetPrimvarsStAttr()""" + interpolation = "varying" + ) + rel proxyPrim ( + doc = '''The proxyPrim relationship allows us to link a + prim whose purpose is "render" to its (single target) + purpose="proxy" prim. This is entirely optional, but can be + useful in several scenarios: + + - In a pipeline that does pruning (for complexity management) + by deactivating prims composed from asset references, when we + deactivate a purpose="render" prim, we will be able to discover + and additionally deactivate its associated purpose="proxy" prim, + so that preview renders reflect the pruning accurately. + + - DCC importers may be able to make more aggressive optimizations + for interactive processing and display if they can discover the proxy + for a given render prim. + + - With a little more work, a Hydra-based application will be able + to map a picked proxy prim back to its render geometry for selection. + + \\note It is only valid to author the proxyPrim relationship on + prims whose purpose is "render".''' + ) + uniform token purpose = "default" ( + allowedTokens = ["default", "render", "proxy", "guide"] + doc = """Purpose is a classification of geometry into categories that + can each be independently included or excluded from traversals of prims + on a stage, such as rendering or bounding-box computation traversals. + + See for more detail about how + purpose is computed and used.""" + ) + token visibility = "inherited" ( + allowedTokens = ["inherited", "invisible"] + doc = '''Visibility is meant to be the simplest form of "pruning" + visibility that is supported by most DCC apps. Visibility is + animatable, allowing a sub-tree of geometry to be present for some + segment of a shot, and absent from others; unlike the action of + deactivating geometry prims, invisible geometry is still + available for inspection, for positioning, for defining volumes, etc.''' + ) + double width = 2 ( + doc = """The width of the plane, which aligns to the x-axis when axis is + 'Z' or 'Y', or to the z-axis when axis is 'X'. If you author width + you must also author extent. + + \\sa UsdGeomGprim::GetExtentAttr()""" + ) + uniform token[] xformOpOrder ( + doc = """Encodes the sequence of transformation operations in the + order in which they should be pushed onto a transform stack while + visiting a UsdStage's prims in a graph traversal that will effect + the desired positioning for this prim and its descendant prims. + + You should rarely, if ever, need to manipulate this attribute directly. + It is managed by the AddXformOp(), SetResetXformStack(), and + SetXformOpOrder(), and consulted by GetOrderedXformOps() and + GetLocalTransformation().""" + ) +} + class "PointBased" ( doc = """Base class for all UsdGeomGprims that possess points, providing common attributes such as normals and velocities.""" diff --git a/pxr/usd/usdGeom/module.cpp b/pxr/usd/usdGeom/module.cpp index fe68983b81..2c8eac34b6 100644 --- a/pxr/usd/usdGeom/module.cpp +++ b/pxr/usd/usdGeom/module.cpp @@ -55,6 +55,7 @@ TF_WRAP_MODULE TF_WRAP(UsdGeomCube); TF_WRAP(UsdGeomCylinder); TF_WRAP(UsdGeomSphere); + TF_WRAP(UsdGeomPlane); TF_WRAP(UsdGeomPointBased); TF_WRAP(UsdGeomMesh); TF_WRAP(UsdGeomNurbsPatch); diff --git a/pxr/usd/usdGeom/plane.cpp b/pxr/usd/usdGeom/plane.cpp new file mode 100644 index 0000000000..3387f71d7e --- /dev/null +++ b/pxr/usd/usdGeom/plane.cpp @@ -0,0 +1,353 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#include "pxr/usd/usdGeom/plane.h" +#include "pxr/usd/usd/schemaRegistry.h" +#include "pxr/usd/usd/typed.h" + +#include "pxr/usd/sdf/types.h" +#include "pxr/usd/sdf/assetPath.h" + +PXR_NAMESPACE_OPEN_SCOPE + +// Register the schema with the TfType system. +TF_REGISTRY_FUNCTION(TfType) +{ + TfType::Define >(); + + // Register the usd prim typename as an alias under UsdSchemaBase. This + // enables one to call + // TfType::Find().FindDerivedByName("Plane") + // to find TfType, which is how IsA queries are + // answered. + TfType::AddAlias("Plane"); +} + +/* virtual */ +UsdGeomPlane::~UsdGeomPlane() +{ +} + +/* static */ +UsdGeomPlane +UsdGeomPlane::Get(const UsdStagePtr &stage, const SdfPath &path) +{ + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdGeomPlane(); + } + return UsdGeomPlane(stage->GetPrimAtPath(path)); +} + +/* static */ +UsdGeomPlane +UsdGeomPlane::Define( + const UsdStagePtr &stage, const SdfPath &path) +{ + static TfToken usdPrimTypeName("Plane"); + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdGeomPlane(); + } + return UsdGeomPlane( + stage->DefinePrim(path, usdPrimTypeName)); +} + +/* virtual */ +UsdSchemaKind UsdGeomPlane::_GetSchemaKind() const +{ + return UsdGeomPlane::schemaKind; +} + +/* static */ +const TfType & +UsdGeomPlane::_GetStaticTfType() +{ + static TfType tfType = TfType::Find(); + return tfType; +} + +/* static */ +bool +UsdGeomPlane::_IsTypedSchema() +{ + static bool isTyped = _GetStaticTfType().IsA(); + return isTyped; +} + +/* virtual */ +const TfType & +UsdGeomPlane::_GetTfType() const +{ + return _GetStaticTfType(); +} + +UsdAttribute +UsdGeomPlane::GetDoubleSidedAttr() const +{ + return GetPrim().GetAttribute(UsdGeomTokens->doubleSided); +} + +UsdAttribute +UsdGeomPlane::CreateDoubleSidedAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->doubleSided, + SdfValueTypeNames->Bool, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdGeomPlane::GetWidthAttr() const +{ + return GetPrim().GetAttribute(UsdGeomTokens->width); +} + +UsdAttribute +UsdGeomPlane::CreateWidthAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->width, + SdfValueTypeNames->Double, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdGeomPlane::GetLengthAttr() const +{ + return GetPrim().GetAttribute(UsdGeomTokens->length); +} + +UsdAttribute +UsdGeomPlane::CreateLengthAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->length, + SdfValueTypeNames->Double, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdGeomPlane::GetAxisAttr() const +{ + return GetPrim().GetAttribute(UsdGeomTokens->axis); +} + +UsdAttribute +UsdGeomPlane::CreateAxisAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->axis, + SdfValueTypeNames->Token, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdGeomPlane::GetExtentAttr() const +{ + return GetPrim().GetAttribute(UsdGeomTokens->extent); +} + +UsdAttribute +UsdGeomPlane::CreateExtentAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->extent, + SdfValueTypeNames->Float3Array, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdGeomPlane::GetPrimvarsStAttr() const +{ + return GetPrim().GetAttribute(UsdGeomTokens->primvarsSt); +} + +UsdAttribute +UsdGeomPlane::CreatePrimvarsStAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->primvarsSt, + SdfValueTypeNames->TexCoord2dArray, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +namespace { +static inline TfTokenVector +_ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right) +{ + TfTokenVector result; + result.reserve(left.size() + right.size()); + result.insert(result.end(), left.begin(), left.end()); + result.insert(result.end(), right.begin(), right.end()); + return result; +} +} + +/*static*/ +const TfTokenVector& +UsdGeomPlane::GetSchemaAttributeNames(bool includeInherited) +{ + static TfTokenVector localNames = { + UsdGeomTokens->doubleSided, + UsdGeomTokens->width, + UsdGeomTokens->length, + UsdGeomTokens->axis, + UsdGeomTokens->extent, + UsdGeomTokens->primvarsSt, + }; + static TfTokenVector allNames = + _ConcatenateAttributeNames( + UsdGeomGprim::GetSchemaAttributeNames(true), + localNames); + + if (includeInherited) + return allNames; + else + return localNames; +} + +PXR_NAMESPACE_CLOSE_SCOPE + +// ===================================================================== // +// Feel free to add custom code below this line. It will be preserved by +// the code generator. +// +// Just remember to wrap code in the appropriate delimiters: +// 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'. +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- + +#include "pxr/usd/usdGeom/boundableComputeExtent.h" +#include "pxr/base/tf/registryManager.h" + +PXR_NAMESPACE_OPEN_SCOPE + +static bool +_ComputeExtentMax(double width, double length, const TfToken& axis, GfVec3f* max) +{ + if (axis == UsdGeomTokens->x) { + *max = GfVec3f(0, length, width); + } else if (axis == UsdGeomTokens->y) { + *max = GfVec3f(width, 0, length); + } else if (axis == UsdGeomTokens->z) { + *max = GfVec3f(width, length, 0); + } else { + return false; // invalid axis + } + + return true; +} + +bool +UsdGeomPlane::ComputeExtent(double width, double length, const TfToken& axis, + VtVec3fArray* extent) +{ + // Create Sized Extent + extent->resize(2); + + GfVec3f max; + if (!_ComputeExtentMax(width, length, axis, &max)) { + return false; + } + + (*extent)[0] = -max; + (*extent)[1] = max; + + return true; +} + +bool +UsdGeomPlane::ComputeExtent(double width, double length, const TfToken& axis, + const GfMatrix4d& transform, VtVec3fArray* extent) +{ + // Create Sized Extent + extent->resize(2); + + GfVec3f max; + if (!_ComputeExtentMax(width, length, axis, &max)) { + return false; + } + + GfBBox3d bbox = GfBBox3d(GfRange3d(-max, max), transform); + GfRange3d range = bbox.ComputeAlignedRange(); + (*extent)[0] = GfVec3f(range.GetMin()); + (*extent)[1] = GfVec3f(range.GetMax()); + + return true; +} + +static bool +_ComputeExtentForPlane( + const UsdGeomBoundable& boundable, + const UsdTimeCode& time, + const GfMatrix4d* transform, + VtVec3fArray* extent) +{ + const UsdGeomPlane planeSchema(boundable); + if (!TF_VERIFY(planeSchema)) { + return false; + } + + double width; + if (!planeSchema.GetWidthAttr().Get(&width)) { + return false; + } + + double length; + if (!planeSchema.GetLengthAttr().Get(&length)) { + return false; + } + + TfToken axis; + if (!planeSchema.GetAxisAttr().Get(&axis)) { + return false; + } + + if (transform) { + return UsdGeomPlane::ComputeExtent(width, length, axis, *transform, extent); + } else { + return UsdGeomPlane::ComputeExtent(width, length, axis, extent); + } +} + +TF_REGISTRY_FUNCTION(UsdGeomBoundable) +{ + UsdGeomRegisterComputeExtentFunction( + _ComputeExtentForPlane); +} + +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usdGeom/plane.h b/pxr/usd/usdGeom/plane.h new file mode 100644 index 0000000000..748f92ecd2 --- /dev/null +++ b/pxr/usd/usdGeom/plane.h @@ -0,0 +1,355 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#ifndef USDGEOM_GENERATED_PLANE_H +#define USDGEOM_GENERATED_PLANE_H + +/// \file usdGeom/plane.h + +#include "pxr/pxr.h" +#include "pxr/usd/usdGeom/api.h" +#include "pxr/usd/usdGeom/gprim.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usd/stage.h" +#include "pxr/usd/usdGeom/tokens.h" + +#include "pxr/base/vt/value.h" + +#include "pxr/base/gf/vec3d.h" +#include "pxr/base/gf/vec3f.h" +#include "pxr/base/gf/matrix4d.h" + +#include "pxr/base/tf/token.h" +#include "pxr/base/tf/type.h" + +PXR_NAMESPACE_OPEN_SCOPE + +class SdfAssetPath; + +// -------------------------------------------------------------------------- // +// PLANE // +// -------------------------------------------------------------------------- // + +/// \class UsdGeomPlane +/// +/// Defines a primitive plane, centered at the origin, and is defined by +/// a cardinal axis, width, and length. It is also double-sided. +/// +/// The axis of width and length are perpendicular to the plane's \em axis: +/// +/// axis | width | length +/// ----- | ------ | ------- +/// X | z-axis | y-axis +/// Y | x-axis | z-axis +/// Z | x-axis | y-axis +/// +/// +/// +/// For any described attribute \em Fallback \em Value or \em Allowed \em Values below +/// that are text/tokens, the actual token is published and defined in \ref UsdGeomTokens. +/// So to set an attribute to the value "rightHanded", use UsdGeomTokens->rightHanded +/// as the value. +/// +class UsdGeomPlane : public UsdGeomGprim +{ +public: + /// Compile time constant representing what kind of schema this class is. + /// + /// \sa UsdSchemaKind + static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped; + + /// Construct a UsdGeomPlane on UsdPrim \p prim . + /// Equivalent to UsdGeomPlane::Get(prim.GetStage(), prim.GetPath()) + /// for a \em valid \p prim, but will not immediately throw an error for + /// an invalid \p prim + explicit UsdGeomPlane(const UsdPrim& prim=UsdPrim()) + : UsdGeomGprim(prim) + { + } + + /// Construct a UsdGeomPlane on the prim held by \p schemaObj . + /// Should be preferred over UsdGeomPlane(schemaObj.GetPrim()), + /// as it preserves SchemaBase state. + explicit UsdGeomPlane(const UsdSchemaBase& schemaObj) + : UsdGeomGprim(schemaObj) + { + } + + /// Destructor. + USDGEOM_API + virtual ~UsdGeomPlane(); + + /// Return a vector of names of all pre-declared attributes for this schema + /// class and all its ancestor classes. Does not include attributes that + /// may be authored by custom/extended methods of the schemas involved. + USDGEOM_API + static const TfTokenVector & + GetSchemaAttributeNames(bool includeInherited=true); + + /// Return a UsdGeomPlane holding the prim adhering to this + /// schema at \p path on \p stage. If no prim exists at \p path on + /// \p stage, or if the prim at that path does not adhere to this schema, + /// return an invalid schema object. This is shorthand for the following: + /// + /// \code + /// UsdGeomPlane(stage->GetPrimAtPath(path)); + /// \endcode + /// + USDGEOM_API + static UsdGeomPlane + Get(const UsdStagePtr &stage, const SdfPath &path); + + /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path + /// is defined (according to UsdPrim::IsDefined()) on this stage. + /// + /// If a prim adhering to this schema at \p path is already defined on this + /// stage, return that prim. Otherwise author an \a SdfPrimSpec with + /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for + /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s + /// with \p specifier == \a SdfSpecifierDef and empty typeName at the + /// current EditTarget for any nonexistent, or existing but not \a Defined + /// ancestors. + /// + /// The given \a path must be an absolute prim path that does not contain + /// any variant selections. + /// + /// If it is impossible to author any of the necessary PrimSpecs, (for + /// example, in case \a path cannot map to the current UsdEditTarget's + /// namespace) issue an error and return an invalid \a UsdPrim. + /// + /// Note that this method may return a defined prim whose typeName does not + /// specify this schema class, in case a stronger typeName opinion overrides + /// the opinion at the current EditTarget. + /// + USDGEOM_API + static UsdGeomPlane + Define(const UsdStagePtr &stage, const SdfPath &path); + +protected: + /// Returns the kind of schema this class belongs to. + /// + /// \sa UsdSchemaKind + USDGEOM_API + UsdSchemaKind _GetSchemaKind() const override; + +private: + // needs to invoke _GetStaticTfType. + friend class UsdSchemaRegistry; + USDGEOM_API + static const TfType &_GetStaticTfType(); + + static bool _IsTypedSchema(); + + // override SchemaBase virtuals. + USDGEOM_API + const TfType &_GetTfType() const override; + +public: + // --------------------------------------------------------------------- // + // DOUBLESIDED + // --------------------------------------------------------------------- // + /// Planes are double-sided by default, clients may also supported + /// single-sided planes. + /// + /// \sa UsdGeomGprim::GetDoubleSidedAttr() + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform bool doubleSided = 1` | + /// | C++ Type | bool | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDGEOM_API + UsdAttribute GetDoubleSidedAttr() const; + + /// See GetDoubleSidedAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDGEOM_API + UsdAttribute CreateDoubleSidedAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // WIDTH + // --------------------------------------------------------------------- // + /// The width of the plane, which aligns to the x-axis when \em axis is + /// 'Z' or 'Y', or to the z-axis when \em axis is 'X'. If you author \em width + /// you must also author \em extent. + /// + /// \sa UsdGeomGprim::GetExtentAttr() + /// + /// | || + /// | -- | -- | + /// | Declaration | `double width = 2` | + /// | C++ Type | double | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Double | + USDGEOM_API + UsdAttribute GetWidthAttr() const; + + /// See GetWidthAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDGEOM_API + UsdAttribute CreateWidthAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // LENGTH + // --------------------------------------------------------------------- // + /// The length of the plane, which aligns to the y-axis when \em axis is + /// 'Z' or 'X', or to the z-axis when \em axis is 'Y'. If you author \em length + /// you must also author \em extent. + /// + /// \sa UsdGeomGprim::GetExtentAttr() + /// + /// | || + /// | -- | -- | + /// | Declaration | `double length = 2` | + /// | C++ Type | double | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Double | + USDGEOM_API + UsdAttribute GetLengthAttr() const; + + /// See GetLengthAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDGEOM_API + UsdAttribute CreateLengthAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // AXIS + // --------------------------------------------------------------------- // + /// The axis along which the surface of the plane is aligned. When set + /// to 'Z' the plane is in the xy-plane; when \em axis is 'X' the plane is in + /// the yz-plane, and when \em axis is 'Y' the plane is in the xz-plane. + /// + /// \sa UsdGeomGprim::GetAxisAttr(). + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform token axis = "Z"` | + /// | C++ Type | TfToken | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + /// | \ref UsdGeomTokens "Allowed Values" | X, Y, Z | + USDGEOM_API + UsdAttribute GetAxisAttr() const; + + /// See GetAxisAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDGEOM_API + UsdAttribute CreateAxisAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // EXTENT + // --------------------------------------------------------------------- // + /// Extent is re-defined on Plane only to provide a fallback + /// value. \sa UsdGeomGprim::GetExtentAttr(). + /// + /// | || + /// | -- | -- | + /// | Declaration | `float3[] extent = [(-1, -1, 0), (1, 1, 0)]` | + /// | C++ Type | VtArray | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float3Array | + USDGEOM_API + UsdAttribute GetExtentAttr() const; + + /// See GetExtentAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDGEOM_API + UsdAttribute CreateExtentAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // PRIMVARSST + // --------------------------------------------------------------------- // + /// The default st coordinates for texture maps. + /// + /// \sa UsdGeomGprim::GetPrimvarsStAttr() + /// + /// | || + /// | -- | -- | + /// | Declaration | `texCoord2d[] primvars:st = [(1, 1), (0, 1), (0, 0), (1, 0)]` | + /// | C++ Type | VtArray | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TexCoord2dArray | + USDGEOM_API + UsdAttribute GetPrimvarsStAttr() const; + + /// See GetPrimvarsStAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDGEOM_API + UsdAttribute CreatePrimvarsStAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // ===================================================================== // + // Feel free to add custom code below this line, it will be preserved by + // the code generator. + // + // Just remember to: + // - Close the class declaration with }; + // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE + // - Close the include guard with #endif + // ===================================================================== // + // --(BEGIN CUSTOM CODE)-- + + /// Compute the extent for the plane defined by the size of each dimension. + /// + /// \return true upon success, false if unable to calculate extent. + /// + /// On success, extent will contain an approximate axis-aligned bounding + /// box of the plane defined by the size of each dimension. + /// + /// This function is to provide easy authoring of extent for usd authoring + /// tools, hence it is static and acts outside a specific prim (as in + /// attribute based methods). + USDGEOM_API + static bool ComputeExtent(double width, double length, const TfToken& axis, + VtVec3fArray* extent); + + /// \overload + /// Computes the extent as if the matrix \p transform was first applied. + USDGEOM_API + static bool ComputeExtent(double width, double length, const TfToken& axis, + const GfMatrix4d& transform, VtVec3fArray* extent); +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif diff --git a/pxr/usd/usdGeom/plugInfo.json b/pxr/usd/usdGeom/plugInfo.json index df47d69e69..26d3a8b286 100644 --- a/pxr/usd/usdGeom/plugInfo.json +++ b/pxr/usd/usdGeom/plugInfo.json @@ -230,6 +230,17 @@ ], "schemaKind": "concreteTyped" }, + "UsdGeomPlane": { + "alias": { + "UsdSchemaBase": "Plane" + }, + "autoGenerated": true, + "bases": [ + "UsdGeomGprim" + ], + "implementsComputeExtent": true, + "schemaKind": "concreteTyped" + }, "UsdGeomPointBased": { "alias": { "UsdSchemaBase": "PointBased" diff --git a/pxr/usd/usdGeom/schema.usda b/pxr/usd/usdGeom/schema.usda index 5c9ab3708d..4bda383f90 100644 --- a/pxr/usd/usdGeom/schema.usda +++ b/pxr/usd/usdGeom/schema.usda @@ -803,6 +803,66 @@ class Cone "Cone" ( ) } +class Plane "Plane" ( + inherits = + doc = """Defines a primitive plane, centered at the origin, and is defined by + a cardinal axis, width, and length. It is also double-sided. + + The axis of width and length are perpendicular to the plane's \\em axis: + + axis | width | length + ----- | ------ | ------- + X | z-axis | y-axis + Y | x-axis | z-axis + Z | x-axis | y-axis + + """ + customData = { + dictionary extraPlugInfo = { + bool implementsComputeExtent = true + } + } +) { + uniform bool doubleSided = true ( + doc = """Planes are double-sided by default, clients may also supported + single-sided planes. + + \\sa UsdGeomGprim::GetDoubleSidedAttr()""" + ) + double width = 2.0 ( + doc = """The width of the plane, which aligns to the x-axis when \\em axis is + 'Z' or 'Y', or to the z-axis when \\em axis is 'X'. If you author \\em width + you must also author \\em extent. + + \\sa UsdGeomGprim::GetExtentAttr()""" + ) + double length = 2.0 ( + doc = """The length of the plane, which aligns to the y-axis when \\em axis is + 'Z' or 'X', or to the z-axis when \\em axis is 'Y'. If you author \\em length + you must also author \\em extent. + + \\sa UsdGeomGprim::GetExtentAttr()""" + ) + uniform token axis = "Z" ( + allowedTokens = ["X", "Y", "Z"] + doc = """The axis along which the surface of the plane is aligned. When set + to 'Z' the plane is in the xy-plane; when \\em axis is 'X' the plane is in + the yz-plane, and when \\em axis is 'Y' the plane is in the xz-plane. + + \\sa UsdGeomGprim::GetAxisAttr().""" + ) + float3[] extent = [(-1.0, -1.0, 0.0), (1.0, 1.0, 0.0)] ( + doc = """Extent is re-defined on Plane only to provide a fallback + value. \\sa UsdGeomGprim::GetExtentAttr().""" + ) + texCoord2d[] primvars:st = [(1.0,1.0),(0.0,1.0),(0.0,0.0),(1.0,0.0)] ( + doc = """The default st coordinates for texture maps. + + \\sa UsdGeomGprim::GetPrimvarsStAttr()""" + interpolation = "varying" + ) +} + class "PointBased" ( doc = """Base class for all UsdGeomGprims that possess points, providing common attributes such as normals and velocities.""" diff --git a/pxr/usd/usdGeom/tokens.cpp b/pxr/usd/usdGeom/tokens.cpp index ceade184ff..dc80f8d2ba 100644 --- a/pxr/usd/usdGeom/tokens.cpp +++ b/pxr/usd/usdGeom/tokens.cpp @@ -92,6 +92,7 @@ UsdGeomTokensType::UsdGeomTokensType() : knots("knots", TfToken::Immortal), left("left", TfToken::Immortal), leftHanded("leftHanded", TfToken::Immortal), + length("length", TfToken::Immortal), linear("linear", TfToken::Immortal), loop("loop", TfToken::Immortal), metersPerUnit("metersPerUnit", TfToken::Immortal), @@ -130,6 +131,7 @@ UsdGeomTokensType::UsdGeomTokensType() : power("power", TfToken::Immortal), primvarsDisplayColor("primvars:displayColor", TfToken::Immortal), primvarsDisplayOpacity("primvars:displayOpacity", TfToken::Immortal), + primvarsSt("primvars:st", TfToken::Immortal), projection("projection", TfToken::Immortal), protoIndices("protoIndices", TfToken::Immortal), prototypes("prototypes", TfToken::Immortal), @@ -180,6 +182,7 @@ UsdGeomTokensType::UsdGeomTokensType() : vOrder("vOrder", TfToken::Immortal), vRange("vRange", TfToken::Immortal), vVertexCount("vVertexCount", TfToken::Immortal), + width("width", TfToken::Immortal), widths("widths", TfToken::Immortal), wrap("wrap", TfToken::Immortal), x("X", TfToken::Immortal), @@ -253,6 +256,7 @@ UsdGeomTokensType::UsdGeomTokensType() : knots, left, leftHanded, + length, linear, loop, metersPerUnit, @@ -291,6 +295,7 @@ UsdGeomTokensType::UsdGeomTokensType() : power, primvarsDisplayColor, primvarsDisplayOpacity, + primvarsSt, projection, protoIndices, prototypes, @@ -341,6 +346,7 @@ UsdGeomTokensType::UsdGeomTokensType() : vOrder, vRange, vVertexCount, + width, widths, wrap, x, diff --git a/pxr/usd/usdGeom/tokens.h b/pxr/usd/usdGeom/tokens.h index af7e556eaa..17841899b3 100644 --- a/pxr/usd/usdGeom/tokens.h +++ b/pxr/usd/usdGeom/tokens.h @@ -76,7 +76,7 @@ struct UsdGeomTokensType { const TfToken angularVelocities; /// \brief "axis" /// - /// UsdGeomCone, UsdGeomCapsule, UsdGeomCylinder + /// UsdGeomPlane, UsdGeomCone, UsdGeomCapsule, UsdGeomCylinder const TfToken axis; /// \brief "basis" /// @@ -184,7 +184,7 @@ struct UsdGeomTokensType { const TfToken default_; /// \brief "doubleSided" /// - /// UsdGeomGprim + /// UsdGeomPlane, UsdGeomGprim const TfToken doubleSided; /// \brief "edgeAndCorner" /// @@ -208,7 +208,7 @@ struct UsdGeomTokensType { const TfToken exposure; /// \brief "extent" /// - /// UsdGeomCone, UsdGeomCapsule, UsdGeomCylinder, UsdGeomSphere, UsdGeomCube, UsdGeomBoundable + /// UsdGeomPlane, UsdGeomCone, UsdGeomCapsule, UsdGeomCylinder, UsdGeomSphere, UsdGeomCube, UsdGeomBoundable const TfToken extent; /// \brief "extentsHint" /// @@ -326,6 +326,10 @@ struct UsdGeomTokensType { /// /// Possible value for UsdGeomGprim::GetOrientationAttr() const TfToken leftHanded; + /// \brief "length" + /// + /// UsdGeomPlane + const TfToken length; /// \brief "linear" /// /// Possible value for UsdGeomBasisCurves::GetTypeAttr() @@ -478,6 +482,10 @@ struct UsdGeomTokensType { /// /// UsdGeomGprim const TfToken primvarsDisplayOpacity; + /// \brief "primvars:st" + /// + /// UsdGeomPlane + const TfToken primvarsSt; /// \brief "projection" /// /// UsdGeomCamera @@ -678,6 +686,10 @@ struct UsdGeomTokensType { /// /// UsdGeomNurbsPatch const TfToken vVertexCount; + /// \brief "width" + /// + /// UsdGeomPlane + const TfToken width; /// \brief "widths" /// /// UsdGeomPoints, UsdGeomCurves @@ -688,7 +700,7 @@ struct UsdGeomTokensType { const TfToken wrap; /// \brief "X" /// - /// Possible value for UsdGeomCone::GetAxisAttr(), Possible value for UsdGeomCapsule::GetAxisAttr(), Possible value for UsdGeomCylinder::GetAxisAttr() + /// Possible value for UsdGeomPlane::GetAxisAttr(), Possible value for UsdGeomCone::GetAxisAttr(), Possible value for UsdGeomCapsule::GetAxisAttr(), Possible value for UsdGeomCylinder::GetAxisAttr() const TfToken x; /// \brief "xformOpOrder" /// @@ -696,11 +708,11 @@ struct UsdGeomTokensType { const TfToken xformOpOrder; /// \brief "Y" /// - /// Possible value for UsdGeomCone::GetAxisAttr(), Possible value for UsdGeomCapsule::GetAxisAttr(), Possible value for UsdGeomCylinder::GetAxisAttr() + /// Possible value for UsdGeomPlane::GetAxisAttr(), Possible value for UsdGeomCone::GetAxisAttr(), Possible value for UsdGeomCapsule::GetAxisAttr(), Possible value for UsdGeomCylinder::GetAxisAttr() const TfToken y; /// \brief "Z" /// - /// Possible value for UsdGeomCone::GetAxisAttr(), Default value for UsdGeomCone::GetAxisAttr(), Possible value for UsdGeomCapsule::GetAxisAttr(), Default value for UsdGeomCapsule::GetAxisAttr(), Possible value for UsdGeomCylinder::GetAxisAttr(), Default value for UsdGeomCylinder::GetAxisAttr() + /// Possible value for UsdGeomPlane::GetAxisAttr(), Default value for UsdGeomPlane::GetAxisAttr(), Possible value for UsdGeomCone::GetAxisAttr(), Default value for UsdGeomCone::GetAxisAttr(), Possible value for UsdGeomCapsule::GetAxisAttr(), Default value for UsdGeomCapsule::GetAxisAttr(), Possible value for UsdGeomCylinder::GetAxisAttr(), Default value for UsdGeomCylinder::GetAxisAttr() const TfToken z; /// A vector of all of the tokens listed above. const std::vector allTokens; diff --git a/pxr/usd/usdGeom/wrapPlane.cpp b/pxr/usd/usdGeom/wrapPlane.cpp new file mode 100644 index 0000000000..3bc409b9a3 --- /dev/null +++ b/pxr/usd/usdGeom/wrapPlane.cpp @@ -0,0 +1,208 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#include "pxr/usd/usdGeom/plane.h" +#include "pxr/usd/usd/schemaBase.h" + +#include "pxr/usd/sdf/primSpec.h" + +#include "pxr/usd/usd/pyConversions.h" +#include "pxr/base/tf/pyContainerConversions.h" +#include "pxr/base/tf/pyResultConversions.h" +#include "pxr/base/tf/pyUtils.h" +#include "pxr/base/tf/wrapTypeHelpers.h" + +#include + +#include + +using namespace boost::python; + +PXR_NAMESPACE_USING_DIRECTIVE + +namespace { + +#define WRAP_CUSTOM \ + template static void _CustomWrapCode(Cls &_class) + +// fwd decl. +WRAP_CUSTOM; + + +static UsdAttribute +_CreateDoubleSidedAttr(UsdGeomPlane &self, + object defaultVal, bool writeSparsely) { + return self.CreateDoubleSidedAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Bool), writeSparsely); +} + +static UsdAttribute +_CreateWidthAttr(UsdGeomPlane &self, + object defaultVal, bool writeSparsely) { + return self.CreateWidthAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Double), writeSparsely); +} + +static UsdAttribute +_CreateLengthAttr(UsdGeomPlane &self, + object defaultVal, bool writeSparsely) { + return self.CreateLengthAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Double), writeSparsely); +} + +static UsdAttribute +_CreateAxisAttr(UsdGeomPlane &self, + object defaultVal, bool writeSparsely) { + return self.CreateAxisAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely); +} + +static UsdAttribute +_CreateExtentAttr(UsdGeomPlane &self, + object defaultVal, bool writeSparsely) { + return self.CreateExtentAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float3Array), writeSparsely); +} + +static UsdAttribute +_CreatePrimvarsStAttr(UsdGeomPlane &self, + object defaultVal, bool writeSparsely) { + return self.CreatePrimvarsStAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->TexCoord2dArray), writeSparsely); +} + +static std::string +_Repr(const UsdGeomPlane &self) +{ + std::string primRepr = TfPyRepr(self.GetPrim()); + return TfStringPrintf( + "UsdGeom.Plane(%s)", + primRepr.c_str()); +} + +} // anonymous namespace + +void wrapUsdGeomPlane() +{ + typedef UsdGeomPlane This; + + class_ > + cls("Plane"); + + cls + .def(init(arg("prim"))) + .def(init(arg("schemaObj"))) + .def(TfTypePythonClass()) + + .def("Get", &This::Get, (arg("stage"), arg("path"))) + .staticmethod("Get") + + .def("Define", &This::Define, (arg("stage"), arg("path"))) + .staticmethod("Define") + + .def("GetSchemaAttributeNames", + &This::GetSchemaAttributeNames, + arg("includeInherited")=true, + return_value_policy()) + .staticmethod("GetSchemaAttributeNames") + + .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find, + return_value_policy()) + .staticmethod("_GetStaticTfType") + + .def(!self) + + + .def("GetDoubleSidedAttr", + &This::GetDoubleSidedAttr) + .def("CreateDoubleSidedAttr", + &_CreateDoubleSidedAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetWidthAttr", + &This::GetWidthAttr) + .def("CreateWidthAttr", + &_CreateWidthAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetLengthAttr", + &This::GetLengthAttr) + .def("CreateLengthAttr", + &_CreateLengthAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetAxisAttr", + &This::GetAxisAttr) + .def("CreateAxisAttr", + &_CreateAxisAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetExtentAttr", + &This::GetExtentAttr) + .def("CreateExtentAttr", + &_CreateExtentAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetPrimvarsStAttr", + &This::GetPrimvarsStAttr) + .def("CreatePrimvarsStAttr", + &_CreatePrimvarsStAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("__repr__", ::_Repr) + ; + + _CustomWrapCode(cls); +} + +// ===================================================================== // +// Feel free to add custom code below this line, it will be preserved by +// the code generator. The entry point for your custom code should look +// minimally like the following: +// +// WRAP_CUSTOM { +// _class +// .def("MyCustomMethod", ...) +// ; +// } +// +// Of course any other ancillary or support code may be provided. +// +// Just remember to wrap code in the appropriate delimiters: +// 'namespace {', '}'. +// +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- + +namespace { + +WRAP_CUSTOM { +} + +} diff --git a/pxr/usd/usdGeom/wrapTokens.cpp b/pxr/usd/usdGeom/wrapTokens.cpp index da92a37b3f..1de739301b 100644 --- a/pxr/usd/usdGeom/wrapTokens.cpp +++ b/pxr/usd/usdGeom/wrapTokens.cpp @@ -130,6 +130,7 @@ void wrapUsdGeomTokens() _AddToken(cls, "knots", UsdGeomTokens->knots); _AddToken(cls, "left", UsdGeomTokens->left); _AddToken(cls, "leftHanded", UsdGeomTokens->leftHanded); + _AddToken(cls, "length", UsdGeomTokens->length); _AddToken(cls, "linear", UsdGeomTokens->linear); _AddToken(cls, "loop", UsdGeomTokens->loop); _AddToken(cls, "metersPerUnit", UsdGeomTokens->metersPerUnit); @@ -168,6 +169,7 @@ void wrapUsdGeomTokens() _AddToken(cls, "power", UsdGeomTokens->power); _AddToken(cls, "primvarsDisplayColor", UsdGeomTokens->primvarsDisplayColor); _AddToken(cls, "primvarsDisplayOpacity", UsdGeomTokens->primvarsDisplayOpacity); + _AddToken(cls, "primvarsSt", UsdGeomTokens->primvarsSt); _AddToken(cls, "projection", UsdGeomTokens->projection); _AddToken(cls, "protoIndices", UsdGeomTokens->protoIndices); _AddToken(cls, "prototypes", UsdGeomTokens->prototypes); @@ -218,6 +220,7 @@ void wrapUsdGeomTokens() _AddToken(cls, "vOrder", UsdGeomTokens->vOrder); _AddToken(cls, "vRange", UsdGeomTokens->vRange); _AddToken(cls, "vVertexCount", UsdGeomTokens->vVertexCount); + _AddToken(cls, "width", UsdGeomTokens->width); _AddToken(cls, "widths", UsdGeomTokens->widths); _AddToken(cls, "wrap", UsdGeomTokens->wrap); _AddToken(cls, "x", UsdGeomTokens->x); diff --git a/pxr/usdImaging/usdImaging/CMakeLists.txt b/pxr/usdImaging/usdImaging/CMakeLists.txt index 580224f589..f3d8c9f0c9 100644 --- a/pxr/usdImaging/usdImaging/CMakeLists.txt +++ b/pxr/usdImaging/usdImaging/CMakeLists.txt @@ -66,6 +66,7 @@ pxr_library(usdImaging meshAdapter nurbsCurvesAdapter nurbsPatchAdapter + planeAdapter pluginLightAdapter pluginLightFilterAdapter pointsAdapter diff --git a/pxr/usdImaging/usdImaging/implicitSurfaceMeshUtils.cpp b/pxr/usdImaging/usdImaging/implicitSurfaceMeshUtils.cpp index c70d9c7f03..83fe10011e 100644 --- a/pxr/usdImaging/usdImaging/implicitSurfaceMeshUtils.cpp +++ b/pxr/usdImaging/usdImaging/implicitSurfaceMeshUtils.cpp @@ -436,6 +436,59 @@ UsdImagingGenerateCapsuleMeshPoints( return pointsArray; } +// Plane ----------------------------------------------------------------------- + +const PxOsdMeshTopology& +UsdImagingGetPlaneTopology() +{ + static const VtIntArray numVerts{ 4 }; + static const VtIntArray verts{ 0, 1, 2, 3 }; + static const PxOsdMeshTopology planeTopo( + PxOsdOpenSubdivTokens->bilinear, + PxOsdOpenSubdivTokens->rightHanded, + numVerts, verts); + + return planeTopo; +} + +VtVec3fArray +UsdImagingGeneratePlaneMeshPoints(double width, + double length, + TfToken const & axis) +{ + int numPoints = 4; + std::vector _points(numPoints); + + if (axis == UsdGeomTokens->x) { + _points = { GfVec3f( 0.0f, 0.5f * length,-0.5f * width ), + GfVec3f( 0.0f, 0.5f * length, 0.5f * width ), + GfVec3f( 0.0f, -0.5f * length, 0.5f * width ), + GfVec3f( 0.0f, -0.5f * length,-0.5f * width ) }; + } else if (axis == UsdGeomTokens->y) { + _points = { + GfVec3f( 0.5f * width, 0.0f,-0.5f * length ), + GfVec3f(-0.5f * width, 0.0f,-0.5f * length ), + GfVec3f(-0.5f * width, 0.0f, 0.5f * length ), + GfVec3f( 0.5f * width, 0.0f, 0.5f * length ) }; + } else { + _points = { GfVec3f( 0.5f * width, 0.5f * length, 0.0f ), + GfVec3f(-0.5f * width, 0.5f * length, 0.0f ), + GfVec3f(-0.5f * width,-0.5f * length, 0.0f ), + GfVec3f( 0.5f * width,-0.5f * length, 0.0f ) }; + } + + VtVec3fArray pointsArray(numPoints); + GfVec3f * p = pointsArray.data(); + + for (int i=0; i >(); + t.SetFactory< UsdImagingPrimAdapterFactory >(); +} + +UsdImagingPlaneAdapter::~UsdImagingPlaneAdapter() +{ +} + +bool +UsdImagingPlaneAdapter::IsSupported(UsdImagingIndexProxy const* index) const +{ + return index->IsRprimTypeSupported(HdPrimTypeTokens->mesh); +} + +SdfPath +UsdImagingPlaneAdapter::Populate(UsdPrim const& prim, + UsdImagingIndexProxy* index, + UsdImagingInstancerContext const* instancerContext) +{ + return _AddRprim(HdPrimTypeTokens->mesh, + prim, index, GetMaterialUsdPath(prim), instancerContext); +} + +void +UsdImagingPlaneAdapter::TrackVariability(UsdPrim const& prim, + SdfPath const& cachePath, + HdDirtyBits* timeVaryingBits, + UsdImagingInstancerContext const* + instancerContext) const +{ + BaseAdapter::TrackVariability( + prim, cachePath, timeVaryingBits, instancerContext); + + // Check DirtyPoints before doing variability checks, in case we can skip + // any of them... + if ((*timeVaryingBits & HdChangeTracker::DirtyPoints) == 0) { + _IsVarying(prim, UsdGeomTokens->width, + HdChangeTracker::DirtyPoints, + UsdImagingTokens->usdVaryingPrimvar, + timeVaryingBits, /*inherited*/false); + } + if ((*timeVaryingBits & HdChangeTracker::DirtyPoints) == 0) { + _IsVarying(prim, UsdGeomTokens->length, + HdChangeTracker::DirtyPoints, + UsdImagingTokens->usdVaryingPrimvar, + timeVaryingBits, /*inherited*/false); + } + if ((*timeVaryingBits & HdChangeTracker::DirtyPoints) == 0) { + _IsVarying(prim, UsdGeomTokens->axis, + HdChangeTracker::DirtyPoints, + UsdImagingTokens->usdVaryingPrimvar, + timeVaryingBits, /*inherited*/false); + } +} + +HdDirtyBits +UsdImagingPlaneAdapter::ProcessPropertyChange(UsdPrim const& prim, + SdfPath const& cachePath, + TfToken const& propertyName) +{ + if (propertyName == UsdGeomTokens->width || + propertyName == UsdGeomTokens->length || + propertyName == UsdGeomTokens->axis) { + return HdChangeTracker::DirtyPoints; + } + + // Allow base class to handle change processing. + return BaseAdapter::ProcessPropertyChange(prim, cachePath, propertyName); +} + +/*virtual*/ +VtValue +UsdImagingPlaneAdapter::GetPoints(UsdPrim const& prim, + UsdTimeCode time) const +{ + return GetMeshPoints(prim, time); +} + +/*static*/ +VtValue +UsdImagingPlaneAdapter::GetMeshPoints(UsdPrim const& prim, + UsdTimeCode time) +{ + UsdGeomPlane plane(prim); + double width = 2.0; + double length = 2.0; + TfToken axis = UsdGeomTokens->z; + TF_VERIFY(plane.GetWidthAttr().Get(&width, time)); + TF_VERIFY(plane.GetLengthAttr().Get(&length, time)); + TF_VERIFY(plane.GetAxisAttr().Get(&axis, time)); + + return VtValue(UsdImagingGeneratePlaneMeshPoints(width, length, axis)); +} + +/*static*/ +VtValue +UsdImagingPlaneAdapter::GetMeshTopology() +{ + // Topology is constant and identical for all planes. + return VtValue(HdMeshTopology(UsdImagingGetPlaneTopology())); +} + +/*virtual*/ +VtValue +UsdImagingPlaneAdapter::GetTopology(UsdPrim const& prim, + SdfPath const& cachePath, + UsdTimeCode time) const +{ + TRACE_FUNCTION(); + HF_MALLOC_TAG_FUNCTION(); + return GetMeshTopology(); +} + +PXR_NAMESPACE_CLOSE_SCOPE + diff --git a/pxr/usdImaging/usdImaging/planeAdapter.h b/pxr/usdImaging/usdImaging/planeAdapter.h new file mode 100644 index 0000000000..8af85c19d5 --- /dev/null +++ b/pxr/usdImaging/usdImaging/planeAdapter.h @@ -0,0 +1,108 @@ +// +// Copyright 2022 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#ifndef PXR_USD_IMAGING_USD_IMAGING_PLANE_ADAPTER_H +#define PXR_USD_IMAGING_USD_IMAGING_PLANE_ADAPTER_H + +/// \file usdImaging/planeAdapter.h + +#include "pxr/pxr.h" +#include "pxr/usdImaging/usdImaging/api.h" +#include "pxr/usdImaging/usdImaging/gprimAdapter.h" + +PXR_NAMESPACE_OPEN_SCOPE + + +class UsdGeomPlane; + +/// \class UsdImagingPlaneAdapter +/// +/// Delegate support for UsdGeomPlane. +/// +class UsdImagingPlaneAdapter : public UsdImagingGprimAdapter { +public: + typedef UsdImagingGprimAdapter BaseAdapter; + + UsdImagingPlaneAdapter() + : UsdImagingGprimAdapter() + {} + USDIMAGING_API + virtual ~UsdImagingPlaneAdapter(); + + USDIMAGING_API + SdfPath Populate( + UsdPrim const& prim, + UsdImagingIndexProxy* index, + UsdImagingInstancerContext const* instancerContext = nullptr) override; + + USDIMAGING_API + bool IsSupported(UsdImagingIndexProxy const* index) const override; + + USDIMAGING_API + HdDirtyBits ProcessPropertyChange(UsdPrim const& prim, + SdfPath const& cachePath, + TfToken const& propertyName); + + // ---------------------------------------------------------------------- // + /// \name Parallel Setup and Resolve + // ---------------------------------------------------------------------- // + + /// Thread Safe. + USDIMAGING_API + void TrackVariability( + UsdPrim const& prim, + SdfPath const& cachePath, + HdDirtyBits* timeVaryingBits, + UsdImagingInstancerContext const* instancerContext = nullptr) + const override; + + // ---------------------------------------------------------------------- // + /// \name Data access + // ---------------------------------------------------------------------- // + + USDIMAGING_API + VtValue GetTopology(UsdPrim const& prim, + SdfPath const& cachePath, + UsdTimeCode time) const override; + + // Override the implemetation in GprimAdapter since we don't fetch the + // points attribute for implicit primitives. + USDIMAGING_API + VtValue GetPoints( + UsdPrim const& prim, + UsdTimeCode time) const override; + + // Used by the legacyEngine. + USDIMAGING_API + static VtValue GetMeshPoints(UsdPrim const& prim, + UsdTimeCode time); + + // Used by the legacyEngine. + USDIMAGING_API + static VtValue GetMeshTopology(); +}; + + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif // PXR_USD_IMAGING_USD_IMAGING_PLANE_ADAPTER_H \ No newline at end of file diff --git a/pxr/usdImaging/usdImaging/plugInfo.json b/pxr/usdImaging/usdImaging/plugInfo.json index b3b9bc6567..cfd179cc2e 100644 --- a/pxr/usdImaging/usdImaging/plugInfo.json +++ b/pxr/usdImaging/usdImaging/plugInfo.json @@ -111,6 +111,13 @@ "isInternal": true, "primTypeName": "NurbsPatch" }, + "UsdImagingPlaneAdapter": { + "bases": [ + "UsdImagingGprimAdapter" + ], + "isInternal": true, + "primTypeName": "Plane" + }, "UsdImagingPointsAdapter": { "bases": [ "UsdImagingGprimAdapter" From c669a8d0d115b7e371933753ee0b92bc2271ecac Mon Sep 17 00:00:00 2001 From: Paul Molodowitch Date: Sun, 3 Apr 2022 06:15:24 -0700 Subject: [PATCH 010/285] [usdImagingGL] fix thresholds for testUsdImagingGLPurpose Currently, testUsdImagingGLPurpose relies solely on perceptual diff, which fails to detect a change between world_0.png (which shows a sphere) and world_1.png (which is empty). Changing to a reasonable default for pixel difference (-fail .1, -failpercent 10) which can successfully distinguish the two images. --- pxr/usdImaging/usdImagingGL/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pxr/usdImaging/usdImagingGL/CMakeLists.txt b/pxr/usdImaging/usdImagingGL/CMakeLists.txt index 8481ec387e..22e8285740 100644 --- a/pxr/usdImaging/usdImagingGL/CMakeLists.txt +++ b/pxr/usdImaging/usdImagingGL/CMakeLists.txt @@ -1854,8 +1854,8 @@ pxr_register_test(testUsdImagingGLPurpose world_1.png world_2.png world_3.png - FAIL 1 - FAIL_PERCENT 1 + FAIL .1 + FAIL_PERCENT 10 PERCEPTUAL EXPECTED_RETURN_CODE 0 TESTENV testUsdImagingGLPurpose From 034df39a78a5fc4cada49b545ad2a87fd6666e1d Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Tue, 19 Apr 2022 14:21:01 -0400 Subject: [PATCH 011/285] Update to MaterialX v1.38.4 --- build_scripts/build_usd.py | 29 +----------------- pxr/imaging/hdSt/materialXFilter.cpp | 15 ++++++++-- pxr/imaging/hdSt/materialXShaderGen.cpp | 30 +++++++++++++++---- .../plugin/hdPrman/matfiltMaterialX.cpp | 12 +++++++- 4 files changed, 50 insertions(+), 36 deletions(-) diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py index 80115c9482..6421f9b3fd 100644 --- a/build_scripts/build_usd.py +++ b/build_scripts/build_usd.py @@ -1349,7 +1349,7 @@ def InstallDraco(context, force, buildArgs): ############################################################ # MaterialX -MATERIALX_URL = "https://github.com/materialx/MaterialX/archive/v1.38.3.zip" +MATERIALX_URL = "https://github.com/materialx/MaterialX/archive/v1.38.4.zip" def InstallMaterialX(context, force, buildArgs): with CurrentWorkingDirectory(DownloadURL(MATERIALX_URL, context, force)): @@ -1357,35 +1357,8 @@ def InstallMaterialX(context, force, buildArgs): cmakeOptions += buildArgs; - if "v1.38.3.zip" in MATERIALX_URL: - # This will be fixed in v1.38.4: - PatchFile(os.path.join('cmake', 'modules', 'MaterialXConfig.cmake.in'), - [('set_and_check(MATERIALX_PYTHON_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/python")\n', - 'IF (@MATERIALX_BUILD_PYTHON@ AND @MATERIALX_INSTALL_PYTHON@)\n' - ' set_and_check(MATERIALX_PYTHON_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/python")\n' - 'ENDIF()\n')], - multiLineMatches=True) - RunCMake(context, force, cmakeOptions) - if "v1.38.3.zip" in MATERIALX_URL: - # This will be fixed in v1.38.4: - # Post-build fix. Make sure MaterialX config is relocatable: - filename = os.path.join(context.instDir, 'lib', 'cmake', 'MaterialX', 'MaterialXTargets.cmake') - oldLines = open(filename, 'r').readlines() - newLines = [] - for s in oldLines: - if s.startswith('set(_IMPORT_PREFIX '): - pathBegin = s.find(' ') + 1 - pathEnd = s.rfind(')') - s = s[:pathBegin] + '${PACKAGE_PREFIX_DIR}' + s[pathEnd:] - newLines.append(s) - if newLines != oldLines: - PrintInfo("Patching file {filename} (original in {oldFilename})..." - .format(filename=filename, oldFilename=filename + ".old")) - shutil.copy(filename, filename + ".old") - open(filename, 'w').writelines(newLines) - MATERIALX = Dependency("MaterialX", InstallMaterialX, "include/MaterialXCore/Library.h") ############################################################ diff --git a/pxr/imaging/hdSt/materialXFilter.cpp b/pxr/imaging/hdSt/materialXFilter.cpp index 788e774133..0bea302121 100644 --- a/pxr/imaging/hdSt/materialXFilter.cpp +++ b/pxr/imaging/hdSt/materialXFilter.cpp @@ -103,8 +103,19 @@ HdSt_GenMaterialXShader( { // Initialize the Context for shaderGen. mx::GenContext mxContext = HdStMaterialXShaderGen::create(mxHdInfo); - mxContext.registerSourceCodeSearchPath(searchPath); - + + // Starting from MaterialX 1.38.4 at PR 877, we must remove the "libraries" part: + mx::FileSearchPath libSearchPaths; + for (const mx::FilePath &path : searchPath) { + if (path.getBaseName() == "libraries") { + libSearchPaths.append(path.getParentPath()); + } + else { + libSearchPaths.append(path); + } + } + mxContext.registerSourceCodeSearchPath(libSearchPaths); + // Add the Direct Light mtlx file to the mxDoc mx::DocumentPtr lightDoc = mx::createDocument(); mx::readFromXmlString(lightDoc, mxDirectLightString); diff --git a/pxr/imaging/hdSt/materialXShaderGen.cpp b/pxr/imaging/hdSt/materialXShaderGen.cpp index 85f6eb9531..7eff2fde05 100644 --- a/pxr/imaging/hdSt/materialXShaderGen.cpp +++ b/pxr/imaging/hdSt/materialXShaderGen.cpp @@ -273,7 +273,8 @@ HdStMaterialXShaderGen::_EmitMxFunctions( mx::ShaderStage& mxStage) const { // Add global constants and type definitions - emitInclude("stdlib/" + mx::GlslShaderGenerator::TARGET + // Starting from MaterialX 1.38.4 at PR 877, we must add the "libraries" part: + emitInclude("libraries/stdlib/" + mx::GlslShaderGenerator::TARGET + "/lib/mx_math.glsl", mxContext, mxStage); emitLine("#if NUM_LIGHTS > 0", mxStage, false); emitLine("#define MAX_LIGHT_SOURCES NUM_LIGHTS", mxStage, false); @@ -391,7 +392,8 @@ HdStMaterialXShaderGen::_EmitMxFunctions( emitSpecularEnvironment(mxContext, mxStage); } if (shadowing) { - emitInclude("pbrlib/" + mx::GlslShaderGenerator::TARGET + // Starting from MaterialX 1.38.4 at PR 877, we must add the "libraries" part: + emitInclude("libraries/pbrlib/" + mx::GlslShaderGenerator::TARGET + "/lib/mx_shadow.glsl", mxContext, mxStage); } @@ -399,7 +401,8 @@ HdStMaterialXShaderGen::_EmitMxFunctions( if (mxContext.getOptions().hwDirectionalAlbedoMethod == mx::HwDirectionalAlbedoMethod::DIRECTIONAL_ALBEDO_TABLE || mxContext.getOptions().hwWriteAlbedoTable) { - emitInclude("pbrlib/" + mx::GlslShaderGenerator::TARGET + // Starting from MaterialX 1.38.4 at PR 877, we must add the "libraries" part: + emitInclude("libraries/pbrlib/" + mx::GlslShaderGenerator::TARGET + "/lib/mx_table.glsl", mxContext, mxStage); emitLineBreak(mxStage); } @@ -464,8 +467,25 @@ HdStMaterialXShaderGen::_EmitMxSurfaceShader( mxStage); } else { - // Add all function calls - emitFunctionCalls(mxGraph, mxContext, mxStage); + // Surface shaders need special handling. + if (mxGraph.hasClassification(mx::ShaderNode::Classification::SHADER | + mx::ShaderNode::Classification::SURFACE)) + { + // Emit all texturing nodes. These are inputs to any + // closure/shader nodes and need to be emitted first. + emitFunctionCalls(mxGraph, mxContext, mxStage, mx::ShaderNode::Classification::TEXTURE); + + // Emit function calls for all surface shader nodes. + // These will internally emit their closure function calls. + emitFunctionCalls(mxGraph, mxContext, mxStage, mx::ShaderNode::Classification::SHADER | + mx::ShaderNode::Classification::SURFACE); + } + else + { + // No surface shader graph so just generate all + // function calls in order. + emitFunctionCalls(mxGraph, mxContext, mxStage); + } // Emit final output std::string finalOutputReturn = "vec4 mxOut = " ; diff --git a/third_party/renderman-24/plugin/hdPrman/matfiltMaterialX.cpp b/third_party/renderman-24/plugin/hdPrman/matfiltMaterialX.cpp index b1da731902..50001c4c0d 100644 --- a/third_party/renderman-24/plugin/hdPrman/matfiltMaterialX.cpp +++ b/third_party/renderman-24/plugin/hdPrman/matfiltMaterialX.cpp @@ -103,7 +103,17 @@ _GenMaterialXShaderCode( { // Initialize the Context for shaderGen mx::GenContext mxContext = mx::OslShaderGenerator::create(); - mxContext.registerSourceCodeSearchPath(searchPath); + // Starting from MaterialX 1.38.4 at PR 877, we must remove the "libraries" part: + mx::FileSearchPath libSearchPaths; + for (const mx::FilePath &path : searchPath) { + if (path.getBaseName() == "libraries") { + libSearchPaths.append(path.getParentPath()); + } + else { + libSearchPaths.append(path); + } + } + mxContext.registerSourceCodeSearchPath(libSearchPaths); mxContext.getOptions().fileTextureVerticalFlip = false; // Get the Node from the Nodegraph/mxDoc From aaf20de564e29c3e59bcd32b3539add08b7597c6 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Tue, 19 Apr 2022 16:22:11 -0400 Subject: [PATCH 012/285] Add support back in for MaterialX v1.38.3 --- pxr/imaging/hdSt/materialXFilter.cpp | 4 ++++ pxr/imaging/hdSt/materialXShaderGen.cpp | 19 +++++++++++-------- .../plugin/hdPrman/matfiltMaterialX.cpp | 4 ++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pxr/imaging/hdSt/materialXFilter.cpp b/pxr/imaging/hdSt/materialXFilter.cpp index 0bea302121..3bc8e36c12 100644 --- a/pxr/imaging/hdSt/materialXFilter.cpp +++ b/pxr/imaging/hdSt/materialXFilter.cpp @@ -104,6 +104,9 @@ HdSt_GenMaterialXShader( // Initialize the Context for shaderGen. mx::GenContext mxContext = HdStMaterialXShaderGen::create(mxHdInfo); +#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION == 38 && MATERIALX_BUILD_VERSION == 3 + mxContext.registerSourceCodeSearchPath(searchPath); +#else // Starting from MaterialX 1.38.4 at PR 877, we must remove the "libraries" part: mx::FileSearchPath libSearchPaths; for (const mx::FilePath &path : searchPath) { @@ -115,6 +118,7 @@ HdSt_GenMaterialXShader( } } mxContext.registerSourceCodeSearchPath(libSearchPaths); +#endif // Add the Direct Light mtlx file to the mxDoc mx::DocumentPtr lightDoc = mx::createDocument(); diff --git a/pxr/imaging/hdSt/materialXShaderGen.cpp b/pxr/imaging/hdSt/materialXShaderGen.cpp index 7eff2fde05..69f3abf8f2 100644 --- a/pxr/imaging/hdSt/materialXShaderGen.cpp +++ b/pxr/imaging/hdSt/materialXShaderGen.cpp @@ -272,9 +272,14 @@ HdStMaterialXShaderGen::_EmitMxFunctions( mx::GenContext& mxContext, mx::ShaderStage& mxStage) const { - // Add global constants and type definitions +#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION == 38 && MATERIALX_BUILD_VERSION == 3 + std::string libPath; +#else // Starting from MaterialX 1.38.4 at PR 877, we must add the "libraries" part: - emitInclude("libraries/stdlib/" + mx::GlslShaderGenerator::TARGET + std::string libPath = "libraries/"; +#endif + // Add global constants and type definitions + emitInclude(libPath + "stdlib/" + mx::GlslShaderGenerator::TARGET + "/lib/mx_math.glsl", mxContext, mxStage); emitLine("#if NUM_LIGHTS > 0", mxStage, false); emitLine("#define MAX_LIGHT_SOURCES NUM_LIGHTS", mxStage, false); @@ -392,8 +397,7 @@ HdStMaterialXShaderGen::_EmitMxFunctions( emitSpecularEnvironment(mxContext, mxStage); } if (shadowing) { - // Starting from MaterialX 1.38.4 at PR 877, we must add the "libraries" part: - emitInclude("libraries/pbrlib/" + mx::GlslShaderGenerator::TARGET + emitInclude(libPath + "pbrlib/" + mx::GlslShaderGenerator::TARGET + "/lib/mx_shadow.glsl", mxContext, mxStage); } @@ -401,8 +405,7 @@ HdStMaterialXShaderGen::_EmitMxFunctions( if (mxContext.getOptions().hwDirectionalAlbedoMethod == mx::HwDirectionalAlbedoMethod::DIRECTIONAL_ALBEDO_TABLE || mxContext.getOptions().hwWriteAlbedoTable) { - // Starting from MaterialX 1.38.4 at PR 877, we must add the "libraries" part: - emitInclude("libraries/pbrlib/" + mx::GlslShaderGenerator::TARGET + emitInclude(libPath + "pbrlib/" + mx::GlslShaderGenerator::TARGET + "/lib/mx_table.glsl", mxContext, mxStage); emitLineBreak(mxStage); } @@ -411,12 +414,12 @@ HdStMaterialXShaderGen::_EmitMxFunctions( // depending on the vertical flip flag. if (mxContext.getOptions().fileTextureVerticalFlip) { _tokenSubstitutions[mx::ShaderGenerator::T_FILE_TRANSFORM_UV] = - "stdlib/" + mx::GlslShaderGenerator::TARGET + + libPath + "stdlib/" + mx::GlslShaderGenerator::TARGET + "/lib/mx_transform_uv_vflip.glsl"; } else { _tokenSubstitutions[mx::ShaderGenerator::T_FILE_TRANSFORM_UV] = - "stdlib/" + mx::GlslShaderGenerator::TARGET + + libPath + "stdlib/" + mx::GlslShaderGenerator::TARGET + "/lib/mx_transform_uv.glsl"; } diff --git a/third_party/renderman-24/plugin/hdPrman/matfiltMaterialX.cpp b/third_party/renderman-24/plugin/hdPrman/matfiltMaterialX.cpp index 50001c4c0d..75936f3022 100644 --- a/third_party/renderman-24/plugin/hdPrman/matfiltMaterialX.cpp +++ b/third_party/renderman-24/plugin/hdPrman/matfiltMaterialX.cpp @@ -103,6 +103,9 @@ _GenMaterialXShaderCode( { // Initialize the Context for shaderGen mx::GenContext mxContext = mx::OslShaderGenerator::create(); +#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION == 38 && MATERIALX_BUILD_VERSION == 3 + mxContext.registerSourceCodeSearchPath(searchPath); +#else // Starting from MaterialX 1.38.4 at PR 877, we must remove the "libraries" part: mx::FileSearchPath libSearchPaths; for (const mx::FilePath &path : searchPath) { @@ -114,6 +117,7 @@ _GenMaterialXShaderCode( } } mxContext.registerSourceCodeSearchPath(libSearchPaths); +#endif mxContext.getOptions().fileTextureVerticalFlip = false; // Get the Node from the Nodegraph/mxDoc From c83265fd57cbbff88bfa73eb31cd9ccfe5108aa9 Mon Sep 17 00:00:00 2001 From: Aloys Baillet Date: Thu, 21 Apr 2022 09:39:16 +1000 Subject: [PATCH 013/285] Fixed missing material dependency on GeomSubSet --- pxr/usdImaging/usdImaging/meshAdapter.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pxr/usdImaging/usdImaging/meshAdapter.cpp b/pxr/usdImaging/usdImaging/meshAdapter.cpp index f95d0e14ae..735652bbd0 100644 --- a/pxr/usdImaging/usdImaging/meshAdapter.cpp +++ b/pxr/usdImaging/usdImaging/meshAdapter.cpp @@ -115,6 +115,11 @@ UsdImagingMeshAdapter::Populate(UsdPrim const& prim, index->GetMaterialAdapter(materialPrim); if (materialAdapter) { materialAdapter->Populate(materialPrim, index, nullptr); + // We need to register a dependency on the material prim so + // that geometry is updated when the material is + // (specifically, DirtyMaterialId). + // XXX: Eventually, it would be great to push this into hydra. + index->AddDependency(cachePath, materialPrim); } } } From a00b7f58cd804b551ffead57557ac3c541a49298 Mon Sep 17 00:00:00 2001 From: tallytalwar Date: Fri, 22 Apr 2022 13:15:27 -0700 Subject: [PATCH 014/285] Bump USD version to anticipated next release 22.08 (Internal change: 2227785) --- cmake/defaults/Version.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/defaults/Version.cmake b/cmake/defaults/Version.cmake index 75cecdf692..2f931938a7 100644 --- a/cmake/defaults/Version.cmake +++ b/cmake/defaults/Version.cmake @@ -24,6 +24,6 @@ # Versioning information set(PXR_MAJOR_VERSION "0") set(PXR_MINOR_VERSION "22") -set(PXR_PATCH_VERSION "5") +set(PXR_PATCH_VERSION "8") math(EXPR PXR_VERSION "${PXR_MAJOR_VERSION} * 10000 + ${PXR_MINOR_VERSION} * 100 + ${PXR_PATCH_VERSION}") From 1a1e7f70029201825741aaad917b3285a93e29a6 Mon Sep 17 00:00:00 2001 From: pixar-oss Date: Mon, 4 Apr 2022 13:24:54 -0700 Subject: [PATCH 015/285] Remove usage of deprecated function GetConnectedSource which is causing warning messages in katana (Internal change: 2224512) --- pxr/usd/usdShade/nodeGraph.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pxr/usd/usdShade/nodeGraph.cpp b/pxr/usd/usdShade/nodeGraph.cpp index d63aaf766c..bdb3e0c342 100644 --- a/pxr/usd/usdShade/nodeGraph.cpp +++ b/pxr/usd/usdShade/nodeGraph.cpp @@ -256,15 +256,14 @@ _ComputeNonTransitiveInputConsumersMap( std::vector internalInputs = connectable.GetInputs(); for (const auto &internalInput: internalInputs) { - UsdShadeConnectableAPI source; - TfToken sourceName; - UsdShadeAttributeType sourceType; - if (UsdShadeConnectableAPI::GetConnectedSource(internalInput, - &source, &sourceName, &sourceType)) { - if (source.GetPrim() == nodeGraph.GetPrim() && - _IsValidInput(source, sourceType)) + UsdShadeSourceInfoVector sources = + UsdShadeConnectableAPI::GetConnectedSources(internalInput); + + for (const auto& sourceInfo : sources) { + if (sourceInfo.source.GetPrim() == nodeGraph.GetPrim() && + _IsValidInput(sourceInfo.source, sourceInfo.sourceType)) { - result[nodeGraph.GetInput(sourceName)].push_back( + result[nodeGraph.GetInput(sourceInfo.sourceName)].push_back( internalInput); } } From 70d76f31c1e928a8e1d44b172e3bcf8ddef6817c Mon Sep 17 00:00:00 2001 From: unhyperbolic Date: Mon, 4 Apr 2022 13:26:45 -0700 Subject: [PATCH 016/285] Animated volumes in Storm: adding scene index plugin that adds a dependency of a volume on its fields and chains it with a dependency forwarding scene index. This way, the voulme pulls the new textures when the filePaths of its volume fields change. Note that this replaces the old mechanism where HdStField::Sync calls HdChangeTracker::MarkAllRprimsDirty - when scene indices or scene index emulation is used. (Internal change: 2224513) (Internal change: 2224657) --- pxr/imaging/hd/volumeFieldBindingSchema.cpp | 11 +- pxr/imaging/hd/volumeFieldBindingSchema.h | 6 +- pxr/imaging/hdSt/CMakeLists.txt | 1 + .../hdSt/dependencySceneIndexPlugin.cpp | 288 ++++++++++++++++++ pxr/imaging/hdSt/dependencySceneIndexPlugin.h | 57 ++++ pxr/imaging/hdSt/field.cpp | 7 +- pxr/imaging/hdSt/plugInfo.json | 8 + 7 files changed, 373 insertions(+), 5 deletions(-) create mode 100644 pxr/imaging/hdSt/dependencySceneIndexPlugin.cpp create mode 100644 pxr/imaging/hdSt/dependencySceneIndexPlugin.h diff --git a/pxr/imaging/hd/volumeFieldBindingSchema.cpp b/pxr/imaging/hd/volumeFieldBindingSchema.cpp index 5337ab1589..416198f961 100644 --- a/pxr/imaging/hd/volumeFieldBindingSchema.cpp +++ b/pxr/imaging/hd/volumeFieldBindingSchema.cpp @@ -36,6 +36,15 @@ PXR_NAMESPACE_OPEN_SCOPE TF_DEFINE_PUBLIC_TOKENS(HdVolumeFieldBindingSchemaTokens, HDVOLUMEFIELDBINDING_SCHEMA_TOKENS); +TfTokenVector +HdVolumeFieldBindingSchema::GetVolumeFieldBindingNames() +{ + HdContainerDataSourceHandle container = GetContainer(); + if (!container) { + return {}; + } + return container->GetNames(); +} HdPathDataSourceHandle HdVolumeFieldBindingSchema::GetVolumeFieldBinding(TfToken const &name) @@ -75,4 +84,4 @@ HdVolumeFieldBindingSchema::GetDefaultLocator() ); return locator; } -PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/imaging/hd/volumeFieldBindingSchema.h b/pxr/imaging/hd/volumeFieldBindingSchema.h index d8a3e17658..99f43eb9d8 100644 --- a/pxr/imaging/hd/volumeFieldBindingSchema.h +++ b/pxr/imaging/hd/volumeFieldBindingSchema.h @@ -57,6 +57,10 @@ class HdVolumeFieldBindingSchema : public HdSchema TfToken *names, HdDataSourceBaseHandle *values); + HD_API + TfTokenVector GetVolumeFieldBindingNames(); + + HD_API HdPathDataSourceHandle GetVolumeFieldBinding(TfToken const &name); @@ -78,4 +82,4 @@ class HdVolumeFieldBindingSchema : public HdSchema PXR_NAMESPACE_CLOSE_SCOPE -#endif \ No newline at end of file +#endif diff --git a/pxr/imaging/hdSt/CMakeLists.txt b/pxr/imaging/hdSt/CMakeLists.txt index ef446ae213..6ae4955e8e 100644 --- a/pxr/imaging/hdSt/CMakeLists.txt +++ b/pxr/imaging/hdSt/CMakeLists.txt @@ -52,6 +52,7 @@ pxr_library(hdSt commandBuffer copyComputation debugCodes + dependencySceneIndexPlugin dispatchBuffer domeLightComputations drawItem diff --git a/pxr/imaging/hdSt/dependencySceneIndexPlugin.cpp b/pxr/imaging/hdSt/dependencySceneIndexPlugin.cpp new file mode 100644 index 0000000000..35034ed52a --- /dev/null +++ b/pxr/imaging/hdSt/dependencySceneIndexPlugin.cpp @@ -0,0 +1,288 @@ +// +// Copyright 2022 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. + +#include "pxr/imaging/hdSt/dependencySceneIndexPlugin.h" + +#include "pxr/imaging/hd/dependenciesSchema.h" +#include "pxr/imaging/hd/dependencyForwardingSceneIndex.h" +#include "pxr/imaging/hd/perfLog.h" +#include "pxr/imaging/hd/retainedDataSource.h" +#include "pxr/imaging/hd/sceneIndexPluginRegistry.h" +#include "pxr/imaging/hd/tokens.h" +#include "pxr/imaging/hd/volumeFieldBindingSchema.h" +#include "pxr/imaging/hd/volumeFieldSchema.h" + +PXR_NAMESPACE_OPEN_SCOPE + +TF_DEFINE_PRIVATE_TOKENS( + _tokens, + ((sceneIndexPluginName, "HdSt_DependencySceneIndexPlugin")) +); + +static const char * const _pluginDisplayName = "GL"; + +TF_REGISTRY_FUNCTION(TfType) +{ + HdSceneIndexPluginRegistry::Define< + HdSt_DependencySceneIndexPlugin, + HdSceneIndexPlugin>(); +} + +TF_REGISTRY_FUNCTION(HdSceneIndexPlugin) +{ + const HdSceneIndexPluginRegistry::InsertionPhase insertionPhase = 0; + + HdSceneIndexPluginRegistry::GetInstance().RegisterSceneIndexForRenderer( + _pluginDisplayName, + _tokens->sceneIndexPluginName, + nullptr, + insertionPhase, + HdSceneIndexPluginRegistry::InsertionOrderAtStart); +} + +namespace +{ + +/// Computes the dependencies for the volumeFieldBindings of a volume +/// prim. They need to be returned when the data source locator __dependencies +/// is querried. +HdRetainedContainerDataSourceHandle +_ComputeVolumeFieldBindingDependencies(HdContainerDataSourceHandle &primSource) +{ + HD_TRACE_FUNCTION(); + + HdVolumeFieldBindingSchema schema = + HdVolumeFieldBindingSchema::GetFromParent(primSource); + + const TfTokenVector names = schema.GetVolumeFieldBindingNames(); + std::vector dependencies; + dependencies.reserve(names.size()); + + for (const TfToken &name : names) { + HdDependencySchema::Builder builder; + builder.SetDependedOnPrimPath( + schema.GetVolumeFieldBinding(name)); + builder.SetDependedOnDataSourceLocator( + HdRetainedTypedSampledDataSource::New( + HdVolumeFieldSchema::GetDefaultLocator())); + builder.SetAffectedDataSourceLocator( + HdRetainedTypedSampledDataSource::New( + HdVolumeFieldBindingSchema::GetDefaultLocator())); + dependencies.push_back(builder.Build()); + } + + return HdRetainedContainerDataSource::New( + names.size(), names.data(), dependencies.data()); +} + +/// Data source adding __dependencies given the data source of a +/// volume. +class _VolumePrimDataSource : public HdContainerDataSource +{ +public: + HD_DECLARE_DATASOURCE(_VolumePrimDataSource); + + _VolumePrimDataSource( + const HdContainerDataSourceHandle &primSource) + : _primSource(primSource) + { + } + + bool Has(const TfToken &name) override + { + if (!_primSource) { + return false; + } + + if (name == HdDependenciesSchemaTokens->__dependencies) { + return true; + } + + return _primSource->Has(name); + } + + TfTokenVector GetNames() override + { + TfTokenVector result; + + if (!_primSource) { + return result; + } + + result = _primSource->GetNames(); + result.push_back(HdDependenciesSchemaTokens->__dependencies); + + return result; + } + + HdDataSourceBaseHandle Get(const TfToken &name) override + { + if (!_primSource) { + return nullptr; + } + + if (name == HdDependenciesSchemaTokens->__dependencies) { + // Note that this clobbers any __dependencies coming from the + // input scene index. If this turned out to be a problem, + // we can use an HdOverlayContainerDataSource created from the + // result of _primSource->Get(name) and + // _ComputeVolumeFieldBindingDependencies instead. + return _ComputeVolumeFieldBindingDependencies(_primSource); + } + + return _primSource->Get(name); + } + +private: + HdContainerDataSourceHandle _primSource; +}; + +HD_DECLARE_DATASOURCE_HANDLES(_VolumePrimDataSource); + +TF_DECLARE_REF_PTRS(_SceneIndex); + +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +/// \class _SceneIndex +/// +/// The scene index feeding into HdDependencyForwardingSceneIndex constructed by +/// by the HdSt_DependencySceneIndexPlugin. +/// +class _SceneIndex : public HdSingleInputFilteringSceneIndexBase +{ +public: + static _SceneIndexRefPtr New( + const HdSceneIndexBaseRefPtr &inputSceneIndex) + { + return TfCreateRefPtr(new _SceneIndex(inputSceneIndex)); + } + + HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override + { + const HdSceneIndexPrim prim = _GetInputSceneIndex()->GetPrim(primPath); + if (prim.primType == HdPrimTypeTokens->volume) { + return + { prim.primType, _VolumePrimDataSource::New(prim.dataSource) }; + } + return prim; + } + + SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override + { + return _GetInputSceneIndex()->GetChildPrimPaths(primPath); + } + +protected: + _SceneIndex( + const HdSceneIndexBaseRefPtr &inputSceneIndex) + : HdSingleInputFilteringSceneIndexBase(inputSceneIndex) + { + } + + void _PrimsAdded( + const HdSceneIndexBase &sender, + const HdSceneIndexObserver::AddedPrimEntries &entries) override + { + if (!_IsObserved()) { + return; + } + + _SendPrimsAdded(entries); + } + + void _PrimsRemoved( + const HdSceneIndexBase &sender, + const HdSceneIndexObserver::RemovedPrimEntries &entries) override + { + if (!_IsObserved()) { + return; + } + + _SendPrimsRemoved(entries); + } + + void _PrimsDirtied( + const HdSceneIndexBase &sender, + const HdSceneIndexObserver::DirtiedPrimEntries &entries) override + { + HD_TRACE_FUNCTION(); + + if (!_IsObserved()) { + return; + } + + // If the volumeFieldBinding locator is dirtied, we also need to + // dirty the __dependencies locator. + + std::vector indices; + for (size_t i = 0; i < entries.size(); i++) { + const HdDataSourceLocatorSet &locators = entries[i].dirtyLocators; + if (locators.Intersects( + HdVolumeFieldBindingSchema::GetDefaultLocator())) { + indices.push_back(i); + } + } + + if (indices.empty()) { + _SendPrimsDirtied(entries); + return; + } + + HdSceneIndexObserver::DirtiedPrimEntries newEntries(entries); + for (const size_t i : indices) { + newEntries[i].dirtyLocators.insert( + HdDependenciesSchema::GetDefaultLocator()); + } + + _SendPrimsDirtied(newEntries); + } +}; + +} + +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +// Implementation of HdSt_DependencySceneIndexPlugin + +HdSt_DependencySceneIndexPlugin::HdSt_DependencySceneIndexPlugin() = default; + +HdSceneIndexBaseRefPtr +HdSt_DependencySceneIndexPlugin::_AppendSceneIndex( + const HdSceneIndexBaseRefPtr &inputScene, + const HdContainerDataSourceHandle &inputArgs) +{ + // Chain the dependency forwarding scene index with the above scene + // index adding __dependencies. The __dependencies are consumed by + // the forwarding scene index and instruct the scene index to dirty + // the volumeFieldBinding locator of a volume prim if any of the + // fields targeted by the volume prim are dirtied. + + return + HdDependencyForwardingSceneIndex::New( + _SceneIndex::New( + inputScene)); +} + +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/imaging/hdSt/dependencySceneIndexPlugin.h b/pxr/imaging/hdSt/dependencySceneIndexPlugin.h new file mode 100644 index 0000000000..34aa2fb5f1 --- /dev/null +++ b/pxr/imaging/hdSt/dependencySceneIndexPlugin.h @@ -0,0 +1,57 @@ +// +// Copyright 2022 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. + +#ifndef PXR_IMAGING_HD_ST_DEPENDENCY_SCENE_INDEX_PLUGIN_H +#define PXR_IMAGING_HD_ST_DEPENDENCY_SCENE_INDEX_PLUGIN_H + +#include "pxr/pxr.h" +#include "pxr/imaging/hdSt/api.h" +#include "pxr/imaging/hd/sceneIndexPlugin.h" + +PXR_NAMESPACE_OPEN_SCOPE + +/// \class HdSt_DependencySceneIndexPlugin +/// +/// Plugin adds a chain of its own scene index generating dependencies +/// and a dependency forwarding scene index to the Storm render delegate. +/// +/// Together, this chain will dirty the volumeFieldBinding data source +/// locator of a volume prim if any of the targeted volume fields changes. +/// That is, if, e.g., the filePath of a volume field changes, then the volume +/// using that volume field will be dirtied so that HdStVolume will update +/// which 3d textures it will use. +/// +class HdSt_DependencySceneIndexPlugin : public HdSceneIndexPlugin +{ +public: + HdSt_DependencySceneIndexPlugin(); + +protected: + HdSceneIndexBaseRefPtr _AppendSceneIndex( + const HdSceneIndexBaseRefPtr &inputScene, + const HdContainerDataSourceHandle &inputArgs) override; +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif // PXR_IMAGING_HD_ST_RENDER_DELEGATE_H diff --git a/pxr/imaging/hdSt/field.cpp b/pxr/imaging/hdSt/field.cpp index 5c99790146..b5ef124ce4 100644 --- a/pxr/imaging/hdSt/field.cpp +++ b/pxr/imaging/hdSt/field.cpp @@ -100,12 +100,13 @@ HdStField::Sync(HdSceneDelegate *sceneDelegate, 1048576 * textureMemoryValue.GetWithDefault(0.0f); if (_isInitialized) { + // This code is no longer needed when using scene indices + // or scene index emulation since this dependency is now tracked + // by the HdSt_DependencySceneIndexPlugin. + // // Force volume prim to pick up the new field resource and // recompute bounding box. // - // XXX:-matthias - // Ideally, this would be more fine-grained than blasting all - // rprims. HdChangeTracker& changeTracker = sceneDelegate->GetRenderIndex().GetChangeTracker(); changeTracker.MarkAllRprimsDirty(HdChangeTracker::DirtyVolumeField); diff --git a/pxr/imaging/hdSt/plugInfo.json b/pxr/imaging/hdSt/plugInfo.json index b60641e438..e76026dda5 100644 --- a/pxr/imaging/hdSt/plugInfo.json +++ b/pxr/imaging/hdSt/plugInfo.json @@ -2,6 +2,14 @@ "Plugins": [ { "Info": { + "Types": { + "HdSt_DependencySceneIndexPlugin" : { + "bases": ["HdSceneIndexPlugin"], + "loadWithRenderer" : "GL", + "priority": 0, + "displayName": "Storm Dependency Scene Index" + } + }, "ShaderResources": "shaders" }, "LibraryPath": "@PLUG_INFO_LIBRARY_PATH@", From 38ce389e78a41369d3becc87d0af86da30536814 Mon Sep 17 00:00:00 2001 From: unhyperbolic Date: Mon, 4 Apr 2022 13:50:48 -0700 Subject: [PATCH 017/285] Introducing HdDependencyForwardingSceneIndex. (Internal change: 2224515) (Internal change: 2224584) (Internal change: 2224658) --- pxr/imaging/hd/CMakeLists.txt | 1 + .../hd/dependencyForwardingSceneIndex.cpp | 444 ++++++++++++++++++ .../hd/dependencyForwardingSceneIndex.h | 242 ++++++++++ 3 files changed, 687 insertions(+) create mode 100644 pxr/imaging/hd/dependencyForwardingSceneIndex.cpp create mode 100644 pxr/imaging/hd/dependencyForwardingSceneIndex.h diff --git a/pxr/imaging/hd/CMakeLists.txt b/pxr/imaging/hd/CMakeLists.txt index 61eb9e4d0c..2952733225 100644 --- a/pxr/imaging/hd/CMakeLists.txt +++ b/pxr/imaging/hd/CMakeLists.txt @@ -49,6 +49,7 @@ pxr_library(hd dataSourceMaterialNetworkInterface debugCodes dependenciesSchema + dependencyForwardingSceneIndex dependencySchema dirtyBitsTranslator dirtyList diff --git a/pxr/imaging/hd/dependencyForwardingSceneIndex.cpp b/pxr/imaging/hd/dependencyForwardingSceneIndex.cpp new file mode 100644 index 0000000000..4b9e263d1f --- /dev/null +++ b/pxr/imaging/hd/dependencyForwardingSceneIndex.cpp @@ -0,0 +1,444 @@ +// +// Copyright 2022 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#include "pxr/imaging/hd/dependencyForwardingSceneIndex.h" +#include "pxr/imaging/hd/dependenciesSchema.h" + +PXR_NAMESPACE_OPEN_SCOPE + +//---------------------------------------------------------------------------- + +HdDependencyForwardingSceneIndex::HdDependencyForwardingSceneIndex( + HdSceneIndexBaseRefPtr inputScene) +: HdSingleInputFilteringSceneIndexBase(inputScene) +{ +} + +HdSceneIndexPrim +HdDependencyForwardingSceneIndex::GetPrim(const SdfPath &primPath) const +{ + if (_GetInputSceneIndex()) { + + if (_affectedPrimToDependsOnPathsMap.find(primPath) == + _affectedPrimToDependsOnPathsMap.end()) { + _UpdateDependencies(primPath); + } + + return _GetInputSceneIndex()->GetPrim(primPath); + } + + return {TfToken(), nullptr}; +} + +SdfPathVector +HdDependencyForwardingSceneIndex::GetChildPrimPaths( + const SdfPath &primPath) const +{ + // pass through without change + if (_GetInputSceneIndex()) { + return _GetInputSceneIndex()->GetChildPrimPaths(primPath); + } + + return {}; +} + +void +HdDependencyForwardingSceneIndex::_PrimsAdded( + const HdSceneIndexBase &sender, + const HdSceneIndexObserver::AddedPrimEntries &entries) +{ + _SendPrimsAdded(entries); +} + +void +HdDependencyForwardingSceneIndex::_PrimsRemoved( + const HdSceneIndexBase &sender, + const HdSceneIndexObserver::RemovedPrimEntries &entries) +{ + for (const HdSceneIndexObserver::RemovedPrimEntry &entry : entries) { + const SdfPath &primPath = entry.primPath; + + _ClearDependencies(primPath); + + //_potentiallyDeletedDependedOnPaths(primPath); + + // if this is depended on, flag its map of affected paths/locators + // for deletion + + _DependedOnPrimsAffectedPrimsMap::iterator it = + _dependedOnPrimToDependentsMap.find(primPath); + + if (it != _dependedOnPrimToDependentsMap.end()) { + for (auto &dependedOnPair : (*it).second) { + dependedOnPair.second.flaggedForDeletion = true; + } + + _potentiallyDeletedDependedOnPaths.insert(primPath); + } + } + + _SendPrimsRemoved(entries); +} + +void +HdDependencyForwardingSceneIndex::_PrimsDirtied( + const HdSceneIndexBase &sender, + const HdSceneIndexObserver::DirtiedPrimEntries &entries) +{ + _VisitedNodeSet visited; + HdSceneIndexObserver::DirtiedPrimEntries affectedEntries; + + for (const HdSceneIndexObserver::DirtiedPrimEntry &entry : entries) { + for (const HdDataSourceLocator &sourceLocator : entry.dirtyLocators) { + _PrimDirtied(entry.primPath, sourceLocator, &visited, + &affectedEntries); + } + } + + if (affectedEntries.empty()) { + _SendPrimsDirtied(entries); + } else { + affectedEntries.insert(affectedEntries.begin(), + entries.begin(), entries.end()); + _SendPrimsDirtied(affectedEntries); + } +} + + +void +HdDependencyForwardingSceneIndex::_PrimDirtied( + const SdfPath &primPath, + const HdDataSourceLocator &sourceLocator, + _VisitedNodeSet *visited, + HdSceneIndexObserver::DirtiedPrimEntries *moreDirtiedEntries) +{ + if (TF_VERIFY(visited)) { + _VisitedNode node = {primPath, sourceLocator}; + + if (visited->find(node) != visited->end()) { + return; + } + + visited->insert(node); + } + + moreDirtiedEntries->emplace_back(primPath, sourceLocator); + + // check to see if dependencies are dirty and should be recomputed + const HdDataSourceLocator &depsLoc = + HdDependenciesSchema::GetDefaultLocator(); + if (sourceLocator.Intersects(depsLoc)) { + if (TF_VERIFY(visited)) { + _VisitedNode dependenciesNode = {primPath, depsLoc}; + if (visited->find(dependenciesNode) == visited->end()) { + visited->insert(dependenciesNode); + _ClearDependencies(primPath); + _UpdateDependencies(primPath); + } + } + } + + + // check me in the reverse update table + // now dirty any dependencies + _DependedOnPrimsAffectedPrimsMap::const_iterator it = + _dependedOnPrimToDependentsMap.find(primPath); + if (it == _dependedOnPrimToDependentsMap.end()) { + return; + } + + for (const auto &affectedPair : (*it).second) { + const SdfPath &affectedPrimPath = affectedPair.first; + + for (const auto &keyEntryPair : affectedPair.second.locatorsEntryMap) { + const _LocatorsEntry &entry = keyEntryPair.second; + + if (entry.dependedOnDataSourceLocator.Intersects(sourceLocator)) { + _PrimDirtied(affectedPrimPath, entry.affectedDataSourceLocator, + visited, moreDirtiedEntries); + } + } + } +} + +//---------------------------------------------------------------------------- + +// when called? +// 1) when our own __dependencies are dirtied +// 2) when someone asks for our prim + +void +HdDependencyForwardingSceneIndex::_ClearDependencies(const SdfPath &primPath) +{ + _AffectedPrimToDependsOnPathsEntryMap::const_iterator it = + _affectedPrimToDependsOnPathsMap.find(primPath); + if (it == _affectedPrimToDependsOnPathsMap.end()) { + return; + } + + _AffectedPrimToDependsOnPathsEntry &affectedPrimEntry = (*it).second; + + affectedPrimEntry.flaggedForDeletion = true; + + const _PathSet &dependsOnPaths = affectedPrimEntry.dependsOnPaths; + + // If we know we are clearing an already empty one, add it to the set + // of potential deletions. If it's not empty, we'll be represented + // by adding our dependedOn paths as removal of those clears the + // affected prim paths which are made empty as result. + if (dependsOnPaths.empty()) { + _potentiallyDeletedAffectedPaths.insert(primPath); + } + + // Flag entries within our depended-on prims and add those prims to the + // set of paths which should be checked during RemoveDeletedEntries + for (const SdfPath &dependedOnPrimPath : dependsOnPaths) { + _DependedOnPrimsAffectedPrimsMap::iterator dependedOnPrimIt = + _dependedOnPrimToDependentsMap.find(dependedOnPrimPath); + + if (dependedOnPrimIt == _dependedOnPrimToDependentsMap.end()) { + continue; + } + + _AffectedPrimsDependencyMap &_affectedPrimsMap = + (*dependedOnPrimIt).second; + + + _AffectedPrimsDependencyMap::iterator thisAffectedPrimEntryIt = + _affectedPrimsMap.find(primPath); + if (thisAffectedPrimEntryIt == _affectedPrimsMap.end()) { + continue; + } + + (*thisAffectedPrimEntryIt).second.flaggedForDeletion = true; + _potentiallyDeletedDependedOnPaths.insert(dependedOnPrimPath); + } +} + +//---------------------------------------------------------------------------- + +void +HdDependencyForwardingSceneIndex::_UpdateDependencies( + const SdfPath &primPath) const +{ + if (!_GetInputSceneIndex()) { + return; + } + + HdContainerDataSourceHandle primDataSource = + _GetInputSceneIndex()->GetPrim(primPath).dataSource; + + if (!primDataSource) { + return; + } + + HdDependenciesSchema dependenciesSchema = + HdDependenciesSchema::GetFromParent(primDataSource); + + // NOTE: This early exit prevents addition of an entry within + // _affectedPrimToDependsOnPathsMap if there isn't one already. + // The trade-off is repeatedly doing this check vs adding an entry + // for every prim which doesn't have dependencies. + if (!dependenciesSchema.IsDefined()) { + return; + } + + // presence (even if empty) indicates we've been checked + // NOTE: we only add to this set. We'll remove entries (and the map itself) + // as part of single-threaded clearing. + + _AffectedPrimToDependsOnPathsEntry &dependsOnPathsEntry = + _affectedPrimToDependsOnPathsMap[primPath]; + + dependsOnPathsEntry.flaggedForDeletion = false; + + _PathSet &dependsOnPaths = dependsOnPathsEntry.dependsOnPaths; + + for (HdDependenciesSchema::EntryPair &entryPair : + dependenciesSchema.GetEntries()) { + + TfToken &entryName = entryPair.first; + HdDependencySchema &depSchema = entryPair.second; + + if (!depSchema.IsDefined()) { + continue; + } + + SdfPath dependedOnPrimPath; + if (HdPathDataSourceHandle dependedOnPrimPathDataSource = + depSchema.GetDependedOnPrimPath()) { + dependedOnPrimPath = + dependedOnPrimPathDataSource->GetTypedValue(0.0f); + } + + HdDataSourceLocator dependedOnDataSourceLocator; + HdDataSourceLocator affectedSourceLocator; + + if (HdLocatorDataSourceHandle lds = + depSchema.GetDependedOnDataSourceLocator()) { + dependedOnDataSourceLocator = lds->GetTypedValue(0.0f); + } + + if (HdLocatorDataSourceHandle lds = + depSchema.GetAffectedDataSourceLocator()) { + affectedSourceLocator = lds->GetTypedValue(0.0f); + } + + // self dependency + if (dependedOnPrimPath.IsEmpty()) { + dependedOnPrimPath = primPath; + } + + dependsOnPaths.insert(dependedOnPrimPath); + + + + _AffectedPrimsDependencyMap &reverseDependencies = + _dependedOnPrimToDependentsMap[dependedOnPrimPath]; + + _AffectedPrimDependencyEntry &reverseDependenciesEntry = + reverseDependencies[primPath]; + + + _LocatorsEntry &entry = + reverseDependenciesEntry.locatorsEntryMap[entryName]; + entry.dependedOnDataSourceLocator = dependedOnDataSourceLocator; + entry.affectedDataSourceLocator = affectedSourceLocator; + + reverseDependenciesEntry.flaggedForDeletion = false; + } + +} + +// --------------------------------------------------------------------------- + +void +HdDependencyForwardingSceneIndex::RemoveDeletedEntries( + SdfPathVector *removedAffectedPrimPaths, + SdfPathVector *removedDependedOnPrimPaths) +{ + SdfPathVector entriesToRemove; + + for (const SdfPath &dependedOnPrimPath : + _potentiallyDeletedDependedOnPaths) { + + _DependedOnPrimsAffectedPrimsMap::iterator dependedOnPrimIt = + _dependedOnPrimToDependentsMap.find(dependedOnPrimPath); + + if (dependedOnPrimIt == _dependedOnPrimToDependentsMap.end()) { + continue; + } + + _AffectedPrimsDependencyMap &_affectedPrimsMap = + (*dependedOnPrimIt).second; + + entriesToRemove.clear(); + + for (auto &affectedPrimPair : _affectedPrimsMap) { + const SdfPath &affectedPrimPath = affectedPrimPair.first; + _AffectedPrimDependencyEntry &affectedPrimDependencyEntry = + affectedPrimPair.second; + + if (!affectedPrimDependencyEntry.flaggedForDeletion) { + continue; + } + + entriesToRemove.push_back(affectedPrimPath); + + + // now remove dependedOn prim from affected prim entry + // if that removal leaves it empty, then remove the whole thing + + _AffectedPrimToDependsOnPathsEntryMap::iterator affectedPrimIt = + _affectedPrimToDependsOnPathsMap.find(affectedPrimPath); + + if (affectedPrimIt == _affectedPrimToDependsOnPathsMap.end()) { + continue; + } + + _AffectedPrimToDependsOnPathsEntry &affectedPrimEntry = + (*affectedPrimIt).second; + + if (affectedPrimEntry.dependsOnPaths.find(dependedOnPrimPath) + == affectedPrimEntry.dependsOnPaths.end()) { + continue; + } + + if (affectedPrimEntry.dependsOnPaths.size() == 1) { + // If I'm the only thing in there, remove the whole entry + _affectedPrimToDependsOnPathsMap.unsafe_erase( + affectedPrimPath); + + if (removedAffectedPrimPaths) { + removedAffectedPrimPaths->push_back(affectedPrimPath); + } + + + } else { + affectedPrimEntry.dependsOnPaths.unsafe_erase( + dependedOnPrimPath); + } + } + + if (entriesToRemove.size() == _affectedPrimsMap.size()) { + // removing everything?, just erase the dependedOn prim entry + _dependedOnPrimToDependentsMap.unsafe_erase(dependedOnPrimPath); + + if (removedDependedOnPrimPaths) { + removedDependedOnPrimPaths->push_back(dependedOnPrimPath); + } + + } else { + for (const SdfPath &affectedPrimPath : entriesToRemove) { + _affectedPrimsMap.unsafe_erase(affectedPrimPath); + } + } + } + + + for (const SdfPath &affectedPrimPath : + _potentiallyDeletedAffectedPaths) { + + // anything in here which flagged for deletion (XXX should it need to be + // empty too?) + + _AffectedPrimToDependsOnPathsEntryMap::iterator it = + _affectedPrimToDependsOnPathsMap.find(affectedPrimPath); + + if (it == _affectedPrimToDependsOnPathsMap.end()) { + continue; + } + + if ((*it).second.flaggedForDeletion) { + if (removedAffectedPrimPaths) { + removedAffectedPrimPaths->push_back(affectedPrimPath); + } + _affectedPrimToDependsOnPathsMap.unsafe_erase(it); + } + } + + _potentiallyDeletedDependedOnPaths.clear(); + _potentiallyDeletedAffectedPaths.clear(); +} + +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/imaging/hd/dependencyForwardingSceneIndex.h b/pxr/imaging/hd/dependencyForwardingSceneIndex.h new file mode 100644 index 0000000000..9b263cc0d3 --- /dev/null +++ b/pxr/imaging/hd/dependencyForwardingSceneIndex.h @@ -0,0 +1,242 @@ +// +// Copyright 2022 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#ifndef PXR_IMAGING_HD_DEPENDENCY_FORWARDING_SCENE_INDEX_H +#define PXR_IMAGING_HD_DEPENDENCY_FORWARDING_SCENE_INDEX_H + +#include "pxr/base/tf/denseHashSet.h" + +#include "pxr/imaging/hd/api.h" +#include "pxr/imaging/hd/filteringSceneIndex.h" + +#include +#include + +PXR_NAMESPACE_OPEN_SCOPE + +class HdDependencyForwardingSceneIndex; +TF_DECLARE_REF_PTRS(HdDependencyForwardingSceneIndex); + + +class HdDependencyForwardingSceneIndex + : public HdSingleInputFilteringSceneIndexBase +{ +public: + + static HdDependencyForwardingSceneIndexRefPtr New( + HdSceneIndexBaseRefPtr inputScene) { + return TfCreateRefPtr( + new HdDependencyForwardingSceneIndex(inputScene)); + } + + // satisfying HdSceneIndexBase + HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override; + SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override; + + +protected: + HD_API + HdDependencyForwardingSceneIndex(HdSceneIndexBaseRefPtr inputScene); + + // satisfying HdSingleInputFilteringSceneIndexBase + void _PrimsAdded( + const HdSceneIndexBase &sender, + const HdSceneIndexObserver::AddedPrimEntries &entries) override; + + void _PrimsRemoved( + const HdSceneIndexBase &sender, + const HdSceneIndexObserver::RemovedPrimEntries &entries) override; + + void _PrimsDirtied( + const HdSceneIndexBase &sender, + const HdSceneIndexObserver::DirtiedPrimEntries &entries) override; +private: + + // ----------------------------------------------------------------------- + + struct _LocatorsEntry + { + HdDataSourceLocator dependedOnDataSourceLocator; + HdDataSourceLocator affectedDataSourceLocator; + }; + + // The token used as a key here corresponds to the first member of an + // HdDependenciesSchema::EntryPair and provides an identifier for a + // dependency declaration. An affected prim may depend on more than one + // data source of another prim. That identifier is used here for updating + // or removing a dependency. + using _LocatorsEntryMap = tbb::concurrent_unordered_map< + TfToken, + _LocatorsEntry, + TfToken::HashFunctor>; + + + struct _AffectedPrimDependencyEntry + { + _LocatorsEntryMap locatorsEntryMap; + bool flaggedForDeletion = false; + }; + + // Reverse mapping from a depended on prim to its discovered-thus-far + // affected prims and data source locators.. + using _AffectedPrimsDependencyMap = tbb::concurrent_unordered_map< + SdfPath, + _AffectedPrimDependencyEntry, + SdfPath::Hash>; + + + // Top-level map keyed by paths of depended-on paths + using _DependedOnPrimsAffectedPrimsMap = tbb::concurrent_unordered_map< + SdfPath, + _AffectedPrimsDependencyMap, + SdfPath::Hash>; + + + // Lazily-populated mapping of depended on paths to the affected paths + // and data source locators used for forwarding of dirtying. + // NOTE: This is mutable because it can be updated during calls to + // GetPrim -- which is defined as const within HdSceneIndexBase. + // This is in service of lazy population goals. + mutable _DependedOnPrimsAffectedPrimsMap _dependedOnPrimToDependentsMap; + + + // ----------------------------------------------------------------------- + + using _PathSet = tbb::concurrent_unordered_set; + + //using _DensePathSet = TfDenseHashSet; + + struct _AffectedPrimToDependsOnPathsEntry + { + _PathSet dependsOnPaths; + bool flaggedForDeletion = false; + }; + + + using _AffectedPrimToDependsOnPathsEntryMap = tbb::concurrent_unordered_map< + SdfPath, + _AffectedPrimToDependsOnPathsEntry, + SdfPath::Hash>; + + // lazily-populated set of depended on paths for affected prims. This + // is used to update _dependedOnPrimToDependentsMap when a prim's + // __dependencies data source is dirtied (or the prim is removed) + // NOTE: This is mutable because it can be updated during calls to + // GetPrim -- which is defined as const within HdSceneIndexBase. + // This is in service of lazy population goals. + mutable _AffectedPrimToDependsOnPathsEntryMap + _affectedPrimToDependsOnPathsMap; + + // ----------------------------------------------------------------------- + + void _ClearDependencies(const SdfPath &primPath); + void _UpdateDependencies(const SdfPath &primPath) const; + + // ----------------------------------------------------------------------- + + // Dependencies may reasonably describe cycles given that: + // 1) Dependancies can exist at different levels of data source nesting + // 2) Dependancy declarations can be present from multiple upstream + // scene indices -- each of which draws its value from its input. + // In that case, it's not a cycle which affects a computed value but + // rather indicates to observers of this scene index that a value + // should be repulled. + // + // When following affected paths to propogate dirtiness, we need to detect + // cycles to avoiding hanging. This is done is by sending a "visited" set + // containing these node keys: + struct _VisitedNode + { + SdfPath primPath; + HdDataSourceLocator locator; + + inline bool operator==(_VisitedNode const &rhs) const noexcept + { + return primPath == rhs.primPath && locator == rhs.locator; + } + + template + friend void TfHashAppend(HashState &h, _VisitedNode const &myObj) { + h.Append(myObj.primPath); + h.Append(myObj.locator); + } + + inline size_t Hash() const; + struct HashFunctor { + size_t operator()(_VisitedNode const &node) const { + return node.Hash(); + } + }; + }; + + using _VisitedNodeSet = TfDenseHashSet< + _VisitedNode, + _VisitedNode::HashFunctor>; + + // impl for PrimDirtied which handles propogation of PrimDirtied notices + // for affected prims/dataSources. + void _PrimDirtied( + const SdfPath &primPath, + const HdDataSourceLocator &sourceLocator, + _VisitedNodeSet *visited, + HdSceneIndexObserver::DirtiedPrimEntries *moreDirtiedEntries); + + // ----------------------------------------------------------------------- + + // accumulated depended-on prim paths whose affected prims may have been + // removed. + mutable _PathSet _potentiallyDeletedDependedOnPaths; + + // Accumulated affected prim paths who may have been deleted. Normally this + // is needed to track affected prims which have an entry in + // _dependedOnPrimToDependentsMap but which is empty -- and therefore + // won't be handled by their dependencies inclusion in + // _potentiallyDeletedDependedOnPaths + mutable _PathSet _potentiallyDeletedAffectedPaths; + + // ----------------------------------------------------------------------- + +public: + // XXX does thread-unsafe deletion. + // NOTE FOR REVIEWERS: temporarily hiding this explosive public method + // down here while we discuss it. It's public because + // only the application knows when it's safe to call? + // + // NOTE: optional arguments are in service of unit testing to provide + // insight in to what was removed. + void RemoveDeletedEntries( + SdfPathVector *removedAffectedPrimPaths = nullptr, + SdfPathVector *removedDependedOnPrimPaths = nullptr); + +}; + + +inline size_t +HdDependencyForwardingSceneIndex::_VisitedNode::Hash() const +{ + return TfHash()(*this); +} + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif From a7e83355913ab1d798e9973a17462797e836a3a1 Mon Sep 17 00:00:00 2001 From: unhyperbolic Date: Mon, 4 Apr 2022 13:56:02 -0700 Subject: [PATCH 018/285] Scene index emulation: fixing inconsistencies so that clipping planes work with USDIMAGINGGL_ENGINE_ENABLE_SCENE_INDEX. Adding clippingPlanes of type VtArray to the HdCameraSchema. This differs from HdCamera where it is called clipPlanes and of type std::vector. Thus, we need to convert in the scene index adapter scene delegate and the data source legacy prim. Adding test case for (animated) clipping planes to usdImagingGL. (Internal change: 2224516) --- pxr/imaging/hd/cameraSchema.cpp | 30 ++++++++++-- pxr/imaging/hd/cameraSchema.h | 10 +++- pxr/imaging/hd/dataSourceLegacyPrim.cpp | 28 ++++++++---- pxr/imaging/hd/dataSourceTypeDefs.h | 5 ++ .../hd/sceneIndexAdapterSceneDelegate.cpp | 18 +++++++- .../usdImaging/dataSourceCamera.cpp | 1 - pxr/usdImaging/usdImagingGL/CMakeLists.txt | 5 ++ .../testUsdImagingGLClippingPlanes_001.png | Bin 0 -> 16343 bytes .../testUsdImagingGLClippingPlanes_002.png | Bin 0 -> 16849 bytes .../clippingPlanes.usda | 43 ++++++++++++++++++ 10 files changed, 124 insertions(+), 16 deletions(-) create mode 100644 pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLClippingPlanes/baseline/testUsdImagingGLClippingPlanes_001.png create mode 100644 pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLClippingPlanes/baseline/testUsdImagingGLClippingPlanes_002.png create mode 100644 pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLClippingPlanes/clippingPlanes.usda diff --git a/pxr/imaging/hd/cameraSchema.cpp b/pxr/imaging/hd/cameraSchema.cpp index de1afc75fb..a6969f9312 100644 --- a/pxr/imaging/hd/cameraSchema.cpp +++ b/pxr/imaging/hd/cameraSchema.cpp @@ -87,6 +87,13 @@ HdCameraSchema::GetClippingRange() HdCameraSchemaTokens->clippingRange); } +HdVec4dArrayDataSourceHandle +HdCameraSchema::GetClippingPlanes() +{ + return _GetTypedDataSource( + HdCameraSchemaTokens->clippingPlanes); +} + /*static*/ HdContainerDataSourceHandle HdCameraSchema::BuildRetained( @@ -96,11 +103,12 @@ HdCameraSchema::BuildRetained( const HdFloatDataSourceHandle &horizontalApertureOffset, const HdFloatDataSourceHandle &verticalApertureOffset, const HdFloatDataSourceHandle &focalLength, - const HdVec2fDataSourceHandle &clippingRange + const HdVec2fDataSourceHandle &clippingRange, + const HdVec4dArrayDataSourceHandle &clippingPlanes ) { - TfToken names[7]; - HdDataSourceBaseHandle values[7]; + TfToken names[8]; + HdDataSourceBaseHandle values[8]; size_t count = 0; if (projection) { @@ -138,6 +146,11 @@ HdCameraSchema::BuildRetained( values[count++] = clippingRange; } + if (clippingPlanes) { + names[count] = HdCameraSchemaTokens->clippingPlanes; + values[count++] = clippingPlanes; + } + return HdRetainedContainerDataSource::New(count, names, values); } @@ -239,6 +252,14 @@ HdCameraSchema::Builder::SetClippingRange( return *this; } +HdCameraSchema::Builder & +HdCameraSchema::Builder::SetClippingPlanes( + const HdVec4dArrayDataSourceHandle &clippingPlanes) +{ + _clippingPlanes = clippingPlanes; + return *this; +} + HdContainerDataSourceHandle HdCameraSchema::Builder::Build() { @@ -249,7 +270,8 @@ HdCameraSchema::Builder::Build() _horizontalApertureOffset, _verticalApertureOffset, _focalLength, - _clippingRange + _clippingRange, + _clippingPlanes ); } diff --git a/pxr/imaging/hd/cameraSchema.h b/pxr/imaging/hd/cameraSchema.h index 9e6291cd80..6ee91fc605 100644 --- a/pxr/imaging/hd/cameraSchema.h +++ b/pxr/imaging/hd/cameraSchema.h @@ -45,6 +45,7 @@ PXR_NAMESPACE_OPEN_SCOPE (verticalApertureOffset) \ (focalLength) \ (clippingRange) \ + (clippingPlanes) \ (perspective) \ (orthographic) \ @@ -75,6 +76,8 @@ class HdCameraSchema : public HdSchema HdFloatDataSourceHandle GetFocalLength(); HD_API HdVec2fDataSourceHandle GetClippingRange(); + HD_API + HdVec4dArrayDataSourceHandle GetClippingPlanes(); // RETRIEVING AND CONSTRUCTING @@ -92,7 +95,8 @@ class HdCameraSchema : public HdSchema const HdFloatDataSourceHandle &horizontalApertureOffset, const HdFloatDataSourceHandle &verticalApertureOffset, const HdFloatDataSourceHandle &focalLength, - const HdVec2fDataSourceHandle &clippingRange + const HdVec2fDataSourceHandle &clippingRange, + const HdVec4dArrayDataSourceHandle &clippingPlanes ); /// \class HdCameraSchema::Builder @@ -125,6 +129,9 @@ class HdCameraSchema : public HdSchema HD_API Builder &SetClippingRange( const HdVec2fDataSourceHandle &clippingRange); + HD_API + Builder &SetClippingPlanes( + const HdVec4dArrayDataSourceHandle &clippingPlanes); /// Returns a container data source containing the members set thus far. HD_API @@ -138,6 +145,7 @@ class HdCameraSchema : public HdSchema HdFloatDataSourceHandle _verticalApertureOffset; HdFloatDataSourceHandle _focalLength; HdVec2fDataSourceHandle _clippingRange; + HdVec4dArrayDataSourceHandle _clippingPlanes; }; /// Retrieves a container data source with the schema's default name token diff --git a/pxr/imaging/hd/dataSourceLegacyPrim.cpp b/pxr/imaging/hd/dataSourceLegacyPrim.cpp index 7a9e58867a..c3dde5e43c 100644 --- a/pxr/imaging/hd/dataSourceLegacyPrim.cpp +++ b/pxr/imaging/hd/dataSourceLegacyPrim.cpp @@ -1222,7 +1222,12 @@ class Hd_DataSourceCamera : public HdContainerDataSource bool Has(const TfToken &name) override { - VtValue v = _sceneDelegate->GetCameraParamValue(_id, name); + TfToken key = name; + if (name == HdCameraSchemaTokens->clippingPlanes) { + key = HdCameraTokens->clipPlanes; + } + + VtValue v = _sceneDelegate->GetCameraParamValue(_id, key); return !v.IsEmpty(); } @@ -1242,6 +1247,7 @@ class Hd_DataSourceCamera : public HdContainerDataSource results.push_back(HdCameraSchemaTokens->verticalApertureOffset); results.push_back(HdCameraSchemaTokens->focalLength); results.push_back(HdCameraSchemaTokens->clippingRange); + results.push_back(HdCameraSchemaTokens->clippingPlanes); return results; } @@ -1280,16 +1286,20 @@ class Hd_DataSourceCamera : public HdContainerDataSource } return HdRetainedTypedSampledDataSource< CameraUtilConformWindowPolicy>::New(wp); - } else if (name == HdCameraTokens->clipPlanes) { - VtValue v = _sceneDelegate->GetCameraParamValue(_id, name); - - // XXX: this should probably be in the schema, and a vec4f array. - std::vector cp; + } else if (name == HdCameraSchemaTokens->clippingPlanes) { + const VtValue v = _sceneDelegate->GetCameraParamValue( + _id, HdCameraTokens->clipPlanes); + VtArray array; if (v.IsHolding>()) { - cp = v.UncheckedGet>(); + const std::vector &vec = + v.UncheckedGet>(); + array.resize(vec.size()); + for (size_t i = 0; i < vec.size(); i++) { + array[i] = vec[i]; + } } - return HdRetainedTypedSampledDataSource>::New( - cp); + return HdRetainedTypedSampledDataSource>::New( + array); } else if (std::find(HdCameraSchemaTokens->allTokens.begin(), HdCameraSchemaTokens->allTokens.end(), name) != HdCameraSchemaTokens->allTokens.end()) { diff --git a/pxr/imaging/hd/dataSourceTypeDefs.h b/pxr/imaging/hd/dataSourceTypeDefs.h index 95d587df2c..604a3dfdce 100644 --- a/pxr/imaging/hd/dataSourceTypeDefs.h +++ b/pxr/imaging/hd/dataSourceTypeDefs.h @@ -99,6 +99,11 @@ using HdVec3dDataSourceHandle = HdVec3dDataSource::Handle; using HdVec3dArrayDataSource = HdTypedSampledDataSource>; using HdVec3dArrayDataSourceHandle = HdVec3dArrayDataSource::Handle; +using HdVec4iDataSource = HdTypedSampledDataSource; +using HdVec4iDataSourceHandle = HdVec4iDataSource::Handle; +using HdVec4dArrayDataSource = HdTypedSampledDataSource>; +using HdVec4dArrayDataSourceHandle = HdVec4dArrayDataSource::Handle; + using HdMatrixDataSource = HdTypedSampledDataSource; using HdMatrixDataSourceHandle = HdMatrixDataSource::Handle; using HdMatrixArrayDataSource = HdTypedSampledDataSource>; diff --git a/pxr/imaging/hd/sceneIndexAdapterSceneDelegate.cpp b/pxr/imaging/hd/sceneIndexAdapterSceneDelegate.cpp index 6f7c957b68..6b94777d7c 100644 --- a/pxr/imaging/hd/sceneIndexAdapterSceneDelegate.cpp +++ b/pxr/imaging/hd/sceneIndexAdapterSceneDelegate.cpp @@ -1039,9 +1039,14 @@ HdSceneIndexAdapterSceneDelegate::GetCameraParamValue( return VtValue(); } + TfToken cameraSchemaToken = paramName; + if (paramName == HdCameraTokens->clipPlanes) { + cameraSchemaToken = HdCameraSchemaTokens->clippingPlanes; + } + HdSampledDataSourceHandle valueDs = HdSampledDataSource::Cast( - camera->Get(paramName)); + camera->Get(cameraSchemaToken)); if (!valueDs) { return VtValue(); } @@ -1063,6 +1068,17 @@ HdSceneIndexAdapterSceneDelegate::GetCameraParamValue( range = value.UncheckedGet(); } return VtValue(GfRange1f(range[0], range[1])); + } else if (paramName == HdCameraTokens->clipPlanes) { + std::vector vec; + if (value.IsHolding>()) { + const VtArray array = + value.UncheckedGet>(); + vec.reserve(array.size()); + for (const GfVec4d &p : array) { + vec.push_back(p); + } + } + return VtValue(vec); } else { return value; } diff --git a/pxr/usdImaging/usdImaging/dataSourceCamera.cpp b/pxr/usdImaging/usdImaging/dataSourceCamera.cpp index 150f7c7ad2..7ae478e8dc 100644 --- a/pxr/usdImaging/usdImaging/dataSourceCamera.cpp +++ b/pxr/usdImaging/usdImaging/dataSourceCamera.cpp @@ -164,7 +164,6 @@ UsdImagingDataSourceCamera::Get(const TfToken &name) // Note that scene index emulation calls this method with // "shutterOpen" (Usd attribute is shutter:open) // "shutterClose" (Usd attribute is shutter:close) - // "clipPlanes" (Usd attribute is clippingPlanes) // "windowPolicy" - does not exist on UsdGeomCamera // // We need to either do the right translation/ignore these values here diff --git a/pxr/usdImaging/usdImagingGL/CMakeLists.txt b/pxr/usdImaging/usdImagingGL/CMakeLists.txt index 8481ec387e..3efbd0262a 100644 --- a/pxr/usdImaging/usdImagingGL/CMakeLists.txt +++ b/pxr/usdImaging/usdImagingGL/CMakeLists.txt @@ -487,6 +487,11 @@ pxr_install_test_dir( DEST testUsdImagingGLAnimatedCamera ) +pxr_install_test_dir( + SRC testenv/testUsdImagingGLClippingPlanes + DEST testUsdImagingGLClippingPlanes +) + pxr_install_test_dir( SRC testenv/testUsdImagingGLAnimatedLights DEST testUsdImagingGLAnimatedLights diff --git a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLClippingPlanes/baseline/testUsdImagingGLClippingPlanes_001.png b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLClippingPlanes/baseline/testUsdImagingGLClippingPlanes_001.png new file mode 100644 index 0000000000000000000000000000000000000000..e1a85b7ffa5b5b15c1445ffd786632bf3779e9d2 GIT binary patch literal 16343 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 literal 0 HcmV?d00001 diff --git a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLClippingPlanes/baseline/testUsdImagingGLClippingPlanes_002.png b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLClippingPlanes/baseline/testUsdImagingGLClippingPlanes_002.png new file mode 100644 index 0000000000000000000000000000000000000000..93b222e6276df79b010024fc551320e785411d7e GIT binary patch literal 16849 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 J4h6<;`aheL4we7_ literal 0 HcmV?d00001 diff --git a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLClippingPlanes/clippingPlanes.usda b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLClippingPlanes/clippingPlanes.usda new file mode 100644 index 0000000000..678f2825ee --- /dev/null +++ b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLClippingPlanes/clippingPlanes.usda @@ -0,0 +1,43 @@ +#usda 1.0 +( + defaultPrim = "world" + endTimeCode = 2 + startTimeCode = 1 + upAxis = "Y" +) + +def "World" +{ + def Camera "main_cam" + { + float4[] clippingPlanes = [ (1,0,0,0)] + float4[] clippingPlanes.timeSamples = { + 1 : [ (1,0,0,0)], + 2 : [ (1,0.5,0,0)], + } + float2 clippingRange = (0.15815565, 6045.622) + float focalLength = 50 + float focusDistance = 5 + float fStop = 5.6 + float horizontalAperture = 41.4214 + float horizontalApertureOffset = 0 + token projection = "perspective" + float verticalAperture = 23.299536 + float verticalApertureOffset = 0 + uniform token[] xformOpOrder = ["xformOp:translate"] + double3 xformOp:translate = (0, 0, 5) + } + + def Mesh "Cube" + { + double xformOp:rotateX = 45 + uniform token[] xformOpOrder = ["xformOp:rotateX"] + + uniform bool doubleSided = 1 + float3[] extent = [(-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)] + int[] faceVertexCounts = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3] + int[] faceVertexIndices = [0, 1, 2, 2, 1, 3, 2, 3, 4, 4, 3, 5, 4, 5, 6, 6, 5, 7, 6, 7, 0, 0, 7, 1, 1, 7, 3, 3, 7, 5, 6, 0, 4, 4, 0, 2] + point3f[] points = [(-0.5, -0.5, 0.5), (0.5, -0.5, 0.5), (-0.5, 0.5, 0.5), (0.5, 0.5, 0.5), (-0.5, 0.5, -0.5), (0.5, 0.5, -0.5), (-0.5, -0.5, -0.5), (0.5, -0.5, -0.5)] + color3f[] primvars:displayColor = [(0.13320851, 0.13320851, 0.13320851)] + } +} \ No newline at end of file From 5096f67a271388344d3bdc69e1380a68c147c6c1 Mon Sep 17 00:00:00 2001 From: pixar-oss Date: Tue, 5 Apr 2022 11:02:14 -0700 Subject: [PATCH 019/285] Change how XPU Devices are set CreateRiley now uses xpu:cpuconfig and xpu:gpuconfig to communicate which devices XPU should use. Note on GPU selection: As off now in rman, only the first GPU is supported regardless of the input type being an array. (Internal change: 2224729) --- .../plugin/hdPrman/renderDelegate.cpp | 15 +++++--- .../plugin/hdPrman/renderDelegate.h | 1 + .../plugin/hdPrman/renderParam.cpp | 36 +++++++++++++++---- .../renderman-24/plugin/hdPrman/renderParam.h | 6 ++-- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/third_party/renderman-24/plugin/hdPrman/renderDelegate.cpp b/third_party/renderman-24/plugin/hdPrman/renderDelegate.cpp index d45efa3889..f48ae243f9 100644 --- a/third_party/renderman-24/plugin/hdPrman/renderDelegate.cpp +++ b/third_party/renderman-24/plugin/hdPrman/renderDelegate.cpp @@ -118,13 +118,18 @@ _ToLower(const std::string &s) HdPrmanRenderDelegate::HdPrmanRenderDelegate( HdRenderSettingsMap const& settingsMap) : HdRenderDelegate(settingsMap) - , _renderParam( - std::make_unique( - _ToLower( +{ + std::string rileyVariant = _ToLower( GetRenderSetting( HdPrmanRenderSettingsTokens->rileyVariant, - TfGetenv("RILEY_VARIANT"))))) -{ + TfGetenv("RILEY_VARIANT"))); + + std::string xpuDevices = GetRenderSetting( + HdPrmanRenderSettingsTokens->xpuDevices, std::string()); + + _renderParam = std::make_unique( + rileyVariant, xpuDevices); + _Initialize(); } diff --git a/third_party/renderman-24/plugin/hdPrman/renderDelegate.h b/third_party/renderman-24/plugin/hdPrman/renderDelegate.h index a1f2b3db6f..7a33f2b021 100644 --- a/third_party/renderman-24/plugin/hdPrman/renderDelegate.h +++ b/third_party/renderman-24/plugin/hdPrman/renderDelegate.h @@ -32,6 +32,7 @@ PXR_NAMESPACE_OPEN_SCOPE #define HDPRMAN_RENDER_SETTINGS_TOKENS \ ((rileyVariant, "ri:variant")) \ + ((xpuDevices, "ri:xpudevices")) \ ((integrator, "integrator")) \ ((integratorName, "ri:integrator:name")) \ ((interactiveIntegrator, "interactiveIntegrator")) \ diff --git a/third_party/renderman-24/plugin/hdPrman/renderParam.cpp b/third_party/renderman-24/plugin/hdPrman/renderParam.cpp index 274abaafb8..431a7e5eb3 100644 --- a/third_party/renderman-24/plugin/hdPrman/renderParam.cpp +++ b/third_party/renderman-24/plugin/hdPrman/renderParam.cpp @@ -94,7 +94,8 @@ TF_MAKE_STATIC_DATA(std::vector, _integratorCameraCallbacks->clear(); } -HdPrman_RenderParam::HdPrman_RenderParam(const std::string &rileyVariant) : +HdPrman_RenderParam::HdPrman_RenderParam(const std::string &rileyVariant, + const std::string &xpuVariant) : resolution(0), _rix(nullptr), _ri(nullptr), @@ -104,7 +105,7 @@ HdPrman_RenderParam::HdPrman_RenderParam(const std::string &rileyVariant) : _lastSettingsVersion(0) { TfRegistryManager::GetInstance().SubscribeTo(); - _CreateRiley(rileyVariant); + _CreateRiley(rileyVariant, xpuVariant); // Register RenderMan display driver HdPrmanFramebuffer::Register(_rix); @@ -1538,7 +1539,8 @@ HdPrman_RenderParam::SetParamFromVtValue( } void -HdPrman_RenderParam::_CreateRiley(const std::string &rileyVariant) +HdPrman_RenderParam::_CreateRiley(const std::string &rileyVariant, + const std::string &xpuDevices) { _rix = RixGetContext(); if (!_rix) { @@ -1578,14 +1580,34 @@ HdPrman_RenderParam::_CreateRiley(const std::string &rileyVariant) // Acquire Riley instance. _mgr = (RixRileyManager*)_rix->GetRixInterface(k_RixRileyManager); - _riley = _mgr->CreateRiley(RtUString(rileyVariant.c_str()), RtParamList()); + + _xpu = (!rileyVariant.empty() || + (rileyVariant.find("xpu") != std::string::npos)); + + // Decide whether to use the CPU, GPU, or both + RtParamList paramList; + if (_xpu) { + static const RtUString cpuConfig("xpu:cpuconfig"); + static const RtUString gpuConfig("xpu:gpuconfig"); + static const int defaultGPUId = 0; + + const bool useCpu = xpuDevices.find("cpu") != std::string::npos; + paramList.SetInteger(cpuConfig, useCpu ? 1 : 0); + + const bool useGpu = xpuDevices.find("gpu") != std::string::npos; + if (useGpu) { + // Currently XPU only supports a single GPU + // Set the 0th GPU as being used + paramList.SetIntegerArray(gpuConfig, &defaultGPUId, 1); + } + } + + _riley = _mgr->CreateRiley(RtUString(rileyVariant.c_str()), paramList); + if(!_riley) { TF_RUNTIME_ERROR("Could not initialize riley API."); return; } - - _xpu = (!rileyVariant.empty() || - (rileyVariant.find("xpu") != std::string::npos)); } diff --git a/third_party/renderman-24/plugin/hdPrman/renderParam.h b/third_party/renderman-24/plugin/hdPrman/renderParam.h index 82318e4e5a..0f913b15d7 100644 --- a/third_party/renderman-24/plugin/hdPrman/renderParam.h +++ b/third_party/renderman-24/plugin/hdPrman/renderParam.h @@ -58,7 +58,8 @@ class HdPrman_RenderParam : public HdRenderParam { public: HDPRMAN_API - HdPrman_RenderParam(const std::string &rileyVariant); + HdPrman_RenderParam(const std::string &rileyVariant, + const std::string &xpuDevices); HDPRMAN_API ~HdPrman_RenderParam() override; @@ -271,7 +272,8 @@ class HdPrman_RenderParam : public HdRenderParam void UpdateRileyShutterInterval(const HdRenderIndex * renderIndex); private: - void _CreateRiley(const std::string &rileyVariant); + void _CreateRiley(const std::string &rileyVariant, + const std::string &xpuVariant); void _CreateFallbackMaterials(); void _CreateFallbackLight(); void _CreateIntegrator(HdRenderDelegate * renderDelegate); From 00273a44ddb52c9db0392ba8bf79339bc1613bc0 Mon Sep 17 00:00:00 2001 From: pixar-oss Date: Tue, 5 Apr 2022 17:00:03 -0700 Subject: [PATCH 020/285] Adding support in USD for declaring properties as API schema overrides. A schema property that is declared as an API schema override does not define that property in that schema. Instead it behaves as an "over: for a property with the same name that may be defined by an API schema that is included as a built-in API schema of the schema declaring the override. This is different than the behavior when included API schemas define the same property (without specifying an override) as in that case, the strongest schema's property wins and completely stomps over the same property from any weaker schema. API schema overrides can be declared for both API and Typed schemas in the source schema files through adding customData on the property of 'bool apiSchemaOverride = true'. This will be converted to a list of API schema override property names stored in the schema prim's customData in the resulting generatedSchema.usda. When the UsdSchemaRegistry is populated, any properties declared as API schema overrides will not be immediately added to the prim definition. Instead they will be composed over the defined property from the schema's built-in API schemas if a property with that name is indeed found. If no property with the name exists in the included API schemas, the override property is ignored. An examples of where this will be used is UsdLuxLightAPI which will now be able to declare: class "LightAPI" ( prepend apiSchemas = ["CollectionAPI:lightLink", "CollectionAPI:shadowLink"] ) { uniform bool collection:lightLink:includeRoot = 1 ( customData = { bool apiSchemaOverride = true } ) uniform bool collection:shadowLink:includeRoot = 1 ( customData = { bool apiSchemaOverride = true } ) } This means that LightAPI can now override just the default values of the includeRoot properties defined in its two built-in CollectionAPIs while leaving the rest of the definition (such as documentation) as defined in the CollectionAPI schema itself. Another example is the light:shaderId property defined in LightAPI which all the concrete Typed light schemas (RectLight, DistantLight, etc.) will be able to override to defaulting to the USD shader ID for the light, once again, without stomping over the entire property definition from LightAPI. Note that this feature is specific to overriding properties from built-in API schemas and doesn't apply to overriding properties via schema inheritance. This is because schema properties are already always composed over via inheritance during schema generation so no specification is necessary. (Internal change: 2224838) --- pxr/usd/usd/codegenTemplates/schemaClass.cpp | 2 + pxr/usd/usd/primDefinition.cpp | 47 +- pxr/usd/usd/primDefinition.h | 29 +- pxr/usd/usd/schemaRegistry.cpp | 568 ++++++++++++- .../usd/testenv/testUsdAppliedAPISchemas.py | 804 +++++++++++++++++- .../resources/generatedSchema.usda | 226 +++++ .../resources/plugInfo.json | 103 +++ .../resources/schema.usda | 381 +++++++++ .../testUsdSchemaGen/baseline/basic/base.cpp | 54 ++ .../testUsdSchemaGen/baseline/basic/base.h | 75 ++ .../baseline/basic/derived.cpp | 72 ++ .../testUsdSchemaGen/baseline/basic/derived.h | 100 +++ .../baseline/basic/generatedSchema.usda | 78 ++ .../baseline/basic/tokens.cpp | 12 + .../testUsdSchemaGen/baseline/basic/tokens.h | 24 + .../baseline/basic/wrapBase.cpp | 42 + .../baseline/basic/wrapDerived.cpp | 56 ++ .../baseline/basic/wrapTokens.cpp | 6 + .../baseline/headerTerminatorString/base.cpp | 54 ++ .../baseline/headerTerminatorString/base.h | 75 ++ .../headerTerminatorString/derived.cpp | 72 ++ .../baseline/headerTerminatorString/derived.h | 100 +++ .../generatedSchema.usda | 78 ++ .../headerTerminatorString/tokens.cpp | 12 + .../baseline/headerTerminatorString/tokens.h | 24 + .../headerTerminatorString/wrapBase.cpp | 42 + .../headerTerminatorString/wrapDerived.cpp | 56 ++ .../headerTerminatorString/wrapTokens.cpp | 6 + .../baseline/namespace/base.cpp | 54 ++ .../baseline/namespace/base.h | 75 ++ .../baseline/namespace/derived.cpp | 72 ++ .../baseline/namespace/derived.h | 100 +++ .../baseline/namespace/generatedSchema.usda | 78 ++ .../baseline/namespace/tokens.cpp | 12 + .../baseline/namespace/tokens.h | 24 + .../baseline/namespace/wrapBase.cpp | 42 + .../baseline/namespace/wrapDerived.cpp | 56 ++ .../baseline/namespace/wrapTokens.cpp | 6 + .../baseline/nestedNamespace/base.cpp | 54 ++ .../baseline/nestedNamespace/base.h | 75 ++ .../baseline/nestedNamespace/derived.cpp | 72 ++ .../baseline/nestedNamespace/derived.h | 100 +++ .../nestedNamespace/generatedSchema.usda | 78 ++ .../baseline/nestedNamespace/tokens.cpp | 12 + .../baseline/nestedNamespace/tokens.h | 24 + .../baseline/nestedNamespace/wrapBase.cpp | 42 + .../baseline/nestedNamespace/wrapDerived.cpp | 56 ++ .../baseline/nestedNamespace/wrapTokens.cpp | 6 + .../testUsdSchemaGen/codeless_schema.usda | 134 +++ .../usd/testenv/testUsdSchemaGen/schema.usda | 134 +++ pxr/usd/usd/usdGenSchema.py | 138 ++- 51 files changed, 4512 insertions(+), 130 deletions(-) diff --git a/pxr/usd/usd/codegenTemplates/schemaClass.cpp b/pxr/usd/usd/codegenTemplates/schemaClass.cpp index 77512f751b..c5081f42d0 100644 --- a/pxr/usd/usd/codegenTemplates/schemaClass.cpp +++ b/pxr/usd/usd/codegenTemplates/schemaClass.cpp @@ -341,7 +341,9 @@ const TfTokenVector& static TfTokenVector localNames = { {% for attrName in cls.attrOrder %} {% set attr = cls.attrs[attrName] %} +{% if not attr.isAPISchemaOverride %} {{ tokensPrefix }}Tokens->{{ attr.name }}, +{% endif %} {% endfor %} }; static TfTokenVector allNames = diff --git a/pxr/usd/usd/primDefinition.cpp b/pxr/usd/usd/primDefinition.cpp index 7fbecda2f5..3fd30cdce0 100644 --- a/pxr/usd/usd/primDefinition.cpp +++ b/pxr/usd/usd/primDefinition.cpp @@ -87,48 +87,15 @@ UsdPrimDefinition::_ListMetadataFields(const TfToken &propName) const } void -UsdPrimDefinition::_ComposePropertiesFromPrimSpec( - const SdfLayerRefPtr &layer, - const SdfPath &weakerPrimSpecPath, - const std::string &instanceName) +UsdPrimDefinition::_AddProperties( + std::vector> &&propNameToPathVec) { - // Get the names of the all the properties found at the prim spec path. - TfTokenVector specProperties; - if (!layer->HasField( - weakerPrimSpecPath, - SdfChildrenKeys->PropertyChildren, - &specProperties)) { - // While its possible for the spec to have no properties, we expect - // the prim spec itself to exist. - if (!layer->HasSpec(weakerPrimSpecPath)) { - TF_WARN("No prim spec exists at path '%s' in schematics layer.", - weakerPrimSpecPath.GetText()); - } - return; - } - _properties.reserve(_properties.size() + specProperties.size()); + _properties.reserve(_properties.size() + propNameToPathVec.size()); - // Map each spec property name to the property spec path and add it to the - // list of properties if it hasn't already been added. - if (instanceName.empty()) { - for (const TfToken &propName : specProperties) { - const SdfPath propPath = - weakerPrimSpecPath.AppendProperty(propName); - if (_propPathMap.emplace(propName, propPath).second) { - _properties.push_back(propName); - } - } - } else { - for (const TfToken &propName : specProperties) { - const SdfPath propPath = - weakerPrimSpecPath.AppendProperty(propName); - // Apply the prefix to each property name before adding it. - const TfToken instancedPropName = - UsdSchemaRegistry::MakeMultipleApplyNameInstance( - propName, instanceName); - if (_propPathMap.emplace(instancedPropName, propPath).second) { - _properties.push_back(instancedPropName); - } + for (auto &propNameAndPath : propNameToPathVec) { + auto insertIt = _propPathMap.insert(std::move(propNameAndPath)); + if (insertIt.second) { + _properties.push_back(insertIt.first->first); } } } diff --git a/pxr/usd/usd/primDefinition.h b/pxr/usd/usd/primDefinition.h index d89939f8eb..64dd199759 100644 --- a/pxr/usd/usd/primDefinition.h +++ b/pxr/usd/usd/primDefinition.h @@ -64,7 +64,7 @@ class UsdPrimDefinition /// SdfSpecTypeUnknown. SdfSpecType GetSpecType(const TfToken &propName) const { - if (const SdfPath *path = TfMapLookupPtr(_propPathMap, propName)) { + if (const SdfPath *path = _GetPropertySpecPath(propName)) { return _GetSchematics()->GetSpecType(*path); } return SdfSpecTypeUnknown; @@ -75,7 +75,7 @@ class UsdPrimDefinition /// if there is no such property spec. SdfPropertySpecHandle GetSchemaPropertySpec(const TfToken& propName) const { - if (const SdfPath *path = TfMapLookupPtr(_propPathMap, propName)) { + if (const SdfPath *path = _GetPropertySpecPath(propName)) { return _GetSchematics()->GetPropertyAtPath(*path); } return TfNullPtr; @@ -86,7 +86,7 @@ class UsdPrimDefinition /// GetSchemaPropertySpec(primType, attrName)); SdfAttributeSpecHandle GetSchemaAttributeSpec(const TfToken& attrName) const { - if (const SdfPath *path = TfMapLookupPtr(_propPathMap, attrName)) { + if (const SdfPath *path = _GetPropertySpecPath(attrName)) { return _GetSchematics()->GetAttributeAtPath(*path); } return TfNullPtr; @@ -97,7 +97,7 @@ class UsdPrimDefinition /// GetSchemaPropertySpec(primType, relName)); SdfRelationshipSpecHandle GetSchemaRelationshipSpec(const TfToken& relName) const { - if (const SdfPath *path = TfMapLookupPtr(_propPathMap, relName)) { + if (const SdfPath *path = _GetPropertySpecPath(relName)) { return _GetSchematics()->GetRelationshipAtPath(*path); } return TfNullPtr; @@ -283,7 +283,7 @@ class UsdPrimDefinition const TfToken& fieldName, T* value) const { - if (const SdfPath *path = TfMapLookupPtr(_propPathMap, propName)) { + if (const SdfPath *path = _GetPropertySpecPath(propName)) { return _GetSchematics()->HasField(*path, fieldName, value); } return false; @@ -295,7 +295,7 @@ class UsdPrimDefinition const TfToken& keyPath, T* value) const { - if (const SdfPath *path = TfMapLookupPtr(_propPathMap, propName)) { + if (const SdfPath *path = _GetPropertySpecPath(propName)) { return _GetSchematics()->HasFieldDictKey( *path, fieldName, keyPath, value); } @@ -314,15 +314,24 @@ class UsdPrimDefinition return UsdSchemaRegistry::GetInstance()._schematics; } + // Accessors for looking property spec paths by name. + const SdfPath *_GetPropertySpecPath(const TfToken& propName) const + { + return TfMapLookupPtr(_propPathMap, propName); + } + + SdfPath *_GetPropertySpecPath(const TfToken& propName) + { + return TfMapLookupPtr(_propPathMap, propName); + } + USD_API TfTokenVector _ListMetadataFields(const TfToken &propName) const; // Helpers for constructing the prim definition. USD_API - void _ComposePropertiesFromPrimSpec( - const SdfLayerRefPtr &layer, - const SdfPath &weakerPrimSpecPath, - const std::string &instanceName = ""); + void _AddProperties( + std::vector> &&propNameToPathVec); USD_API void _ComposePropertiesFromPrimDef( diff --git a/pxr/usd/usd/schemaRegistry.cpp b/pxr/usd/usd/schemaRegistry.cpp index 343724974f..851eb1e82c 100644 --- a/pxr/usd/usd/schemaRegistry.cpp +++ b/pxr/usd/usd/schemaRegistry.cpp @@ -542,33 +542,41 @@ _CopySpec(const T &srcSpec, const T &dstSpec) } static void -_AddSchema(SdfLayerRefPtr const &source, SdfLayerRefPtr const &target) +_CopyAttrSpec(const SdfAttributeSpecHandle &srcAttr, + const SdfPrimSpecHandle &dstPrim, + const std::string &dstName) { - TRACE_FUNCTION(); - for (SdfPrimSpecHandle const &prim: source->GetRootPrims()) { - if (!target->GetPrimAtPath(prim->GetPath())) { - - SdfPrimSpecHandle newPrim = - SdfPrimSpec::New(target, prim->GetName(), prim->GetSpecifier(), - prim->GetTypeName()); - _CopySpec(prim, newPrim); + SdfAttributeSpecHandle newAttr = + SdfAttributeSpec::New( + dstPrim, dstName, srcAttr->GetTypeName(), + srcAttr->GetVariability(), srcAttr->IsCustom()); + _CopySpec(srcAttr, newAttr); +} - for (SdfAttributeSpecHandle const &attr: prim->GetAttributes()) { - SdfAttributeSpecHandle newAttr = - SdfAttributeSpec::New( - newPrim, attr->GetName(), attr->GetTypeName(), - attr->GetVariability(), attr->IsCustom()); - _CopySpec(attr, newAttr); - } +static void +_CopyRelSpec(const SdfRelationshipSpecHandle &srcRel, + const SdfPrimSpecHandle &dstPrim, + const std::string &dstName) +{ + SdfRelationshipSpecHandle newRel = + SdfRelationshipSpec::New( + dstPrim, dstName, srcRel->IsCustom()); + _CopySpec(srcRel, newRel); +} - for (SdfRelationshipSpecHandle const &rel: - prim->GetRelationships()) { - SdfRelationshipSpecHandle newRel = - SdfRelationshipSpec::New( - newPrim, rel->GetName(), rel->IsCustom()); - _CopySpec(rel, newRel); - } - } +static void +_CopyPropSpec(const SdfPropertySpecHandle &srcProp, + const SdfPrimSpecHandle &dstPrim, + const std::string &dstName) +{ + if (SdfAttributeSpecHandle attr = + TfDynamic_cast(srcProp)) { + _CopyAttrSpec(attr, dstPrim, dstName); + } else if (SdfRelationshipSpecHandle attr = + TfDynamic_cast(srcProp)) { + _CopyRelSpec(attr, dstPrim, dstName); + } else { + TF_CODING_ERROR("Property spec is neither an attribute or a relationship"); } } @@ -766,6 +774,13 @@ class UsdSchemaRegistry::_SchemaDefInitHelper } private: + using _PropNameAndPath = std::pair; + using _PropNameAndPathVector = std::vector<_PropNameAndPath>; + + using _PropNameAndPathsToCompose = std::pair; + using _PropNameAndPathsToComposeVector = + std::vector<_PropNameAndPathsToCompose>; + // Applied API schemas require some processing to determine the entire // expanded list of included API schemas that need to be composed into its // prim definition. This structure is used to hold this info. @@ -793,6 +808,14 @@ class UsdSchemaRegistry::_SchemaDefInitHelper // be included. Used for cycle detection. const _BuiltinAPISchemaInfo *includedBy; + // Composition of API schema property overrides only happen across + // an individual branch of an built-in API schema inclusion hierarchy + // (i.e. sibling built-ins cannot compose in overrides to each others + // properties). Thus we have to maintain a stack of the found property + // overrides during built-in expansion through passing them in this + // schema info bundle. + _PropNameAndPathsToComposeVector *propsWithOversToComposePtr; + // Checks if this info's apiSchemaDef would cause a cycle by checking // if it matches any of the recursively expanded API definitions that // caused it to be included. @@ -810,18 +833,46 @@ class UsdSchemaRegistry::_SchemaDefInitHelper void _InitializePrimDefsAndSchematicsForPluginSchemas(); + void _AddSchemaToSchematics( + SdfLayerRefPtr const &source); + void _AddOverridePropertyNamesFromSourceSpec( + const SdfPrimSpecHandle &prim); + void _PrependAPISchemasFromSchemaPrim( const SdfPath &schematicsPrimPath, - TfTokenVector *appliedAPISchemas); + TfTokenVector *appliedAPISchemas) const; void _ExpandBuiltinAPISchemasRecursive( const _BuiltinAPISchemaInfo &builtinAPISchema, _BuiltinAPISchemaExpansionInfo *expansionInfo) const; - void _PopulateAppliedAPIPrimDefinitions(); - void _PopulateConcretePrimDefinitions(); + void _AddSchemaSpecPropertiesAndUpdateOversToCompose( + const _BuiltinAPISchemaInfo &includedSchemaInfo, + UsdPrimDefinition *primDef, + _PropNameAndPathsToComposeVector *propsWithOversToCompose) const; + + _PropNameAndPathVector _GetPropertyPathsForSpec( + const SdfPath &primSpecPath, + _PropNameAndPathVector *overrideProperties = nullptr) const; + + _PropNameAndPathVector _GetPropertyPathsForSpec( + const SdfPath &primSpecPath, + const TfToken &instanceName, + _PropNameAndPathVector *overrideProperties = nullptr) const; + + void _ComposePropertiesWithOverrides( + UsdPrimDefinition *primDef, + _PropNameAndPathsToComposeVector *propsWithOversToCompose) const; + + void _PopulateAppliedAPIPrimDefinitions() const; + void _PopulateConcretePrimDefinitions() const; UsdSchemaRegistry *_registry; + + // Storage for the override property names that may be defined for each + // schema. See _AddOverridePropertyNamesFromSourceSpec for details. + std::unordered_map + _overridePropertyNamesPerSchema; }; void @@ -964,7 +1015,7 @@ _InitializePrimDefsAndSchematicsForPluginSchemas() bool hasErrors = false; - _AddSchema(generatedSchema, _registry->_schematics); + _AddSchemaToSchematics(generatedSchema); // Schema generation will have added any defined fallback prim // types as a dictionary in layer metadata which will be composed @@ -996,12 +1047,63 @@ _InitializePrimDefsAndSchematicsForPluginSchemas() } } +void +UsdSchemaRegistry::_SchemaDefInitHelper::_AddSchemaToSchematics( + SdfLayerRefPtr const &source) +{ + TRACE_FUNCTION(); + const SdfLayerRefPtr &schematicsLayer = _registry->_schematics; + for (SdfPrimSpecHandle const &prim: source->GetRootPrims()) { + if (!schematicsLayer->GetPrimAtPath(prim->GetPath())) { + + SdfPrimSpecHandle newPrim = SdfPrimSpec::New( + schematicsLayer, prim->GetName(), + prim->GetSpecifier(), prim->GetTypeName()); + _CopySpec(prim, newPrim); + + for (SdfAttributeSpecHandle const &attr: prim->GetAttributes()) { + _CopyAttrSpec(attr, newPrim, attr->GetName()); + } + + for (SdfRelationshipSpecHandle const &rel: + prim->GetRelationships()) { + _CopyRelSpec(rel, newPrim, rel->GetName()); + } + + _AddOverridePropertyNamesFromSourceSpec(prim); + } + } +} + +void +UsdSchemaRegistry::_SchemaDefInitHelper::_AddOverridePropertyNamesFromSourceSpec( + const SdfPrimSpecHandle &prim) +{ + // Override property names are stored in a customData field for each schema + // prim spec in the generatedSchema layers that we combine into the full + // schematics layer. But we don't copy customData fields into the final + // schematics (nor do we want to) so we have to extract this information + // from the prim specs in the generatedSchemas and store it away to used + // during the rest of schema initialization. + static const TfToken apiSchemaOverridePropertyNamesToken( + "apiSchemaOverridePropertyNames"); + VtTokenArray overridePropertyNames; + if (prim->GetLayer()->HasFieldDictKey( + prim->GetPath(), + SdfFieldKeys->CustomData, + apiSchemaOverridePropertyNamesToken, + &overridePropertyNames)) { + _overridePropertyNamesPerSchema.emplace( + prim->GetName(), std::move(overridePropertyNames)); + } +} + // Helper that gets the authored API schemas from the schema prim path in the // schematics layer and prepends them to the given applied API schemas list. void UsdSchemaRegistry::_SchemaDefInitHelper::_PrependAPISchemasFromSchemaPrim( const SdfPath &schematicsPrimPath, - TfTokenVector *appliedAPISchemas) + TfTokenVector *appliedAPISchemas) const { // Get the API schemas from the list op field in the schematics. SdfTokenListOp apiSchemasListOp; @@ -1057,16 +1159,38 @@ UsdSchemaRegistry::_SchemaDefInitHelper::_ExpandBuiltinAPISchemasRecursive( MakeMultipleApplyNameInstance( appliedAPISchemas.front(), includedSchemaInfo.instanceName); - // Compose the included schema's properties from its schematic's prim - // spec into the prim definition we're expanding. - expansionInfo->primDef->_ComposePropertiesFromPrimSpec( - _registry->_schematics, - includedSchemaInfo.apiSchemaDef->_schematicsPrimPath, - includedSchemaInfo.instanceName); - // Add the included API schema to the expanded list. expansionInfo->allAPISchemaNames.push_back(includedAPISchemaName); + // Make a copy the parent's override properties to compose. We need a copy + // since the overrides from this branch of the API schema expansion do + // not apply to the other API schemas included by the parent schema. Note + // that we expect the number of property overrides to be very small (and + // frequently empty) and we also expect that the depth of recursion of + // API schema expansion to be very minimal, so the copying of this structure + // is unlikely to have a performance impact. + _PropNameAndPathsToComposeVector propsWithOversToCompose; + if (includedSchemaInfo.propsWithOversToComposePtr) { + propsWithOversToCompose = + *(includedSchemaInfo.propsWithOversToComposePtr); + } + + // Add the properties that come directly from the API schema's class + // schematics. Any newly found defined properties that have overrides in + // propsWithOversToCompose will be fully composed into their final property + // spec for the expanded prim definition. Existing overrides in + // propsWithOversToCompose that were able to be composed with a defined + // property will be removed (we are done with them and won't need/want to + // compose them again). Any new properties that are declared as overrides in + // this schematics spec will be added to propsWithOversToCompose so they + // can be composed with defined properties from API schemas that this + // schema includes. + // \ref Usd_APISchemaStrengthOrdering + _AddSchemaSpecPropertiesAndUpdateOversToCompose( + includedSchemaInfo, + expansionInfo->primDef, + &propsWithOversToCompose); + // Recursively gather the built-in API schemas which are listed after the // included API schema in its applied API schemas list. // @@ -1151,7 +1275,8 @@ UsdSchemaRegistry::_SchemaDefInitHelper::_ExpandBuiltinAPISchemasRecursive( // included both "OtherMultiApplyAPI:__INSTANCE_NAME__:foo" and // "OtherMultiApplyAPI:__INSTANCE_NAME__:bar"). _BuiltinAPISchemaInfo builtinApiSchemaInfo = - {builtinApiSchemaDef, builtinInstanceName, &includedSchemaInfo}; + {builtinApiSchemaDef, builtinInstanceName, + &includedSchemaInfo, &propsWithOversToCompose}; if (builtinApiSchemaInfo.CheckForCycle()) { TF_WARN("Found unrecoverable API schema cycle while expanding " "built-in API schema chain '%s'. An API schema of the same " @@ -1165,12 +1290,345 @@ UsdSchemaRegistry::_SchemaDefInitHelper::_ExpandBuiltinAPISchemasRecursive( // Gather the built-in schemas prim specs and built-in API schemas. _ExpandBuiltinAPISchemasRecursive(builtinApiSchemaInfo, expansionInfo); + + // Each of the API schemas we recursively expand in this loop may have + // defined and composed any number of the properties that we have + // overrides stored for. We remove the overrides for these composed + // properties here so that we don't inadvertently compose over the + // property again if one of the weaker sibling API schemas happens to + // define the same property. + if (!propsWithOversToCompose.empty()) { + const auto removeIt = std::remove_if( + propsWithOversToCompose.begin(), + propsWithOversToCompose.end(), + [&](const _PropNameAndPathsToCompose &propWithOversToCompose) { + return expansionInfo->primDef->_GetPropertySpecPath( + propWithOversToCompose.first); + }); + propsWithOversToCompose.erase( + removeIt, propsWithOversToCompose.end()); + } } } +void +UsdSchemaRegistry::_SchemaDefInitHelper:: +_AddSchemaSpecPropertiesAndUpdateOversToCompose( + const _BuiltinAPISchemaInfo &includedSchemaInfo, + UsdPrimDefinition *primDef, + _PropNameAndPathsToComposeVector *propsWithOversToCompose) const +{ + // Get all the defined property paths and override property paths from the + // API schema's schematics spec. + _PropNameAndPathVector overrideProperties; + _PropNameAndPathVector definedProperties = _GetPropertyPathsForSpec( + includedSchemaInfo.apiSchemaDef->_schematicsPrimPath, + includedSchemaInfo.instanceName, + &overrideProperties); + + // Compose the schema's defined properties into the expanded prim + // definition. + primDef->_AddProperties(std::move(definedProperties)); + + // With the new defined properties added, compose any overrides gathered + // from the schemas that caused this API schema to be included over the + // defined property definitions to which they apply. The composed property + // specs will be added (or updated) under the schematics prim spec of the + // expanded prim definition's type. Note that this removes any + // properties that are composed from propsWithOversToCompose so that we + // don't process these overrides again. Any property overrides that we don't + // have a defined property for yet will remain in propsWithOversToCompose + // as they may be defined elsewhere in the schema expansion. + _ComposePropertiesWithOverrides(primDef, propsWithOversToCompose); + + // Now process the API schema override properties that this schema itself + // defines. + for (_PropNameAndPath &overridePropNameAndPath : overrideProperties) { + TfToken &overridePropName = overridePropNameAndPath.first; + SdfPath &overridePropPath = overridePropNameAndPath.second; + + // If the property name is already found in the composed prim + // definition, then we've already found a def for the property and don't + // process any more overrides. + if (primDef->_GetPropertySpecPath(overridePropName)) { + continue; + } + + // Add the override property's path to the list of schema specs that + // will need to be composed for the property with that name, starting + // a new list of paths if necessary. + // + // We expect the number of override properties to be extemely small + // making linear search efficient. + auto findIt = std::find_if( + propsWithOversToCompose->begin(), + propsWithOversToCompose->end(), + [&](const _PropNameAndPathsToCompose &propWithOversToCompose){ + return propWithOversToCompose.first == overridePropName; + }); + + if (findIt == propsWithOversToCompose->end()) { + propsWithOversToCompose->emplace_back( + std::move(overridePropName), + SdfPathVector({std::move(overridePropPath)})); + } else { + findIt->second.push_back(std::move(overridePropPath)); + } + } +} + +UsdSchemaRegistry::_SchemaDefInitHelper::_PropNameAndPathVector +UsdSchemaRegistry::_SchemaDefInitHelper::_GetPropertyPathsForSpec( + const SdfPath &primSpecPath, + _PropNameAndPathVector *overrideProperties) const +{ + _PropNameAndPathVector definedProperties; + + // Get the names of all the properties defined in the prim spec. + TfTokenVector specPropertyNames; + if (!_registry->_schematics->HasField( + primSpecPath, + SdfChildrenKeys->PropertyChildren, + &specPropertyNames)) { + // While its possible for the spec to have no properties, we expect + // the prim spec itself to exist. + if (!_registry->_schematics->HasSpec(primSpecPath)) { + TF_WARN("No prim spec exists at path '%s' in schematics layer.", + primSpecPath.GetText()); + } + return definedProperties; + } + + definedProperties.reserve(specPropertyNames.size()); + + // Get the override property names for this schema if there are any. If + // there aren't any, return the path for each property name. + const VtTokenArray *overridePropertyNames = TfMapLookupPtr( + _overridePropertyNamesPerSchema, primSpecPath.GetNameToken()); + if (!overridePropertyNames) { + for (TfToken &propName : specPropertyNames) { + definedProperties.emplace_back( + std::move(propName), + primSpecPath.AppendProperty(propName)); + } + return definedProperties; + } + + // Otherwish we have to filter out the override properties from the list + // and optionally return their paths via the output parameter. + if (overrideProperties) { + overrideProperties->reserve(overridePropertyNames->size()); + } + for (TfToken &propName : specPropertyNames) { + if (std::find(overridePropertyNames->begin(), + overridePropertyNames->end(), + propName) == overridePropertyNames->end()) { + definedProperties.emplace_back( + std::move(propName), + primSpecPath.AppendProperty(propName)); + } else if (overrideProperties) { + overrideProperties->emplace_back( + std::move(propName), + primSpecPath.AppendProperty(propName)); + } + } + + return definedProperties; +} + +UsdSchemaRegistry::_SchemaDefInitHelper::_PropNameAndPathVector +UsdSchemaRegistry::_SchemaDefInitHelper::_GetPropertyPathsForSpec( + const SdfPath &primSpecPath, + const TfToken &instanceName, + _PropNameAndPathVector *overrideProperties) const +{ + // First get the property names and specs without the instance name. + _PropNameAndPathVector definedProperties = + _GetPropertyPathsForSpec(primSpecPath, overrideProperties); + if (instanceName.IsEmpty()) { + return definedProperties; + } + + // Apply the instance to all the property names before returning property + // paths. + for (_PropNameAndPath &propNameAndPath : definedProperties) { + propNameAndPath.first = + UsdSchemaRegistry::MakeMultipleApplyNameInstance( + propNameAndPath.first, instanceName); + } + if (overrideProperties) { + for (_PropNameAndPath &propNameAndPath : *overrideProperties) { + propNameAndPath.first = + UsdSchemaRegistry::MakeMultipleApplyNameInstance( + propNameAndPath.first, instanceName); + } + } + + return definedProperties; +} + +// Returns true if the property with the given name in these two separate prim +// definitions have the same type. "Same type" here means that they are both +// the same kind of property (attribute or relationship), have the same +// variability (varying or uniform) and if they are attributes, that their +// attribute type names are the same. +static bool _PropertyTypesMatch( + const SdfLayerRefPtr &layer, + const SdfPath &strongerPropPath, + const SdfPath &weakerPropPath) +{ + const SdfSpecType specType = layer->GetSpecType(strongerPropPath); + const bool specIsAttribute = (specType == SdfSpecTypeAttribute); + + // Compare spec types (relationship vs attribute) + if (specType != layer->GetSpecType(weakerPropPath)) { + TF_WARN("%s at path '%s' from stronger schema failed to override %s at " + "'%s' from weaker schema during schema prim definition " + "composition because of the property spec types do not match.", + specIsAttribute ? "Attribute" : "Relationsip", + strongerPropPath.GetText(), + specIsAttribute ? "relationsip" : "attribute", + weakerPropPath.GetText()); + return false; + } + + // Compare variability + SdfVariability strongerVariability, weakerVariability; + layer->HasField( + strongerPropPath, SdfFieldKeys->Variability, &strongerVariability); + layer->HasField( + weakerPropPath, SdfFieldKeys->Variability, &weakerVariability); + if (weakerVariability != strongerVariability) { + TF_WARN("Property at path '%s' from stronger schema failed to override " + "property at path '%s' from weaker schema during schema prim " + "definition composition because their variability does not " + "match.", + strongerPropPath.GetText(), + weakerPropPath.GetText()); + return false; + } + + // Done comparing if its not an attribute. + if (!specIsAttribute) { + return true; + } + + // Compare the type name field of the attributes. + TfToken strongerTypeName; + layer->HasField(strongerPropPath, SdfFieldKeys->TypeName, &strongerTypeName); + TfToken weakerTypeName; + layer->HasField(weakerPropPath, SdfFieldKeys->TypeName, &weakerTypeName); + if (weakerTypeName != strongerTypeName) { + TF_WARN("Attribute at path '%s' with type name '%s' from stronger " + "schema failed to override attribute at path '%s' with type " + "name '%s' from weaker schema during schema prim definition " + "composition because of the attribute type names do not match.", + strongerPropPath.GetText(), + strongerTypeName.GetText(), + weakerPropPath.GetText(), + weakerTypeName.GetText()); + return false; + } + return true; +} + +void +UsdSchemaRegistry::_SchemaDefInitHelper:: +_ComposePropertiesWithOverrides( + UsdPrimDefinition *primDef, + _PropNameAndPathsToComposeVector *propsWithOversToCompose) const +{ + if (propsWithOversToCompose->empty()) { + return; + } + + _PropNameAndPathsToComposeVector uncomposedPropsWithOversToCompose; + const SdfLayerRefPtr &schematicsLayer = _registry->_schematics; + + for (auto &propWithOversToCompose : *propsWithOversToCompose) { + const TfToken &propName = propWithOversToCompose.first; + SdfPathVector &propertyPaths = propWithOversToCompose.second; + + // Get the defined property spec for the override property spec. If + // there isn't one yet, move the override properties to the uncomposed + // list so we can return them back at the end. + SdfPath *defPath = primDef->_GetPropertySpecPath(propName); + if (!defPath) { + uncomposedPropsWithOversToCompose.push_back( + std::move(propWithOversToCompose)); + continue; + } + + // Property overrides are not allowed to change the type of a property + // from its defining spec so remove any override specs that are + // invalid. + const auto badPropsIt = std::remove_if( + propertyPaths.begin(), propertyPaths.end(), + [&](const SdfPath &propPath) { + return !_PropertyTypesMatch( + schematicsLayer, propPath, *defPath); + } + ); + if (badPropsIt != propertyPaths.end()) { + propertyPaths.erase(badPropsIt, propertyPaths.end()); + if (propertyPaths.empty()) { + continue; + } + } + + // The composed property will always live under the prim definition's + // schematics prim spec, regardless of where the defs it is + // composed from come from. + const SdfPath dstPath = + primDef->_schematicsPrimPath.AppendProperty(propName); + + // If the first override path is not from the composed prim + // definition itself, then the schematics prim doesn't have a + // spec for this prorperty yet. Copy the first override to + // create the needed property spec. + if (dstPath != propertyPaths.front()) { + SdfPrimSpecHandle dstPrim = + schematicsLayer->GetPrimAtPath(primDef->_schematicsPrimPath); + SdfPropertySpecHandle srcProp = + schematicsLayer->GetPropertyAtPath(propertyPaths.front()); + _CopyPropSpec(srcProp, dstPrim, propName); + } + + // Compose function. Any fields from the srcPath spec that aren't + // already in the dstPath spec are copied into the dstPath spec. + auto composeFn = [&](const SdfPath &srcPath) { + for (const TfToken srcField : schematicsLayer->ListFields(srcPath)) { + if (!schematicsLayer->HasField(dstPath, srcField)) { + schematicsLayer->SetField(dstPath, srcField, + schematicsLayer->GetField(srcPath, srcField)); + } + } + }; + + // Now compose in the rest of the override property specs under + // our destination. We always skip the first entry as that will + // already be the spec the destination path starts with. + for (auto pathIt = propertyPaths.begin() + 1; + pathIt != propertyPaths.end(); ++pathIt) { + composeFn(*pathIt); + } + + // Last compose in the property definition itself. + composeFn(*defPath); + + // Now that the spec is fully composed, set the definition's + // path for the property to the composed property's path. + *defPath = dstPath; + } + + // Update the propsWithOversToCompose to be the remaining prop overs that + // weren't able to compose here. + propsWithOversToCompose->swap(uncomposedPropsWithOversToCompose); +} + void UsdSchemaRegistry::_SchemaDefInitHelper:: -_PopulateAppliedAPIPrimDefinitions() +_PopulateAppliedAPIPrimDefinitions() const { TRACE_FUNCTION(); // All applied API schemas may contain other applied API schemas which may @@ -1211,8 +1669,9 @@ _PopulateAppliedAPIPrimDefinitions() // schema is itself), we can just add the prim spec's properties and be // done. if (primDef->_appliedAPISchemas.size() == 1) { - primDef->_ComposePropertiesFromPrimSpec( - _registry->_schematics, primDef->_schematicsPrimPath); + _PropNameAndPathVector definedProperties = + _GetPropertyPathsForSpec(primDef->_schematicsPrimPath); + primDef->_AddProperties(std::move(definedProperties)); continue; } @@ -1309,7 +1768,7 @@ _PopulateAppliedAPIPrimDefinitions() void UsdSchemaRegistry::_SchemaDefInitHelper:: -_PopulateConcretePrimDefinitions() +_PopulateConcretePrimDefinitions() const { TRACE_FUNCTION(); // Populate all concrete API schema definitions; it is expected that all @@ -1331,10 +1790,15 @@ _PopulateConcretePrimDefinitions() primDef->_schematicsPrimPath, &primDef->_appliedAPISchemas); - // Compose the properties from the prim spec to the prim definition - // first as these are stronger than the built-in API schema properties. - primDef->_ComposePropertiesFromPrimSpec( - _registry->_schematics, primDef->_schematicsPrimPath); + // Get both the defined properties and API schema override properties + // from the concrete prim spec. We compose the defined properties from + // the prim spec to the prim definition first as these are stronger + // than the built-in API schema properties. + _PropNameAndPathVector overrideProperties; + _PropNameAndPathVector definedProperties = + _GetPropertyPathsForSpec(primDef->_schematicsPrimPath, + &overrideProperties); + primDef->_AddProperties(std::move(definedProperties)); // If there are any applied API schemas in the list, compose them // in now @@ -1353,6 +1817,20 @@ _PopulateConcretePrimDefinitions() _registry->_ComposeAPISchemasIntoPrimDefinition( primDef, apiSchemasToCompose); } + + // With all the built-in API schemas applied, we can now compose any + // API schema property overrides declared in the types schema over the + // current defined properties. + if (!overrideProperties.empty()) { + _PropNameAndPathsToComposeVector overridePropertiesToCompose; + for (_PropNameAndPath &overrideProperty : overrideProperties) { + overridePropertiesToCompose.emplace_back( + std::move(overrideProperty.first), + SdfPathVector({std::move(overrideProperty.second)})); + } + _ComposePropertiesWithOverrides( + primDef, &overridePropertiesToCompose); + } } } diff --git a/pxr/usd/usd/testenv/testUsdAppliedAPISchemas.py b/pxr/usd/usd/testenv/testUsdAppliedAPISchemas.py index 5fec809162..849869dad9 100644 --- a/pxr/usd/usd/testenv/testUsdAppliedAPISchemas.py +++ b/pxr/usd/usd/testenv/testUsdAppliedAPISchemas.py @@ -72,7 +72,27 @@ def setUpClass(cls): Tf.Type(Usd.SchemaBase).FindDerivedByName("TestNestedAutoAppliedToAPI") cls.NestedAutoAppliedToAPIAppliedToPrimType = \ Tf.Type(Usd.SchemaBase).FindDerivedByName("TestNestedAutoAppliedToAPIAppliedToPrim") - + cls.PropertyOversOneAPIType = \ + Tf.Type(Usd.SchemaBase).FindDerivedByName("TestPropertyOversOneAPI") + cls.PropertyOversTwoAPIType = \ + Tf.Type(Usd.SchemaBase).FindDerivedByName("TestPropertyOversTwoAPI") + cls.PropertyOversThreeAPIType = \ + Tf.Type(Usd.SchemaBase).FindDerivedByName("TestPropertyOversThreeAPI") + cls.PropertyOversFourAPIType = \ + Tf.Type(Usd.SchemaBase).FindDerivedByName("TestPropertyOversFourAPI") + cls.PropertyOversMultiOneAPIType = \ + Tf.Type(Usd.SchemaBase).FindDerivedByName("TestPropertyOversMultiOneAPI") + cls.PropertyOversMultiTwoAPIType = \ + Tf.Type(Usd.SchemaBase).FindDerivedByName("TestPropertyOversMultiTwoAPI") + cls.PropertyOversMultiThreeAPIType = \ + Tf.Type(Usd.SchemaBase).FindDerivedByName("TestPropertyOversMultiThreeAPI") + cls.PropertyOversAutoApplyAPIType = \ + Tf.Type(Usd.SchemaBase).FindDerivedByName("TestPropertyOversAutoApplyAPI") + cls.PropertyOversTypedPrimBasePrimType = \ + Tf.Type(Usd.SchemaBase).FindDerivedByName("TestPropertyOversTypedPrimBase") + cls.PropertyOversTypedPrimDerivedPrimType = \ + Tf.Type(Usd.SchemaBase).FindDerivedByName("TestPropertyOversTypedPrimDerived") + def test_SimpleTypedSchemaPrimDefinition(self): """ Tests the prim definition for a simple typed schema that has no @@ -2838,5 +2858,787 @@ def _VerifyIsRel(prim, **kwargs): rel1 = (True, conflictPrimTypeDocStr), rel2 = (False, conflictPrimTypeDocStr)) + @unittest.skipIf(Tf.GetEnvSetting('USD_DISABLE_AUTO_APPLY_API_SCHEMAS'), + "Auto apply API schemas are disabled") + def test_PropertyOversInAPISchemas(self): + """ + Tests the behavior of API schema override properties in schemas that + built-in API schemas. + """ + stage = Usd.Stage.CreateInMemory() + + # Simple helper for testing that a prim has expected attributes that + # resolve to expected values. + def _VerifyAttrValues(prim, expectedAttrValues): + values = {name : prim.GetAttribute(name).Get() + for name in expectedAttrValues.keys()} + self.assertEqual(values, expectedAttrValues) + + def _VerifyAttribute(prim, name, typeName, + variability = Sdf.VariabilityVarying, + custom = False, + **kwargs): + kwargs['typeName'] = typeName + kwargs['variability'] = variability + kwargs['custom'] = custom + attr = prim.GetAttribute(name) + self.assertTrue(attr) + self.assertEqual(attr.GetAllMetadata(), kwargs) + + # Built-in API schema inclusion structure for the PropertyOvers API + # schemas defined for this test: + # + # OneAPI + # | + # ------------------------- + # | | + # TwoAPI ThreeAPI + # | | + # | ------------- + # | | | + # MultiOneAPI:two FourAPI AutoApplyAPI (via auto-apply) + # | + # ------------------------------------------------- + # | | | + # MultiTwoAPI:two MultiTwoAPI:two:multiOne MultiThreeAPI:two:multiOne + # + # The Typed schemas structure is: + # + # inherits + # TypePrimDerived ------------------> TypedPrimBase + # | | + # | | + # | | + # ThreeAPI TwoAPI + # | | + # ... ... + # + + # prim_1 : Prim with PropertyOversOneAPI applied which includes a tree + # of all instances of the API schemas we're testing. + prim_1 = stage.DefinePrim("/Prim1") + prim_1.ApplyAPI(self.PropertyOversOneAPIType) + self.assertEqual(prim_1.GetAppliedSchemas(), [ + "TestPropertyOversOneAPI", + "TestPropertyOversTwoAPI", + "TestPropertyOversMultiOneAPI:two", + "TestPropertyOversMultiTwoAPI:two", + "TestPropertyOversMultiTwoAPI:two:multiOne", + "TestPropertyOversMultiThreeAPI:two:multiOne", + "TestPropertyOversThreeAPI", + "TestPropertyOversFourAPI", + "TestPropertyOversAutoApplyAPI"]) + + # prim_2 : Prim with PropertyOversTwoAPI applied which includes the + # first subtree of the instances of the API schemas we're testing. + prim_2 = stage.DefinePrim("/Prim2") + prim_2.ApplyAPI(self.PropertyOversTwoAPIType) + self.assertEqual(prim_2.GetAppliedSchemas(), [ + "TestPropertyOversTwoAPI", + "TestPropertyOversMultiOneAPI:two", + "TestPropertyOversMultiTwoAPI:two", + "TestPropertyOversMultiTwoAPI:two:multiOne", + "TestPropertyOversMultiThreeAPI:two:multiOne"]) + + # prim_3 : Prim with PropertyOversThreeAPI applied which includes the + # second subtree of the instances of the API schemas we're testing. + prim_3 = stage.DefinePrim("/Prim3") + prim_3.ApplyAPI(self.PropertyOversThreeAPIType) + self.assertEqual(prim_3.GetAppliedSchemas(), [ + "TestPropertyOversThreeAPI", + "TestPropertyOversFourAPI", + "TestPropertyOversAutoApplyAPI"]) + + # prim_4 : Prim with PropertyOversFourAPI applied which doesn't include + # any other API schemas of its own, but is included in the API schema + # trees of the prims mentioned above. + prim_4 = stage.DefinePrim("/Prim4") + prim_4.ApplyAPI(self.PropertyOversFourAPIType) + self.assertEqual(prim_4.GetAppliedSchemas(), [ + "TestPropertyOversFourAPI"]) + + # prim_m_1 : Prim with an instance of multiple apply schema + # PropertyOversMultiOneAPI applied using the instance name "two". The + # API schema includes a tree of other multiple apply API schemas and + # this instance matches the subtree included by PropertyOversTwoAPI + prim_m_1 = stage.DefinePrim("/PrimM1") + prim_m_1.ApplyAPI(self.PropertyOversMultiOneAPIType, "two") + self.assertEqual(prim_m_1.GetAppliedSchemas(), [ + "TestPropertyOversMultiOneAPI:two", + "TestPropertyOversMultiTwoAPI:two", + "TestPropertyOversMultiTwoAPI:two:multiOne", + "TestPropertyOversMultiThreeAPI:two:multiOne" + ]) + + # prim_m_1 : Prim with an instance of multiple apply schema + # PropertyOversMultiTwoAPI applied using the instance name "two". This + # schema doesn't include any other API schemas of its own, but this + # instance of the schema is included in the API schema trees of the + # prims mentioned above. + prim_m_2 = stage.DefinePrim("/PrimM2") + prim_m_2.ApplyAPI(self.PropertyOversMultiTwoAPIType, "two") + self.assertEqual(prim_m_2.GetAppliedSchemas(), [ + "TestPropertyOversMultiTwoAPI:two", + ]) + + # primBase : Prim of type PropertyOversTypedPrimBase which includes the + # built-in PropertyOversTwoAPI and therefore all of the API schemas that + # includes. + primBase = stage.DefinePrim("/PrimBase", + "TestPropertyOversTypedPrimBase") + self.assertTrue(primBase) + self.assertEqual(primBase.GetAppliedSchemas(), [ + "TestPropertyOversTwoAPI", + "TestPropertyOversMultiOneAPI:two", + "TestPropertyOversMultiTwoAPI:two", + "TestPropertyOversMultiTwoAPI:two:multiOne", + "TestPropertyOversMultiThreeAPI:two:multiOne"]) + + # primDerived : Prim of type PropertyOversTypedPrimDerived which both + # inherits from PropertyOversTypedPrimBase and prepends its own built-in + # PropertyOversThreeAPI. Thus it includes properties from the base prim + # type as well as the all the include API schemas imparted by + # PropertyOversThreeAPI and PropertyOversTwoAPI + primDerived = stage.DefinePrim("/PrimDerived", + "TestPropertyOversTypedPrimDerived") + self.assertTrue(primDerived) + self.assertEqual(primDerived.GetAppliedSchemas(), [ + "TestPropertyOversThreeAPI", + "TestPropertyOversFourAPI", + "TestPropertyOversAutoApplyAPI", + "TestPropertyOversTwoAPI", + "TestPropertyOversMultiOneAPI:two", + "TestPropertyOversMultiTwoAPI:two", + "TestPropertyOversMultiTwoAPI:two:multiOne", + "TestPropertyOversMultiThreeAPI:two:multiOne"]) + + # Verify the expected properties of all of the prims we defined above. + # We check the exact fields of all of these expected properties later + # but this serves as a first verification that we got what we expected. + # + # But more importantly this is a useful way to test that none our prims + # include any form of the "overrides_nothing" property which is defined + # in every one of these test schemas as an API schema override but is + # never defined as a concrete property in any of them. + self.assertEqual(prim_1.GetPropertyNames(), [ + "defined_in_auto", + "defined_in_four_1", + "defined_in_four_2", + "defined_in_three", + "defined_in_two", + "int_defined_in_two", + "multi:two:defined_in_m1", + "multi:two:defined_in_m2", + "multi:two:multiOne:defined_in_m2", + "otherMulti:two:multiOne:defined_in_m3", + "uniform_token_defined_in_four" + ]) + + self.assertEqual(prim_2.GetPropertyNames(), [ + "defined_in_two", + "int_defined_in_two", + "multi:two:defined_in_m1", + "multi:two:defined_in_m2", + "multi:two:multiOne:defined_in_m2", + "otherMulti:two:multiOne:defined_in_m3" + ]) + + self.assertEqual(prim_3.GetPropertyNames(), [ + "defined_in_auto", + "defined_in_four_1", + "defined_in_four_2", + "defined_in_three", + "uniform_token_defined_in_four" + ]) + + self.assertEqual(prim_4.GetPropertyNames(), [ + "defined_in_four_1", + "defined_in_four_2", + "uniform_token_defined_in_four" + ]) + + self.assertEqual(prim_m_1.GetPropertyNames(), [ + "multi:two:defined_in_m1", + "multi:two:defined_in_m2", + "multi:two:multiOne:defined_in_m2", + "otherMulti:two:multiOne:defined_in_m3" + ]) + + self.assertEqual(prim_m_2.GetPropertyNames(), [ + "multi:two:defined_in_m2" + ]) + + self.assertEqual(primBase.GetPropertyNames(), [ + "defined_in_base", + "defined_in_two", + "int_defined_in_two", + "multi:two:defined_in_m1", + "multi:two:defined_in_m2", + "multi:two:multiOne:defined_in_m2", + "otherMulti:two:multiOne:defined_in_m3" + ]) + + self.assertEqual(primDerived.GetPropertyNames(), [ + "defined_in_auto", + "defined_in_base", + "defined_in_four_1", + "defined_in_four_2", + "defined_in_three", + "defined_in_two", + "int_defined_in_two", + "multi:two:defined_in_m1", + "multi:two:defined_in_m2", + "multi:two:multiOne:defined_in_m2", + "otherMulti:two:multiOne:defined_in_m3", + "over_in_base", + "uniform_token_defined_in_four" + ]) + + # Property: defined_in_two + # Defined in PropertyOversTwoAPI + # value = "two" + # allowedTokens = "two", "2" + # doc = "Defined in Two" + # Override in PropertyOversOneAPI sets default value to "1" + # Override in PropertyOversThreeAPI tries to set doc string + # Override in PropertyOversFourAPI tries to set default value to "4" + # Override in PropertyOversTypedPrimBase sets default value to "base_over" + propName = "defined_in_two" + # Default value changed by OneAPI, overrides from ThreeAPI and FourAPI + # are ignored because they don't affect sibling TwoAPI. + _VerifyAttribute(prim_1, propName, 'token', + allowedTokens = Vt.TokenArray(["two", "2"]), + default = "1", + documentation = "Defined in Two") + # Matches def in TwoAPI as there are no overrides. + _VerifyAttribute(prim_2, propName, 'token', + allowedTokens = Vt.TokenArray(["two", "2"]), + default = "two", + documentation = "Defined in Two") + # ThreeAPI and FourAPI only define overrides but there's no actual + # property def included in their built-ins, so the properties don't + # exist. + self.assertFalse(prim_3.GetAttribute(propName)) + self.assertFalse(prim_4.GetAttribute(propName)) + + # The TypedPrimBase includes PropertyOversTwoAPI and overrides the + # default. Both the base and derived types get this property with the + # default value override. + _VerifyAttribute(primBase, propName, 'token', + allowedTokens = Vt.TokenArray(["two", "2"]), + default = "base_over", + documentation = "Defined in Two") + _VerifyAttribute(primDerived, propName, 'token', + allowedTokens = Vt.TokenArray(["two", "2"]), + default = "base_over", + documentation = "Defined in Two") + + # Property: defined_in_three + # Defined in PropertyOversThreeAPI + # value = "three" + # allowedTokens = "three", "3" + # doc = "Defined in Three" + # Override in PropertyOversTwoAPI tries to set doc string + # Override in PropertyOversTypedPrimBase sets default value to "base_over" + propName = "defined_in_three" + # Doc value override in built-in TwoAPI, which is a stronger sibling + # of built-in ThreeAPI, is ignored because we don't process overrides + # across sibling API schemas. + _VerifyAttribute(prim_1, propName, 'token', + allowedTokens = Vt.TokenArray(["three", "3"]), + default = "three", + documentation = "Defined in Three") + # TwoAPI defines an override but doesn't include any API schemas that + # define this property. + self.assertFalse(prim_2.GetAttribute(propName)) + # Matches def in ThreeAPI as there are no overrides. + _VerifyAttribute(prim_3, propName, 'token', + allowedTokens = Vt.TokenArray(["three", "3"]), + default = "three", + documentation = "Defined in Three") + # Not defined in FourAPI at all. + self.assertFalse(prim_4.GetAttribute(propName)) + + # Since the TypedPrimBase overrides the default value of the property, + # the derived TypedPrimDerived inherits this override and applies it + # to this property it includes via PropertyOversThreeAPI. However, the + # TypedPrimBase does not itself include PropertyOversThreeAPI so it + # doesn't include the property at all. + self.assertFalse(primBase.GetAttribute(propName)) + _VerifyAttribute(primDerived, propName, 'token', + allowedTokens = Vt.TokenArray(["three", "3"]), + default = "base_over", + documentation = "Defined in Three") + + # Property: defined_in_four_1 + # Defined in PropertyOversFourAPI + # value = "four" + # allowedTokens = "four", "4" + # doc = "Defined in Four" + # Override in PropertyOversOneAPI sets default value to "1" + # Override in PropertyOversTwoAPI sets default value to "2" and + # allowedTokens to ["two", "2"] + # Override in PropertyOversTypedPrimDerived sets default value to + # "derived_over" + propName = "defined_in_four_1" + # Gets overrides from both OneAPI and TwoAPI. However TwoAPI's override + # is ignored since FourAPI is not included through TwoAPI or any of + # its built-in APIs. So only the default value is overridden to use + # OneAPI's value. + _VerifyAttribute(prim_1, propName, 'token', + allowedTokens = Vt.TokenArray(["four", "4"]), + default = "1", + documentation = "Defined in Four") + # TwoAPI defines an override but doesn't include any API schemas that + # define this property. + self.assertFalse(prim_2.GetAttribute(propName)) + # ThreeAPI includes FourAPI but doesn't define overrides so it and + # FourAPI match the defined property. + _VerifyAttribute(prim_3, propName, 'token', + allowedTokens = Vt.TokenArray(["four", "4"]), + default = "four", + documentation = "Defined in Four") + _VerifyAttribute(prim_4, propName, 'token', + allowedTokens = Vt.TokenArray(["four", "4"]), + default = "four", + documentation = "Defined in Four") + + # The TypedPrimDerived includes PropertyOversFourAPI and overrides the + # default value. The base type does not include this API schema and + # does not have this property. + self.assertFalse(primBase.GetAttribute(propName)) + _VerifyAttribute(primDerived, propName, 'token', + allowedTokens = Vt.TokenArray(["four", "4"]), + default = "derived_over", + documentation = "Defined in Four") + + # Property: defined_in_four_2 + # Defined in PropertyOversFourAPI + # value = "four" + # allowedTokens = "four", "4" + # doc = "Defined in Four also" + # Override in PropertyOversOneAPI sets default value to "1" + # Override in PropertyOversThreeAPI sets default value to "3" and + # allowedTokens to ["three", "3"] + # Override in TypedPrimBase that sets the default value to "base_over" + # and allowedTokens to ["base_over", "over_base"] + # Override in TypedPrimDerived that sets the default value to + # "derived_over" + propName = "defined_in_four_2" + # Gets overrides from both OneAPI and ThreeAPI. OneAPI's default value + # override overwrites the default value override from ThreeAPI. OneAPI + # has no opinion on the allowedTokens so ThreeAPI's override comes + # through. + _VerifyAttribute(prim_1, propName, 'token', + allowedTokens = Vt.TokenArray(["three", "3"]), + default = "1", + documentation = "Defined in Four also") + # TwoAPI doesn't include FourAPI + self.assertFalse(prim_2.GetAttribute(propName)) + # ThreeAPI overrides both the default value and the allowed tokens. + _VerifyAttribute(prim_3, propName, 'token', + allowedTokens = Vt.TokenArray(["three", "3"]), + default = "3", + documentation = "Defined in Four also") + # FourAPI defines the property. + _VerifyAttribute(prim_4, propName, 'token', + allowedTokens = Vt.TokenArray(["four", "4"]), + default = "four", + documentation = "Defined in Four also") + + # TypedPrimDerived includes PropertyOversThreeAPI (which includes + # PropertyOversFourAPI) and overrides the default value. But it also + # inherits from TypedPrimBase which also overrides the default value and + # the allowedTokens. Since TypePrimDerived has a stronger override + # opinion about the default value, its default value is used. Since + # TypePrimDerived does NOT have an opinion about the allowedTokens, the + # base's override for allowed Tokens is used. + # TypedPrimBase still does not include PropertyOversFourAPI itself so + # it does not have this property. + self.assertFalse(primBase.GetAttribute(propName)) + _VerifyAttribute(primDerived, propName, 'token', + allowedTokens = Vt.TokenArray(["base_over", "over_base"]), + default = "derived_over", + documentation = "Defined in Four also") + + # Property: multi:two:defined_in_m1 + # Defined in PropertyOversMultiOneAPI as multi:_INST_:defined_in_m1 + # value = "multi_one" + # allowedTokens = "multi_one", "m1" + # doc = "Defined in MultiOne" + # Override in PropertyOversOneAPI sets default value to "1" + # Override in PropertyOversTypedPrimDerived sets default value to + # "derived_over" + propName = "multi:two:defined_in_m1" + # OneAPI overrides the explicit instance of multi-apply property to + # set its value to "1" + _VerifyAttribute(prim_1, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_one", "m1"]), + default = "1", + documentation = "Defined in MultiOne") + # TwoAPI includes MultiOneAPI:two but doesn't override this property + _VerifyAttribute(prim_2, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_one", "m1"]), + default = "multi_one", + documentation = "Defined in MultiOne") + # MultiOneAPI:two defines this property + _VerifyAttribute(prim_m_1, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_one", "m1"]), + default = "multi_one", + documentation = "Defined in MultiOne") + # MulitTwoAPI doesn't include a def for this property. + self.assertFalse(prim_m_2.GetAttribute(propName)) + + # TypedPrimBase includes OversTwoAPI which includes MultiOneAPI:two + # but does not define any overrides to the property. TypedPrimDerived + # does define a default value override so that value is used in the + # derived type prim. + _VerifyAttribute(primBase, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_one", "m1"]), + default = "multi_one", + documentation = "Defined in MultiOne") + _VerifyAttribute(primDerived, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_one", "m1"]), + default = "derived_over", + documentation = "Defined in MultiOne") + + # Property: multi:two:defined_in_m2 + # Defined in PropertyOversMultiTwoAPI as multi:_INST_:defined_in_m2 + # value = "multi_two" + # allowedTokens = "multi_two", "m2" + # doc = "Defined in MultiTwo" + # Override of multi:_INST_:defined_in_m2 in PropertyOversMultiOneAPI + # sets default value to "m1" + # + # Override of multi:two:defined_in_m2 in PropertyOversTypedPrimBase sets + # default value to "base_over" and allowed tokens to + # ["base_over", "over_base"] + # Override of multi:two:defined_in_m2 in PropertyOversTypedPrimDerived + # sets default value to "default_over" + propName = "multi:two:defined_in_m2" + # The default value override from MultiOneAPI applies over the property + # defined in MultiTwoAPI for all API schemas that directly or + # indirectly include an instance of MultiOneAPI + _VerifyAttribute(prim_1, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_two", "m2"]), + default = "m1", + documentation = "Defined in MultiTwo") + _VerifyAttribute(prim_2, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_two", "m2"]), + default = "m1", + documentation = "Defined in MultiTwo") + _VerifyAttribute(prim_m_1, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_two", "m2"]), + default = "m1", + documentation = "Defined in MultiTwo") + # The prim that only includes the MultiTwoAPI:two instance uses + # MultiTwo's definition of the prim as it is defined. + _VerifyAttribute(prim_m_2, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_two", "m2"]), + default = "multi_two", + documentation = "Defined in MultiTwo") + + # TypedPrimBase includes OversTwoAPI which includes MultiTwoAPI:two + # so this property is present. Since TypedPrimBase overrides the + # default value and allowed tokens, those values are used in the + # TypedPrimBase prim + _VerifyAttribute(primBase, propName, 'token', + allowedTokens = Vt.TokenArray(["base_over", "over_base"]), + default = "base_over", + documentation = "Defined in MultiTwo") + # TypedPrimDerived additionally overrides the default value with its + # own override so its default value is used. The override for allowed + # tokens from TypedPrimBase is used since the TypedPrimDerived doesn't + # specify its own value for the field. + _VerifyAttribute(primDerived, propName, 'token', + allowedTokens = Vt.TokenArray(["base_over", "over_base"]), + default = "derived_over", + documentation = "Defined in MultiTwo") + + # Property: multi:two:multiOne:defined_in_m2 + # Defined in PropertyOversMultiTwoAPI as multi:_INST_:defined_in_m2 + # value = "multi_two" + # allowedTokens = "multi_two", "m2" + # doc = "Defined in MultiTwo" + # Override of multi:_INST_:multiOne:defined_in_m2 in + # PropertyOversMultiOneAPI sets default value to "m1" + propName = "multi:two:multiOne:defined_in_m2" + + # This test case serves as a complement to the one above. + # MultiOneAPI includes MultiTwoAPI twice. + # First as the MultiTwoAPI:_INST_ + # Second as the MultiTwoAPI:_INST_:multiOne. + # These two instances provide to MultiOneAPI definitions for the + # respective properties + # multi:_INST_:defined_in_m2 + # multi:_INST_:multiOne:defined_in_m2 + # MultiOneAPI provides overrides for both of these properties, in this + # case overriding the default value to "multiOne:m1" + _VerifyAttribute(prim_1, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_two", "m2"]), + default = "multiOne:m1", + documentation = "Defined in MultiTwo") + _VerifyAttribute(prim_2, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_two", "m2"]), + default = "multiOne:m1", + documentation = "Defined in MultiTwo") + _VerifyAttribute(prim_m_1, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_two", "m2"]), + default = "multiOne:m1", + documentation = "Defined in MultiTwo") + # This prim includes MultiTwoAPI:two not MultiTwoAPI:two:multiOne, so + # it doesn't have this property. + self.assertFalse(prim_m_2.GetAttribute(propName)) + + # No additional overrides in the typed prim schemas for this property + # so the properties match the one's from the other prim's above. + _VerifyAttribute(primBase, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_two", "m2"]), + default = "multiOne:m1", + documentation = "Defined in MultiTwo") + _VerifyAttribute(primDerived, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_two", "m2"]), + default = "multiOne:m1", + documentation = "Defined in MultiTwo") + + # XXX: This case is meant to test the behavior of overriding an property + # in a multiple apply API schema that includes another multiple apply + # API schema with a different property namespace prefix. This is + # supported in the generateSchema.usda layers, but there's currently + # no way to specify this in the schema.usda for usdGenSchema to + # produce generateSchema.usda files that do these overrides. The + # generatedSchema.usda for this test is manually updated to include this + # override so that we can still test this functionality until we're able + # to generate these types of overrides in usdGenSchema in the future. + # + # Property: otherMulti:two:multiOne:defined_in_m3 + # Defined in PropertyOversMultiThreeAPI as otherMulti:_INST_:defined_in_m3 + # value = "multi_three" + # allowedTokens = "multi_three", "m3" + # doc = "Defined in MultiThree" + # Override of otherMulti:_INST_:multiOne:defined_in_m3 in + # PropertyOversMultiOneAPI sets default value to "m1" + propName = "otherMulti:two:multiOne:defined_in_m3" + + # This is similar to how there's a property override for + # multi:_INST_:defined_in_m2 in MultiOneAPI in an above case. Here, + # we're proving that we can define a multiple apply API schema property + # override in another multi apply API schema even if they have + # differing property namespace prefixes as long as we define the + # override using the correct prefix. + _VerifyAttribute(prim_1, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_three", "m3"]), + default = "m1", + documentation = "Defined in MultiThree") + _VerifyAttribute(prim_2, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_three", "m3"]), + default = "m1", + documentation = "Defined in MultiThree") + _VerifyAttribute(prim_m_1, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_three", "m3"]), + default = "m1", + documentation = "Defined in MultiThree") + self.assertFalse(prim_m_2.GetAttribute(propName)) + + # No overrides in the typed prim schemas. + _VerifyAttribute(primBase, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_three", "m3"]), + default = "m1", + documentation = "Defined in MultiThree") + _VerifyAttribute(primDerived, propName, 'token', + allowedTokens = Vt.TokenArray(["multi_three", "m3"]), + default = "m1", + documentation = "Defined in MultiThree") + + # Property: int_defined_in_two + # Defined in PropertyOversTwoAPI + # value = 2 + # typeName = int + # doc = "Defined in Two" + # Override in PropertyOversOneAPI tries to override the typeName to + # 'token' and set the value to "1" + # Override in PropertyOversTypedPrimBase overrides the default value to + # 10 using the correct typeName 'int' and overrides the doc string. + # Override in PropertyOversTypedPrimDerived tries to override the + # typeName to 'token' and set the value to "1" + propName = "int_defined_in_two" + # It is invalid for an override to change the typeName of the defined + # property. The override in OneAPI is ignored. + _VerifyAttribute(prim_1, propName, 'int', + default = 2, + documentation = "Int defined in Two") + _VerifyAttribute(prim_2, propName, 'int', + default = 2, + documentation = "Int defined in Two") + + # TypedPrimBase includes PropertyOversTwoAPI and has an override for + # the property (using the correct type) that sets the default to 10 and + # changes the doc string. + _VerifyAttribute(primBase, propName, 'int', + default = 10, + documentation = "Int override in Base") + # TypedPrimDerived has an override with a mismatched typeName. We + # however compose all type inheritance first so the override from the + # TypedPrimDerived is composed over TypedPrimBase's override before it + # is composed with the API schema properties so no override of this + # property is applied because of the type mismatch. + _VerifyAttribute(primDerived, propName, 'int', + default = 2, + documentation = "Int defined in Two") + + # Property: uniform_token_defined_in_four + # Defined in PropertyOversFourAPI + # value = "unt_form" + # variability = uniform + # allowedTokens = "uni_four", "uni_4" + # doc = "Uniform token defined in Four" + # Override in PropertyOversThreeAPI tries to override the default value + # and allowed token but declares the attribute as a non-uniform token + # attribute. + # Override in PropertyOversOneAPI overrides the default value on a + # properly uniform attribute. + # Override in PropertyOversTypedPrimDerived tries to override the + # default value but declares the attribute as a non-uniform token + # attribute. + propName = "uniform_token_defined_in_four" + # OversOneAPI includes OversThreeAPI which includes OversFourAPI. + # The OversThreeAPI's override is a variability mismatch which causes + # it to be ignored but that doesn't prevent the correctly matched + # override from OversOneAPI from overriding the default value. + _VerifyAttribute(prim_1, propName, 'token', + variability = Sdf.VariabilityUniform, + allowedTokens = Vt.TokenArray(["uni_four", "uni_4"]), + default = "uni_1", + documentation = "Uniform token defined in Four") + self.assertFalse(prim_2.GetAttribute(propName)) + # The OversThreeAPI override variability mismatch causes it to be + # ignored. + _VerifyAttribute(prim_3, propName, 'token', + variability = Sdf.VariabilityUniform, + allowedTokens = Vt.TokenArray(["uni_four", "uni_4"]), + default = "uni_four", + documentation = "Uniform token defined in Four") + _VerifyAttribute(prim_4, propName, 'token', + variability = Sdf.VariabilityUniform, + allowedTokens = Vt.TokenArray(["uni_four", "uni_4"]), + default = "uni_four", + documentation = "Uniform token defined in Four") + + # TypedPrimBase does not include the property. TypedPrimDerived's + # override is a variability mismatch and is ignored. + self.assertFalse(primBase.GetAttribute(propName)) + _VerifyAttribute(primDerived, propName, 'token', + variability = Sdf.VariabilityUniform, + allowedTokens = Vt.TokenArray(["uni_four", "uni_4"]), + default = "uni_four", + documentation = "Uniform token defined in Four") + + # Property: defined_in_auto + # Defined in PropertyOversAutoApplyAPI + # value = "auto" + # allowedTokens = "auto" + # doc = "Defined in Auto" + # Override in PropertyOversOneAPI sets default value to "1" + # Override in PropertyOversThreeAPI sets default value to "3" and + # allowedTokens to ["three", "3"] + # Override in PropertyOversFour attempts to set default value and + # doc string + # + # This case is to verify that API schema property overrides can apply + # to built-in schemas that are auto-applied which behave the same as + # other built-in API schemas. + propName = "defined_in_auto" + # OneAPI includes ThreeAPI which AutoApplyAPI is applied to. OneAPI + # composes its override with ThreeAPI's override which composes over + # the auto apply schemas attribute definition. + _VerifyAttribute(prim_1, propName, 'token', + allowedTokens = Vt.TokenArray(["three", "3"]), + default = "1", + documentation = "Defined in Auto") + # TwoAPI does not include AutoApplyAPI + self.assertFalse(prim_2.GetAttribute(propName)) + # AutoApplyAPI is auto applied to ThreeAPI so ThreeAPI has the attribute + # with its override composed over it. Note that FourAPI (which ThreeAPI + # includes) declares an override that would change the doc string and + # default value, but it's a sibling of AutoApplyAPI under ThreeAPI so + # the override is not composed. + _VerifyAttribute(prim_3, propName, 'token', + allowedTokens = Vt.TokenArray(["three", "3"]), + default = "3", + documentation = "Defined in Auto") + # FourAPI defines an override for the attribute, but it does not include + # the AutoApplyAPI so it does not have the attribute. + self.assertFalse(prim_4.GetAttribute(propName)) + + # For comparison, define a prim with just the auto apply API applied. + # It has the originally defined field with no overrides for the + # property. + prim_auto = stage.DefinePrim("/PrimAuto") + prim_auto.ApplyAPI(self.PropertyOversAutoApplyAPIType) + _VerifyAttribute(prim_auto, propName, 'token', + allowedTokens = Vt.TokenArray(["auto"]), + default = "auto", + documentation = "Defined in Auto") + + # The TypedPrimDerived includes PropertyOversThreeAPI with no overrides + # of its own so the value matches ThreeAPI. The base type does not + # include this API schema and does not have this property. + self.assertFalse(primBase.GetAttribute(propName)) + _VerifyAttribute(primDerived, propName, 'token', + allowedTokens = Vt.TokenArray(["three", "3"]), + default = "3", + documentation = "Defined in Auto") + + # Property: defined_in_base + # Defined in PropertyOversTypedPrimBase + # value = "base_def" + # allowedTokens = "base_def", "def_base" + # doc = "Defined in Base" + # Property also defined in PropertyOversTypedPrimDerived setting just + # the default value to "derived_over" + propName = "defined_in_base" + # These are Typed schemas with inheritance, no API schema overrides on + # the property. This is just to verify that standard property + # composition happens for Typed schema inheritance. + _VerifyAttribute(primBase, propName, 'token', + allowedTokens = Vt.TokenArray(["base_def", "def_base"]), + default = "base_def", + documentation = "Defined in Base") + # The derived schema's default value composes with the property + # defintion from the base class. + _VerifyAttribute(primDerived, propName, 'token', + allowedTokens = Vt.TokenArray(["base_def", "def_base"]), + default = "derived_over", + documentation = "Defined in Base") + + # Property: over_in_base + # Defined in PropertyOversTypedPrimBase + # value = "base_over" + # allowedTokens = "base_over", "over_base" + # doc = "Override in Base" + # apiSchemaOverride = true + # + # Defined in PropertyOversTypedPrimDerived + # value = "derived_def" + # apiSchemaOverride = false + propName = "over_in_base" + # This is testing inheritance composition of a property in Typed schemas + # where a derived class turns an API schema override property into a + # defined property. + # + # TypedPrimBase defines this as an API schema override with but there's + # no property defined in its built-in API schemas to make it exist in + # the base prim. + self.assertFalse(primBase.GetAttribute(propName)) + # TypedPrimDerived changes the property to no longer be an API schema + # override so it is defined in the derived prim. The derived property + # is still composed with the base property to create the derived + # schema's property even though the base was declared as an API schema + # override. + _VerifyAttribute(primDerived, propName, 'token', + allowedTokens = Vt.TokenArray(["base_over", "over_base"]), + default = "derived_def", + documentation = "Override in Base") + if __name__ == "__main__": unittest.main() diff --git a/pxr/usd/usd/testenv/testUsdAppliedAPISchemas/resources/generatedSchema.usda b/pxr/usd/usd/testenv/testUsdAppliedAPISchemas/resources/generatedSchema.usda index 1ba26eb970..645538cc06 100644 --- a/pxr/usd/usd/testenv/testUsdAppliedAPISchemas/resources/generatedSchema.usda +++ b/pxr/usd/usd/testenv/testUsdAppliedAPISchemas/resources/generatedSchema.usda @@ -510,3 +510,229 @@ class "TestPropTypeConflictNestedAuthoredAPI" ( ) } +class "TestPropertyOversOneAPI" ( + apiSchemas = ["TestPropertyOversTwoAPI", "TestPropertyOversThreeAPI"] + customData = { + token[] apiSchemaOverridePropertyNames = ["defined_in_auto", "defined_in_four_1", "defined_in_four_2", "defined_in_two", "int_defined_in_two", "multi:two:defined_in_m1", "overrides_nothing", "uniform_token_defined_in_four"] + } +) +{ + token defined_in_auto = "1" + token defined_in_four_1 = "1" + token defined_in_four_2 = "1" + token defined_in_two = "1" + token int_defined_in_two = "1" + token multi:two:defined_in_m1 = "1" + bool overrides_nothing = 1 + uniform token uniform_token_defined_in_four = "uni_1" +} + +class "TestPropertyOversTwoAPI" ( + apiSchemas = ["TestPropertyOversMultiOneAPI:two"] + customData = { + token[] apiSchemaOverridePropertyNames = ["defined_in_four_1", "defined_in_three", "overrides_nothing"] + } +) +{ + token defined_in_four_1 = "2" ( + allowedTokens = ["two", "2"] + ) + token defined_in_three ( + doc = "Doc override in Two" + ) + token defined_in_two = "two" ( + allowedTokens = ["two", "2"] + doc = "Defined in Two" + ) + int int_defined_in_two = 2 ( + doc = "Int defined in Two" + ) + bool overrides_nothing = 1 +} + +class "TestPropertyOversThreeAPI" ( + apiSchemas = ["TestPropertyOversFourAPI"] + customData = { + token[] apiSchemaOverridePropertyNames = ["defined_in_auto", "defined_in_four_2", "defined_in_two", "overrides_nothing", "uniform_token_defined_in_four"] + } +) +{ + token defined_in_auto = "3" ( + allowedTokens = ["three", "3"] + ) + token defined_in_four_2 = "3" ( + allowedTokens = ["three", "3"] + ) + token defined_in_three = "three" ( + allowedTokens = ["three", "3"] + doc = "Defined in Three" + ) + token defined_in_two ( + doc = "Doc override in Three" + ) + bool overrides_nothing = 1 + token uniform_token_defined_in_four = "uni_3" ( + allowedTokens = ["uni_three", "uni_3"] + ) +} + +class "TestPropertyOversFourAPI" ( + customData = { + token[] apiSchemaOverridePropertyNames = ["defined_in_auto", "defined_in_two", "overrides_nothing"] + } +) +{ + token defined_in_auto = "4" ( + doc = "Override doc in Four" + ) + token defined_in_four_1 = "four" ( + allowedTokens = ["four", "4"] + doc = "Defined in Four" + ) + token defined_in_four_2 = "four" ( + allowedTokens = ["four", "4"] + doc = "Defined in Four also" + ) + token defined_in_two = "4" + bool overrides_nothing = 1 + uniform token uniform_token_defined_in_four = "uni_four" ( + allowedTokens = ["uni_four", "uni_4"] + doc = "Uniform token defined in Four" + ) +} + +class "TestPropertyOversMultiOneAPI" ( + apiSchemas = ["TestPropertyOversMultiTwoAPI:__INSTANCE_NAME__", "TestPropertyOversMultiTwoAPI:__INSTANCE_NAME__:multiOne", "TestPropertyOversMultiThreeAPI:__INSTANCE_NAME__:multiOne"] + customData = { + # XXX: Note that "otherMulti:__INSTANCE_NAME__:multiOne:defined_in_m3" + # has been added manually as there is not a current way to generate + # API schema property overrides in multiple apply schemas for properties + # with a different namespace prefix. However, the schema registry and + # our generatedSchema.usda files are capable of supporting it so it is + # worthwhile to test it. "otherMulti:__INSTANCE_NAME__:multiOne:defined_in_m3" + # must be manually added back in after any regeneration of this file for + # changes to the schema.usda used to generate this test. We do plan to + # add support for this in usdGenSchema in the future. + token[] apiSchemaOverridePropertyNames = ["multi:__INSTANCE_NAME__:defined_in_m2", "multi:__INSTANCE_NAME__:multiOne:defined_in_m2", "otherMulti:__INSTANCE_NAME__:multiOne:defined_in_m3", "multi:__INSTANCE_NAME__:overrides_nothing"] + } +) +{ + token multi:__INSTANCE_NAME__:defined_in_m1 = "multi_one" ( + allowedTokens = ["multi_one", "m1"] + doc = "Defined in MultiOne" + ) + token multi:__INSTANCE_NAME__:defined_in_m2 = "m1" + token multi:__INSTANCE_NAME__:multiOne:defined_in_m2 = "multiOne:m1" + bool multi:__INSTANCE_NAME__:overrides_nothing = 1 + # XXX: Note that "otherMulti:__INSTANCE_NAME__:multiOne:defined_in_m3" + # has been added manually as there is not a current way to generate + # API schema property overrides in multiple apply schemas for properties + # with a different namespace prefix. However, the schema registry and + # our generatedSchema.usda files are capable of supporting it so it is + # worthwhile to test it. "otherMulti:__INSTANCE_NAME__:multiOne:defined_in_m3" + # must be manually added back in after any regeneration of this file for + # changes to the schema.usda used to generate this test. We do plan to + # add support for this in usdGenSchema in the future. + token otherMulti:__INSTANCE_NAME__:multiOne:defined_in_m3 = "m1" +} + +class "TestPropertyOversMultiTwoAPI" ( + customData = { + token[] apiSchemaOverridePropertyNames = ["multi:__INSTANCE_NAME__:overrides_nothing"] + } +) +{ + token multi:__INSTANCE_NAME__:defined_in_m2 = "multi_two" ( + allowedTokens = ["multi_two", "m2"] + doc = "Defined in MultiTwo" + ) + bool multi:__INSTANCE_NAME__:overrides_nothing = 1 +} + +class "TestPropertyOversMultiThreeAPI" ( + customData = { + token[] apiSchemaOverridePropertyNames = ["otherMulti:__INSTANCE_NAME__:overrides_nothing"] + } +) +{ + token otherMulti:__INSTANCE_NAME__:defined_in_m3 = "multi_three" ( + allowedTokens = ["multi_three", "m3"] + doc = "Defined in MultiThree" + ) + bool otherMulti:__INSTANCE_NAME__:overrides_nothing = 1 +} + +class TestPropertyOversTypedPrimBase "TestPropertyOversTypedPrimBase" ( + apiSchemas = ["TestPropertyOversTwoAPI"] + customData = { + token[] apiSchemaOverridePropertyNames = ["defined_in_four_2", "defined_in_three", "defined_in_two", "int_defined_in_two", "multi:two:defined_in_m2", "over_in_base", "overrides_nothing"] + } +) +{ + token defined_in_base = "base_def" ( + allowedTokens = ["base_def", "def_base"] + doc = "Defined in Base" + ) + token defined_in_four_2 = "base_over" ( + allowedTokens = ["base_over", "over_base"] + ) + token defined_in_three = "base_over" + token defined_in_two = "base_over" + int int_defined_in_two = 10 ( + doc = "Int override in Base" + ) + token multi:two:defined_in_m2 = "base_over" ( + allowedTokens = ["base_over", "over_base"] + ) + token over_in_base = "base_over" ( + allowedTokens = ["base_over", "over_base"] + doc = "Override in Base" + ) + bool overrides_nothing = 1 +} + +class TestPropertyOversTypedPrimDerived "TestPropertyOversTypedPrimDerived" ( + apiSchemas = ["TestPropertyOversThreeAPI", "TestPropertyOversTwoAPI"] + customData = { + token[] apiSchemaOverridePropertyNames = ["defined_in_four_1", "defined_in_four_2", "defined_in_three", "defined_in_two", "int_defined_in_two", "multi:two:defined_in_m1", "multi:two:defined_in_m2", "overrides_nothing", "uniform_token_defined_in_four"] + } +) +{ + token defined_in_base = "derived_over" ( + allowedTokens = ["base_def", "def_base"] + doc = "Defined in Base" + ) + token defined_in_four_1 = "derived_over" + token defined_in_four_2 = "derived_over" ( + allowedTokens = ["base_over", "over_base"] + ) + token defined_in_three = "base_over" + token defined_in_two = "base_over" + token int_defined_in_two = "derived_over" ( + doc = "Int override in Base" + ) + token multi:two:defined_in_m1 = "derived_over" + token multi:two:defined_in_m2 = "derived_over" ( + allowedTokens = ["base_over", "over_base"] + ) + token over_in_base = "derived_def" ( + allowedTokens = ["base_over", "over_base"] + doc = "Override in Base" + ) + bool overrides_nothing = 1 + token uniform_token_defined_in_four = "uni_derived" +} + +class "TestPropertyOversAutoApplyAPI" ( + customData = { + token[] apiSchemaOverridePropertyNames = ["overrides_nothing"] + } +) +{ + token defined_in_auto = "auto" ( + allowedTokens = ["auto"] + doc = "Defined in Auto" + ) + bool overrides_nothing = 1 +} + diff --git a/pxr/usd/usd/testenv/testUsdAppliedAPISchemas/resources/plugInfo.json b/pxr/usd/usd/testenv/testUsdAppliedAPISchemas/resources/plugInfo.json index 4e8f4b3464..b17f88b9c3 100644 --- a/pxr/usd/usd/testenv/testUsdAppliedAPISchemas/resources/plugInfo.json +++ b/pxr/usd/usd/testenv/testUsdAppliedAPISchemas/resources/plugInfo.json @@ -320,6 +320,109 @@ ], "schemaKind": "concreteTyped" }, + "TestUsdAppliedAPISchemasTestPropertyOversAutoApplyAPI": { + "alias": { + "UsdSchemaBase": "TestPropertyOversAutoApplyAPI" + }, + "apiSchemaAutoApplyTo": [ + "TestPropertyOversThreeAPI" + ], + "autoGenerated": true, + "bases": [ + "UsdAPISchemaBase" + ], + "schemaKind": "singleApplyAPI" + }, + "TestUsdAppliedAPISchemasTestPropertyOversFourAPI": { + "alias": { + "UsdSchemaBase": "TestPropertyOversFourAPI" + }, + "autoGenerated": true, + "bases": [ + "UsdAPISchemaBase" + ], + "schemaKind": "singleApplyAPI" + }, + "TestUsdAppliedAPISchemasTestPropertyOversMultiOneAPI": { + "alias": { + "UsdSchemaBase": "TestPropertyOversMultiOneAPI" + }, + "autoGenerated": true, + "bases": [ + "UsdAPISchemaBase" + ], + "schemaKind": "multipleApplyAPI" + }, + "TestUsdAppliedAPISchemasTestPropertyOversMultiThreeAPI": { + "alias": { + "UsdSchemaBase": "TestPropertyOversMultiThreeAPI" + }, + "autoGenerated": true, + "bases": [ + "UsdAPISchemaBase" + ], + "schemaKind": "multipleApplyAPI" + }, + "TestUsdAppliedAPISchemasTestPropertyOversMultiTwoAPI": { + "alias": { + "UsdSchemaBase": "TestPropertyOversMultiTwoAPI" + }, + "autoGenerated": true, + "bases": [ + "UsdAPISchemaBase" + ], + "schemaKind": "multipleApplyAPI" + }, + "TestUsdAppliedAPISchemasTestPropertyOversOneAPI": { + "alias": { + "UsdSchemaBase": "TestPropertyOversOneAPI" + }, + "autoGenerated": true, + "bases": [ + "UsdAPISchemaBase" + ], + "schemaKind": "singleApplyAPI" + }, + "TestUsdAppliedAPISchemasTestPropertyOversThreeAPI": { + "alias": { + "UsdSchemaBase": "TestPropertyOversThreeAPI" + }, + "autoGenerated": true, + "bases": [ + "UsdAPISchemaBase" + ], + "schemaKind": "singleApplyAPI" + }, + "TestUsdAppliedAPISchemasTestPropertyOversTwoAPI": { + "alias": { + "UsdSchemaBase": "TestPropertyOversTwoAPI" + }, + "autoGenerated": true, + "bases": [ + "UsdAPISchemaBase" + ], + "schemaKind": "singleApplyAPI" + }, + "TestUsdAppliedAPISchemasTestPropertyOversTypedPrimBase": { + "alias": { + "UsdSchemaBase": "TestPropertyOversTypedPrimBase" + }, + "autoGenerated": true, + "bases": [ + "UsdTyped" + ], + "schemaKind": "concreteTyped" + }, + "TestUsdAppliedAPISchemasTestPropertyOversTypedPrimDerived": { + "alias": { + "UsdSchemaBase": "TestPropertyOversTypedPrimDerived" + }, + "autoGenerated": true, + "bases": [ + "TestUsdAppliedAPISchemasTestPropertyOversTypedPrimBase" + ], + "schemaKind": "concreteTyped" + }, "TestUsdAppliedAPISchemasTestTypedSchema": { "alias": { "UsdSchemaBase": "TestTypedSchema" diff --git a/pxr/usd/usd/testenv/testUsdAppliedAPISchemas/resources/schema.usda b/pxr/usd/usd/testenv/testUsdAppliedAPISchemas/resources/schema.usda index 68e2fcfa6c..32f2a4f9e8 100644 --- a/pxr/usd/usd/testenv/testUsdAppliedAPISchemas/resources/schema.usda +++ b/pxr/usd/usd/testenv/testUsdAppliedAPISchemas/resources/schema.usda @@ -614,3 +614,384 @@ class "TestPropTypeConflictNestedAuthoredAPI" ( int rel2 ( doc = "From TestPropTypeConflictNestedAuthoredAPI" ) } +class "TestPropertyOversOneAPI" ( + inherits = + prepend apiSchemas = ["TestPropertyOversTwoAPI", + "TestPropertyOversThreeAPI"] +) +{ + token int_defined_in_two = "1" ( + customData = { + bool apiSchemaOverride = true + } + ) + + bool overrides_nothing = 1 ( + customData = { + bool apiSchemaOverride = true + } + ) + token defined_in_two = "1" ( + customData = { + bool apiSchemaOverride = true + } + ) + + token defined_in_four_1 = "1" ( + customData = { + bool apiSchemaOverride = true + } + ) + + token defined_in_four_2 = "1" ( + customData = { + bool apiSchemaOverride = true + } + ) + + token multi:two:defined_in_m1 = "1" ( + customData = { + bool apiSchemaOverride = true + } + ) + + uniform token uniform_token_defined_in_four = "uni_1" ( + customData = { + bool apiSchemaOverride = true + } + ) + + token defined_in_auto = "1" ( + customData = { + bool apiSchemaOverride = true + } + ) +} + +class "TestPropertyOversTwoAPI" ( + inherits = + prepend apiSchemas = ["TestPropertyOversMultiOneAPI:two"] +) +{ + int int_defined_in_two = 2 ( + doc = "Int defined in Two" + ) + + bool overrides_nothing = 1 ( + customData = { + bool apiSchemaOverride = true + } + ) + token defined_in_two = "two" ( + allowedTokens = ["two", "2"] + doc = "Defined in Two" + ) + + # Overrides just the doc string from TestPropertyOversThreeAPI + # when included by TestPropertyOversOneAPI. Does NOT add this + # property to this schema itself + token defined_in_three ( + customData = { + bool apiSchemaOverride = true + } + doc = "Doc override in Two" + ) + + token defined_in_four_1 = "2" ( + customData = { + bool apiSchemaOverride = true + } + allowedTokens = ["two", "2"] + ) +} + +class "TestPropertyOversThreeAPI" ( + inherits = + prepend apiSchemas = ["TestPropertyOversFourAPI"] +) +{ + bool overrides_nothing = 1 ( + customData = { + bool apiSchemaOverride = true + } + ) + token defined_in_three = "three" ( + allowedTokens = ["three", "3"] + doc = "Defined in Three" + ) + + # Deos nothing because it's weaker than the def in + # TestPropertyOversTwoAPI + token defined_in_two ( + customData = { + bool apiSchemaOverride = true + } + doc = "Doc override in Three" + ) + + token uniform_token_defined_in_four = "uni_3" ( + allowedTokens = ["uni_three", "uni_3"] + customData = { + bool apiSchemaOverride = true + } + ) + + token defined_in_four_2 = "3" ( + allowedTokens = ["three", "3"] + customData = { + bool apiSchemaOverride = true + } + ) + + token defined_in_auto = "3" ( + allowedTokens = ["three", "3"] + customData = { + bool apiSchemaOverride = true + } + ) +} + +class "TestPropertyOversFourAPI" ( + inherits = +) +{ + bool overrides_nothing = 1 ( + customData = { + bool apiSchemaOverride = true + } + ) + token defined_in_two = "4" ( + customData = { + bool apiSchemaOverride = true + } + ) + + token defined_in_four_1 = "four" ( + allowedTokens = ["four", "4"] + doc = "Defined in Four" + ) + + token defined_in_four_2 = "four" ( + allowedTokens = ["four", "4"] + doc = "Defined in Four also" + ) + + uniform token uniform_token_defined_in_four = "uni_four" ( + allowedTokens = ["uni_four", "uni_4"] + doc = "Uniform token defined in Four" + ) + + token defined_in_auto = "4" ( + doc = "Override doc in Four" + customData = { + bool apiSchemaOverride = true + } + ) +} + +class "TestPropertyOversMultiOneAPI" ( + inherits = + prepend apiSchemas = ["TestPropertyOversMultiTwoAPI", + "TestPropertyOversMultiTwoAPI:multiOne", + "TestPropertyOversMultiThreeAPI:multiOne"] + customData = { + token apiSchemaType = "multipleApply" + token propertyNamespacePrefix = "multi" + } +) +{ + bool overrides_nothing = 1 ( + customData = { + bool apiSchemaOverride = true + } + ) + token defined_in_m1 = "multi_one" ( + allowedTokens = ["multi_one", "m1"] + doc = "Defined in MultiOne" + ) + + token defined_in_m2 = "m1" ( + customData = { + bool apiSchemaOverride = true + } + ) + + token multiOne:defined_in_m2 = "multiOne:m1" ( + customData = { + bool apiSchemaOverride = true + } + ) +} + +class "TestPropertyOversMultiTwoAPI" ( + inherits = + customData = { + token apiSchemaType = "multipleApply" + token propertyNamespacePrefix = "multi" + } +) +{ + bool overrides_nothing = 1 ( + customData = { + bool apiSchemaOverride = true + } + ) + token defined_in_m2 = "multi_two" ( + allowedTokens = ["multi_two", "m2"] + doc = "Defined in MultiTwo" + ) +} + +class "TestPropertyOversMultiThreeAPI" ( + inherits = + customData = { + token apiSchemaType = "multipleApply" + token propertyNamespacePrefix = "otherMulti" + } +) +{ + bool overrides_nothing = 1 ( + customData = { + bool apiSchemaOverride = true + } + ) + + token defined_in_m3 = "multi_three" ( + allowedTokens = ["multi_three", "m3"] + doc = "Defined in MultiThree" + ) +} + +class TestPropertyOversTypedPrimBase "TestPropertyOversTypedPrimBase" ( + inherits = + prepend apiSchemas = ["TestPropertyOversTwoAPI"] +) +{ + bool overrides_nothing = 1 ( + customData = { + bool apiSchemaOverride = true + } + ) + + token defined_in_two = "base_over" ( + customData = { + bool apiSchemaOverride = true + } + ) + + int int_defined_in_two = 10 ( + customData = { + bool apiSchemaOverride = true + } + doc = "Int override in Base" + ) + + token defined_in_three = "base_over" ( + customData = { + bool apiSchemaOverride = true + } + ) + + token multi:two:defined_in_m2 = "base_over" ( + allowedTokens = ["base_over", "over_base"] + customData = { + bool apiSchemaOverride = true + } + ) + + token defined_in_four_2 = "base_over" ( + allowedTokens = ["base_over", "over_base"] + customData = { + bool apiSchemaOverride = true + } + ) + + token defined_in_base = "base_def" ( + allowedTokens = ["base_def", "def_base"] + doc = "Defined in Base" + ) + + token over_in_base = "base_over" ( + allowedTokens = ["base_over", "over_base"] + doc = "Override in Base" + customData = { + bool apiSchemaOverride = true + } + ) +} + +class TestPropertyOversTypedPrimDerived "TestPropertyOversTypedPrimDerived" ( + inherits = + prepend apiSchemas = ["TestPropertyOversThreeAPI"] +) +{ + bool overrides_nothing = 1 ( + customData = { + bool apiSchemaOverride = true + } + ) + + token int_defined_in_two = "derived_over" ( + customData = { + bool apiSchemaOverride = true + } + ) + + token multi:two:defined_in_m1 = "derived_over" ( + customData = { + bool apiSchemaOverride = true + } + ) + + token defined_in_four_1 = "derived_over" ( + customData = { + bool apiSchemaOverride = true + } + ) + + token multi:two:defined_in_m2 = "derived_over" ( + customData = { + bool apiSchemaOverride = true + } + ) + + token defined_in_four_2 = "derived_over" ( + customData = { + bool apiSchemaOverride = true + } + ) + + token uniform_token_defined_in_four = "uni_derived" ( + customData = { + bool apiSchemaOverride = true + } + ) + + token defined_in_base = "derived_over" + + token over_in_base = "derived_def" ( + customData = { + bool apiSchemaOverride = false + } + ) +} + +class "TestPropertyOversAutoApplyAPI" ( + inherits = + customData = { + token[] apiSchemaAutoApplyTo = [ + "TestPropertyOversThreeAPI" + ] + } +) +{ + bool overrides_nothing = 1 ( + customData = { + bool apiSchemaOverride = true + } + ) + token defined_in_auto = "auto" ( + allowedTokens = ["auto"] + doc = "Defined in Auto" + ) +} diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/base.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/base.cpp index 281c9c7221..eaa8f68a0a 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/base.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/base.cpp @@ -1716,6 +1716,57 @@ UsdContrivedBase::CreateFrame4dArrayAttr(VtValue const &defaultValue, bool write writeSparsely); } +UsdAttribute +UsdContrivedBase::GetOverrideBaseFalseDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedFalse); +} + +UsdAttribute +UsdContrivedBase::CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedBase::GetOverrideBaseFalseDerivedNoneAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedNone); +} + +UsdAttribute +UsdContrivedBase::CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedNone, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedBase::GetOverrideBaseNoneDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseNoneDerivedFalse); +} + +UsdAttribute +UsdContrivedBase::CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseNoneDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + namespace { static inline TfTokenVector _ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right) @@ -1829,6 +1880,9 @@ UsdContrivedBase::GetSchemaAttributeNames(bool includeInherited) UsdContrivedTokens->matrix3dArray, UsdContrivedTokens->matrix4dArray, UsdContrivedTokens->frame4dArray, + UsdContrivedTokens->overrideBaseFalseDerivedFalse, + UsdContrivedTokens->overrideBaseFalseDerivedNone, + UsdContrivedTokens->overrideBaseNoneDerivedFalse, }; static TfTokenVector allNames = _ConcatenateAttributeNames( diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/base.h b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/base.h index e11599acc9..ccb1a07086 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/base.h +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/base.h @@ -2244,6 +2244,81 @@ class UsdContrivedBase : public UsdTyped USDCONTRIVED_API UsdAttribute CreateFrame4dArrayAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Base. (1/3) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedFalseAttr() const; + + /// See GetOverrideBaseFalseDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDNONE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override has no opinion in Derived. + /// Generates API functions in Base. (2/3) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedNone = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedNoneAttr() const; + + /// See GetOverrideBaseFalseDerivedNoneAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASENONEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override has no opinion in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Base. (3/3) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseNoneDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseNoneDerivedFalseAttr() const; + + /// See GetOverrideBaseNoneDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + public: // ===================================================================== // // Feel free to add custom code below this line, it will be preserved by diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/derived.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/derived.cpp index f230e0e2db..a71db784dd 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/derived.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/derived.cpp @@ -273,6 +273,74 @@ UsdContrivedDerived::CreateJustDefaultAttr(VtValue const &defaultValue, bool wri writeSparsely); } +UsdAttribute +UsdContrivedDerived::GetOverrideBaseTrueDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseTrueDerivedFalse); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseTrueDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseTrueDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedDerived::GetOverrideBaseFalseDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedFalse); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedDerived::GetOverrideBaseFalseDerivedNoneAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedNone); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedNone, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedDerived::GetOverrideBaseNoneDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseNoneDerivedFalse); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseNoneDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + UsdRelationship UsdContrivedDerived::GetBindingRel() const { @@ -313,6 +381,10 @@ UsdContrivedDerived::GetSchemaAttributeNames(bool includeInherited) UsdContrivedTokens->testingAsset, UsdContrivedTokens->namespacedProperty, UsdContrivedTokens->justDefault, + UsdContrivedTokens->overrideBaseTrueDerivedFalse, + UsdContrivedTokens->overrideBaseFalseDerivedFalse, + UsdContrivedTokens->overrideBaseFalseDerivedNone, + UsdContrivedTokens->overrideBaseNoneDerivedFalse, }; static TfTokenVector allNames = _ConcatenateAttributeNames( diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/derived.h b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/derived.h index 13dcc713ac..4b2c5b4955 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/derived.h +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/derived.h @@ -385,6 +385,106 @@ class UsdContrivedDerived : public UsdContrivedBase USDCONTRIVED_API UsdAttribute CreateJustDefaultAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASETRUEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to True in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Derived. (1/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseTrueDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseTrueDerivedFalseAttr() const; + + /// See GetOverrideBaseTrueDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseTrueDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Derived. (2/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedFalseAttr() const; + + /// See GetOverrideBaseFalseDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDNONE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override has no opinion in Derived. + /// Generates API functions in Derived. (3/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedNone = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedNoneAttr() const; + + /// See GetOverrideBaseFalseDerivedNoneAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASENONEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override has no opinion in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Derived. (4/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseNoneDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseNoneDerivedFalseAttr() const; + + /// See GetOverrideBaseNoneDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + public: // --------------------------------------------------------------------- // // BINDING diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/generatedSchema.usda b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/generatedSchema.usda index 27925867f8..fe66902a23 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/generatedSchema.usda +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/generatedSchema.usda @@ -40,6 +40,9 @@ class "PublicMultipleApplyAPI" ( class "Base" ( apiSchemas = ["BuiltinAPI"] + customData = { + token[] apiSchemaOverridePropertyNames = ["overrideBaseTrueDerivedFalse", "overrideBaseTrueDerivedNone", "overrideBaseTrueDerivedTrue"] + } doc = 'This doc should only exist on the "Base" class.' ) { @@ -119,6 +122,42 @@ class "Base" ( normal3f[] normal3fArray normal3h normal3h = (0, 0, 0) normal3h[] normal3hArray + int overrideBaseFalseDerivedFalse = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Base. (1/3) + """ + ) + int overrideBaseFalseDerivedNone = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override has no opinion in Derived. + Generates API functions in Base. (2/3) + """ + ) + int overrideBaseNoneDerivedFalse = 1 ( + doc = """API schema override has no opinion in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Base. (3/3) + """ + ) + int overrideBaseTrueDerivedFalse = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to False in Derived. + Does not generate API functions in Base. + """ + ) + int overrideBaseTrueDerivedNone = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override has no opinion in Derived. + Does not generate API functions in Base. + """ + ) + int overrideBaseTrueDerivedTrue = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to True in Derived. + Does not generate API functions in Base. + """ + ) point3d point3d = (0, 0, 0) point3d[] point3dArray point3f point3f = (0, 0, 0) @@ -151,6 +190,9 @@ class "Base" ( class Derived "Derived" ( apiSchemas = ["BuiltinAPI"] + customData = { + token[] apiSchemaOverridePropertyNames = ["overrideBaseTrueDerivedNone", "overrideBaseTrueDerivedTrue"] + } doc = "Emphasized! Test Section" ) { @@ -258,6 +300,42 @@ class Derived "Derived" ( normal3f[] normal3fArray normal3h normal3h = (0, 0, 0) normal3h[] normal3hArray + int overrideBaseFalseDerivedFalse = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (2/4) + """ + ) + int overrideBaseFalseDerivedNone = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override has no opinion in Derived. + Generates API functions in Derived. (3/4) + """ + ) + int overrideBaseNoneDerivedFalse = 1 ( + doc = """API schema override has no opinion in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (4/4) + """ + ) + int overrideBaseTrueDerivedFalse = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (1/4) + """ + ) + int overrideBaseTrueDerivedNone = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override has no opinion in Derived. + Does not generate API functions in Derived. + """ + ) + int overrideBaseTrueDerivedTrue = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to True in Derived. + Does not generate API functions in Derived. + """ + ) float3 pivotPosition = (0, 0, 0) ( doc = """Rotation pivot position for this prim's transformation. Provided as advisory data only for use by authoring applications, diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/tokens.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/tokens.cpp index d8b8f29758..2111f008d9 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/tokens.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/tokens.cpp @@ -106,6 +106,12 @@ UsdContrivedTokensType::UsdContrivedTokensType() : normal3fArray("normal3fArray", TfToken::Immortal), normal3h("normal3h", TfToken::Immortal), normal3hArray("normal3hArray", TfToken::Immortal), + overrideBaseFalseDerivedFalse("overrideBaseFalseDerivedFalse", TfToken::Immortal), + overrideBaseFalseDerivedNone("overrideBaseFalseDerivedNone", TfToken::Immortal), + overrideBaseNoneDerivedFalse("overrideBaseNoneDerivedFalse", TfToken::Immortal), + overrideBaseTrueDerivedFalse("overrideBaseTrueDerivedFalse", TfToken::Immortal), + overrideBaseTrueDerivedNone("overrideBaseTrueDerivedNone", TfToken::Immortal), + overrideBaseTrueDerivedTrue("overrideBaseTrueDerivedTrue", TfToken::Immortal), pivotPosition("pivotPosition", TfToken::Immortal), point3d("point3d", TfToken::Immortal), point3dArray("point3dArray", TfToken::Immortal), @@ -236,6 +242,12 @@ UsdContrivedTokensType::UsdContrivedTokensType() : normal3fArray, normal3h, normal3hArray, + overrideBaseFalseDerivedFalse, + overrideBaseFalseDerivedNone, + overrideBaseNoneDerivedFalse, + overrideBaseTrueDerivedFalse, + overrideBaseTrueDerivedNone, + overrideBaseTrueDerivedTrue, pivotPosition, point3d, point3dArray, diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/tokens.h b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/tokens.h index 4aca62733c..bbe6053451 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/tokens.h +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/tokens.h @@ -382,6 +382,30 @@ struct UsdContrivedTokensType { /// /// UsdContrivedBase const TfToken normal3hArray; + /// \brief "overrideBaseFalseDerivedFalse" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseFalseDerivedFalse; + /// \brief "overrideBaseFalseDerivedNone" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseFalseDerivedNone; + /// \brief "overrideBaseNoneDerivedFalse" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseNoneDerivedFalse; + /// \brief "overrideBaseTrueDerivedFalse" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseTrueDerivedFalse; + /// \brief "overrideBaseTrueDerivedNone" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseTrueDerivedNone; + /// \brief "overrideBaseTrueDerivedTrue" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseTrueDerivedTrue; /// \brief "pivotPosition" /// /// UsdContrivedDerived diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/wrapBase.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/wrapBase.cpp index 4d75b3da8a..7b87a94a51 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/wrapBase.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/wrapBase.cpp @@ -720,6 +720,27 @@ _CreateFrame4dArrayAttr(UsdContrivedBase &self, return self.CreateFrame4dArrayAttr( UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Frame4dArray), writeSparsely); } + +static UsdAttribute +_CreateOverrideBaseFalseDerivedFalseAttr(UsdContrivedBase &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseFalseDerivedNoneAttr(UsdContrivedBase &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedNoneAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseNoneDerivedFalseAttr(UsdContrivedBase &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseNoneDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} static std::string _Repr(const UsdContrivedBase &self) @@ -1431,6 +1452,27 @@ void wrapUsdContrivedBase() &_CreateFrame4dArrayAttr, (arg("defaultValue")=object(), arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedFalseAttr", + &This::GetOverrideBaseFalseDerivedFalseAttr) + .def("CreateOverrideBaseFalseDerivedFalseAttr", + &_CreateOverrideBaseFalseDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedNoneAttr", + &This::GetOverrideBaseFalseDerivedNoneAttr) + .def("CreateOverrideBaseFalseDerivedNoneAttr", + &_CreateOverrideBaseFalseDerivedNoneAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseNoneDerivedFalseAttr", + &This::GetOverrideBaseNoneDerivedFalseAttr) + .def("CreateOverrideBaseNoneDerivedFalseAttr", + &_CreateOverrideBaseNoneDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) .def("__repr__", ::_Repr) ; diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/wrapDerived.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/wrapDerived.cpp index 5e188fade0..89b785009a 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/wrapDerived.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/wrapDerived.cpp @@ -118,6 +118,34 @@ _CreateJustDefaultAttr(UsdContrivedDerived &self, return self.CreateJustDefaultAttr( UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely); } + +static UsdAttribute +_CreateOverrideBaseTrueDerivedFalseAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseTrueDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseFalseDerivedFalseAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseFalseDerivedNoneAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedNoneAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseNoneDerivedFalseAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseNoneDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} static std::string _Repr(const UsdContrivedDerived &self) @@ -230,6 +258,34 @@ void wrapUsdContrivedDerived() &_CreateJustDefaultAttr, (arg("defaultValue")=object(), arg("writeSparsely")=false)) + + .def("GetOverrideBaseTrueDerivedFalseAttr", + &This::GetOverrideBaseTrueDerivedFalseAttr) + .def("CreateOverrideBaseTrueDerivedFalseAttr", + &_CreateOverrideBaseTrueDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedFalseAttr", + &This::GetOverrideBaseFalseDerivedFalseAttr) + .def("CreateOverrideBaseFalseDerivedFalseAttr", + &_CreateOverrideBaseFalseDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedNoneAttr", + &This::GetOverrideBaseFalseDerivedNoneAttr) + .def("CreateOverrideBaseFalseDerivedNoneAttr", + &_CreateOverrideBaseFalseDerivedNoneAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseNoneDerivedFalseAttr", + &This::GetOverrideBaseNoneDerivedFalseAttr) + .def("CreateOverrideBaseNoneDerivedFalseAttr", + &_CreateOverrideBaseNoneDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) .def("GetBindingRel", diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/wrapTokens.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/wrapTokens.cpp index a02bab6ebb..475e17c9b5 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/wrapTokens.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/basic/wrapTokens.cpp @@ -144,6 +144,12 @@ void wrapUsdContrivedTokens() _AddToken(cls, "normal3fArray", UsdContrivedTokens->normal3fArray); _AddToken(cls, "normal3h", UsdContrivedTokens->normal3h); _AddToken(cls, "normal3hArray", UsdContrivedTokens->normal3hArray); + _AddToken(cls, "overrideBaseFalseDerivedFalse", UsdContrivedTokens->overrideBaseFalseDerivedFalse); + _AddToken(cls, "overrideBaseFalseDerivedNone", UsdContrivedTokens->overrideBaseFalseDerivedNone); + _AddToken(cls, "overrideBaseNoneDerivedFalse", UsdContrivedTokens->overrideBaseNoneDerivedFalse); + _AddToken(cls, "overrideBaseTrueDerivedFalse", UsdContrivedTokens->overrideBaseTrueDerivedFalse); + _AddToken(cls, "overrideBaseTrueDerivedNone", UsdContrivedTokens->overrideBaseTrueDerivedNone); + _AddToken(cls, "overrideBaseTrueDerivedTrue", UsdContrivedTokens->overrideBaseTrueDerivedTrue); _AddToken(cls, "pivotPosition", UsdContrivedTokens->pivotPosition); _AddToken(cls, "point3d", UsdContrivedTokens->point3d); _AddToken(cls, "point3dArray", UsdContrivedTokens->point3dArray); diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/base.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/base.cpp index 281c9c7221..eaa8f68a0a 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/base.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/base.cpp @@ -1716,6 +1716,57 @@ UsdContrivedBase::CreateFrame4dArrayAttr(VtValue const &defaultValue, bool write writeSparsely); } +UsdAttribute +UsdContrivedBase::GetOverrideBaseFalseDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedFalse); +} + +UsdAttribute +UsdContrivedBase::CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedBase::GetOverrideBaseFalseDerivedNoneAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedNone); +} + +UsdAttribute +UsdContrivedBase::CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedNone, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedBase::GetOverrideBaseNoneDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseNoneDerivedFalse); +} + +UsdAttribute +UsdContrivedBase::CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseNoneDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + namespace { static inline TfTokenVector _ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right) @@ -1829,6 +1880,9 @@ UsdContrivedBase::GetSchemaAttributeNames(bool includeInherited) UsdContrivedTokens->matrix3dArray, UsdContrivedTokens->matrix4dArray, UsdContrivedTokens->frame4dArray, + UsdContrivedTokens->overrideBaseFalseDerivedFalse, + UsdContrivedTokens->overrideBaseFalseDerivedNone, + UsdContrivedTokens->overrideBaseNoneDerivedFalse, }; static TfTokenVector allNames = _ConcatenateAttributeNames( diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/base.h b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/base.h index ebcc196cbb..c3fbbe9c9e 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/base.h +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/base.h @@ -2244,6 +2244,81 @@ class UsdContrivedBase : public UsdTyped USDCONTRIVED_API UsdAttribute CreateFrame4dArrayAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Base. (1/3) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedFalseAttr() const; + + /// See GetOverrideBaseFalseDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDNONE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override has no opinion in Derived. + /// Generates API functions in Base. (2/3) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedNone = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedNoneAttr() const; + + /// See GetOverrideBaseFalseDerivedNoneAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASENONEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override has no opinion in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Base. (3/3) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseNoneDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseNoneDerivedFalseAttr() const; + + /// See GetOverrideBaseNoneDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + public: // ===================================================================== // // Feel free to add custom code below this line, it will be preserved by diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/derived.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/derived.cpp index f230e0e2db..a71db784dd 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/derived.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/derived.cpp @@ -273,6 +273,74 @@ UsdContrivedDerived::CreateJustDefaultAttr(VtValue const &defaultValue, bool wri writeSparsely); } +UsdAttribute +UsdContrivedDerived::GetOverrideBaseTrueDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseTrueDerivedFalse); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseTrueDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseTrueDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedDerived::GetOverrideBaseFalseDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedFalse); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedDerived::GetOverrideBaseFalseDerivedNoneAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedNone); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedNone, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedDerived::GetOverrideBaseNoneDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseNoneDerivedFalse); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseNoneDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + UsdRelationship UsdContrivedDerived::GetBindingRel() const { @@ -313,6 +381,10 @@ UsdContrivedDerived::GetSchemaAttributeNames(bool includeInherited) UsdContrivedTokens->testingAsset, UsdContrivedTokens->namespacedProperty, UsdContrivedTokens->justDefault, + UsdContrivedTokens->overrideBaseTrueDerivedFalse, + UsdContrivedTokens->overrideBaseFalseDerivedFalse, + UsdContrivedTokens->overrideBaseFalseDerivedNone, + UsdContrivedTokens->overrideBaseNoneDerivedFalse, }; static TfTokenVector allNames = _ConcatenateAttributeNames( diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/derived.h b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/derived.h index 712b71f9de..6db8b58c01 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/derived.h +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/derived.h @@ -385,6 +385,106 @@ class UsdContrivedDerived : public UsdContrivedBase USDCONTRIVED_API UsdAttribute CreateJustDefaultAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASETRUEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to True in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Derived. (1/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseTrueDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseTrueDerivedFalseAttr() const; + + /// See GetOverrideBaseTrueDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseTrueDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Derived. (2/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedFalseAttr() const; + + /// See GetOverrideBaseFalseDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDNONE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override has no opinion in Derived. + /// Generates API functions in Derived. (3/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedNone = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedNoneAttr() const; + + /// See GetOverrideBaseFalseDerivedNoneAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASENONEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override has no opinion in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Derived. (4/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseNoneDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseNoneDerivedFalseAttr() const; + + /// See GetOverrideBaseNoneDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + public: // --------------------------------------------------------------------- // // BINDING diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/generatedSchema.usda b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/generatedSchema.usda index 27925867f8..fe66902a23 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/generatedSchema.usda +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/generatedSchema.usda @@ -40,6 +40,9 @@ class "PublicMultipleApplyAPI" ( class "Base" ( apiSchemas = ["BuiltinAPI"] + customData = { + token[] apiSchemaOverridePropertyNames = ["overrideBaseTrueDerivedFalse", "overrideBaseTrueDerivedNone", "overrideBaseTrueDerivedTrue"] + } doc = 'This doc should only exist on the "Base" class.' ) { @@ -119,6 +122,42 @@ class "Base" ( normal3f[] normal3fArray normal3h normal3h = (0, 0, 0) normal3h[] normal3hArray + int overrideBaseFalseDerivedFalse = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Base. (1/3) + """ + ) + int overrideBaseFalseDerivedNone = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override has no opinion in Derived. + Generates API functions in Base. (2/3) + """ + ) + int overrideBaseNoneDerivedFalse = 1 ( + doc = """API schema override has no opinion in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Base. (3/3) + """ + ) + int overrideBaseTrueDerivedFalse = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to False in Derived. + Does not generate API functions in Base. + """ + ) + int overrideBaseTrueDerivedNone = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override has no opinion in Derived. + Does not generate API functions in Base. + """ + ) + int overrideBaseTrueDerivedTrue = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to True in Derived. + Does not generate API functions in Base. + """ + ) point3d point3d = (0, 0, 0) point3d[] point3dArray point3f point3f = (0, 0, 0) @@ -151,6 +190,9 @@ class "Base" ( class Derived "Derived" ( apiSchemas = ["BuiltinAPI"] + customData = { + token[] apiSchemaOverridePropertyNames = ["overrideBaseTrueDerivedNone", "overrideBaseTrueDerivedTrue"] + } doc = "Emphasized! Test Section" ) { @@ -258,6 +300,42 @@ class Derived "Derived" ( normal3f[] normal3fArray normal3h normal3h = (0, 0, 0) normal3h[] normal3hArray + int overrideBaseFalseDerivedFalse = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (2/4) + """ + ) + int overrideBaseFalseDerivedNone = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override has no opinion in Derived. + Generates API functions in Derived. (3/4) + """ + ) + int overrideBaseNoneDerivedFalse = 1 ( + doc = """API schema override has no opinion in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (4/4) + """ + ) + int overrideBaseTrueDerivedFalse = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (1/4) + """ + ) + int overrideBaseTrueDerivedNone = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override has no opinion in Derived. + Does not generate API functions in Derived. + """ + ) + int overrideBaseTrueDerivedTrue = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to True in Derived. + Does not generate API functions in Derived. + """ + ) float3 pivotPosition = (0, 0, 0) ( doc = """Rotation pivot position for this prim's transformation. Provided as advisory data only for use by authoring applications, diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/tokens.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/tokens.cpp index d8b8f29758..2111f008d9 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/tokens.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/tokens.cpp @@ -106,6 +106,12 @@ UsdContrivedTokensType::UsdContrivedTokensType() : normal3fArray("normal3fArray", TfToken::Immortal), normal3h("normal3h", TfToken::Immortal), normal3hArray("normal3hArray", TfToken::Immortal), + overrideBaseFalseDerivedFalse("overrideBaseFalseDerivedFalse", TfToken::Immortal), + overrideBaseFalseDerivedNone("overrideBaseFalseDerivedNone", TfToken::Immortal), + overrideBaseNoneDerivedFalse("overrideBaseNoneDerivedFalse", TfToken::Immortal), + overrideBaseTrueDerivedFalse("overrideBaseTrueDerivedFalse", TfToken::Immortal), + overrideBaseTrueDerivedNone("overrideBaseTrueDerivedNone", TfToken::Immortal), + overrideBaseTrueDerivedTrue("overrideBaseTrueDerivedTrue", TfToken::Immortal), pivotPosition("pivotPosition", TfToken::Immortal), point3d("point3d", TfToken::Immortal), point3dArray("point3dArray", TfToken::Immortal), @@ -236,6 +242,12 @@ UsdContrivedTokensType::UsdContrivedTokensType() : normal3fArray, normal3h, normal3hArray, + overrideBaseFalseDerivedFalse, + overrideBaseFalseDerivedNone, + overrideBaseNoneDerivedFalse, + overrideBaseTrueDerivedFalse, + overrideBaseTrueDerivedNone, + overrideBaseTrueDerivedTrue, pivotPosition, point3d, point3dArray, diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/tokens.h b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/tokens.h index 4aca62733c..bbe6053451 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/tokens.h +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/tokens.h @@ -382,6 +382,30 @@ struct UsdContrivedTokensType { /// /// UsdContrivedBase const TfToken normal3hArray; + /// \brief "overrideBaseFalseDerivedFalse" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseFalseDerivedFalse; + /// \brief "overrideBaseFalseDerivedNone" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseFalseDerivedNone; + /// \brief "overrideBaseNoneDerivedFalse" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseNoneDerivedFalse; + /// \brief "overrideBaseTrueDerivedFalse" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseTrueDerivedFalse; + /// \brief "overrideBaseTrueDerivedNone" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseTrueDerivedNone; + /// \brief "overrideBaseTrueDerivedTrue" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseTrueDerivedTrue; /// \brief "pivotPosition" /// /// UsdContrivedDerived diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/wrapBase.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/wrapBase.cpp index 4d75b3da8a..7b87a94a51 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/wrapBase.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/wrapBase.cpp @@ -720,6 +720,27 @@ _CreateFrame4dArrayAttr(UsdContrivedBase &self, return self.CreateFrame4dArrayAttr( UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Frame4dArray), writeSparsely); } + +static UsdAttribute +_CreateOverrideBaseFalseDerivedFalseAttr(UsdContrivedBase &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseFalseDerivedNoneAttr(UsdContrivedBase &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedNoneAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseNoneDerivedFalseAttr(UsdContrivedBase &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseNoneDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} static std::string _Repr(const UsdContrivedBase &self) @@ -1431,6 +1452,27 @@ void wrapUsdContrivedBase() &_CreateFrame4dArrayAttr, (arg("defaultValue")=object(), arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedFalseAttr", + &This::GetOverrideBaseFalseDerivedFalseAttr) + .def("CreateOverrideBaseFalseDerivedFalseAttr", + &_CreateOverrideBaseFalseDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedNoneAttr", + &This::GetOverrideBaseFalseDerivedNoneAttr) + .def("CreateOverrideBaseFalseDerivedNoneAttr", + &_CreateOverrideBaseFalseDerivedNoneAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseNoneDerivedFalseAttr", + &This::GetOverrideBaseNoneDerivedFalseAttr) + .def("CreateOverrideBaseNoneDerivedFalseAttr", + &_CreateOverrideBaseNoneDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) .def("__repr__", ::_Repr) ; diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/wrapDerived.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/wrapDerived.cpp index 5e188fade0..89b785009a 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/wrapDerived.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/wrapDerived.cpp @@ -118,6 +118,34 @@ _CreateJustDefaultAttr(UsdContrivedDerived &self, return self.CreateJustDefaultAttr( UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely); } + +static UsdAttribute +_CreateOverrideBaseTrueDerivedFalseAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseTrueDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseFalseDerivedFalseAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseFalseDerivedNoneAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedNoneAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseNoneDerivedFalseAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseNoneDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} static std::string _Repr(const UsdContrivedDerived &self) @@ -230,6 +258,34 @@ void wrapUsdContrivedDerived() &_CreateJustDefaultAttr, (arg("defaultValue")=object(), arg("writeSparsely")=false)) + + .def("GetOverrideBaseTrueDerivedFalseAttr", + &This::GetOverrideBaseTrueDerivedFalseAttr) + .def("CreateOverrideBaseTrueDerivedFalseAttr", + &_CreateOverrideBaseTrueDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedFalseAttr", + &This::GetOverrideBaseFalseDerivedFalseAttr) + .def("CreateOverrideBaseFalseDerivedFalseAttr", + &_CreateOverrideBaseFalseDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedNoneAttr", + &This::GetOverrideBaseFalseDerivedNoneAttr) + .def("CreateOverrideBaseFalseDerivedNoneAttr", + &_CreateOverrideBaseFalseDerivedNoneAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseNoneDerivedFalseAttr", + &This::GetOverrideBaseNoneDerivedFalseAttr) + .def("CreateOverrideBaseNoneDerivedFalseAttr", + &_CreateOverrideBaseNoneDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) .def("GetBindingRel", diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/wrapTokens.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/wrapTokens.cpp index a02bab6ebb..475e17c9b5 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/wrapTokens.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/headerTerminatorString/wrapTokens.cpp @@ -144,6 +144,12 @@ void wrapUsdContrivedTokens() _AddToken(cls, "normal3fArray", UsdContrivedTokens->normal3fArray); _AddToken(cls, "normal3h", UsdContrivedTokens->normal3h); _AddToken(cls, "normal3hArray", UsdContrivedTokens->normal3hArray); + _AddToken(cls, "overrideBaseFalseDerivedFalse", UsdContrivedTokens->overrideBaseFalseDerivedFalse); + _AddToken(cls, "overrideBaseFalseDerivedNone", UsdContrivedTokens->overrideBaseFalseDerivedNone); + _AddToken(cls, "overrideBaseNoneDerivedFalse", UsdContrivedTokens->overrideBaseNoneDerivedFalse); + _AddToken(cls, "overrideBaseTrueDerivedFalse", UsdContrivedTokens->overrideBaseTrueDerivedFalse); + _AddToken(cls, "overrideBaseTrueDerivedNone", UsdContrivedTokens->overrideBaseTrueDerivedNone); + _AddToken(cls, "overrideBaseTrueDerivedTrue", UsdContrivedTokens->overrideBaseTrueDerivedTrue); _AddToken(cls, "pivotPosition", UsdContrivedTokens->pivotPosition); _AddToken(cls, "point3d", UsdContrivedTokens->point3d); _AddToken(cls, "point3dArray", UsdContrivedTokens->point3dArray); diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/base.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/base.cpp index 66722f3a82..f6973f1801 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/base.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/base.cpp @@ -1716,6 +1716,57 @@ UsdContrivedBase::CreateFrame4dArrayAttr(VtValue const &defaultValue, bool write writeSparsely); } +UsdAttribute +UsdContrivedBase::GetOverrideBaseFalseDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedFalse); +} + +UsdAttribute +UsdContrivedBase::CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedBase::GetOverrideBaseFalseDerivedNoneAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedNone); +} + +UsdAttribute +UsdContrivedBase::CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedNone, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedBase::GetOverrideBaseNoneDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseNoneDerivedFalse); +} + +UsdAttribute +UsdContrivedBase::CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseNoneDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + namespace { static inline TfTokenVector _ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right) @@ -1829,6 +1880,9 @@ UsdContrivedBase::GetSchemaAttributeNames(bool includeInherited) UsdContrivedTokens->matrix3dArray, UsdContrivedTokens->matrix4dArray, UsdContrivedTokens->frame4dArray, + UsdContrivedTokens->overrideBaseFalseDerivedFalse, + UsdContrivedTokens->overrideBaseFalseDerivedNone, + UsdContrivedTokens->overrideBaseNoneDerivedFalse, }; static TfTokenVector allNames = _ConcatenateAttributeNames( diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/base.h b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/base.h index 7696270e7c..abfe4589dc 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/base.h +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/base.h @@ -2244,6 +2244,81 @@ class UsdContrivedBase : public UsdTyped USDCONTRIVED_API UsdAttribute CreateFrame4dArrayAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Base. (1/3) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedFalseAttr() const; + + /// See GetOverrideBaseFalseDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDNONE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override has no opinion in Derived. + /// Generates API functions in Base. (2/3) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedNone = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedNoneAttr() const; + + /// See GetOverrideBaseFalseDerivedNoneAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASENONEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override has no opinion in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Base. (3/3) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseNoneDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseNoneDerivedFalseAttr() const; + + /// See GetOverrideBaseNoneDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + public: // ===================================================================== // // Feel free to add custom code below this line, it will be preserved by diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/derived.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/derived.cpp index bf344fa25a..6136ca9116 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/derived.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/derived.cpp @@ -273,6 +273,74 @@ UsdContrivedDerived::CreateJustDefaultAttr(VtValue const &defaultValue, bool wri writeSparsely); } +UsdAttribute +UsdContrivedDerived::GetOverrideBaseTrueDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseTrueDerivedFalse); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseTrueDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseTrueDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedDerived::GetOverrideBaseFalseDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedFalse); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedDerived::GetOverrideBaseFalseDerivedNoneAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedNone); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedNone, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedDerived::GetOverrideBaseNoneDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseNoneDerivedFalse); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseNoneDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + UsdRelationship UsdContrivedDerived::GetBindingRel() const { @@ -313,6 +381,10 @@ UsdContrivedDerived::GetSchemaAttributeNames(bool includeInherited) UsdContrivedTokens->testingAsset, UsdContrivedTokens->namespacedProperty, UsdContrivedTokens->justDefault, + UsdContrivedTokens->overrideBaseTrueDerivedFalse, + UsdContrivedTokens->overrideBaseFalseDerivedFalse, + UsdContrivedTokens->overrideBaseFalseDerivedNone, + UsdContrivedTokens->overrideBaseNoneDerivedFalse, }; static TfTokenVector allNames = _ConcatenateAttributeNames( diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/derived.h b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/derived.h index 915a996fde..16955c1c9f 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/derived.h +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/derived.h @@ -385,6 +385,106 @@ class UsdContrivedDerived : public UsdContrivedBase USDCONTRIVED_API UsdAttribute CreateJustDefaultAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASETRUEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to True in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Derived. (1/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseTrueDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseTrueDerivedFalseAttr() const; + + /// See GetOverrideBaseTrueDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseTrueDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Derived. (2/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedFalseAttr() const; + + /// See GetOverrideBaseFalseDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDNONE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override has no opinion in Derived. + /// Generates API functions in Derived. (3/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedNone = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedNoneAttr() const; + + /// See GetOverrideBaseFalseDerivedNoneAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASENONEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override has no opinion in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Derived. (4/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseNoneDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseNoneDerivedFalseAttr() const; + + /// See GetOverrideBaseNoneDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + public: // --------------------------------------------------------------------- // // BINDING diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/generatedSchema.usda b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/generatedSchema.usda index 27925867f8..fe66902a23 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/generatedSchema.usda +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/generatedSchema.usda @@ -40,6 +40,9 @@ class "PublicMultipleApplyAPI" ( class "Base" ( apiSchemas = ["BuiltinAPI"] + customData = { + token[] apiSchemaOverridePropertyNames = ["overrideBaseTrueDerivedFalse", "overrideBaseTrueDerivedNone", "overrideBaseTrueDerivedTrue"] + } doc = 'This doc should only exist on the "Base" class.' ) { @@ -119,6 +122,42 @@ class "Base" ( normal3f[] normal3fArray normal3h normal3h = (0, 0, 0) normal3h[] normal3hArray + int overrideBaseFalseDerivedFalse = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Base. (1/3) + """ + ) + int overrideBaseFalseDerivedNone = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override has no opinion in Derived. + Generates API functions in Base. (2/3) + """ + ) + int overrideBaseNoneDerivedFalse = 1 ( + doc = """API schema override has no opinion in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Base. (3/3) + """ + ) + int overrideBaseTrueDerivedFalse = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to False in Derived. + Does not generate API functions in Base. + """ + ) + int overrideBaseTrueDerivedNone = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override has no opinion in Derived. + Does not generate API functions in Base. + """ + ) + int overrideBaseTrueDerivedTrue = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to True in Derived. + Does not generate API functions in Base. + """ + ) point3d point3d = (0, 0, 0) point3d[] point3dArray point3f point3f = (0, 0, 0) @@ -151,6 +190,9 @@ class "Base" ( class Derived "Derived" ( apiSchemas = ["BuiltinAPI"] + customData = { + token[] apiSchemaOverridePropertyNames = ["overrideBaseTrueDerivedNone", "overrideBaseTrueDerivedTrue"] + } doc = "Emphasized! Test Section" ) { @@ -258,6 +300,42 @@ class Derived "Derived" ( normal3f[] normal3fArray normal3h normal3h = (0, 0, 0) normal3h[] normal3hArray + int overrideBaseFalseDerivedFalse = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (2/4) + """ + ) + int overrideBaseFalseDerivedNone = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override has no opinion in Derived. + Generates API functions in Derived. (3/4) + """ + ) + int overrideBaseNoneDerivedFalse = 1 ( + doc = """API schema override has no opinion in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (4/4) + """ + ) + int overrideBaseTrueDerivedFalse = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (1/4) + """ + ) + int overrideBaseTrueDerivedNone = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override has no opinion in Derived. + Does not generate API functions in Derived. + """ + ) + int overrideBaseTrueDerivedTrue = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to True in Derived. + Does not generate API functions in Derived. + """ + ) float3 pivotPosition = (0, 0, 0) ( doc = """Rotation pivot position for this prim's transformation. Provided as advisory data only for use by authoring applications, diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/tokens.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/tokens.cpp index cd93845be8..5cadd6099f 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/tokens.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/tokens.cpp @@ -106,6 +106,12 @@ UsdContrivedTokensType::UsdContrivedTokensType() : normal3fArray("normal3fArray", TfToken::Immortal), normal3h("normal3h", TfToken::Immortal), normal3hArray("normal3hArray", TfToken::Immortal), + overrideBaseFalseDerivedFalse("overrideBaseFalseDerivedFalse", TfToken::Immortal), + overrideBaseFalseDerivedNone("overrideBaseFalseDerivedNone", TfToken::Immortal), + overrideBaseNoneDerivedFalse("overrideBaseNoneDerivedFalse", TfToken::Immortal), + overrideBaseTrueDerivedFalse("overrideBaseTrueDerivedFalse", TfToken::Immortal), + overrideBaseTrueDerivedNone("overrideBaseTrueDerivedNone", TfToken::Immortal), + overrideBaseTrueDerivedTrue("overrideBaseTrueDerivedTrue", TfToken::Immortal), pivotPosition("pivotPosition", TfToken::Immortal), point3d("point3d", TfToken::Immortal), point3dArray("point3dArray", TfToken::Immortal), @@ -236,6 +242,12 @@ UsdContrivedTokensType::UsdContrivedTokensType() : normal3fArray, normal3h, normal3hArray, + overrideBaseFalseDerivedFalse, + overrideBaseFalseDerivedNone, + overrideBaseNoneDerivedFalse, + overrideBaseTrueDerivedFalse, + overrideBaseTrueDerivedNone, + overrideBaseTrueDerivedTrue, pivotPosition, point3d, point3dArray, diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/tokens.h b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/tokens.h index a126b6ae78..6a39bb6a45 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/tokens.h +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/tokens.h @@ -382,6 +382,30 @@ struct UsdContrivedTokensType { /// /// UsdContrivedBase const TfToken normal3hArray; + /// \brief "overrideBaseFalseDerivedFalse" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseFalseDerivedFalse; + /// \brief "overrideBaseFalseDerivedNone" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseFalseDerivedNone; + /// \brief "overrideBaseNoneDerivedFalse" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseNoneDerivedFalse; + /// \brief "overrideBaseTrueDerivedFalse" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseTrueDerivedFalse; + /// \brief "overrideBaseTrueDerivedNone" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseTrueDerivedNone; + /// \brief "overrideBaseTrueDerivedTrue" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseTrueDerivedTrue; /// \brief "pivotPosition" /// /// UsdContrivedDerived diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/wrapBase.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/wrapBase.cpp index 5c6fc4cbd2..7246553d7f 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/wrapBase.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/wrapBase.cpp @@ -720,6 +720,27 @@ _CreateFrame4dArrayAttr(UsdContrivedBase &self, return self.CreateFrame4dArrayAttr( UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Frame4dArray), writeSparsely); } + +static UsdAttribute +_CreateOverrideBaseFalseDerivedFalseAttr(UsdContrivedBase &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseFalseDerivedNoneAttr(UsdContrivedBase &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedNoneAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseNoneDerivedFalseAttr(UsdContrivedBase &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseNoneDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} static std::string _Repr(const UsdContrivedBase &self) @@ -1431,6 +1452,27 @@ void wrapUsdContrivedBase() &_CreateFrame4dArrayAttr, (arg("defaultValue")=object(), arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedFalseAttr", + &This::GetOverrideBaseFalseDerivedFalseAttr) + .def("CreateOverrideBaseFalseDerivedFalseAttr", + &_CreateOverrideBaseFalseDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedNoneAttr", + &This::GetOverrideBaseFalseDerivedNoneAttr) + .def("CreateOverrideBaseFalseDerivedNoneAttr", + &_CreateOverrideBaseFalseDerivedNoneAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseNoneDerivedFalseAttr", + &This::GetOverrideBaseNoneDerivedFalseAttr) + .def("CreateOverrideBaseNoneDerivedFalseAttr", + &_CreateOverrideBaseNoneDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) .def("__repr__", ::_Repr) ; diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/wrapDerived.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/wrapDerived.cpp index 5a939c83e0..30330e70ec 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/wrapDerived.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/wrapDerived.cpp @@ -118,6 +118,34 @@ _CreateJustDefaultAttr(UsdContrivedDerived &self, return self.CreateJustDefaultAttr( UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely); } + +static UsdAttribute +_CreateOverrideBaseTrueDerivedFalseAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseTrueDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseFalseDerivedFalseAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseFalseDerivedNoneAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedNoneAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseNoneDerivedFalseAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseNoneDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} static std::string _Repr(const UsdContrivedDerived &self) @@ -230,6 +258,34 @@ void wrapUsdContrivedDerived() &_CreateJustDefaultAttr, (arg("defaultValue")=object(), arg("writeSparsely")=false)) + + .def("GetOverrideBaseTrueDerivedFalseAttr", + &This::GetOverrideBaseTrueDerivedFalseAttr) + .def("CreateOverrideBaseTrueDerivedFalseAttr", + &_CreateOverrideBaseTrueDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedFalseAttr", + &This::GetOverrideBaseFalseDerivedFalseAttr) + .def("CreateOverrideBaseFalseDerivedFalseAttr", + &_CreateOverrideBaseFalseDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedNoneAttr", + &This::GetOverrideBaseFalseDerivedNoneAttr) + .def("CreateOverrideBaseFalseDerivedNoneAttr", + &_CreateOverrideBaseFalseDerivedNoneAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseNoneDerivedFalseAttr", + &This::GetOverrideBaseNoneDerivedFalseAttr) + .def("CreateOverrideBaseNoneDerivedFalseAttr", + &_CreateOverrideBaseNoneDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) .def("GetBindingRel", diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/wrapTokens.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/wrapTokens.cpp index d38d62148d..6924a9070d 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/wrapTokens.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/namespace/wrapTokens.cpp @@ -144,6 +144,12 @@ void wrapUsdContrivedTokens() _AddToken(cls, "normal3fArray", UsdContrivedTokens->normal3fArray); _AddToken(cls, "normal3h", UsdContrivedTokens->normal3h); _AddToken(cls, "normal3hArray", UsdContrivedTokens->normal3hArray); + _AddToken(cls, "overrideBaseFalseDerivedFalse", UsdContrivedTokens->overrideBaseFalseDerivedFalse); + _AddToken(cls, "overrideBaseFalseDerivedNone", UsdContrivedTokens->overrideBaseFalseDerivedNone); + _AddToken(cls, "overrideBaseNoneDerivedFalse", UsdContrivedTokens->overrideBaseNoneDerivedFalse); + _AddToken(cls, "overrideBaseTrueDerivedFalse", UsdContrivedTokens->overrideBaseTrueDerivedFalse); + _AddToken(cls, "overrideBaseTrueDerivedNone", UsdContrivedTokens->overrideBaseTrueDerivedNone); + _AddToken(cls, "overrideBaseTrueDerivedTrue", UsdContrivedTokens->overrideBaseTrueDerivedTrue); _AddToken(cls, "pivotPosition", UsdContrivedTokens->pivotPosition); _AddToken(cls, "point3d", UsdContrivedTokens->point3d); _AddToken(cls, "point3dArray", UsdContrivedTokens->point3dArray); diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/base.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/base.cpp index d0e35ac28f..eb6bc28c69 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/base.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/base.cpp @@ -1716,6 +1716,57 @@ UsdContrivedBase::CreateFrame4dArrayAttr(VtValue const &defaultValue, bool write writeSparsely); } +UsdAttribute +UsdContrivedBase::GetOverrideBaseFalseDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedFalse); +} + +UsdAttribute +UsdContrivedBase::CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedBase::GetOverrideBaseFalseDerivedNoneAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedNone); +} + +UsdAttribute +UsdContrivedBase::CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedNone, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedBase::GetOverrideBaseNoneDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseNoneDerivedFalse); +} + +UsdAttribute +UsdContrivedBase::CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseNoneDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + namespace { static inline TfTokenVector _ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right) @@ -1829,6 +1880,9 @@ UsdContrivedBase::GetSchemaAttributeNames(bool includeInherited) UsdContrivedTokens->matrix3dArray, UsdContrivedTokens->matrix4dArray, UsdContrivedTokens->frame4dArray, + UsdContrivedTokens->overrideBaseFalseDerivedFalse, + UsdContrivedTokens->overrideBaseFalseDerivedNone, + UsdContrivedTokens->overrideBaseNoneDerivedFalse, }; static TfTokenVector allNames = _ConcatenateAttributeNames( diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/base.h b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/base.h index 11faec63c0..780a06b11d 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/base.h +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/base.h @@ -2244,6 +2244,81 @@ class UsdContrivedBase : public UsdTyped USDCONTRIVED_API UsdAttribute CreateFrame4dArrayAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Base. (1/3) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedFalseAttr() const; + + /// See GetOverrideBaseFalseDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDNONE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override has no opinion in Derived. + /// Generates API functions in Base. (2/3) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedNone = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedNoneAttr() const; + + /// See GetOverrideBaseFalseDerivedNoneAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASENONEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override has no opinion in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Base. (3/3) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseNoneDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseNoneDerivedFalseAttr() const; + + /// See GetOverrideBaseNoneDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + public: // ===================================================================== // // Feel free to add custom code below this line, it will be preserved by diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/derived.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/derived.cpp index 59cc16253f..4e48d3b21a 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/derived.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/derived.cpp @@ -273,6 +273,74 @@ UsdContrivedDerived::CreateJustDefaultAttr(VtValue const &defaultValue, bool wri writeSparsely); } +UsdAttribute +UsdContrivedDerived::GetOverrideBaseTrueDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseTrueDerivedFalse); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseTrueDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseTrueDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedDerived::GetOverrideBaseFalseDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedFalse); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedDerived::GetOverrideBaseFalseDerivedNoneAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseFalseDerivedNone); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseFalseDerivedNone, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdContrivedDerived::GetOverrideBaseNoneDerivedFalseAttr() const +{ + return GetPrim().GetAttribute(UsdContrivedTokens->overrideBaseNoneDerivedFalse); +} + +UsdAttribute +UsdContrivedDerived::CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->overrideBaseNoneDerivedFalse, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + UsdRelationship UsdContrivedDerived::GetBindingRel() const { @@ -313,6 +381,10 @@ UsdContrivedDerived::GetSchemaAttributeNames(bool includeInherited) UsdContrivedTokens->testingAsset, UsdContrivedTokens->namespacedProperty, UsdContrivedTokens->justDefault, + UsdContrivedTokens->overrideBaseTrueDerivedFalse, + UsdContrivedTokens->overrideBaseFalseDerivedFalse, + UsdContrivedTokens->overrideBaseFalseDerivedNone, + UsdContrivedTokens->overrideBaseNoneDerivedFalse, }; static TfTokenVector allNames = _ConcatenateAttributeNames( diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/derived.h b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/derived.h index 763f06539d..085e42c7b1 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/derived.h +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/derived.h @@ -385,6 +385,106 @@ class UsdContrivedDerived : public UsdContrivedBase USDCONTRIVED_API UsdAttribute CreateJustDefaultAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASETRUEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to True in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Derived. (1/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseTrueDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseTrueDerivedFalseAttr() const; + + /// See GetOverrideBaseTrueDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseTrueDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Derived. (2/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedFalseAttr() const; + + /// See GetOverrideBaseFalseDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASEFALSEDERIVEDNONE + // --------------------------------------------------------------------- // + /// API schema override explicitly set to False in Base. + /// API schema override has no opinion in Derived. + /// Generates API functions in Derived. (3/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseFalseDerivedNone = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseFalseDerivedNoneAttr() const; + + /// See GetOverrideBaseFalseDerivedNoneAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseFalseDerivedNoneAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERRIDEBASENONEDERIVEDFALSE + // --------------------------------------------------------------------- // + /// API schema override has no opinion in Base. + /// API schema override explicitly set to False in Derived. + /// Generates API functions in Derived. (4/4) + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `int overrideBaseNoneDerivedFalse = 1` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + USDCONTRIVED_API + UsdAttribute GetOverrideBaseNoneDerivedFalseAttr() const; + + /// See GetOverrideBaseNoneDerivedFalseAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDCONTRIVED_API + UsdAttribute CreateOverrideBaseNoneDerivedFalseAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + public: // --------------------------------------------------------------------- // // BINDING diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/generatedSchema.usda b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/generatedSchema.usda index 27925867f8..fe66902a23 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/generatedSchema.usda +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/generatedSchema.usda @@ -40,6 +40,9 @@ class "PublicMultipleApplyAPI" ( class "Base" ( apiSchemas = ["BuiltinAPI"] + customData = { + token[] apiSchemaOverridePropertyNames = ["overrideBaseTrueDerivedFalse", "overrideBaseTrueDerivedNone", "overrideBaseTrueDerivedTrue"] + } doc = 'This doc should only exist on the "Base" class.' ) { @@ -119,6 +122,42 @@ class "Base" ( normal3f[] normal3fArray normal3h normal3h = (0, 0, 0) normal3h[] normal3hArray + int overrideBaseFalseDerivedFalse = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Base. (1/3) + """ + ) + int overrideBaseFalseDerivedNone = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override has no opinion in Derived. + Generates API functions in Base. (2/3) + """ + ) + int overrideBaseNoneDerivedFalse = 1 ( + doc = """API schema override has no opinion in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Base. (3/3) + """ + ) + int overrideBaseTrueDerivedFalse = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to False in Derived. + Does not generate API functions in Base. + """ + ) + int overrideBaseTrueDerivedNone = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override has no opinion in Derived. + Does not generate API functions in Base. + """ + ) + int overrideBaseTrueDerivedTrue = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to True in Derived. + Does not generate API functions in Base. + """ + ) point3d point3d = (0, 0, 0) point3d[] point3dArray point3f point3f = (0, 0, 0) @@ -151,6 +190,9 @@ class "Base" ( class Derived "Derived" ( apiSchemas = ["BuiltinAPI"] + customData = { + token[] apiSchemaOverridePropertyNames = ["overrideBaseTrueDerivedNone", "overrideBaseTrueDerivedTrue"] + } doc = "Emphasized! Test Section" ) { @@ -258,6 +300,42 @@ class Derived "Derived" ( normal3f[] normal3fArray normal3h normal3h = (0, 0, 0) normal3h[] normal3hArray + int overrideBaseFalseDerivedFalse = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (2/4) + """ + ) + int overrideBaseFalseDerivedNone = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override has no opinion in Derived. + Generates API functions in Derived. (3/4) + """ + ) + int overrideBaseNoneDerivedFalse = 1 ( + doc = """API schema override has no opinion in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (4/4) + """ + ) + int overrideBaseTrueDerivedFalse = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (1/4) + """ + ) + int overrideBaseTrueDerivedNone = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override has no opinion in Derived. + Does not generate API functions in Derived. + """ + ) + int overrideBaseTrueDerivedTrue = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to True in Derived. + Does not generate API functions in Derived. + """ + ) float3 pivotPosition = (0, 0, 0) ( doc = """Rotation pivot position for this prim's transformation. Provided as advisory data only for use by authoring applications, diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/tokens.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/tokens.cpp index 9f8ba3ae05..cbebbe845b 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/tokens.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/tokens.cpp @@ -106,6 +106,12 @@ UsdContrivedTokensType::UsdContrivedTokensType() : normal3fArray("normal3fArray", TfToken::Immortal), normal3h("normal3h", TfToken::Immortal), normal3hArray("normal3hArray", TfToken::Immortal), + overrideBaseFalseDerivedFalse("overrideBaseFalseDerivedFalse", TfToken::Immortal), + overrideBaseFalseDerivedNone("overrideBaseFalseDerivedNone", TfToken::Immortal), + overrideBaseNoneDerivedFalse("overrideBaseNoneDerivedFalse", TfToken::Immortal), + overrideBaseTrueDerivedFalse("overrideBaseTrueDerivedFalse", TfToken::Immortal), + overrideBaseTrueDerivedNone("overrideBaseTrueDerivedNone", TfToken::Immortal), + overrideBaseTrueDerivedTrue("overrideBaseTrueDerivedTrue", TfToken::Immortal), pivotPosition("pivotPosition", TfToken::Immortal), point3d("point3d", TfToken::Immortal), point3dArray("point3dArray", TfToken::Immortal), @@ -236,6 +242,12 @@ UsdContrivedTokensType::UsdContrivedTokensType() : normal3fArray, normal3h, normal3hArray, + overrideBaseFalseDerivedFalse, + overrideBaseFalseDerivedNone, + overrideBaseNoneDerivedFalse, + overrideBaseTrueDerivedFalse, + overrideBaseTrueDerivedNone, + overrideBaseTrueDerivedTrue, pivotPosition, point3d, point3dArray, diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/tokens.h b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/tokens.h index 1ca15bb791..7999289a6d 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/tokens.h +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/tokens.h @@ -382,6 +382,30 @@ struct UsdContrivedTokensType { /// /// UsdContrivedBase const TfToken normal3hArray; + /// \brief "overrideBaseFalseDerivedFalse" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseFalseDerivedFalse; + /// \brief "overrideBaseFalseDerivedNone" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseFalseDerivedNone; + /// \brief "overrideBaseNoneDerivedFalse" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseNoneDerivedFalse; + /// \brief "overrideBaseTrueDerivedFalse" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseTrueDerivedFalse; + /// \brief "overrideBaseTrueDerivedNone" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseTrueDerivedNone; + /// \brief "overrideBaseTrueDerivedTrue" + /// + /// UsdContrivedDerived, UsdContrivedBase + const TfToken overrideBaseTrueDerivedTrue; /// \brief "pivotPosition" /// /// UsdContrivedDerived diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/wrapBase.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/wrapBase.cpp index adab4bfa85..e0f9e0ec10 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/wrapBase.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/wrapBase.cpp @@ -720,6 +720,27 @@ _CreateFrame4dArrayAttr(UsdContrivedBase &self, return self.CreateFrame4dArrayAttr( UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Frame4dArray), writeSparsely); } + +static UsdAttribute +_CreateOverrideBaseFalseDerivedFalseAttr(UsdContrivedBase &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseFalseDerivedNoneAttr(UsdContrivedBase &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedNoneAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseNoneDerivedFalseAttr(UsdContrivedBase &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseNoneDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} static std::string _Repr(const UsdContrivedBase &self) @@ -1431,6 +1452,27 @@ void wrapUsdContrivedBase() &_CreateFrame4dArrayAttr, (arg("defaultValue")=object(), arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedFalseAttr", + &This::GetOverrideBaseFalseDerivedFalseAttr) + .def("CreateOverrideBaseFalseDerivedFalseAttr", + &_CreateOverrideBaseFalseDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedNoneAttr", + &This::GetOverrideBaseFalseDerivedNoneAttr) + .def("CreateOverrideBaseFalseDerivedNoneAttr", + &_CreateOverrideBaseFalseDerivedNoneAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseNoneDerivedFalseAttr", + &This::GetOverrideBaseNoneDerivedFalseAttr) + .def("CreateOverrideBaseNoneDerivedFalseAttr", + &_CreateOverrideBaseNoneDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) .def("__repr__", ::_Repr) ; diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/wrapDerived.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/wrapDerived.cpp index 5faf288d65..6844453a51 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/wrapDerived.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/wrapDerived.cpp @@ -118,6 +118,34 @@ _CreateJustDefaultAttr(UsdContrivedDerived &self, return self.CreateJustDefaultAttr( UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely); } + +static UsdAttribute +_CreateOverrideBaseTrueDerivedFalseAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseTrueDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseFalseDerivedFalseAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseFalseDerivedNoneAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseFalseDerivedNoneAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateOverrideBaseNoneDerivedFalseAttr(UsdContrivedDerived &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverrideBaseNoneDerivedFalseAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} static std::string _Repr(const UsdContrivedDerived &self) @@ -230,6 +258,34 @@ void wrapUsdContrivedDerived() &_CreateJustDefaultAttr, (arg("defaultValue")=object(), arg("writeSparsely")=false)) + + .def("GetOverrideBaseTrueDerivedFalseAttr", + &This::GetOverrideBaseTrueDerivedFalseAttr) + .def("CreateOverrideBaseTrueDerivedFalseAttr", + &_CreateOverrideBaseTrueDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedFalseAttr", + &This::GetOverrideBaseFalseDerivedFalseAttr) + .def("CreateOverrideBaseFalseDerivedFalseAttr", + &_CreateOverrideBaseFalseDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseFalseDerivedNoneAttr", + &This::GetOverrideBaseFalseDerivedNoneAttr) + .def("CreateOverrideBaseFalseDerivedNoneAttr", + &_CreateOverrideBaseFalseDerivedNoneAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverrideBaseNoneDerivedFalseAttr", + &This::GetOverrideBaseNoneDerivedFalseAttr) + .def("CreateOverrideBaseNoneDerivedFalseAttr", + &_CreateOverrideBaseNoneDerivedFalseAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) .def("GetBindingRel", diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/wrapTokens.cpp b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/wrapTokens.cpp index 5952b76356..96ad9805b1 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/wrapTokens.cpp +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/baseline/nestedNamespace/wrapTokens.cpp @@ -144,6 +144,12 @@ void wrapUsdContrivedTokens() _AddToken(cls, "normal3fArray", UsdContrivedTokens->normal3fArray); _AddToken(cls, "normal3h", UsdContrivedTokens->normal3h); _AddToken(cls, "normal3hArray", UsdContrivedTokens->normal3hArray); + _AddToken(cls, "overrideBaseFalseDerivedFalse", UsdContrivedTokens->overrideBaseFalseDerivedFalse); + _AddToken(cls, "overrideBaseFalseDerivedNone", UsdContrivedTokens->overrideBaseFalseDerivedNone); + _AddToken(cls, "overrideBaseNoneDerivedFalse", UsdContrivedTokens->overrideBaseNoneDerivedFalse); + _AddToken(cls, "overrideBaseTrueDerivedFalse", UsdContrivedTokens->overrideBaseTrueDerivedFalse); + _AddToken(cls, "overrideBaseTrueDerivedNone", UsdContrivedTokens->overrideBaseTrueDerivedNone); + _AddToken(cls, "overrideBaseTrueDerivedTrue", UsdContrivedTokens->overrideBaseTrueDerivedTrue); _AddToken(cls, "pivotPosition", UsdContrivedTokens->pivotPosition); _AddToken(cls, "point3d", UsdContrivedTokens->point3d); _AddToken(cls, "point3dArray", UsdContrivedTokens->point3dArray); diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/codeless_schema.usda b/pxr/usd/usd/testenv/testUsdSchemaGen/codeless_schema.usda index a78d439f92..3ac34379d9 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/codeless_schema.usda +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/codeless_schema.usda @@ -263,6 +263,73 @@ class "Base" ( matrix4d[] matrix4dArray frame4d[] frame4dArray + + int overrideBaseTrueDerivedTrue = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to True in Derived. + Does not generate API functions in Base. + """ + customData = { + bool apiSchemaOverride = true + } + ) + int overrideBaseTrueDerivedFalse = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to False in Derived. + Does not generate API functions in Base. + """ + customData = { + bool apiSchemaOverride = true + } + ) + int overrideBaseTrueDerivedNone = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override has no opinion in Derived. + Does not generate API functions in Base. + """ + customData = { + bool apiSchemaOverride = true + } + ) +# int overrideBaseFalseDerivedTrue = 1 ( +# doc = """API schema override explicitly set to False in Base. +# API schema override explicitly set to True in Derived. +# This is an illegal specification and would cause usdGenSchema to fail. +# """ +# customData = { +# bool apiSchemaOverride = false +# } +# ) + int overrideBaseFalseDerivedFalse = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Base. (1/3) + """ + customData = { + bool apiSchemaOverride = false + } + ) + int overrideBaseFalseDerivedNone = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override has no opinion in Derived. + Generates API functions in Base. (2/3) + """ + customData = { + bool apiSchemaOverride = false + } + ) +# int overrideBaseNoneDerivedTrue = 1 ( +# doc = """API schema override has no opinion in Base. +# API schema override explicitly set to True in Derived. +# This is an illegal specification and would cause usdGenSchema to fail. +# """ +# ) + int overrideBaseNoneDerivedFalse = 1 ( + doc = """API schema override has no opinion in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Base. (3/3) + """ + ) } class Derived "Derived" ( @@ -315,6 +382,73 @@ class Derived "Derived" ( token justDefault = "newToken" ( doc = """newToken should be included in the global token set.""") + + int overrideBaseTrueDerivedTrue = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to True in Derived. + Does not generate API functions in Derived. + """ + customData = { + bool apiSchemaOverride = true + } + ) + int overrideBaseTrueDerivedFalse = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (1/4) + """ + customData = { + bool apiSchemaOverride = false + } + ) + int overrideBaseTrueDerivedNone = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override has no opinion in Derived. + Does not generate API functions in Derived. + """ + ) +# int overrideBaseFalseDerivedTrue = 1 ( +# doc = """API schema override explicitly set to False in Base. +# API schema override explicitly set to True in Derived. +# This is an illegal specification and would cause usdGenSchema to fail. +# """ +# customData = { +# bool apiSchemaOverride = true +# } +# ) + int overrideBaseFalseDerivedFalse = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (2/4) + """ + customData = { + bool apiSchemaOverride = false + } + ) + int overrideBaseFalseDerivedNone = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override has no opinion in Derived. + Generates API functions in Derived. (3/4) + """ + ) +# int overrideBaseNoneDerivedTrue = 1 ( +# doc = """API schema override has no opinion in Base. +# API schema override explicitly set to True in Derived. +# This is an illegal specification and would cause usdGenSchema to fail. +# """ +# customData = { +# bool apiSchemaOverride = true +# } +# ) + int overrideBaseNoneDerivedFalse = 1 ( + doc = """API schema override has no opinion in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (4/4) + """ + customData = { + bool apiSchemaOverride = false + } + ) } class TestPxHairman "TestPxHairman" ( diff --git a/pxr/usd/usd/testenv/testUsdSchemaGen/schema.usda b/pxr/usd/usd/testenv/testUsdSchemaGen/schema.usda index 247a5acad7..021a61a430 100644 --- a/pxr/usd/usd/testenv/testUsdSchemaGen/schema.usda +++ b/pxr/usd/usd/testenv/testUsdSchemaGen/schema.usda @@ -262,6 +262,73 @@ class "Base" ( matrix4d[] matrix4dArray frame4d[] frame4dArray + + int overrideBaseTrueDerivedTrue = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to True in Derived. + Does not generate API functions in Base. + """ + customData = { + bool apiSchemaOverride = true + } + ) + int overrideBaseTrueDerivedFalse = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to False in Derived. + Does not generate API functions in Base. + """ + customData = { + bool apiSchemaOverride = true + } + ) + int overrideBaseTrueDerivedNone = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override has no opinion in Derived. + Does not generate API functions in Base. + """ + customData = { + bool apiSchemaOverride = true + } + ) +# int overrideBaseFalseDerivedTrue = 1 ( +# doc = """API schema override explicitly set to False in Base. +# API schema override explicitly set to True in Derived. +# This is an illegal specification and would cause usdGenSchema to fail. +# """ +# customData = { +# bool apiSchemaOverride = false +# } +# ) + int overrideBaseFalseDerivedFalse = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Base. (1/3) + """ + customData = { + bool apiSchemaOverride = false + } + ) + int overrideBaseFalseDerivedNone = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override has no opinion in Derived. + Generates API functions in Base. (2/3) + """ + customData = { + bool apiSchemaOverride = false + } + ) +# int overrideBaseNoneDerivedTrue = 1 ( +# doc = """API schema override has no opinion in Base. +# API schema override explicitly set to True in Derived. +# This is an illegal specification and would cause usdGenSchema to fail. +# """ +# ) + int overrideBaseNoneDerivedFalse = 1 ( + doc = """API schema override has no opinion in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Base. (3/3) + """ + ) } class Derived "Derived" ( @@ -314,6 +381,73 @@ class Derived "Derived" ( token justDefault = "newToken" ( doc = """newToken should be included in the global token set.""") + + int overrideBaseTrueDerivedTrue = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to True in Derived. + Does not generate API functions in Derived. + """ + customData = { + bool apiSchemaOverride = true + } + ) + int overrideBaseTrueDerivedFalse = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (1/4) + """ + customData = { + bool apiSchemaOverride = false + } + ) + int overrideBaseTrueDerivedNone = 1 ( + doc = """API schema override explicitly set to True in Base. + API schema override has no opinion in Derived. + Does not generate API functions in Derived. + """ + ) +# int overrideBaseFalseDerivedTrue = 1 ( +# doc = """API schema override explicitly set to False in Base. +# API schema override explicitly set to True in Derived. +# This is an illegal specification and would cause usdGenSchema to fail. +# """ +# customData = { +# bool apiSchemaOverride = true +# } +# ) + int overrideBaseFalseDerivedFalse = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (2/4) + """ + customData = { + bool apiSchemaOverride = false + } + ) + int overrideBaseFalseDerivedNone = 1 ( + doc = """API schema override explicitly set to False in Base. + API schema override has no opinion in Derived. + Generates API functions in Derived. (3/4) + """ + ) +# int overrideBaseNoneDerivedTrue = 1 ( +# doc = """API schema override has no opinion in Base. +# API schema override explicitly set to True in Derived. +# This is an illegal specification and would cause usdGenSchema to fail. +# """ +# customData = { +# bool apiSchemaOverride = true +# } +# ) + int overrideBaseNoneDerivedFalse = 1 ( + doc = """API schema override has no opinion in Base. + API schema override explicitly set to False in Derived. + Generates API functions in Derived. (4/4) + """ + customData = { + bool apiSchemaOverride = false + } + ) } class TestPxHairman "TestPxHairman" ( diff --git a/pxr/usd/usd/usdGenSchema.py b/pxr/usd/usd/usdGenSchema.py index 379d7c5545..9325c54695 100644 --- a/pxr/usd/usd/usdGenSchema.py +++ b/pxr/usd/usd/usdGenSchema.py @@ -287,6 +287,74 @@ def _CamelCase(aString): Token = namedtuple('Token', ['id', 'value', 'desc']) +# To correctly determine if a property is going to be an API schema override, +# we need to look at the USD property and how the apiSchemaOverride custom data +# will be composed. +def _GetIsAPISchemaOverride(usdProp): + # We need the property stack because we need to compose the customData value + # to determine if the composition is valid + propStack = usdProp.GetPropertyStack(Usd.TimeCode.Default()) + # Query 'apiSchemaOverride' from the last spec in the prop stack which will + # be the most inherited opinion and then go back up the prop stack querying + # whether each closer inherited spec has a stronger opinion. We do this + # because we need to insure that once a class defines a property as not + # being an API schema override property (it is a concrete property of the + # class) that no class that derives from the class is allowed to change that + # property into being an API schema override. This is important since API + # schema overrides will only be added to a schema's prim definition if an + # included API schema actually defines the property. Changing a property + # from a base class into an API schema override may have the effect of + # deleting that base class property from the derived class if that property + # isn't defined in one of its built-in API schemas. We don't want a to + # introduce a backdoor way of deleting properties in derived classes. + # + # Note that we do allow derived classes to convert an API schema override + # into a concrete defined property. + isAPISchemaOverride = propStack[-1].customData.get( + 'apiSchemaOverride', False) + for prop in reversed(propStack[:-1]): + newIsAPISchemaOverride = prop.customData.get( + 'apiSchemaOverride', isAPISchemaOverride) + if not isAPISchemaOverride and newIsAPISchemaOverride: + raise _GetSchemaDefException( + "Invalid schema property definition encountered while " + "processing property %s.\n" + "Property declarations in schema classes cannot set " + "'apiSchemaOverride=true' on properties which exist in their " + "inherited classes but are not already defined as API schemas " + "overrides." + % usdProp.GetPath(), + prop.path) + isAPISchemaOverride = newIsAPISchemaOverride + return isAPISchemaOverride + +def _GetNameAndRawNameForPropInfo(sdfProp, classInfo): + if classInfo.propertyNamespacePrefix: + # A property namespace prefix will only exist for multiple apply API + # schemas and is used to create the instanceable namespace prefix + # prepended to all its properties. We prepend this instanceable + # prefix to the raw name here. + rawName = Usd.SchemaRegistry.MakeMultipleApplyNameTemplate( + classInfo.propertyNamespacePrefix, sdfProp.name) + # Since the property info's name is used to create the identifier + # used for tokens and such, we make it from the instanced property + # name with the instance name placeholder replaced with + # "_MultipleApplyTemplate_". This is so we don't end up with an + # the implementation detail of "__INSTANCE_NAME__" in the identifier + # itself. + name = _CamelCase( + Usd.SchemaRegistry.MakeMultipleApplyNameInstance( + rawName, "_MultipleApplyTemplate_")) + else: + rawName = sdfProp.name + # For property names, camelCase all tokens irrespective of + # useLiteralIdentifier, so that we are consistent in our attribute + # naming when namespace prefix are provided and respect our coding + # convention. (Example: namespacePrefix:attrName -> + # namespacePrefixAttrName) + name = _MakeValidToken(rawName, False) + return (name, rawName) + class PropInfo(object): class CodeGen: """Specifies how code gen constructs get methods for a property @@ -299,40 +367,28 @@ class CodeGen: Generated = 'generated' Custom = 'custom' - def __init__(self, sdfProp, classInfo): + def __init__(self, sdfProp, usdProp, classInfo): # Allow user to specify custom naming through customData metadata. self.customData = dict(sdfProp.customData) + self.name, self.rawName = _GetNameAndRawNameForPropInfo( + sdfProp, classInfo) - if classInfo.propertyNamespacePrefix: - # A property namespace prefix will only exist for multiple apply API - # schemas and is used to create the instanceable namespace prefix - # prepended to all its properties. We prepend this instanceable - # prefix to the raw name here. - self.rawName = Usd.SchemaRegistry.MakeMultipleApplyNameTemplate( - classInfo.propertyNamespacePrefix, sdfProp.name) - # Since the property info's name is used to create the identifier - # used for tokens and such, we make it from the instanced property - # name with the instance name placeholder replaced with - # "_MultipleApplyTemplate_". This is so we don't end up with an - # the implementation detail of "__INSTANCE_NAME__" in the identifier - # itself. - self.name = _CamelCase( - Usd.SchemaRegistry.MakeMultipleApplyNameInstance( - self.rawName, "_MultipleApplyTemplate_")) - else: - self.rawName = sdfProp.name - # For property names, camelCase all tokens irrespective of - # useLiteralIdentifier, so that we are consistent in our attribute - # naming when namespace prefix are provided and respect our coding - # convention. (Example: namespacePrefix:attrName -> - # namespacePrefixAttrName) - self.name = _MakeValidToken(self.rawName, False) + # Determine if this property will be an API schema override in the + # flattened stage. + self.isAPISchemaOverride = _GetIsAPISchemaOverride(usdProp) - self.apiName = self.customData.get('apiName', _CamelCase(sdfProp.name)) - self.apiGet = self.customData.get('apiGetImplementation', self.CodeGen.Generated) + # If the property is an API schema override, force the apiName to + # empty so it isn't added to any of the C++ API + if self.isAPISchemaOverride: + self.apiName = '' + else: + self.apiName = self.customData.get( + 'apiName', _CamelCase(sdfProp.name)) + self.apiGet = self.customData.get( + 'apiGetImplementation', self.CodeGen.Generated) if self.apiGet not in [self.CodeGen.Generated, self.CodeGen.Custom]: Print.Err("Token '%s' is not valid." % self.apiGet) - self.doc = _SanitizeDoc(sdfProp.documentation, '\n /// ') + self.doc = _SanitizeDoc(sdfProp.documentation, '\n /// ') # Keep around the property spec so that we can pull any other data we # may need from it. self._sdfPropSpec = sdfProp @@ -346,8 +402,8 @@ def __getattr__(self, attr): return getattr(self._sdfPropSpec, attr) class RelInfo(PropInfo): - def __init__(self, sdfProp, classInfo): - super(RelInfo, self).__init__(sdfProp, classInfo) + def __init__(self, sdfProp, usdProp, classInfo): + super(RelInfo, self).__init__(sdfProp, usdProp, classInfo) # Map an Sdf.ValueTypeName.XXX object to the 'XXX' token string -- we use this # to go from sdf attribute types to their symbolic tokens, for example: @@ -368,8 +424,8 @@ def _GetSchemaDefException(msg, path): return Exception(errorMsg(msg)) class AttrInfo(PropInfo): - def __init__(self, sdfProp, classInfo): - super(AttrInfo, self).__init__(sdfProp, classInfo) + def __init__(self, sdfProp, usdProp, classInfo): + super(AttrInfo, self).__init__(sdfProp, usdProp, classInfo) self.allowedTokens = sdfProp.GetInfo('allowedTokens') self.variability = str(sdfProp.variability).replace('Sdf.', 'Sdf') @@ -786,9 +842,11 @@ def ParseUsd(usdFilePath): if not _ValidateFields(sdfProp): hasInvalidFields = True + usdProp = stage.GetPropertyAtPath(sdfProp.path) + # Attribute if isinstance(sdfProp, Sdf.AttributeSpec): - attrInfo = AttrInfo(sdfProp, classInfo) + attrInfo = AttrInfo(sdfProp, usdProp, classInfo) # Assert unique attribute names if (attrInfo.apiName != ''): @@ -810,7 +868,7 @@ def ParseUsd(usdFilePath): # Relationship else: - relInfo = RelInfo(sdfProp, classInfo) + relInfo = RelInfo(sdfProp, usdProp, classInfo) # Assert unique relationship names if (relInfo.apiName != ''): @@ -1485,8 +1543,20 @@ def GenerateRegistry(codeGenPath, filePath, classes, validate, env): Sdf.TokenListOp.CreateExplicit(appliedAPISchemas)) p.ClearCustomData() + # Properties may have customData indicating that they are an + # 'apiSchemaOverride'. We don't leave this data on the property in + # in the generatedSchema, but rather we use it to collect the names of + # all API schema override properties for the schema prim. We then store + # this list of API schema override properties as custom data on the + # prim spec and delete the custom data on the property. + apiSchemaOverridePropertyNames = [] for myproperty in p.GetAuthoredProperties(): + if myproperty.GetCustomDataByKey('apiSchemaOverride'): + apiSchemaOverridePropertyNames.append(myproperty.GetName()) myproperty.ClearCustomData() + if apiSchemaOverridePropertyNames: + p.SetCustomDataByKey('apiSchemaOverridePropertyNames', + Vt.TokenArray(apiSchemaOverridePropertyNames)) for p in pathsToDelete: flatStage.RemovePrim(p) From adee846b14ff159b329ae80603eb8177921c3c8b Mon Sep 17 00:00:00 2001 From: unhyperbolic Date: Tue, 5 Apr 2022 17:25:29 -0700 Subject: [PATCH 021/285] Clients of HdSceneIndexPluginRegistry: do not add HdSceneIndexPlugin as Base to HdSceneIndexPluginRegistry::Define already does it. (Internal change: 2224869) --- pxr/imaging/hdSt/dependencySceneIndexPlugin.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pxr/imaging/hdSt/dependencySceneIndexPlugin.cpp b/pxr/imaging/hdSt/dependencySceneIndexPlugin.cpp index 35034ed52a..c195bdd8ca 100644 --- a/pxr/imaging/hdSt/dependencySceneIndexPlugin.cpp +++ b/pxr/imaging/hdSt/dependencySceneIndexPlugin.cpp @@ -43,9 +43,7 @@ static const char * const _pluginDisplayName = "GL"; TF_REGISTRY_FUNCTION(TfType) { - HdSceneIndexPluginRegistry::Define< - HdSt_DependencySceneIndexPlugin, - HdSceneIndexPlugin>(); + HdSceneIndexPluginRegistry::Define(); } TF_REGISTRY_FUNCTION(HdSceneIndexPlugin) From f71dacf0fb7b105ddc8c74aedc08f6e70852d63e Mon Sep 17 00:00:00 2001 From: unhyperbolic Date: Tue, 5 Apr 2022 17:25:42 -0700 Subject: [PATCH 022/285] Clients of HdSceneIndexPluginRegistry: do not add HdSceneIndexPlugin as Base to HdSceneIndexPluginRegistry::Define already does it. (Internal change: 2224870) --- .../plugin/hdPrman/matfiltSceneIndexPlugins.cpp | 9 +++------ .../hdPrman/velocityMotionBlurSceneIndexPlugin.cpp | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/third_party/renderman-24/plugin/hdPrman/matfiltSceneIndexPlugins.cpp b/third_party/renderman-24/plugin/hdPrman/matfiltSceneIndexPlugins.cpp index d5eca905bf..4be274c8a7 100644 --- a/third_party/renderman-24/plugin/hdPrman/matfiltSceneIndexPlugins.cpp +++ b/third_party/renderman-24/plugin/hdPrman/matfiltSceneIndexPlugins.cpp @@ -64,16 +64,13 @@ static const bool _resolveVstructsWithConditionals = true; TF_REGISTRY_FUNCTION(TfType) { HdSceneIndexPluginRegistry::Define< - HdPrman_PreviewMaterialFilteringSceneIndexPlugin, - HdSceneIndexPlugin>(); + HdPrman_PreviewMaterialFilteringSceneIndexPlugin>(); HdSceneIndexPluginRegistry::Define< - HdPrman_MaterialXFilteringSceneIndexPlugin, - HdSceneIndexPlugin>(); + HdPrman_MaterialXFilteringSceneIndexPlugin>(); HdSceneIndexPluginRegistry::Define< - HdPrman_VirtualStructResolvingSceneIndexPlugin, - HdSceneIndexPlugin>(); + HdPrman_VirtualStructResolvingSceneIndexPlugin>(); } TF_REGISTRY_FUNCTION(HdSceneIndexPlugin) diff --git a/third_party/renderman-24/plugin/hdPrman/velocityMotionBlurSceneIndexPlugin.cpp b/third_party/renderman-24/plugin/hdPrman/velocityMotionBlurSceneIndexPlugin.cpp index 538a7cdf0b..aaa2312b70 100644 --- a/third_party/renderman-24/plugin/hdPrman/velocityMotionBlurSceneIndexPlugin.cpp +++ b/third_party/renderman-24/plugin/hdPrman/velocityMotionBlurSceneIndexPlugin.cpp @@ -53,8 +53,7 @@ static const float _minimumShutterInterval = 1.0e-10; TF_REGISTRY_FUNCTION(TfType) { HdSceneIndexPluginRegistry::Define< - HdPrman_VelocityMotionBlurSceneIndexPlugin, - HdSceneIndexPlugin>(); + HdPrman_VelocityMotionBlurSceneIndexPlugin>(); } TF_REGISTRY_FUNCTION(HdSceneIndexPlugin) From 1e53b41006ca6f9ab32188a25e619d710f08dae2 Mon Sep 17 00:00:00 2001 From: unhyperbolic Date: Mon, 11 Apr 2022 11:46:00 -0700 Subject: [PATCH 023/285] testUsdImagingGLUsdLux: avoiding degeneracies. The box had a degenerate transform and the sphere and sphere light were at exactly the same position with the same radius. Note that the test uses auto framing for the camera and thus is sensitive to geometry movements changing the bounding box. (Internal change: 2225336) --- .../baseline/usdLux.png | Bin 15268 -> 15716 bytes .../testUsdImagingGLUsdLux/usdLux.usda | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLUsdLux/baseline/usdLux.png b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLUsdLux/baseline/usdLux.png index 50f723a5740dc97bae80f88cd2aed19068b7fd1b..6c5ed0a1f78f88a8f6c7d58457a1df69ef94ee4e 100644 GIT binary patch literal 15716 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 literal 15268 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 Date: Mon, 11 Apr 2022 11:47:49 -0700 Subject: [PATCH 024/285] Replace all description of .usda as "ASCII" in user doc with "text", and enhance the FAQ to describe that usda is a UTF-8 encoding. Doc-only change. (Internal change: 2225469) --- docs/intro.rst | 8 ++-- docs/maxperf.rst | 28 ++++++------ docs/plugins_alembic.rst | 7 +-- docs/toolset.rst | 22 +++++----- docs/tut_converting_between_layer_formats.rst | 14 +----- docs/usdfaq.rst | 43 +++++++++++++------ pxr/usd/bin/usdedit/usdedit.py | 2 +- 7 files changed, 66 insertions(+), 58 deletions(-) diff --git a/docs/intro.rst b/docs/intro.rst index 4a760de3b5..d4131d4b26 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -304,7 +304,7 @@ following plugin-points: A USD Layer can be taught to be populated with data translated from any kind of compatible file format, by implementing an :usdcpp:`SdfFileFormat` - plugin for the format. USD's own native *usda* (ascii), *usdc* (binary), + plugin for the format. USD's own native *usda* (text), *usdc* (binary), and *usdz* (packaged archive) formats are implemented this way, as is the included support for reading Alembic files via the :doc:`Alembic USD Plugin `, as well as `MaterialX xml files @@ -320,7 +320,7 @@ following plugin-points: USD includes :doc:`a tool for generating new schemas ` (C++ classes, python bindings, and all - required boilerplate) from a simple usd ascii description of the + required boilerplate) from a simple usda text description of the schema. This can be used to add new USD prim schema types and API's to your pipeline or package, with which you will be able to interact in your application-level plugins just as if they were native USD schemas. For @@ -345,7 +345,7 @@ flexibility of composition. In past iterations of USD, Pixar used a form of GUID at the model/asset granularity, and after carefully weighing the pros and cons, we have decided that for us, the cost of occasional "namespace fix-up" operations run over a collection of assets is worth paying for the ease of asset -construction and aggregation, and readable ascii asset representations that we +construction and aggregation, and readable text asset representations that we get from namespace-paths as identifiers. Not an execution or rigging system @@ -398,7 +398,7 @@ could not always be used together effectively, because they were spread across three different formats and "composition engines". Presto delivered a second generation of scene description that was *unified*, enabling referencing, overriding, variation, and other operations at all granularities from a single -mesh, to an entire model, to an environment or shot, encoded in a single ascii +mesh, to an entire model, to an environment or shot, encoded in a single text format and evaluated with a single composition engine. However, at the same time, Pixar, along with much of the film and effects diff --git a/docs/maxperf.rst b/docs/maxperf.rst index beebb054b4..b34f718afe 100644 --- a/docs/maxperf.rst +++ b/docs/maxperf.rst @@ -53,18 +53,18 @@ variable. For example: Use binary ".usd" files for geometry and shading caches ####################################################### -ASCII USD files can be a good choice for small files that primarily -reference/subLayer other files together, such as the top-level "asset interface" -file that defines a :ref:`Model `, provides its :ref:`AssetInfo -`, declares its :ref:`VariantSets `, -and contains a :ref:`payload arc ` to the asset's -contents. But for files that contain more than a few small definitions or -overrides, the binary :ref:`"usdc" format ` will -open faster and consume substantially much less memory while held open (a -:ref:`UsdStage ` keeps open all the layers that participate in a -composition). You should not need to exert any extra effort to get this behavior -since creating a new layer or stage with a filename :filename:`someFile.usd` -will, by default, create a usdc file. +:filename:`.usda` text files can be a good choice for small files +that primarily reference/subLayer other files together, such as the top-level +"asset interface" file that defines a :ref:`Model `, provides +its :ref:`AssetInfo `, declares its :ref:`VariantSets +`, and contains a :ref:`payload arc ` +to the asset's contents. But for files that contain more than a few small +definitions or overrides, the binary :ref:`"usdc" format ` will open faster and consume substantially much less memory while +held open (a :ref:`UsdStage ` keeps open all the layers that +participate in a composition). You should not need to exert any extra effort +to get this behavior since creating a new layer or stage with a filename +:filename:`someFile.usd` will, by default, create a usdc file. As much as your pipeline allows, you should also prefer binary USD files over Alembic caches, for performance. Alembic is a ground-breaking and outstanding @@ -146,8 +146,8 @@ guidelines that we try to keep in mind: * **Prefer crate files.** - As described above, putting big data in ASCII USD files increases latency - to opening a :ref:`Stage ` and memory footprint. + As described above, putting big data in :filename:`.usda` files increases + latency to opening a :ref:`Stage ` and memory footprint. * **Monitor Layer count.** diff --git a/docs/plugins_alembic.rst b/docs/plugins_alembic.rst index 5fb354c091..c4814a3f57 100644 --- a/docs/plugins_alembic.rst +++ b/docs/plugins_alembic.rst @@ -13,7 +13,7 @@ Alembic USD Plugin For more information see our page on `Advanced Build Configuration `_. -As shipped, USD supports its own ASCII (usda) and binary (usdc) file +As shipped, USD supports its own text (usda) and binary (usdc) file formats. However, it is possible for USD to support additional formats by providing it with a custom file format plugin. One of these plugins, usdAbc, which provides the ability to interact with Alembic files, is included in the @@ -33,8 +33,9 @@ Let's start by creating a simple USD file (save it as :filename:`hello.usda`): } } -The previous snippet defined a simple sphere in an ASCII-backed USD file. Now, -let's use :ref:`toolset:usdcat` to convert it to an Alembic file! +The previous snippet defined a simple sphere in the :filename:`.usda` file +format. Now, let's use :ref:`toolset:usdcat` to convert it to an Alembic +file! .. code-block:: sh diff --git a/docs/toolset.rst b/docs/toolset.rst index 6358dda8e9..fec47e9414 100644 --- a/docs/toolset.rst +++ b/docs/toolset.rst @@ -9,10 +9,10 @@ usdedit ******* :program:`usdedit` is a simple script that converts any single USD-readable -file into its (temp) .usda ascii equivalent and brings the result up in your -editor of choice, which is taken from the :envvar:`EDITOR` environment -variable. Upon quitting the editor, any changes to the temp file will be -converted back to the original file's format (assuming the +file into its (temp) :filename:`.usda` text equivalent and brings the +result up in your editor of choice, which is taken from the :envvar:`EDITOR` +environment variable. Upon quitting the editor, any changes to the temp file +will be converted back to the original file's format (assuming the :code:`FileFormatPlugin` for the format allows writing), and the original file's contents will be replaced with the edited contents. @@ -22,12 +22,12 @@ file's contents will be replaced with the edited contents. usage: usdedit [-h] [-n] [-f] usdFileName - Convert a usd-readable file to the usd ascii format in a temporary location - and invoke an editor on it. After saving and quitting the editor, the edited - file will be converted back to the original format and OVERWRITE the original - file, unless you supply the "-n" (--noeffect) flag, in which case no changes - will be saved back to the original file. The editor to use will be queried - from the EDITOR environment variable. + Convert a usd-readable file to the .usda text format in a temporary + location and invoke an editor on it. After saving and quitting the editor, + the edited file will be converted back to the original format and + OVERWRITE the original file, unless you supply the "-n" (--noeffect) flag, + in which case no changes will be saved back to the original file. The + editor to use will be queried from the EDITOR environment variable. positional arguments: usdFileName The usd file to edit. @@ -46,7 +46,7 @@ file's contents will be replaced with the edited contents. being used as a source file, since the roundtripping is lossy! * Running :program:`usdedit` on a very large file with lots of dense, - numeric data may take a long time, create a really large ascii file in + numeric data may take a long time, create a really large text file in your temp area (wherever python's :python:`tempfile` package decides to put it), and may push the boundaries of your editor's scalability. diff --git a/docs/tut_converting_between_layer_formats.rst b/docs/tut_converting_between_layer_formats.rst index b8d05f4051..675f7baf60 100644 --- a/docs/tut_converting_between_layer_formats.rst +++ b/docs/tut_converting_between_layer_formats.rst @@ -6,18 +6,8 @@ Converting Between Layer Formats ================================ -This tutorial walks through converting layer files between the different native -USD file formats. USD includes three native file formats: - - +--------------------------------+--------------------------------+ - | Extension | Content | - +================================+================================+ - | :filename:`.usda` | Human-readable text | - +--------------------------------+--------------------------------+ - | :filename:`.usdc` | Random-access binary | - +--------------------------------+--------------------------------+ - | :filename:`.usd` | Either of the above | - +--------------------------------+--------------------------------+ +This tutorial walks through converting layer files between the +:ref:`different native USD file formats `. The :ref:`toolset:usdcat` tool is useful for inspecting these files, but it can also convert files between the different formats by using the :option:`-o` diff --git a/docs/usdfaq.rst b/docs/usdfaq.rst index 0a997430d7..f3c4506c36 100644 --- a/docs/usdfaq.rst +++ b/docs/usdfaq.rst @@ -80,26 +80,42 @@ integral part of the user-experience, rather than simply as an interchange. So what file formats does USD support? ###################################### -Out of the box, USD includes a human-readable text file format -(":filename:`usda`") and a binary file format (":filename:`usdc`"), also known -as :ref:`Crate `. It also includes support for +Out of the box, USD the following three file formats: + + +--------------------------------+--------------------------------+ + | Extension | Content | + +================================+================================+ + | :filename:`.usda` | Human-readable UTF-8 text | + +--------------------------------+--------------------------------+ + | :filename:`.usdc` | Random-access "Crate" binary | + +--------------------------------+--------------------------------+ + | :filename:`.usd` | Either of the above | + +--------------------------------+--------------------------------+ + +It also includes plugins that provide support for reading and writing :doc:`Alembic ` files, and for reading -`MaterialX files `_. Users can extend +`MaterialX files `_. Developers can extend USD to read and write from other file formats by writing a plugin that will translate the data in that format to the USD scenegraph. What file format is my :filename:`.usd` file? ############################################# -USD files created with the plain :filename:`.usd` extension, can be either -binary-backed :ref:`Crate ` files, or ASCII-backed -files. This can be advantageous in certain scenarios; for example, if one has -USD files which contain references to plain :filename:`.usd` assets, those -assets can be converted between binary and ASCII without changing the sources -which refer to them. +As shown in the table above, USD files created with the plain +:filename:`.usd` extension, can be either binary-backed +:ref:`Crate ` files, or text files. +This can be advantageous in certain scenarios; for example, if one has USD +files which contain references to plain :filename:`.usd` assets, those assets +can be converted between binary and text without changing the sources which +refer to them. -How can I convert USD files between binary and ASCII? -##################################################### +What character encoding does :filename:`.usda` support? +####################################################### + +The :filename:`.usda` file format encodes text as UTF-8. + +How can I convert USD files between binary and text? +#################################################### :ref:`usdcat ` can be used to convert files between file formats. With plain, :filename:`.usd` files, you can change them using the @@ -136,7 +152,8 @@ What does a USD file look like? ############################### Here's an example using references, inheritance, and variants. This is the -representation generated by the ASCII file format. +representation generated by the native text file format, whose extension is +:filename:`.usda`. .. code-block:: usda :caption: solarSystem.usda diff --git a/pxr/usd/bin/usdedit/usdedit.py b/pxr/usd/bin/usdedit/usdedit.py index a301ba040c..5f28bdea56 100644 --- a/pxr/usd/bin/usdedit/usdedit.py +++ b/pxr/usd/bin/usdedit/usdedit.py @@ -142,7 +142,7 @@ def _writeOutChanges(temporaryFileName, permanentFileName): def main(): import argparse parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]), - description= 'Convert a usd-readable file to the usd ascii format in \n' + description= 'Convert a usd-readable file to the .usda text format in\n' 'a temporary location and invoke an editor on it. After \n' 'saving and quitting the editor, the edited file will be \n' 'converted back to the original format and OVERWRITE the \n' From 4fc71678bda7437e6c593c7553766a644b02da4e Mon Sep 17 00:00:00 2001 From: unhyperbolic Date: Tue, 12 Apr 2022 08:57:21 -0700 Subject: [PATCH 025/285] Hydra, usdImaging and Storm: adding cube prim type and schema to Hydra. Adding a implicits data source for usdImaging. Adding scene index to storm to convert the cube into a mesh. (Internal change: 2225666) (Internal change: 2225696) (Internal change: 2225865) --- pxr/imaging/hd/CMakeLists.txt | 1 + pxr/imaging/hd/cubeSchema.cpp | 104 +++++ pxr/imaging/hd/cubeSchema.h | 111 ++++++ pxr/imaging/hd/dataSourceTypeDefs.h | 2 + pxr/imaging/hd/overlayContainerDataSource.h | 4 + pxr/imaging/hd/tokens.h | 1 + pxr/imaging/hdSt/CMakeLists.txt | 1 + .../hdSt/implicitSurfaceSceneIndexPlugin.cpp | 354 ++++++++++++++++++ .../hdSt/implicitSurfaceSceneIndexPlugin.h | 51 +++ pxr/imaging/hdSt/plugInfo.json | 6 + pxr/usdImaging/usdImaging/CMakeLists.txt | 3 + pxr/usdImaging/usdImaging/cubeAdapter.cpp | 33 ++ pxr/usdImaging/usdImaging/cubeAdapter.h | 20 + .../usdImaging/dataSourceImplicits-Impl.h | 158 ++++++++ 14 files changed, 849 insertions(+) create mode 100644 pxr/imaging/hd/cubeSchema.cpp create mode 100644 pxr/imaging/hd/cubeSchema.h create mode 100644 pxr/imaging/hdSt/implicitSurfaceSceneIndexPlugin.cpp create mode 100644 pxr/imaging/hdSt/implicitSurfaceSceneIndexPlugin.h create mode 100644 pxr/usdImaging/usdImaging/dataSourceImplicits-Impl.h diff --git a/pxr/imaging/hd/CMakeLists.txt b/pxr/imaging/hd/CMakeLists.txt index 2952733225..610324ff29 100644 --- a/pxr/imaging/hd/CMakeLists.txt +++ b/pxr/imaging/hd/CMakeLists.txt @@ -43,6 +43,7 @@ pxr_library(hd containerDataSourceEditor coordSys coordSysBindingSchema + cubeSchema dataSource dataSourceLegacyPrim dataSourceLocator diff --git a/pxr/imaging/hd/cubeSchema.cpp b/pxr/imaging/hd/cubeSchema.cpp new file mode 100644 index 0000000000..dab3148524 --- /dev/null +++ b/pxr/imaging/hd/cubeSchema.cpp @@ -0,0 +1,104 @@ +// +// Copyright 2022 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +//////////////////////////////////////////////////////////////////////// +// This file is generated by a script. Do not edit directly. Edit the +// schema.template.cpp file to make changes. + +#include "pxr/imaging/hd/cubeSchema.h" +#include "pxr/imaging/hd/retainedDataSource.h" + +#include "pxr/base/trace/trace.h" + + +PXR_NAMESPACE_OPEN_SCOPE + +TF_DEFINE_PUBLIC_TOKENS(HdCubeSchemaTokens, + HDCUBE_SCHEMA_TOKENS); + + + +HdDoubleDataSourceHandle +HdCubeSchema::GetSize() +{ + return _GetTypedDataSource( + HdCubeSchemaTokens->size); +} + +/*static*/ +HdContainerDataSourceHandle +HdCubeSchema::BuildRetained( + const HdDoubleDataSourceHandle &size +) +{ + TfToken names[1]; + HdDataSourceBaseHandle values[1]; + + size_t count = 0; + if (size) { + names[count] = HdCubeSchemaTokens->size; + values[count++] = size; + } + + return HdRetainedContainerDataSource::New(count, names, values); +} + +/*static*/ +HdCubeSchema +HdCubeSchema::GetFromParent( + const HdContainerDataSourceHandle &fromParentContainer) +{ + return HdCubeSchema( + fromParentContainer + ? HdContainerDataSource::Cast(fromParentContainer->Get( + HdCubeSchemaTokens->cube)) + : nullptr); +} + +/*static*/ +const HdDataSourceLocator & +HdCubeSchema::GetDefaultLocator() +{ + static const HdDataSourceLocator locator( + HdCubeSchemaTokens->cube + ); + return locator; +} +HdCubeSchema::Builder & +HdCubeSchema::Builder::SetSize( + const HdDoubleDataSourceHandle &size) +{ + _size = size; + return *this; +} + +HdContainerDataSourceHandle +HdCubeSchema::Builder::Build() +{ + return HdCubeSchema::BuildRetained( + _size + ); +} + + +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/imaging/hd/cubeSchema.h b/pxr/imaging/hd/cubeSchema.h new file mode 100644 index 0000000000..fc5552a4db --- /dev/null +++ b/pxr/imaging/hd/cubeSchema.h @@ -0,0 +1,111 @@ +// +// Copyright 2022 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +//////////////////////////////////////////////////////////////////////// +// This file is generated by a script. Do not edit directly. Edit the +// schema.template.h file to make changes. + +#ifndef PXR_IMAGING_HD_CUBE_SCHEMA_H +#define PXR_IMAGING_HD_CUBE_SCHEMA_H + +#include "pxr/imaging/hd/api.h" + +#include "pxr/imaging/hd/schema.h" + +PXR_NAMESPACE_OPEN_SCOPE + +//----------------------------------------------------------------------------- + +#define HDCUBE_SCHEMA_TOKENS \ + (cube) \ + (size) \ + +TF_DECLARE_PUBLIC_TOKENS(HdCubeSchemaTokens, HD_API, + HDCUBE_SCHEMA_TOKENS); + +//----------------------------------------------------------------------------- + +class HdCubeSchema : public HdSchema +{ +public: + HdCubeSchema(HdContainerDataSourceHandle container) + : HdSchema(container) {} + + //ACCESSORS + + HD_API + HdDoubleDataSourceHandle GetSize(); + + // RETRIEVING AND CONSTRUCTING + + /// Builds a container data source which includes the provided child data + /// sources. Parameters with nullptr values are excluded. This is a + /// low-level interface. For cases in which it's desired to define + /// the container with a sparse set of child fields, the Builder class + /// is often more convenient and readable. + HD_API + static HdContainerDataSourceHandle + BuildRetained( + const HdDoubleDataSourceHandle &size + ); + + /// \class HdCubeSchema::Builder + /// + /// Utility class for setting sparse sets of child data source fields to be + /// filled as arguments into BuildRetained. Because all setter methods + /// return a reference to the instance, this can be used in the "builder + /// pattern" form. + class Builder + { + public: + HD_API + Builder &SetSize( + const HdDoubleDataSourceHandle &size); + + /// Returns a container data source containing the members set thus far. + HD_API + HdContainerDataSourceHandle Build(); + + private: + HdDoubleDataSourceHandle _size; + }; + + /// Retrieves a container data source with the schema's default name token + /// "cube" from the parent container and constructs a + /// HdCubeSchema instance. + /// Because the requested container data source may not exist, the result + /// should be checked with IsDefined() or a bool comparison before use. + HD_API + static HdCubeSchema GetFromParent( + const HdContainerDataSourceHandle &fromParentContainer); + + /// Returns an HdDataSourceLocator (relative to the prim-level data source) + /// where the container representing this schema is found by default. + HD_API + static const HdDataSourceLocator &GetDefaultLocator(); + +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif diff --git a/pxr/imaging/hd/dataSourceTypeDefs.h b/pxr/imaging/hd/dataSourceTypeDefs.h index 604a3dfdce..7c10b46c95 100644 --- a/pxr/imaging/hd/dataSourceTypeDefs.h +++ b/pxr/imaging/hd/dataSourceTypeDefs.h @@ -51,6 +51,8 @@ using HdSizetDataSourceHandle = HdSizetDataSource::Handle; using HdFloatDataSource = HdTypedSampledDataSource; using HdFloatDataSourceHandle = HdFloatDataSource::Handle; +using HdDoubleDataSource = HdTypedSampledDataSource; +using HdDoubleDataSourceHandle = HdDoubleDataSource::Handle; using HdFloatArrayDataSource = HdTypedSampledDataSource>; using HdFloatArrayDataSourceHandle = HdFloatArrayDataSource::Handle; diff --git a/pxr/imaging/hd/overlayContainerDataSource.h b/pxr/imaging/hd/overlayContainerDataSource.h index c2394ceb69..ff6634b376 100644 --- a/pxr/imaging/hd/overlayContainerDataSource.h +++ b/pxr/imaging/hd/overlayContainerDataSource.h @@ -39,12 +39,16 @@ class HdOverlayContainerDataSource : public HdContainerDataSource public: HD_DECLARE_DATASOURCE(HdOverlayContainerDataSource); + HD_API HdOverlayContainerDataSource( size_t count, HdContainerDataSourceHandle *containers); + HD_API bool Has(const TfToken &name) override; + HD_API TfTokenVector GetNames() override; + HD_API HdDataSourceBaseHandle Get(const TfToken &name) override; private: diff --git a/pxr/imaging/hd/tokens.h b/pxr/imaging/hd/tokens.h index 64d3587e5b..5dce1cdff5 100644 --- a/pxr/imaging/hd/tokens.h +++ b/pxr/imaging/hd/tokens.h @@ -246,6 +246,7 @@ PXR_NAMESPACE_OPEN_SCOPE #define HD_PRIMTYPE_TOKENS \ /* Rprims */ \ + (cube) \ (mesh) \ (basisCurves) \ (points) \ diff --git a/pxr/imaging/hdSt/CMakeLists.txt b/pxr/imaging/hdSt/CMakeLists.txt index 6ae4955e8e..62b897ee74 100644 --- a/pxr/imaging/hdSt/CMakeLists.txt +++ b/pxr/imaging/hdSt/CMakeLists.txt @@ -76,6 +76,7 @@ pxr_library(hdSt hgiConversions hioConversions imageShaderRenderPass + implicitSurfaceSceneIndexPlugin instancer interleavedMemoryManager light diff --git a/pxr/imaging/hdSt/implicitSurfaceSceneIndexPlugin.cpp b/pxr/imaging/hdSt/implicitSurfaceSceneIndexPlugin.cpp new file mode 100644 index 0000000000..250e30139e --- /dev/null +++ b/pxr/imaging/hdSt/implicitSurfaceSceneIndexPlugin.cpp @@ -0,0 +1,354 @@ +// +// Copyright 2022 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. + +#include "pxr/imaging/hdSt/implicitSurfaceSceneIndexPlugin.h" + +#include "pxr/imaging/hd/cubeSchema.h" +#include "pxr/imaging/hd/filteringSceneIndex.h" +#include "pxr/imaging/hd/meshSchema.h" +#include "pxr/imaging/hd/meshTopologySchema.h" +#include "pxr/imaging/hd/overlayContainerDataSource.h" +#include "pxr/imaging/hd/primvarSchema.h" +#include "pxr/imaging/hd/primvarsSchema.h" +#include "pxr/imaging/hd/retainedDataSource.h" +#include "pxr/imaging/hd/sceneIndexPluginRegistry.h" +#include "pxr/imaging/hd/tokens.h" + +#include "pxr/base/tf/iterator.h" + +PXR_NAMESPACE_OPEN_SCOPE + +TF_DEFINE_PRIVATE_TOKENS( + _tokens, + ((sceneIndexPluginName, "HdSt_ImplicitSurfaceSceneIndexPlugin")) +); + +static const char * const _pluginDisplayName = "GL"; + +TF_REGISTRY_FUNCTION(TfType) +{ + HdSceneIndexPluginRegistry::Define(); +} + +TF_REGISTRY_FUNCTION(HdSceneIndexPlugin) +{ + const HdSceneIndexPluginRegistry::InsertionPhase insertionPhase = 0; + + HdSceneIndexPluginRegistry::GetInstance().RegisterSceneIndexForRenderer( + _pluginDisplayName, + _tokens->sceneIndexPluginName, + nullptr, + insertionPhase, + HdSceneIndexPluginRegistry::InsertionOrderAtStart); +} + +namespace +{ + +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +// Cube + +namespace _CubeToMesh +{ + +HdContainerDataSourceHandle +_ComputeMeshDataSource() +{ + static const VtIntArray numVerts{ 4, 4, 4, 4, 4, 4 }; + static const VtIntArray verts{ 0, 1, 2, 3, + 4, 5, 6, 7, + 0, 6, 5, 1, + 4, 7, 3, 2, + 0, 3, 7, 6, + 4, 2, 1, 5 }; + + return + HdMeshSchema::Builder() + .SetTopology( + HdMeshTopologySchema::Builder() + .SetFaceVertexCounts( + HdRetainedTypedSampledDataSource::New( + numVerts)) + .SetFaceVertexIndices( + HdRetainedTypedSampledDataSource::New( + verts)) + .SetOrientation( + HdRetainedTypedSampledDataSource::New( + HdMeshTopologySchemaTokens->rightHanded)) + .Build()) + .SetDoubleSided( + HdRetainedTypedSampledDataSource::New(false)) + .Build(); +} + +class _PointsDataSource : public HdVec3fArrayDataSource +{ +public: + HD_DECLARE_DATASOURCE(_PointsDataSource); + + _PointsDataSource(const HdContainerDataSourceHandle &primDataSource) + : _primDataSource(primDataSource) + { + } + + VtValue GetValue(const Time shutterOffset) override { + return VtValue(GetTypedValue(shutterOffset)); + } + + VtVec3fArray GetTypedValue(const Time shutterOffset) override { + static const VtVec3fArray points{ + GfVec3f( 0.5f, 0.5f, 0.5f), + GfVec3f(-0.5f, 0.5f, 0.5f), + GfVec3f(-0.5f, -0.5f, 0.5f), + GfVec3f( 0.5f, -0.5f, 0.5f), + GfVec3f(-0.5f, -0.5f, -0.5f), + GfVec3f(-0.5f, 0.5f, -0.5f), + GfVec3f( 0.5f, 0.5f, -0.5f), + GfVec3f( 0.5f, -0.5f, -0.5f) + }; + + const double size = _GetSize(shutterOffset); + + VtVec3fArray scaledPoints; + scaledPoints.resize(points.size()); + for (size_t i = 0; i < points.size(); i++) { + scaledPoints[i] = size * points[i]; + } + + return scaledPoints; + } + + bool GetContributingSampleTimesForInterval( + const Time startTime, + const Time endTime, + std::vector