flatteningSceneIndex.h
1 //
2 // Copyright 2021 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_IMAGING_HD_FLATTENING_SCENE_H
25 #define PXR_IMAGING_HD_FLATTENING_SCENE_H
26 
27 #include "pxr/imaging/hd/api.h"
28 
29 #include "pxr/imaging/hd/dataSourceTypeDefs.h"
30 #include "pxr/imaging/hd/filteringSceneIndex.h"
31 
32 #include "pxr/usd/sdf/pathTable.h"
33 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
37 
49 {
50 public:
51 
54  static HdFlatteningSceneIndexRefPtr New(
55  HdSceneIndexBaseRefPtr const &inputScene,
56  HdContainerDataSourceHandle const &inputArgs = nullptr) {
57  return TfCreateRefPtr(
58  new HdFlatteningSceneIndex(inputScene, inputArgs));
59  }
60 
61  HD_API
62  ~HdFlatteningSceneIndex() override;
63 
64  // satisfying HdSceneIndexBase
65  HD_API
66  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
67 
68  HD_API
69  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
70 
71 protected:
72 
73  HD_API
75  HdSceneIndexBaseRefPtr const &inputScene,
76  HdContainerDataSourceHandle const &inputArgs);
77 
78  // satisfying HdSingleInputFilteringSceneIndexBase
79  void _PrimsAdded(
80  const HdSceneIndexBase &sender,
81  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
82 
83  void _PrimsRemoved(
84  const HdSceneIndexBase &sender,
85  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
86 
87  void _PrimsDirtied(
88  const HdSceneIndexBase &sender,
89  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
90 private:
91  // members
92  struct _PrimEntry
93  {
94  HdSceneIndexPrim prim;
95  };
96 
97  using _PrimEntryTable = SdfPathTable<_PrimEntry>;
98  _PrimEntryTable _prims;
99 
100  bool _flattenXform;
101  bool _flattenVisibility;
102  bool _flattenPurpose;
103  bool _flattenModel;
104  bool _flattenMaterialBinding;
105  TfTokenVector _dataSourceNames;
106 
107  HdContainerDataSourceHandle _identityXform;
108  HdContainerDataSourceHandle _identityVis;
109  HdContainerDataSourceHandle _identityPurpose;
110  HdTokenDataSourceHandle _identityDrawMode;
111 
112  // methods
113  void _FillPrimsRecursively(const SdfPath &primPath);
114 
115  void _DirtyHierarchy(
116  const SdfPath &primPath,
117  const HdDataSourceLocatorSet &dirtyLocators,
119 
120  // ------------------------------------------------------------------------
121 
122  friend class _PrimLevelWrappingDataSource;
123 
126  class _PrimLevelWrappingDataSource : public HdContainerDataSource
127  {
128  public:
129  HD_DECLARE_DATASOURCE(_PrimLevelWrappingDataSource);
130 
131  _PrimLevelWrappingDataSource(
132  const HdFlatteningSceneIndex &scene,
133  const SdfPath &primPath,
134  HdContainerDataSourceHandle inputDataSource);
135 
136  void UpdateInputDataSource(HdContainerDataSourceHandle inputDataSource);
137 
138  bool PrimDirtied(const HdDataSourceLocatorSet &locators);
139 
140  TfTokenVector GetNames() override;
141  HdDataSourceBaseHandle Get(const TfToken &name) override;
142 
143  private:
144  HdDataSourceBaseHandle _GetXform();
145  HdDataSourceBaseHandle _GetVis();
146  HdDataSourceBaseHandle _GetPurpose();
147  HdDataSourceBaseHandle _GetModel();
148  HdDataSourceBaseHandle _GetDrawMode(
149  const HdContainerDataSourceHandle &model);
150  HdTokenDataSourceHandle _GetDrawModeUncached(
151  const HdContainerDataSourceHandle &model);
152  HdDataSourceBaseHandle _GetMaterialBinding();
153  HdDataSourceBaseHandle _GetMaterialBindingUncached();
154 
155  const HdFlatteningSceneIndex &_sceneIndex;
156  SdfPath _primPath;
157  HdContainerDataSourceHandle _inputDataSource;
158  HdContainerDataSourceAtomicHandle _computedXformDataSource;
159  HdContainerDataSourceAtomicHandle _computedVisDataSource;
160  HdContainerDataSourceAtomicHandle _computedPurposeDataSource;
161  HdTokenDataSource::AtomicHandle _computedDrawModeDataSource;
162 
163  // Stored as a base rather than a container so we can use cast to
164  // distinguish between a cached value and the absence of a cached value.
165  // Internally, this is set to a retained bool=false data source to
166  // indicate that no binding is present.
167  HdDataSourceBaseAtomicHandle _computedMaterialBindingDataSource;
168  };
169 
170  HD_DECLARE_DATASOURCE_HANDLES(_PrimLevelWrappingDataSource);
171 
172 };
173 
174 PXR_NAMESPACE_CLOSE_SCOPE
175 
176 #endif
An abstract base class for a filtering scene index that observes a single input scene index.
HD_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Returns the paths of all scene index prims located immediately below primPath.
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
Definition: dataSource.h:110
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:49
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
Abstract interface to scene data.
Definition: sceneIndex.h:62
Represents a set of data source locators closed under descendancy.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
HD_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource) for the object at primPath.
A scene index that observes an input scene index and produces a comparable scene in which inherited s...
static HdFlatteningSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputScene, HdContainerDataSourceHandle const &inputArgs=nullptr)
Creates a new flattening scene index.
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
static HD_API HdDataSourceBaseHandle Get(const Handle &container, const HdDataSourceLocator &locator)
A convenience function: given container, return the descendant identified by locator,...