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 
38 
50 {
51 public:
52 
55  static HdFlatteningSceneIndexRefPtr New(
56  const HdSceneIndexBaseRefPtr &inputScene) {
57  return TfCreateRefPtr(new HdFlatteningSceneIndex(inputScene));
58  }
59 
60  HD_API
61  ~HdFlatteningSceneIndex() override;
62 
63  // satisfying HdSceneIndexBase
64  HD_API
65  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
66 
67  HD_API
68  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
69 
70 protected:
71 
72  HD_API
73  HdFlatteningSceneIndex(const HdSceneIndexBaseRefPtr &inputScene);
74 
75  // satisfying HdSingleInputFilteringSceneIndexBase
76  void _PrimsAdded(
77  const HdSceneIndexBase &sender,
78  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
79 
80  void _PrimsRemoved(
81  const HdSceneIndexBase &sender,
82  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
83 
84  void _PrimsDirtied(
85  const HdSceneIndexBase &sender,
86  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
87 private:
88 
89  // members
90  struct _PrimEntry
91  {
92  HdSceneIndexPrim prim;
93  };
94 
95  using _PrimEntryTable = SdfPathTable<_PrimEntry>;
96  _PrimEntryTable _prims;
97 
98  HdContainerDataSourceHandle _identityXform;
99  HdContainerDataSourceHandle _identityVis;
100  HdContainerDataSourceHandle _identityPurpose;
101  HdTokenDataSourceHandle _identityDrawMode;
102 
103  // methods
104  void _DirtyHierarchy(
105  const SdfPath &primPath,
106  const HdDataSourceLocatorSet &dirtyLocators,
108 
109  // ------------------------------------------------------------------------
110 
111  friend class _PrimLevelWrappingDataSource;
112 
115  class _PrimLevelWrappingDataSource : public HdContainerDataSource
116  {
117  public:
118  HD_DECLARE_DATASOURCE(_PrimLevelWrappingDataSource);
119 
120  _PrimLevelWrappingDataSource(
121  const HdFlatteningSceneIndex &scene,
122  const SdfPath &primPath,
123  HdContainerDataSourceHandle inputDataSource);
124 
125  void UpdateInputDataSource(HdContainerDataSourceHandle inputDataSource);
126 
127  bool PrimDirtied(const HdDataSourceLocatorSet &locators);
128 
129  bool Has(const TfToken &name) override;
130  TfTokenVector GetNames() override;
131  HdDataSourceBaseHandle Get(const TfToken &name) override;
132 
133  private:
134  HdDataSourceBaseHandle _GetXform();
135  HdDataSourceBaseHandle _GetVis();
136  HdDataSourceBaseHandle _GetPurpose();
137  HdDataSourceBaseHandle _GetModel();
138  HdDataSourceBaseHandle _GetDrawMode(
139  const HdContainerDataSourceHandle &model);
140  HdTokenDataSourceHandle _GetDrawModeUncached(
141  const HdContainerDataSourceHandle &model);
142  HdDataSourceBaseHandle _GetMaterialBinding();
143  HdDataSourceBaseHandle _GetMaterialBindingUncached();
144  HdDataSourceBaseHandle _GetInstancedBy();
145  HdDataSourceBaseHandle _GetInstancedByUncached();
146 
147  const HdFlatteningSceneIndex &_sceneIndex;
148  SdfPath _primPath;
149  HdContainerDataSourceHandle _inputDataSource;
150  HdContainerDataSourceAtomicHandle _computedXformDataSource;
151  HdContainerDataSourceAtomicHandle _computedVisDataSource;
152  HdContainerDataSourceAtomicHandle _computedPurposeDataSource;
153  HdTokenDataSource::AtomicHandle _computedDrawModeDataSource;
154 
155  // Stored as a base rather than a container so we can use cast to
156  // distinguish between a cached value and the absence of a cached value.
157  // Internally, this is set to a retained bool=false data source to
158  // indicate that no binding is present.
159  HdDataSourceBaseAtomicHandle _computedMaterialBindingDataSource;
160  HdDataSourceBaseAtomicHandle _computedInstancedByDataSource;
161  };
162 
163  HD_DECLARE_DATASOURCE_HANDLES(_PrimLevelWrappingDataSource);
164 
165 };
166 
167 PXR_NAMESPACE_CLOSE_SCOPE
168 
169 #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:102
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
static HdFlatteningSceneIndexRefPtr New(const HdSceneIndexBaseRefPtr &inputScene)
Creates a new flattening scene index.
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...
#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,...