Loading...
Searching...
No Matches
stageSceneIndex.h
1//
2// Copyright 2022 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_IMAGING_USD_IMAGING_STAGE_SCENE_INDEX_H
8#define PXR_USD_IMAGING_USD_IMAGING_STAGE_SCENE_INDEX_H
9
10#include "pxr/pxr.h"
11
12#include "pxr/usdImaging/usdImaging/api.h"
13#include "pxr/usdImaging/usdImaging/dataSourceStageGlobals.h"
14#include "pxr/usdImaging/usdImaging/types.h"
15
16#include "pxr/imaging/hd/sceneIndex.h"
17
18#include "pxr/usd/usd/notice.h"
19#include "pxr/usd/usd/stage.h"
20
21#include <mutex>
22#include <set>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
26using UsdImagingPrimAdapterSharedPtr =
27 std::shared_ptr<class UsdImagingPrimAdapter>;
28class UsdImaging_AdapterManager;
29
31
41{
42public:
43 static UsdImagingStageSceneIndexRefPtr New(
44 HdContainerDataSourceHandle const &inputArgs = nullptr) {
45 return TfCreateRefPtr(new UsdImagingStageSceneIndex(inputArgs));
46 }
47
48 USDIMAGING_API
50
51 // ------------------------------------------------------------------------
52 // Scene index API
53
54 USDIMAGING_API
55 HdSceneIndexPrim GetPrim(const SdfPath & primPath) const override;
56
57 USDIMAGING_API
58 SdfPathVector GetChildPrimPaths(const SdfPath & primPath) const override;
59
62
66 USDIMAGING_API
67 void SetStage(UsdStageRefPtr stage);
68
73 USDIMAGING_API
74 void SetTime(UsdTimeCode time, bool forceDirtyingTimeDeps = false);
75
77 USDIMAGING_API
79
85 USDIMAGING_API
87
89
90private:
91 USDIMAGING_API
92 UsdImagingStageSceneIndex(HdContainerDataSourceHandle const &inputArgs);
93
94 Usd_PrimFlagsPredicate _GetPrimPredicate() const;
95
96 void _ApplyPendingResyncs();
97 void _ComputeDirtiedEntries(
98 const std::map<SdfPath, TfTokenVector> &pathToUsdProperties,
99 SdfPathVector * primPathsToResync,
100 UsdImagingPropertyInvalidationType invalidationType,
101 HdSceneIndexObserver::DirtiedPrimEntries * dirtiedPrims) const;
102
103 class _StageGlobals : public UsdImagingDataSourceStageGlobals
104 {
105 public:
106 // Datasource-facing API
107 void FlagAsTimeVarying(
108 const SdfPath & hydraPath,
109 const HdDataSourceLocator & locator) const override;
110
111 void FlagAsAssetPathDependent(
112 const SdfPath & usdPath) const override;
113
114 UsdTimeCode GetTime() const override;
115
116 // Scene index-facing API
117 void SetTime(UsdTimeCode time,
119
120 void RemoveAssetPathDependentsUnder(const SdfPath &path);
121
122 void InvalidateAssetPathDependentsUnder(
123 const SdfPath &path,
124 std::vector<SdfPath> *primsToInvalidate,
125 std::map<SdfPath, TfTokenVector> *propertiesToInvalidate) const;
126
127 void Clear();
128
129 private:
130 struct _PathHashCompare {
131 static bool equal(const SdfPath &a, const SdfPath &b) {
132 return a == b;
133 }
134 static size_t hash(const SdfPath &p) {
135 return hash_value(p);
136 }
137 };
138 using _VariabilityMap = tbb::concurrent_hash_map<SdfPath,
139 HdDataSourceLocatorSet, _PathHashCompare>;
140 mutable _VariabilityMap _timeVaryingLocators;
141
142 using _AssetPathDependentsSet = std::set<SdfPath>;
143 mutable _AssetPathDependentsSet _assetPathDependents;
144 mutable std::mutex _assetPathDependentsMutex;
145
146 UsdTimeCode _time;
147 };
148
149 const bool _includeUnloadedPrims;
150
151 UsdStageRefPtr _stage;
152 _StageGlobals _stageGlobals;
153
154 // Population
155 void _Populate();
156 void _PopulateSubtree(UsdPrim subtreeRoot,
158
159 // Edit processing
160 void _OnUsdObjectsChanged(UsdNotice::ObjectsChanged const& notice,
161 UsdStageWeakPtr const& sender);
162 TfNotice::Key _objectsChangedNoticeKey;
163
164 // Keep track of populated paths for use in _ApplyPendingResyncs().
165 SdfPathSet _populatedPaths;
166
167 // Note: resync paths mean we remove the whole subtree and repopulate.
168 SdfPathVector _usdPrimsToResync;
169 // Property changes get converted into PrimsDirtied messages.
170 std::map<SdfPath, TfTokenVector> _usdPropertiesToUpdate;
171 std::map<SdfPath, TfTokenVector> _usdPropertiesToResync;
172
173 using _PrimAdapterPair = std::pair<UsdPrim, UsdImagingPrimAdapterSharedPtr>;
174 _PrimAdapterPair _FindResponsibleAncestor(const UsdPrim &prim) const;
175
176 std::unique_ptr<UsdImaging_AdapterManager> const _adapterManager;
177};
178
179PXR_NAMESPACE_CLOSE_SCOPE
180
181#endif
Represents an object that can identify the location of a data source.
Represents a set of data source locators closed under descendancy.
Abstract interface to scene data.
Definition: sceneIndex.h:55
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:281
Handle-object returned by TfNotice::Register().
Definition: notice.h:243
This class is used as a context object with global stage information, that gets passed down to dataso...
A scene index consuming a UsdStage.
USDIMAGING_API UsdTimeCode GetTime() const
Return the current time.
USDIMAGING_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Returns the paths of all scene index prims located immediately below primPath.
USDIMAGING_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource).
USDIMAGING_API void SetStage(UsdStageRefPtr stage)
Set the USD stage to pull data from.
USDIMAGING_API void SetTime(UsdTimeCode time, bool forceDirtyingTimeDeps=false)
Set the time, and call PrimsDirtied for any time-varying attributes.
USDIMAGING_API void ApplyPendingUpdates()
Apply queued stage edits to imaging scene.
Notice sent in response to authored changes that affect UsdObjects.
Definition: notice.h:111
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:72
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:58
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:36
size_t hash_value(const TfToken &x)
Overload hash_value for TfToken.
Definition: token.h:437