HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
instancerTopologySchema.h
Go to the documentation of this file.
1 //
2 // Copyright 2023 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 ////////////////////////////////////////////////////////////////////////
25 
26 /* ************************************************************************** */
27 /* ** This file is generated by a script. Do not edit directly. Edit ** */
28 /* ** defs.py or the (*)Schema.template.h files to make changes. ** */
29 /* ************************************************************************** */
30 
31 #ifndef PXR_IMAGING_HD_INSTANCER_TOPOLOGY_SCHEMA_H
32 #define PXR_IMAGING_HD_INSTANCER_TOPOLOGY_SCHEMA_H
33 
34 #include "pxr/imaging/hd/api.h"
35 
36 #include "pxr/imaging/hd/schema.h"
37 
39 
40 //-----------------------------------------------------------------------------
41 
42 #define HDINSTANCERTOPOLOGY_SCHEMA_TOKENS \
43  (instancerTopology) \
44  (prototypes) \
45  (instanceIndices) \
46  (mask) \
47  (instanceLocations) \
48 
49 TF_DECLARE_PUBLIC_TOKENS(HdInstancerTopologySchemaTokens, HD_API,
51 
52 //-----------------------------------------------------------------------------
53 
54 // Since the instancing schema is complicated:
55 //
56 // An instancer is a prim at a certain scenegraph location that causes other
57 // prims to be duplicated. The instancer can also hold instance-varying data
58 // like constant primvars or material relationships.
59 //
60 // The important things an instancer has is:
61 // 1.) Instancer topology, describing how exactly the prims are duplicated;
62 // 2.) Instance-rate data, meaning data that varies per instance, such as
63 // primvars or material bindings.
64 //
65 // If an instancer causes prims "/A" and "/B" to be duplicated, we encode that
66 // by setting prototypes = ["/A", "/B"]. Note that "/A" and "/B" can be
67 // subtrees, not direct gprims. instanceIndices encodes both multiplicity
68 // and position in arrays of instance-rate data, per prototype path; if
69 // instanceIndices = { [0,2], [1] }, then we draw /A twice (with instance
70 // primvar indices 0 and 2); and /B once (with instance primvar index 1).
71 // Mask is an auxiliary parameter that can be used to deactivate certain
72 // instances; mask = [true, true, false] would disable the
73 // second copy of "/A". An empty mask array is the same as all-true.
74 //
75 // Scenes generally specify instancing in one of two ways:
76 // 1.) Explicit instancing: prim /Instancer wants to draw its subtree at
77 // an array of locations. This is a data expansion form.
78 // 2.) Implicit instancing: prims /X and /Y are marked as being identical,
79 // and scene load replaces them with a single prim and an instancer.
80 // This is a data coalescing form.
81 //
82 // For implicit instancing, we want to know the original paths of /X and /Y,
83 // for doing things like resolving inheritance. This is encoded in the
84 // "instanceLocations" path, while the prototype prims (e.g. /_Prototype/Cube,
85 // the deduplicated version of /X/Cube and /Y/Cube) is encoded in the
86 // "prototypes" path.
87 //
88 // For explicit instancing, the "instanceLocations" attribute is meaningless
89 // and should be left null.
90 
92 {
93 public:
94  HdInstancerTopologySchema(HdContainerDataSourceHandle container)
95  : HdSchema(container) {}
96 
97  //ACCESSORS
98 
99  HD_API
101  HD_API
103  HD_API
105  HD_API
107 
108  // RETRIEVING AND CONSTRUCTING
109 
110  /// Builds a container data source which includes the provided child data
111  /// sources. Parameters with nullptr values are excluded. This is a
112  /// low-level interface. For cases in which it's desired to define
113  /// the container with a sparse set of child fields, the Builder class
114  /// is often more convenient and readable.
115  HD_API
116  static HdContainerDataSourceHandle
118  const HdPathArrayDataSourceHandle &prototypes,
119  const HdVectorDataSourceHandle &instanceIndices,
121  const HdPathArrayDataSourceHandle &instanceLocations
122  );
123 
124  /// \class HdInstancerTopologySchema::Builder
125  ///
126  /// Utility class for setting sparse sets of child data source fields to be
127  /// filled as arguments into BuildRetained. Because all setter methods
128  /// return a reference to the instance, this can be used in the "builder
129  /// pattern" form.
130  class Builder
131  {
132  public:
133  HD_API
135  const HdPathArrayDataSourceHandle &prototypes);
136  HD_API
138  const HdVectorDataSourceHandle &instanceIndices);
139  HD_API
140  Builder &SetMask(
142  HD_API
144  const HdPathArrayDataSourceHandle &instanceLocations);
145 
146  /// Returns a container data source containing the members set thus far.
147  HD_API
148  HdContainerDataSourceHandle Build();
149 
150  private:
151  HdPathArrayDataSourceHandle _prototypes;
152  HdVectorDataSourceHandle _instanceIndices;
154  HdPathArrayDataSourceHandle _instanceLocations;
155  };
156  // HELPERS
157  HD_API
159 
160 
161  /// Retrieves a container data source with the schema's default name token
162  /// "instancerTopology" from the parent container and constructs a
163  /// HdInstancerTopologySchema instance.
164  /// Because the requested container data source may not exist, the result
165  /// should be checked with IsDefined() or a bool comparison before use.
166  HD_API
168  const HdContainerDataSourceHandle &fromParentContainer);
169 
170  /// Returns a token where the container representing this schema is found in
171  /// a container by default.
172  HD_API
173  static const TfToken &GetSchemaToken();
174 
175  /// Returns an HdDataSourceLocator (relative to the prim-level data source)
176  /// where the container representing this schema is found by default.
177  HD_API
178  static const HdDataSourceLocator &GetDefaultLocator();
179 
180 };
181 
183 
184 #endif
HD_API HdIntArrayVectorSchema GetInstanceIndices()
HD_API Builder & SetPrototypes(const HdPathArrayDataSourceHandle &prototypes)
#define HDINSTANCERTOPOLOGY_SCHEMA_TOKENS
HdBoolArrayDataSource::Handle HdBoolArrayDataSourceHandle
HD_API HdPathArrayDataSourceHandle GetPrototypes()
HdPathArrayDataSource::Handle HdPathArrayDataSourceHandle
static HD_API HdContainerDataSourceHandle BuildRetained(const HdPathArrayDataSourceHandle &prototypes, const HdVectorDataSourceHandle &instanceIndices, const HdBoolArrayDataSourceHandle &mask, const HdPathArrayDataSourceHandle &instanceLocations)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
#define HD_API
Definition: api.h:40
HD_API Builder & SetInstanceIndices(const HdVectorDataSourceHandle &instanceIndices)
static HD_API HdInstancerTopologySchema GetFromParent(const HdContainerDataSourceHandle &fromParentContainer)
HD_API Builder & SetInstanceLocations(const HdPathArrayDataSourceHandle &instanceLocations)
HD_API Builder & SetMask(const HdBoolArrayDataSourceHandle &mask)
Definition: token.h:87
HD_API VtArray< int > ComputeInstanceIndicesForProto(SdfPath const &path)
static HD_API const TfToken & GetSchemaToken()
GLint GLuint mask
Definition: glcorearb.h:124
TF_DECLARE_PUBLIC_TOKENS(HdInstancerTopologySchemaTokens, HD_API, HDINSTANCERTOPOLOGY_SCHEMA_TOKENS)
Definition: types.h:173
Definition: path.h:291
HdInstancerTopologySchema(HdContainerDataSourceHandle container)
HD_API HdContainerDataSourceHandle Build()
Returns a container data source containing the members set thus far.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HD_API HdPathArrayDataSourceHandle GetInstanceLocations()
static HD_API const HdDataSourceLocator & GetDefaultLocator()
HD_API HdBoolArrayDataSourceHandle GetMask()