Loading...
Searching...
No Matches
coordSysPrimSceneIndex.h
1//
2// Copyright 2023 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_IMAGING_HDSI_COORD_SYS_PRIM_SCENE_INDEX_H
8#define PXR_IMAGING_HDSI_COORD_SYS_PRIM_SCENE_INDEX_H
9
10#include "pxr/imaging/hdsi/api.h"
11
12#include "pxr/imaging/hd/filteringSceneIndex.h"
13
14PXR_NAMESPACE_OPEN_SCOPE
15
17
63{
64public:
65
68 static HdsiCoordSysPrimSceneIndexRefPtr New(
69 HdSceneIndexBaseRefPtr const &inputScene)
70 {
71 return TfCreateRefPtr(
72 new HdsiCoordSysPrimSceneIndex(inputScene));
73 }
74
75 HDSI_API
76 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
77
78 HDSI_API
79 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
80
81protected:
82
83 HDSI_API
85 HdSceneIndexBaseRefPtr const &inputScene);
86
87 // satisfying HdSingleInputFilteringSceneIndexBase
88 void _PrimsAdded(
89 const HdSceneIndexBase &sender,
90 const HdSceneIndexObserver::AddedPrimEntries &entries) override;
91
92 void _PrimsRemoved(
93 const HdSceneIndexBase &sender,
94 const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
95
96 void _PrimsDirtied(
97 const HdSceneIndexBase &sender,
98 const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
99
100 struct _Binding
101 {
102 TfToken name;
103 SdfPath path;
104 };
105 using _Bindings = std::vector<_Binding>;
106 using _PrimToBindings = std::map<SdfPath, _Bindings>;
107
108 // Record coordSys bindings of prim at primPath. That is, add entries to the
109 // below data structures if needed and increase ref-counts.
110 // Optionally, return prims of type coord system that this scene index needs
111 // to add.
112 void _AddBindingsForPrim(const SdfPath &primPath,
113 SdfPathSet * addedCoordSysPrims = nullptr);
114 // Remove coordSys bindings. That is, decrease ref-counts and remove entries
115 // from below data structures if needed.
116 // Optionally, return prims of type coord system that this scene index needs
117 // to remove.
118 void _RemoveBindings(const _Bindings &bindings,
119 SdfPathSet * removedCoordSysPrims);
120 // Similar to above, but give the prim path explicitly to look-up bindings
121 // in map.
122 void _RemoveBindingsForPrim(const SdfPath &primPath,
123 SdfPathSet * removedCoordSysPrims);
124 // Removes bindings for given prim and all its descendants stored in below
125 // data structures.
126 void _RemoveBindingsForSubtree(const SdfPath &primPath,
127 SdfPathSet * removedCoordSysPrims);
128
129 // If path is for coord sys prim added by this scene index, give the
130 // prim source for it.
131 HdContainerDataSourceHandle _GetCoordSysPrimSource(
132 const SdfPath &primPath) const;
133
134private:
135 using _NameToRefCount =
136 std::unordered_map<TfToken, size_t, TfToken::HashFunctor>;
137 using _PrimToNameToRefCount =
138 std::unordered_map<SdfPath, _NameToRefCount, SdfPath::Hash>;
139 // Maps prim which is targeted by coord sys binding to name of binding to
140 // count how many bindings are referencing that prim using that name.
141 //
142 // We delete an inner entry when there is no longer any coord sys binding
143 // with that name targeting the prim.
144 // We delete a prim when it is no longer targeted by any binding.
145 //
146 // This map is used to determine which coord sys prims we need to create
147 // under the targeted prim.
148 //
149 //
150 // In the above example, the content of the map will be:
151 //
152 // {
153 // /MyXform: {
154 // FOO: 1
155 // }
156 // }
157 //
158 _PrimToNameToRefCount _targetedPrimToNameToRefCount;
159
160 // Maps prim to the coord sys bindings of that prim.
161 //
162 // Used to decrease ref counts when a prim gets deleted or modified.
163 //
164 // In the above example, the content of the map will be:
165 //
166 // { /MyPrim: [(FOO, /MyXform)] }
167 //
168 _PrimToBindings _primToBindings;
169};
170
171PXR_NAMESPACE_CLOSE_SCOPE
172
173#endif
Abstract interface to scene data.
Definition: sceneIndex.h:54
An abstract base class for a filtering scene index that observes a single input scene index.
If prim P has a coord sys binding FOO to another prim Q, the scene index will add a coord sys prim Q....
HDSI_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource).
static HdsiCoordSysPrimSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputScene)
Creates a new coord sys prim scene index.
HDSI_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Returns the paths of all scene index prims located immediately below primPath.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
#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:35