generativeProcedural.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_IMAGING_HD_GP_GENERATIVE_PROCEDURAL_H
25 #define PXR_IMAGING_HD_GP_GENERATIVE_PROCEDURAL_H
26 
27 #include "pxr/imaging/hd/sceneIndex.h"
29 
30 PXR_NAMESPACE_OPEN_SCOPE
31 
32 #define HDGPGENERATIVEPROCEDURAL_TOKENS \
33  ((generativeProcedural, "hydraGenerativeProcedural")) \
34  ((proceduralType, "hdGp:proceduralType")) \
35 
36 TF_DECLARE_PUBLIC_TOKENS(HdGpGenerativeProceduralTokens,
37  HDGPGENERATIVEPROCEDURAL_TOKENS);
38 
49 {
50 public:
51  HdGpGenerativeProcedural(const SdfPath &proceduralPrimPath);
52  virtual ~HdGpGenerativeProcedural();
53 
54  using DependencyMap =
56 
57  using ChildPrimTypeMap =
59 
60  // Given access to the input scene (specifically the primvars serving as
61  // arguments on the procedural's own prim), return what other data sources
62  // of what other prims we depend upon and should be given the opportunity
63  // to update in response their changes.
64  //
65  // For a single instance, UpdateDependencies will not be called from
66  // multiple threads -- nor concurrent to Update
67  virtual DependencyMap UpdateDependencies(
68  const HdSceneIndexBaseRefPtr &inputScene) = 0;
69 
70  // This is the primary "cook" method called when a procedural is initially
71  // resolved or invalidated. The result is a map of child prim paths and
72  // their hydra scene prim types. Because a cook/recook can add, remove or
73  // dirty child prims, the returned ChildPrimTypeMap must always contain
74  // the full set of child prims. It is interpreted in this way:
75  // 1) Prims which did not exist in the result of
76  // of previous calls to this method will be added.
77  // 2) Prims which existed in the results of previous calls but not in this
78  // result will be removed.
79  // 3) Prims whose type has changed between calls to this method will be
80  // re-added.
81  //
82  // Prims which exist in both (and have not changed type) are not considered
83  // dirty unless added to the outputDirtiedPrims vector. Because each entry
84  // in that vector contains an HdDataSourceLocatorSet, invalidation can be
85  // as broad or specific as possible. In order to reduce the amount of
86  // bookkeeping for the procedural itself, previousResult contains the
87  // result of the previous call to this method.
88  //
89  // dirtiedDependencies contains the prim paths and locator sets of
90  // declared dependencies which have been dirtied since the last cook. For
91  // initial cooks (and in response to things like removal of prims previously
92  // dependeded upon), the full set of declared dependencies is sent here. A
93  // procedural may choose to cache values previously queried from the input
94  // scene and invalidate based on the contents of dirtiedDependencies.
95  //
96  // NOTE: For initial cooks, changes to the procedural's own prim will not
97  // be included within dirtiedDependencies. (TODO: reconsider this.)
98  //
99  // ALSO NOTE: Because this method is responsible only for describing the
100  // presence and type (and potential dirtiness) of its child
101  // prims -- and not the data sources for those prims -- it may
102  // choose to defer some computation of values to happen within
103  // data sources returned by GetChildPrim.
104  //
105  // For a single instance, Update will not be called from
106  // multiple threads -- nor concurrent to UpdateDependencies
107  virtual ChildPrimTypeMap Update(
108  const HdSceneIndexBaseRefPtr &inputScene,
109  const ChildPrimTypeMap &previousResult,
110  const DependencyMap &dirtiedDependencies,
111  HdSceneIndexObserver::DirtiedPrimEntries *outputDirtiedPrims) = 0;
112 
113  // Returns the type and prim-level data source for a child prim previously
114  // added or invalidated from the Update method.
115  //
116  // This should expect to be called from multiple threads
117  virtual HdSceneIndexPrim GetChildPrim(
118  const HdSceneIndexBaseRefPtr &inputScene,
119  const SdfPath &childPrimPath) = 0;
120 
121 protected:
122  const SdfPath &_GetProceduralPrimPath();
123 
124 private:
125  const SdfPath _proceduralPrimPath;
126 };
127 
128 PXR_NAMESPACE_CLOSE_SCOPE
129 
130 #endif
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:49
HdGpGenerativeProcedural is the base class for procedurals which have full access to an input scene i...
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290