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
26#define USDIMAGING_STAGE_SCENE_INDEX_TOKENS \
27 (includeUnloadedPrims) \
28
29TF_DECLARE_PUBLIC_TOKENS(UsdImagingStageSceneIndexTokens, USDIMAGING_API,
30 USDIMAGING_STAGE_SCENE_INDEX_TOKENS);
31
32using UsdImagingPrimAdapterSharedPtr =
33 std::shared_ptr<class UsdImagingPrimAdapter>;
34class UsdImaging_AdapterManager;
35
37
47{
48public:
49 static UsdImagingStageSceneIndexRefPtr New(
50 HdContainerDataSourceHandle const &inputArgs = nullptr) {
51 return TfCreateRefPtr(new UsdImagingStageSceneIndex(inputArgs));
52 }
53
54 USDIMAGING_API
56
57 // ------------------------------------------------------------------------
58 // Scene index API
59
60 USDIMAGING_API
61 HdSceneIndexPrim GetPrim(const SdfPath & primPath) const override;
62
63 USDIMAGING_API
64 SdfPathVector GetChildPrimPaths(const SdfPath & primPath) const override;
65
66 // ------------------------------------------------------------------------
67 // App-facing API
68
69 // Set the USD stage to pull data from. Note that this will delete all
70 // scene index prims and reset stage global data.
71 USDIMAGING_API
72 void SetStage(UsdStageRefPtr stage);
73
74 // Set the time, and call PrimsDirtied for any time-varying attributes.
75 //
76 // PrimsDirtied is only called if the time is different from the last call
77 // or forceDirtyingTimeDeps is true.
78 USDIMAGING_API
79 void SetTime(UsdTimeCode time, bool forceDirtyingTimeDeps = false);
80
81 // Return the current time.
82 USDIMAGING_API
83 UsdTimeCode GetTime() const;
84
85 // Apply queued stage edits to imaging scene.
86 // If the USD stage is edited while the scene index is pulling from it,
87 // those edits get queued and deferred. Calling ApplyPendingUpdates will
88 // turn resync requests into PrimsAdded/PrimsRemoved, and property changes
89 // into PrimsDirtied.
90 USDIMAGING_API
91 void ApplyPendingUpdates();
92
93private:
94 USDIMAGING_API
95 UsdImagingStageSceneIndex(HdContainerDataSourceHandle const &inputArgs);
96
97 Usd_PrimFlagsPredicate _GetPrimPredicate() const;
98
99 void _ApplyPendingResyncs();
100 void _ComputeDirtiedEntries(
101 const std::map<SdfPath, TfTokenVector> &pathToUsdProperties,
102 SdfPathVector * primPathsToResync,
103 UsdImagingPropertyInvalidationType invalidationType,
104 HdSceneIndexObserver::DirtiedPrimEntries * dirtiedPrims) const;
105
106 class _StageGlobals : public UsdImagingDataSourceStageGlobals
107 {
108 public:
109 // Datasource-facing API
110 void FlagAsTimeVarying(
111 const SdfPath & hydraPath,
112 const HdDataSourceLocator & locator) const override;
113
114 void FlagAsAssetPathDependent(
115 const SdfPath & usdPath) const override;
116
117 UsdTimeCode GetTime() const override;
118
119 // Scene index-facing API
120 void SetTime(UsdTimeCode time,
122
123 void RemoveAssetPathDependentsUnder(const SdfPath &path);
124
125 void InvalidateAssetPathDependentsUnder(
126 const SdfPath &path,
127 std::vector<SdfPath> *primsToInvalidate,
128 std::map<SdfPath, TfTokenVector> *propertiesToInvalidate) const;
129
130 void Clear();
131
132 private:
133 struct _PathHashCompare {
134 static bool equal(const SdfPath &a, const SdfPath &b) {
135 return a == b;
136 }
137 static size_t hash(const SdfPath &p) {
138 return hash_value(p);
139 }
140 };
141 using _VariabilityMap = tbb::concurrent_hash_map<SdfPath,
142 HdDataSourceLocatorSet, _PathHashCompare>;
143 mutable _VariabilityMap _timeVaryingLocators;
144
145 using _AssetPathDependentsSet = std::set<SdfPath>;
146 mutable _AssetPathDependentsSet _assetPathDependents;
147 mutable std::mutex _assetPathDependentsMutex;
148
149 UsdTimeCode _time;
150 };
151
152 const bool _includeUnloadedPrims;
153
154 UsdStageRefPtr _stage;
155 _StageGlobals _stageGlobals;
156
157 // Population
158 void _Populate();
159 void _PopulateSubtree(UsdPrim subtreeRoot,
161
162 // Edit processing
163 void _OnUsdObjectsChanged(UsdNotice::ObjectsChanged const& notice,
164 UsdStageWeakPtr const& sender);
165 TfNotice::Key _objectsChangedNoticeKey;
166
167 // Keep track of populated paths for use in _ApplyPendingResyncs().
168 SdfPathSet _populatedPaths;
169
170 // Note: resync paths mean we remove the whole subtree and repopulate.
171 SdfPathVector _usdPrimsToResync;
172 // Property changes get converted into PrimsDirtied messages.
173 std::map<SdfPath, TfTokenVector> _usdPropertiesToUpdate;
174 std::map<SdfPath, TfTokenVector> _usdPropertiesToResync;
175
176 using _PrimAdapterPair = std::pair<UsdPrim, UsdImagingPrimAdapterSharedPtr>;
177 _PrimAdapterPair _FindResponsibleAncestor(const UsdPrim &prim) const;
178
179 std::unique_ptr<UsdImaging_AdapterManager> const _adapterManager;
180};
181
182PXR_NAMESPACE_CLOSE_SCOPE
183
184#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:54
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:280
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 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).
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
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:92
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:35
size_t hash_value(const TfToken &x)
Overload hash_value for TfToken.
Definition: token.h:437