instancerTopologySchema.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 //
25 // This file is generated by a script. Do not edit directly. Edit the
26 // schema.template.h file to make changes.
27 
28 #ifndef PXR_IMAGING_HD_INSTANCER_TOPOLOGY_SCHEMA_H
29 #define PXR_IMAGING_HD_INSTANCER_TOPOLOGY_SCHEMA_H
30 
31 #include "pxr/imaging/hd/api.h"
32 
33 #include "pxr/imaging/hd/schema.h"
34 
35 PXR_NAMESPACE_OPEN_SCOPE
36 
37 //-----------------------------------------------------------------------------
38 
39 #define HDINSTANCERTOPOLOGY_SCHEMA_TOKENS \
40  (instancerTopology) \
41  (prototypes) \
42  (instanceIndices) \
43  (mask) \
44  (instanceLocations) \
45 
46 TF_DECLARE_PUBLIC_TOKENS(HdInstancerTopologySchemaTokens, HD_API,
47  HDINSTANCERTOPOLOGY_SCHEMA_TOKENS);
48 
49 //-----------------------------------------------------------------------------
50 
51 // Since the instancing schema is complicated:
52 //
53 // An instancer is a prim at a certain scenegraph location that causes other
54 // prims to be duplicated. The instancer can also hold instance-varying data
55 // like constant primvars or material relationships.
56 //
57 // The important things an instancer has is:
58 // 1.) Instancer topology, describing how exactly the prims are duplicated;
59 // 2.) Instance-rate data, meaning data that varies per instance, such as
60 // primvars or material bindings.
61 //
62 // If an instancer causes prims "/A" and "/B" to be duplicated, we encode that
63 // by setting prototypes = ["/A", "/B"]. Note that "/A" and "/B" can be
64 // subtrees, not direct gprims. instanceIndices encodes both multiplicity
65 // and position in arrays of instance-rate data, per prototype path; if
66 // instanceIndices = { [0,2], [1] }, then we draw /A twice (with instance
67 // primvar indices 0 and 2); and /B once (with instance primvar index 1).
68 // Mask is an auxiliary parameter that can be used to deactivate certain
69 // instances; mask = [true, true, false] would disable the
70 // second copy of "/A". An empty mask array is the same as all-true.
71 //
72 // Scenes generally specify instancing in one of two ways:
73 // 1.) Explicit instancing: prim /Instancer wants to draw its subtree at
74 // an array of locations. This is a data expansion form.
75 // 2.) Implicit instancing: prims /X and /Y are marked as being identical,
76 // and scene load replaces them with a single prim and an instancer.
77 // This is a data coalescing form.
78 //
79 // For implicit instancing, we want to know the original paths of /X and /Y,
80 // for doing things like resolving inheritance. This is encoded in the
81 // "instanceLocations" path, while the prototype prims (e.g. /_Prototype/Cube,
82 // the deduplicated version of /X/Cube and /Y/Cube) is encoded in the
83 // "prototypes" path.
84 //
85 // For explicit instancing, the "instanceLocations" attribute is meaningless
86 // and should be left null.
87 
88 class HdInstancerTopologySchema : public HdSchema
89 {
90 public:
91  HdInstancerTopologySchema(HdContainerDataSourceHandle container)
92  : HdSchema(container) {}
93 
94  //ACCESSORS
95 
96  HD_API
97  HdPathArrayDataSourceHandle GetPrototypes();
98 
99  // Note: expected to be a vector of HdIntArrayDataSource.
100  HD_API
101  HdVectorDataSourceHandle GetInstanceIndices();
102  HD_API
103  HdBoolArrayDataSourceHandle GetMask();
104  HD_API
105  HdPathArrayDataSourceHandle GetInstanceLocations();
106 
107  // RETRIEVING AND CONSTRUCTING
108 
114  HD_API
115  static HdContainerDataSourceHandle
116  BuildRetained(
117  const HdPathArrayDataSourceHandle &prototypes,
118  const HdVectorDataSourceHandle &instanceIndices,
119  const HdBoolArrayDataSourceHandle &mask,
120  const HdPathArrayDataSourceHandle &instanceLocations
121  );
122 
129  class Builder
130  {
131  public:
132  HD_API
133  Builder &SetPrototypes(
134  const HdPathArrayDataSourceHandle &prototypes);
135  HD_API
136  Builder &SetInstanceIndices(
137  const HdVectorDataSourceHandle &instanceIndices);
138  HD_API
139  Builder &SetMask(
140  const HdBoolArrayDataSourceHandle &mask);
141  HD_API
142  Builder &SetInstanceLocations(
143  const HdPathArrayDataSourceHandle &instanceLocations);
144 
146  HD_API
147  HdContainerDataSourceHandle Build();
148 
149  private:
150  HdPathArrayDataSourceHandle _prototypes;
151  HdVectorDataSourceHandle _instanceIndices;
152  HdBoolArrayDataSourceHandle _mask;
153  HdPathArrayDataSourceHandle _instanceLocations;
154  };
155  // HELPERS
156  VtArray<int> ComputeInstanceIndicesForProto(SdfPath const &path);
157 
158 
164  HD_API
165  static HdInstancerTopologySchema GetFromParent(
166  const HdContainerDataSourceHandle &fromParentContainer);
167 
170  HD_API
171  static const HdDataSourceLocator &GetDefaultLocator();
172 
173 };
174 
175 PXR_NAMESPACE_CLOSE_SCOPE
176 
177 #endif
HD_API HdContainerDataSourceHandle Build()
Returns a container data source containing the members set thus far.
Utility class for setting sparse sets of child data source fields to be filled as arguments into Buil...
Represents an object that can identify the location of a data source.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:229
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Schema classes represent a structured view of the inherently unstructured container data source passe...
Definition: schema.h:42