Skip to content

Commit 9055125

Browse files
committed
Linking the prototype's underlay visibility to the instancer's visibility, including a dependency to track updates (i.e., if the instancer's visibility is dirtied, the prototype's visibility will be dirtied)
1 parent df885fc commit 9055125

File tree

3 files changed

+85
-28
lines changed

3 files changed

+85
-28
lines changed

pxr/usdImaging/usdImaging/piPrototypePropagatingSceneIndex.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ _InstancerObserver::_InstancerObserver(
340340
_RerootingSceneIndex(
341341
context->inputSceneIndex,
342342
prototype, prototype),
343+
context->inputSceneIndex,
343344
instancer,
344345
prototype))
345346
, _rerootingSceneIndex(

pxr/usdImaging/usdImaging/piPrototypeSceneIndex.cpp

Lines changed: 78 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "pxr/imaging/hd/dataSource.h"
1414
#include "pxr/imaging/hd/dataSourceTypeDefs.h"
15+
#include "pxr/imaging/hd/dependenciesSchema.h"
1516
#include "pxr/imaging/hd/filteringSceneIndex.h"
1617
#include "pxr/imaging/hd/instancedBySchema.h"
1718
#include "pxr/imaging/hd/overlayContainerDataSource.h"
@@ -44,6 +45,45 @@ using namespace UsdImaging_PrototypeSceneIndexUtils;
4445
namespace
4546
{
4647

48+
class _ReferencedVisibilityDataSource : public HdContainerDataSource
49+
{
50+
public:
51+
HD_DECLARE_DATASOURCE(_ReferencedVisibilityDataSource);
52+
53+
TfTokenVector GetNames() override
54+
{
55+
return { HdVisibilitySchema::GetSchemaToken() };
56+
}
57+
58+
HdDataSourceBaseHandle Get(const TfToken &name) override
59+
{
60+
if (name != HdVisibilitySchema::GetSchemaToken()) {
61+
return nullptr;
62+
}
63+
if (!_referencedSceneIndex || _referencedPrimPath.IsEmpty()) {
64+
return nullptr;
65+
}
66+
HdSceneIndexPrim referencedPrim =
67+
_referencedSceneIndex->GetPrim(_referencedPrimPath);
68+
if (!referencedPrim.dataSource) {
69+
return nullptr;
70+
}
71+
return referencedPrim.dataSource->Get(name);
72+
}
73+
74+
protected:
75+
_ReferencedVisibilityDataSource(
76+
HdSceneIndexBaseRefPtr const &referencedSceneIndex,
77+
SdfPath const &referencedPrimPath)
78+
: _referencedSceneIndex(referencedSceneIndex)
79+
, _referencedPrimPath(referencedPrimPath)
80+
{}
81+
82+
private:
83+
HdSceneIndexBaseRefPtr _referencedSceneIndex;
84+
SdfPath _referencedPrimPath;
85+
};
86+
4787
bool
4888
_ContainsStrictPrefixOfPath(
4989
const std::unordered_set<SdfPath, SdfPath::Hash> &pathSet,
@@ -76,23 +116,16 @@ _ComputeUnderlaySource(const SdfPath &instancer, const SdfPath &prototypeRoot)
76116
}
77117

78118
HdContainerDataSourceHandle
79-
_ComputePrototypeRootUnderlaySource(const SdfPath &instancer)
119+
_ComputePrototypeRootUnderlaySource(
120+
const HdSceneIndexBaseRefPtr &instancerSceneIndex,
121+
const SdfPath &instancer)
80122
{
81123
if (instancer.IsEmpty()) {
82124
return nullptr;
83125
}
84126

85-
static HdContainerDataSourceHandle const ds =
86-
HdRetainedContainerDataSource::New(
87-
// By underlaying this data, we do not override visibility explicitly authored on a prototype instanced
88-
// by a point instancer in USD.
89-
HdVisibilitySchema::GetSchemaToken(),
90-
HdVisibilitySchema::Builder()
91-
.SetVisibility(
92-
HdRetainedTypedSampledDataSource<bool>::New(
93-
true))
94-
.Build());
95-
return ds;
127+
// By underlaying this data, we do not override invisibility explicitly authored on a prototype.
128+
return _ReferencedVisibilityDataSource::New(instancerSceneIndex, instancer);
96129
}
97130

98131
HdContainerDataSourceHandle
@@ -109,7 +142,20 @@ _ComputePrototypeRootOverlaySource(const SdfPath &instancer)
109142
.SetResetXformStack(
110143
HdRetainedTypedSampledDataSource<bool>::New(
111144
true))
112-
.Build());
145+
.Build(),
146+
HdDependenciesSchema::GetSchemaToken(),
147+
HdRetainedContainerDataSource::New(
148+
TfToken(instancer.GetName()),
149+
HdDependencySchema::Builder()
150+
.SetDependedOnPrimPath(
151+
HdRetainedTypedSampledDataSource<SdfPath>::New(instancer))
152+
.SetDependedOnDataSourceLocator(
153+
HdRetainedTypedSampledDataSource<HdDataSourceLocator>::New(
154+
HdVisibilitySchema::GetDefaultLocator()))
155+
.SetAffectedDataSourceLocator(
156+
HdRetainedTypedSampledDataSource<HdDataSourceLocator>::New(
157+
HdVisibilitySchema::GetDefaultLocator()))
158+
.Build()));
113159
return ds;
114160
}
115161

@@ -130,22 +176,28 @@ _IsOver(const HdSceneIndexPrim &prim)
130176
UsdImaging_PiPrototypeSceneIndexRefPtr
131177
UsdImaging_PiPrototypeSceneIndex::New(
132178
HdSceneIndexBaseRefPtr const &inputSceneIndex,
179+
HdSceneIndexBaseRefPtr const &instancerSceneIndex,
133180
const SdfPath &instancer,
134181
const SdfPath &prototypeRoot)
135182
{
136183
return TfCreateRefPtr(
137184
new UsdImaging_PiPrototypeSceneIndex(
138-
inputSceneIndex, instancer, prototypeRoot));
185+
inputSceneIndex, instancerSceneIndex, instancer, prototypeRoot));
139186
}
140187

141188
UsdImaging_PiPrototypeSceneIndex::
142189
UsdImaging_PiPrototypeSceneIndex(
143190
HdSceneIndexBaseRefPtr const &inputSceneIndex,
191+
HdSceneIndexBaseRefPtr const &instancerSceneIndex,
144192
const SdfPath &instancer,
145193
const SdfPath &prototypeRoot)
146194
: HdSingleInputFilteringSceneIndexBase(inputSceneIndex)
147195
, _instancer(instancer)
148196
, _prototypeRoot(prototypeRoot)
197+
, _underlaySource(_ComputeUnderlaySource(instancer, prototypeRoot))
198+
, _prototypeRootUnderlaySource(_ComputePrototypeRootUnderlaySource(
199+
instancerSceneIndex, instancer))
200+
, _prototypeRootOverlaySource(_ComputePrototypeRootOverlaySource(instancer))
149201
{
150202
_Populate();
151203
}
@@ -222,25 +274,23 @@ UsdImaging_PiPrototypeSceneIndex::GetPrim(const SdfPath &primPath) const
222274

223275
TfSmallVector<HdContainerDataSourceHandle, 4> dsVec;
224276

225-
if (HdContainerDataSourceHandle ds =
226-
_ComputePrototypeRootOverlaySource(_instancer);
227-
ds && primPath == _prototypeRoot)
228-
dsVec.emplace_back(ds);
229-
277+
if (_prototypeRootOverlaySource) {
278+
dsVec.emplace_back(_prototypeRootOverlaySource);
279+
}
280+
230281
dsVec.emplace_back(prim.dataSource);
231-
232-
if (HdContainerDataSourceHandle ds =
233-
_ComputePrototypeRootUnderlaySource(_instancer);
234-
ds && primPath == _prototypeRoot)
235-
dsVec.emplace_back(ds);
236282

237-
if (HdContainerDataSourceHandle ds =
238-
_ComputeUnderlaySource(_instancer, _prototypeRoot))
239-
dsVec.emplace_back(ds);
283+
if (_prototypeRootUnderlaySource) {
284+
dsVec.emplace_back(_prototypeRootUnderlaySource);
285+
}
286+
if (_underlaySource) {
287+
dsVec.emplace_back(_underlaySource);
288+
}
240289

241-
if (dsVec.size() > 1)
290+
if (dsVec.size() > 1) {
242291
prim.dataSource = HdOverlayContainerDataSource::New(
243292
dsVec.size(), dsVec.data());
293+
}
244294

245295
return prim;
246296
}

pxr/usdImaging/usdImaging/piPrototypeSceneIndex.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class UsdImaging_PiPrototypeSceneIndex final
121121
public:
122122
static UsdImaging_PiPrototypeSceneIndexRefPtr New(
123123
HdSceneIndexBaseRefPtr const &inputSceneIndex,
124+
HdSceneIndexBaseRefPtr const &instancerSceneIndex,
124125
const SdfPath &instancer,
125126
const SdfPath &prototypeRoot);
126127

@@ -131,6 +132,7 @@ class UsdImaging_PiPrototypeSceneIndex final
131132
protected:
132133
UsdImaging_PiPrototypeSceneIndex(
133134
HdSceneIndexBaseRefPtr const &inputSceneIndex,
135+
HdSceneIndexBaseRefPtr const &instancerSceneIndex,
134136
const SdfPath &instancer,
135137
const SdfPath &prototypeRoot);
136138

@@ -151,6 +153,10 @@ class UsdImaging_PiPrototypeSceneIndex final
151153
SdfPath _instancer;
152154
SdfPath _prototypeRoot;
153155

156+
HdContainerDataSourceHandle _underlaySource;
157+
HdContainerDataSourceHandle _prototypeRootUnderlaySource;
158+
HdContainerDataSourceHandle _prototypeRootOverlaySource;
159+
154160
// Instancers and overs within the prototype.
155161
// Note that this does not include instancers or overs nested
156162
// under an instancer or over.

0 commit comments

Comments
 (0)