instancerTopologySchema.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 //
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 
38 PXR_NAMESPACE_OPEN_SCOPE
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,
50  HDINSTANCERTOPOLOGY_SCHEMA_TOKENS);
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 
91 class HdInstancerTopologySchema : public HdSchema
92 {
93 public:
94  HdInstancerTopologySchema(HdContainerDataSourceHandle container)
95  : HdSchema(container) {}
96 
97  //ACCESSORS
98 
99  HD_API
100  HdPathArrayDataSourceHandle GetPrototypes();
101  HD_API
102  HdIntArrayVectorSchema GetInstanceIndices();
103  HD_API
104  HdBoolArrayDataSourceHandle GetMask();
105  HD_API
106  HdPathArrayDataSourceHandle GetInstanceLocations();
107 
108  // RETRIEVING AND CONSTRUCTING
109 
115  HD_API
116  static HdContainerDataSourceHandle
117  BuildRetained(
118  const HdPathArrayDataSourceHandle &prototypes,
119  const HdVectorDataSourceHandle &instanceIndices,
120  const HdBoolArrayDataSourceHandle &mask,
121  const HdPathArrayDataSourceHandle &instanceLocations
122  );
123 
130  class Builder
131  {
132  public:
133  HD_API
134  Builder &SetPrototypes(
135  const HdPathArrayDataSourceHandle &prototypes);
136  HD_API
137  Builder &SetInstanceIndices(
138  const HdVectorDataSourceHandle &instanceIndices);
139  HD_API
140  Builder &SetMask(
141  const HdBoolArrayDataSourceHandle &mask);
142  HD_API
143  Builder &SetInstanceLocations(
144  const HdPathArrayDataSourceHandle &instanceLocations);
145 
147  HD_API
148  HdContainerDataSourceHandle Build();
149 
150  private:
151  HdPathArrayDataSourceHandle _prototypes;
152  HdVectorDataSourceHandle _instanceIndices;
153  HdBoolArrayDataSourceHandle _mask;
154  HdPathArrayDataSourceHandle _instanceLocations;
155  };
156  // HELPERS
157  HD_API
158  VtArray<int> ComputeInstanceIndicesForProto(SdfPath const &path);
159 
160 
166  HD_API
167  static HdInstancerTopologySchema GetFromParent(
168  const HdContainerDataSourceHandle &fromParentContainer);
169 
172  HD_API
173  static const HdDataSourceLocator &GetDefaultLocator();
174 
175 };
176 
177 PXR_NAMESPACE_CLOSE_SCOPE
178 
179 #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:43
Base class for vector schema classes that represent a view of a vector data source containing data so...
Definition: vectorSchema.h:73