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 
102  // Note: expected to be a vector of HdIntArrayDataSource.
103  HD_API
104  HdVectorDataSourceHandle GetInstanceIndices();
105  HD_API
106  HdBoolArrayDataSourceHandle GetMask();
107  HD_API
108  HdPathArrayDataSourceHandle GetInstanceLocations();
109 
110  // RETRIEVING AND CONSTRUCTING
111 
117  HD_API
118  static HdContainerDataSourceHandle
119  BuildRetained(
120  const HdPathArrayDataSourceHandle &prototypes,
121  const HdVectorDataSourceHandle &instanceIndices,
122  const HdBoolArrayDataSourceHandle &mask,
123  const HdPathArrayDataSourceHandle &instanceLocations
124  );
125 
132  class Builder
133  {
134  public:
135  HD_API
136  Builder &SetPrototypes(
137  const HdPathArrayDataSourceHandle &prototypes);
138  HD_API
139  Builder &SetInstanceIndices(
140  const HdVectorDataSourceHandle &instanceIndices);
141  HD_API
142  Builder &SetMask(
143  const HdBoolArrayDataSourceHandle &mask);
144  HD_API
145  Builder &SetInstanceLocations(
146  const HdPathArrayDataSourceHandle &instanceLocations);
147 
149  HD_API
150  HdContainerDataSourceHandle Build();
151 
152  private:
153  HdPathArrayDataSourceHandle _prototypes;
154  HdVectorDataSourceHandle _instanceIndices;
155  HdBoolArrayDataSourceHandle _mask;
156  HdPathArrayDataSourceHandle _instanceLocations;
157  };
158  // HELPERS
159  HD_API
160  VtArray<int> ComputeInstanceIndicesForProto(SdfPath const &path);
161 
162 
168  HD_API
169  static HdInstancerTopologySchema GetFromParent(
170  const HdContainerDataSourceHandle &fromParentContainer);
171 
174  HD_API
175  static const HdDataSourceLocator &GetDefaultLocator();
176 
177 };
178 
179 PXR_NAMESPACE_CLOSE_SCOPE
180 
181 #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:228
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