Loading...
Searching...
No Matches
stageSceneIndex.h
1//
2// Copyright 2022 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_USD_IMAGING_USD_IMAGING_STAGE_SCENE_INDEX_H
25#define PXR_USD_IMAGING_USD_IMAGING_STAGE_SCENE_INDEX_H
26
27#include "pxr/pxr.h"
28
29#include "pxr/usdImaging/usdImaging/api.h"
30#include "pxr/usdImaging/usdImaging/dataSourceStageGlobals.h"
31#include "pxr/usdImaging/usdImaging/types.h"
32
33#include "pxr/imaging/hd/sceneIndex.h"
34
35#include "pxr/usd/usd/notice.h"
36#include "pxr/usd/usd/stage.h"
37
38#include <mutex>
39#include <set>
40
41PXR_NAMESPACE_OPEN_SCOPE
42
43#define USDIMAGING_STAGE_SCENE_INDEX_TOKENS \
44 (includeUnloadedPrims) \
45
46TF_DECLARE_PUBLIC_TOKENS(UsdImagingStageSceneIndexTokens, USDIMAGING_API,
47 USDIMAGING_STAGE_SCENE_INDEX_TOKENS);
48
49using UsdImagingPrimAdapterSharedPtr =
50 std::shared_ptr<class UsdImagingPrimAdapter>;
51class UsdImaging_AdapterManager;
52
53TF_DECLARE_REF_PTRS(UsdImagingStageSceneIndex);
54
55class UsdImagingStageSceneIndex : public HdSceneIndexBase
56{
57public:
58 static UsdImagingStageSceneIndexRefPtr New(
59 HdContainerDataSourceHandle const &inputArgs = nullptr) {
60 return TfCreateRefPtr(new UsdImagingStageSceneIndex(inputArgs));
61 }
62
63 USDIMAGING_API
64 ~UsdImagingStageSceneIndex();
65
66 // ------------------------------------------------------------------------
67 // Scene index API
68
69 USDIMAGING_API
70 HdSceneIndexPrim GetPrim(const SdfPath & primPath) const override;
71
72 USDIMAGING_API
73 SdfPathVector GetChildPrimPaths(const SdfPath & primPath) const override;
74
75 // ------------------------------------------------------------------------
76 // App-facing API
77
78 // Set the USD stage to pull data from. Note that this will delete all
79 // scene index prims and reset stage global data.
80 USDIMAGING_API
81 void SetStage(UsdStageRefPtr stage);
82
83 // Set the time, and call PrimsDirtied for any time-varying attributes.
84 //
85 // PrimsDirtied is only called if the time is different from the last call
86 // or forceDirtyingTimeDeps is true.
87 USDIMAGING_API
88 void SetTime(UsdTimeCode time, bool forceDirtyingTimeDeps = false);
89
90 // Return the current time.
91 USDIMAGING_API
92 UsdTimeCode GetTime() const;
93
94 // Apply queued stage edits to imaging scene.
95 // If the USD stage is edited while the scene index is pulling from it,
96 // those edits get queued and deferred. Calling ApplyPendingUpdates will
97 // turn resync requests into PrimsAdded/PrimsRemoved, and property changes
98 // into PrimsDirtied.
99 USDIMAGING_API
100 void ApplyPendingUpdates();
101
102private:
103 USDIMAGING_API
104 UsdImagingStageSceneIndex(HdContainerDataSourceHandle const &inputArgs);
105
106 Usd_PrimFlagsConjunction _GetTraversalPredicate() const;
107
108 void _ApplyPendingResyncs();
109 void _ComputeDirtiedEntries(
110 const std::map<SdfPath, TfTokenVector> &pathToUsdProperties,
111 SdfPathVector * primPathsToResync,
112 UsdImagingPropertyInvalidationType invalidationType,
113 HdSceneIndexObserver::DirtiedPrimEntries * dirtiedPrims) const;
114
115 class _StageGlobals : public UsdImagingDataSourceStageGlobals
116 {
117 public:
118 // Datasource-facing API
119 void FlagAsTimeVarying(
120 const SdfPath & hydraPath,
121 const HdDataSourceLocator & locator) const override;
122
123 void FlagAsAssetPathDependent(
124 const SdfPath & usdPath) const override;
125
126 UsdTimeCode GetTime() const override;
127
128 // Scene index-facing API
129 void SetTime(UsdTimeCode time,
131
132 void RemoveAssetPathDependentsUnder(const SdfPath &path);
133
134 void InvalidateAssetPathDependentsUnder(
135 const SdfPath &path,
136 std::vector<SdfPath> *primsToInvalidate,
137 std::map<SdfPath, TfTokenVector> *propertiesToInvalidate) const;
138
139 void Clear();
140
141 private:
142 struct _PathHashCompare {
143 static bool equal(const SdfPath &a, const SdfPath &b) {
144 return a == b;
145 }
146 static size_t hash(const SdfPath &p) {
147 return hash_value(p);
148 }
149 };
150 using _VariabilityMap = tbb::concurrent_hash_map<SdfPath,
151 HdDataSourceLocatorSet, _PathHashCompare>;
152 mutable _VariabilityMap _timeVaryingLocators;
153
154 using _AssetPathDependentsSet = std::set<SdfPath>;
155 mutable _AssetPathDependentsSet _assetPathDependents;
156 mutable std::mutex _assetPathDependentsMutex;
157
158 UsdTimeCode _time;
159 };
160
161 const bool _includeUnloadedPrims;
162
163 UsdStageRefPtr _stage;
164 _StageGlobals _stageGlobals;
165
166 // Population
167 void _Populate();
168 void _PopulateSubtree(UsdPrim subtreeRoot);
169
170 // Edit processing
171 void _OnUsdObjectsChanged(UsdNotice::ObjectsChanged const& notice,
172 UsdStageWeakPtr const& sender);
173 TfNotice::Key _objectsChangedNoticeKey;
174
175 // Note: resync paths mean we remove the whole subtree and repopulate.
176 SdfPathVector _usdPrimsToResync;
177 // Property changes get converted into PrimsDirtied messages.
178 std::map<SdfPath, TfTokenVector> _usdPropertiesToUpdate;
179 std::map<SdfPath, TfTokenVector> _usdPropertiesToResync;
180
181 using _PrimAdapterPair = std::pair<UsdPrim, UsdImagingPrimAdapterSharedPtr>;
182 _PrimAdapterPair _FindResponsibleAncestor(const UsdPrim &prim) const;
183
184 std::unique_ptr<UsdImaging_AdapterManager> const _adapterManager;
185};
186
187PXR_NAMESPACE_CLOSE_SCOPE
188
189#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:65
virtual SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const =0
Returns the paths of all scene index prims located immediately below primPath.
virtual HdSceneIndexPrim GetPrim(const SdfPath &primPath) const =0
Returns a pair of (prim type, datasource) for the object at primPath.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Handle-object returned by TfNotice::Register().
Definition: notice.h:256
This class is used as a context object with global stage information, that gets passed down to dataso...
Notice sent in response to authored changes that affect UsdObjects.
Definition: notice.h:128
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:134
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:84
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:98
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:52
size_t hash_value(const TfToken &x)
Overload hash_value for TfToken.
Definition: token.h:454