HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
generativeProceduralFilteringSceneIndex.h
Go to the documentation of this file.
1 //
2 // Copyright 2024 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_HD_GP_GENERATIVE_PROCEDURAL_FILTERING_SCENE_INDEX_H
8 #define PXR_IMAGING_HD_GP_GENERATIVE_PROCEDURAL_FILTERING_SCENE_INDEX_H
9 
12 #include "pxr/usd/sdf/pathTable.h"
13 
14 #include <optional>
15 
17 
20 
21 /// \class HdGpGenerativeProceduralFilteringSceneIndex
22 ///
23 /// HdGpGenerativeProceduralFilteringSceneIndex is a scene index which
24 /// filters prims representing generative procedurals within its incoming
25 /// scene against a requested pattern.
26 ///
27 /// Typically, this scene index re-types (to its observers) any procedural prim
28 /// it filters to the type "skippedGenerativeProcedural" and ones that are
29 /// allowed will have their types remain the same. This scene index can also
30 /// be configured to have specific primTypes for procedurals that are skipped
31 /// or allowed.
32 ///
33 /// The hydra prim type used to identify generative procedurals can be
34 /// configured per instance of this scene index to allow for a pipeline to
35 /// stage when certain procedural prims are resolved within the chain of scene
36 /// indicies. By default that type is "generativeProcedural".
37 ///
40 {
41 public:
42  static HdGpGenerativeProceduralFilteringSceneIndexRefPtr New(
43  const HdSceneIndexBaseRefPtr &inputScene,
44  const TfTokenVector &allowedProceduralTypes) {
45  return TfCreateRefPtr(
47  inputScene, allowedProceduralTypes));
48  }
49 
50  /// This constructs a filtering scene index that will try to filter prims of
51  /// type \p targetPrimType. For each prim of this type,
52  /// \p allowedProceduralTypes will be used to determined if the procedural
53  /// is "allowed" or "skipped".
54  ///
55  /// Prims that are not of type \p targetPrimType are left alone.
56  ///
57  /// If \p allowedPrimTypeName is specified, then "allowed" prims will have
58  /// their type set to that. Otherwise, it will be set to \p targetPrimType.
59  ///
60  /// If \p skippedPrimTypeName is specified, then "skipped" prims will have
61  /// their type set to that. Otherwise, it will be set to
62  /// "skippedGenerativeProcedural".
63  static HdGpGenerativeProceduralFilteringSceneIndexRefPtr New(
64  const HdSceneIndexBaseRefPtr &inputScene,
65  const TfTokenVector &allowedProceduralTypes,
66  const std::optional<TfToken> &targetPrimTypeName,
67  const std::optional<TfToken> &allowedPrimTypeName,
68  const std::optional<TfToken> &skippedPrimTypeName) {
69  return TfCreateRefPtr(
71  inputScene, allowedProceduralTypes, targetPrimTypeName,
72  allowedPrimTypeName, skippedPrimTypeName));
73  }
74 
75  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
76  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
77 
78 private:
80  const HdSceneIndexBaseRefPtr &inputScene,
81  const TfTokenVector &allowedProceduralTypes);
83  const HdSceneIndexBaseRefPtr &inputScene,
84  const TfTokenVector &allowedProceduralTypes,
85  const std::optional<TfToken> &targetPrimTypeName,
86  const std::optional<TfToken> &allowedPrimTypeName,
87  const std::optional<TfToken> &skippedPrimTypeName);
88 
89  void _PrimsAdded(
90  const HdSceneIndexBase &sender,
91  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
92  void _PrimsRemoved(
93  const HdSceneIndexBase &sender,
94  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
95  void _PrimsDirtied(
96  const HdSceneIndexBase &sender,
97  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
98 
99  TfToken _GetProceduralType(HdSceneIndexPrim const& prim) const;
100 
101  enum class _ShouldSkipResult {
102  Ignore = 0,
103  Skip,
104  Allow,
105  };
106  _ShouldSkipResult _ShouldSkipPrim(HdSceneIndexPrim const& prim) const;
107 
108  const TfTokenVector _allowedProceduralTypes;
109  const TfToken _targetPrimTypeName;
110 
111  TfToken _allowedPrimTypeName;
112  TfToken _skippedPrimTypeName;
113 };
114 
116 
117 #endif
static HdGpGenerativeProceduralFilteringSceneIndexRefPtr New(const HdSceneIndexBaseRefPtr &inputScene, const TfTokenVector &allowedProceduralTypes)
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1190
TF_DECLARE_REF_PTRS(HdGpGenerativeProceduralFilteringSceneIndex)
SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
static HdGpGenerativeProceduralFilteringSceneIndexRefPtr New(const HdSceneIndexBaseRefPtr &inputScene, const TfTokenVector &allowedProceduralTypes, const std::optional< TfToken > &targetPrimTypeName, const std::optional< TfToken > &allowedPrimTypeName, const std::optional< TfToken > &skippedPrimTypeName)
Definition: token.h:70
std::vector< class SdfPath > SdfPathVector
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:273
HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74