@@ -108,6 +108,18 @@ bool isGeomSubset(const HdSceneIndexPrim& prim) {
108108#endif
109109}
110110
111+ HdContainerDataSourceHandle setInstancerMaskDataSource (
112+ const HdSceneIndexPrim& inputPrim,
113+ const VtArray<bool >& instanceMask
114+ )
115+ {
116+ auto maskDs = HdRetainedTypedSampledDataSource<VtArray<bool >>::New (instanceMask);
117+
118+ return HdContainerDataSourceEditor (inputPrim.dataSource )
119+ .Set (instancerMaskLocator, maskDs)
120+ .Finish ();
121+ }
122+
111123}
112124
113125namespace FVP_NS_DEF {
@@ -159,11 +171,8 @@ HdSceneIndexPrim IsolateSelectSceneIndex::GetPrim(const SdfPath& primPath) const
159171
160172 auto instancerMask = _instancerMasks.find (primPath);
161173 if (instancerMask != _instancerMasks.end ()) {
162- auto maskDs = HdRetainedTypedSampledDataSource<VtArray<bool >>::New (instancerMask->second );
163-
164- inputPrim.dataSource = HdContainerDataSourceEditor (inputPrim.dataSource )
165- .Set (instancerMaskLocator, maskDs)
166- .Finish ();
174+ inputPrim.dataSource =
175+ setInstancerMaskDataSource (inputPrim, instancerMask->second );
167176
168177 return inputPrim;
169178 }
@@ -179,6 +188,20 @@ HdSceneIndexPrim IsolateSelectSceneIndex::GetPrim(const SdfPath& primPath) const
179188 // HYDRA-1242: setting visibility on GeomSubset prim causes hang in Hydra
180189 // Storm.
181190 if (!included && !isGeomSubset (inputPrim)) {
191+ // If an instancer is not included, none of its instances are, so set
192+ // an instance mask that is entirely false.
193+ if (inputPrim.primType == HdPrimTypeTokens->instancer ) {
194+ auto instancerTopologySchema = HdInstancerTopologySchema::GetFromParent (inputPrim.dataSource );
195+ const auto nbInstances = getNbInstances (instancerTopologySchema);
196+ VtArray<bool > instanceMask (nbInstances, false );
197+
198+ inputPrim.dataSource = setInstancerMaskDataSource (inputPrim, instanceMask);
199+ }
200+
201+ // Unclear whether instancers need their visibility off. As of OpenUSD
202+ // 0.24.11, Hydra Storm seems to ignore visibility for instancers, but
203+ // there seems to be no harm in setting it false.
204+
182205 inputPrim.dataSource = HdContainerDataSourceEditor (inputPrim.dataSource )
183206 .Set (HdVisibilitySchema::GetDefaultLocator (), visOff)
184207 .Finish ();
@@ -437,21 +460,45 @@ void IsolateSelectSceneIndex::_DirtyVisibilityRecursive(
437460 HdSceneIndexObserver::DirtiedPrimEntries* dirtiedEntries
438461) const
439462{
440- TF_DEBUG (FVP_ISOLATE_SELECT_SCENE_INDEX)
441- .Msg (" %s: marking %s visibility locator dirty.\n " , _viewportId.c_str (), primPath.GetText ());
442-
463+ // If the prim is a material, early out: visibility is not
464+ // relevant for materials
443465 auto prim = GetInputSceneIndex ()->GetPrim (primPath);
466+ if (prim.primType == HdPrimTypeTokens->material ) {
467+ return ;
468+ }
444469
445470 // GeomSubset visibility must not be set (see GetPrim()), so no need to
446471 // dirty it.
447472 if (isGeomSubset (prim)) {
448473 return ;
449474 }
450475
476+ TF_DEBUG (FVP_ISOLATE_SELECT_SCENE_INDEX)
477+ .Msg (" %s: marking %s visibility locator dirty.\n " , _viewportId.c_str (), primPath.GetText ());
478+
479+ // Unclear whether instancers need their visibility off. As of OpenUSD
480+ // 0.24.11, Hydra Storm seems to ignore visibility for instancers, but
481+ // there seems to be no harm in setting it false.
482+
451483 dirtiedEntries->emplace_back (
452484 primPath, HdVisibilitySchema::GetDefaultLocator ());
453485
486+ // If the prim is an instancer, set its mask dirty, but don't recurse, as
487+ // the hierarchy beneath an instancer is its prototypes, whose visibility
488+ // is managed by the instancer mask data source.
489+ if (prim.primType == HdPrimTypeTokens->instancer ) {
490+ _AddDirtyInstancerMaskEntry (primPath, dirtiedEntries);
491+ return ;
492+ }
493+
454494 for (const auto & childPath : GetChildPrimPaths (primPath)) {
495+ #if PXR_VERSION >= 2403
496+ // Recursing down to set visibility on a geomSubset child is wasteful.
497+ auto childPrim = GetInputSceneIndex ()->GetPrim (childPath);
498+ if (childPrim.primType == HdPrimTypeTokens->geomSubset ) {
499+ continue ;
500+ }
501+ #endif
455502 _DirtyVisibilityRecursive (childPath, dirtiedEntries);
456503 }
457504}
0 commit comments