forked from dreamworksanimation/USD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubset.h
428 lines (388 loc) · 18.1 KB
/
subset.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDGEOM_GENERATED_SUBSET_H
#define USDGEOM_GENERATED_SUBSET_H
/// \file usdGeom/subset.h
#include "pxr/pxr.h"
#include "pxr/usd/usdGeom/api.h"
#include "pxr/usd/usd/typed.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdGeom/tokens.h"
#include "pxr/base/tf/token.h"
#include "pxr/usd/usdGeom/imageable.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// GEOMSUBSET //
// -------------------------------------------------------------------------- //
/// \class UsdGeomSubset
///
/// Encodes a subset of a piece of geometry (i.e. a UsdGeomImageable)
/// as a set of indices. Currently only supports encoding of face-subsets, but
/// could be extended in the future to support subsets representing edges,
/// segments, points etc.
///
/// To apply to a geometric prim, a GeomSubset prim must be defined as a
/// child of it in namespace. This restriction makes it easy and efficient
/// to discover subsets of a prim. We might want to relax this restriction if
/// it's common to have multiple <b>families</b> of subsets on a gprim and if
/// it's useful to be able to organize subsets belonging to a </b>family</b>
/// under a common scope. See 'familyName' attribute for more info on defining
/// a family of subsets.
///
/// Note that a GeomSubset isn't an imageable (i.e. doesn't derive from
/// UsdGeomImageable). So, you can't author <b>visibility</b> for it or
/// override its <b>purpose</b>.
///
/// Materials are bound to GeomSubsets just as they are for regular
/// geometry using API available in UsdShade (UsdShadeMaterial::Bind).
///
///
/// For any described attribute \em Fallback \em Value or \em Allowed \em Values below
/// that are text/tokens, the actual token is published and defined in \ref UsdGeomTokens.
/// So to set an attribute to the value "rightHanded", use UsdGeomTokens->rightHanded
/// as the value.
///
class UsdGeomSubset : public UsdTyped
{
public:
/// Compile-time constant indicating whether or not this class corresponds
/// to a concrete instantiable prim type in scene description. If this is
/// true, GetStaticPrimDefinition() will return a valid prim definition with
/// a non-empty typeName.
static const bool IsConcrete = true;
/// Compile-time constant indicating whether or not this class inherits from
/// UsdTyped. Types which inherit from UsdTyped can impart a typename on a
/// UsdPrim.
static const bool IsTyped = true;
/// Construct a UsdGeomSubset on UsdPrim \p prim .
/// Equivalent to UsdGeomSubset::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdGeomSubset(const UsdPrim& prim=UsdPrim())
: UsdTyped(prim)
{
}
/// Construct a UsdGeomSubset on the prim held by \p schemaObj .
/// Should be preferred over UsdGeomSubset(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdGeomSubset(const UsdSchemaBase& schemaObj)
: UsdTyped(schemaObj)
{
}
/// Destructor.
USDGEOM_API
virtual ~UsdGeomSubset();
/// Return a vector of names of all pre-declared attributes for this schema
/// class and all its ancestor classes. Does not include attributes that
/// may be authored by custom/extended methods of the schemas involved.
USDGEOM_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdGeomSubset holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p stage, or if the prim at that path does not adhere to this schema,
/// return an invalid schema object. This is shorthand for the following:
///
/// \code
/// UsdGeomSubset(stage->GetPrimAtPath(path));
/// \endcode
///
USDGEOM_API
static UsdGeomSubset
Get(const UsdStagePtr &stage, const SdfPath &path);
/// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
/// is defined (according to UsdPrim::IsDefined()) on this stage.
///
/// If a prim adhering to this schema at \p path is already defined on this
/// stage, return that prim. Otherwise author an \a SdfPrimSpec with
/// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
/// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
/// with \p specifier == \a SdfSpecifierDef and empty typeName at the
/// current EditTarget for any nonexistent, or existing but not \a Defined
/// ancestors.
///
/// The given \a path must be an absolute prim path that does not contain
/// any variant selections.
///
/// If it is impossible to author any of the necessary PrimSpecs, (for
/// example, in case \a path cannot map to the current UsdEditTarget's
/// namespace) issue an error and return an invalid \a UsdPrim.
///
/// Note that this method may return a defined prim whose typeName does not
/// specify this schema class, in case a stronger typeName opinion overrides
/// the opinion at the current EditTarget.
///
USDGEOM_API
static UsdGeomSubset
Define(const UsdStagePtr &stage, const SdfPath &path);
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDGEOM_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDGEOM_API
virtual const TfType &_GetTfType() const;
public:
// --------------------------------------------------------------------- //
// ELEMENTTYPE
// --------------------------------------------------------------------- //
/// The type of element that the indices target. Currently only
/// allows "face" and defaults to it.
///
/// \n C++ Type: TfToken
/// \n Usd Type: SdfValueTypeNames->Token
/// \n Variability: SdfVariabilityUniform
/// \n Fallback Value: face
/// \n \ref UsdGeomTokens "Allowed Values": [face]
USDGEOM_API
UsdAttribute GetElementTypeAttr() const;
/// See GetElementTypeAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDGEOM_API
UsdAttribute CreateElementTypeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// INDICES
// --------------------------------------------------------------------- //
/// The set of indices included in this subset. The indices need not
/// be sorted, but the same index should not appear more than once.
///
/// \n C++ Type: VtArray<int>
/// \n Usd Type: SdfValueTypeNames->IntArray
/// \n Variability: SdfVariabilityVarying
/// \n Fallback Value: []
USDGEOM_API
UsdAttribute GetIndicesAttr() const;
/// See GetIndicesAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDGEOM_API
UsdAttribute CreateIndicesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// FAMILYNAME
// --------------------------------------------------------------------- //
/// The name of the family of subsets that this subset belongs to.
/// This is optional and is primarily useful when there are multiple
/// families of subsets under a geometric prim. In some cases, this could
/// also be used for achieving proper roundtripping of subset data between
/// DCC apps.
/// When multiple subsets belonging to a prim have the same familyName, they
/// are said to belong to the family. A <i>familyType</i> value can be
/// encoded on the owner of a family of subsets as a token using the static
/// method UsdGeomSubset::SetFamilyType(). "familyType" can have one of the
/// following values:
/// <ul><li><b>UsdGeomTokens->partition</b>: implies that every element of
/// the whole geometry appears exactly once in only one of the subsets
/// belonging to the family.</li>
/// <li><b>UsdGeomTokens->nonOverlapping</b>: an element that appears in one
/// subset may not appear in any other subset belonging to the family.</li>
/// <li><b>UsdGeomTokens->unrestricted</b>: implies that there are no
/// restrictions w.r.t. the membership of elements in the subsets. They
/// could be overlapping and the union of all subsets in the family may
/// not represent the whole.</li>
/// </ul>
/// \note The validity of subset data is not enforced by the authoring
/// APIs, however they can be checked using UsdGeomSubset::ValidateFamily().
///
///
/// \n C++ Type: TfToken
/// \n Usd Type: SdfValueTypeNames->Token
/// \n Variability: SdfVariabilityUniform
/// \n Fallback Value:
USDGEOM_API
UsdAttribute GetFamilyNameAttr() const;
/// See GetFamilyNameAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDGEOM_API
UsdAttribute CreateFamilyNameAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
/// Creates a new GeomSubset below the given \p geom with the given
/// name, \p subsetName, element type, \p elementType and \p indices.
///
/// If a subset named \p subsetName already exists below \p geom, then
/// this updates its attributes with the values of the provided arguments
/// (indices value at time 'default' will be updated) and returns it.
///
/// The family type is set / updated on \p geom only if a non-empty value
/// is passed in for \p familyType and \p familyName.
USDGEOM_API
static UsdGeomSubset CreateGeomSubset(
const UsdGeomImageable &geom,
const std::string &subsetName,
const TfToken &elementType,
const VtIntArray &indices,
const TfToken &familyName=TfToken(),
const TfToken &familyType=TfToken());
/// Creates a new GeomSubset below the given imageable, \p geom with the
/// given name, \p subsetName, element type, \p elementType and \p indices.
///
/// If a subset named \p subsetName already exists below \p geom, then
/// this creates a new subset by appending a suitable index as suffix to
/// \p subsetName (eg, subsetName_1) to avoid name collisions.
///
/// The family type is set / updated on \p geom only if a non-empty value
/// is passed in for \p familyType and \p familyName.
USDGEOM_API
static UsdGeomSubset CreateUniqueGeomSubset(
const UsdGeomImageable &geom,
const std::string &subsetName,
const TfToken &elementType,
const VtIntArray &indices,
const TfToken &familyName=TfToken(),
const TfToken &familyType=TfToken());
/// Returns all the GeomSubsets defined on the given imageable, \p geom.
USDGEOM_API
static std::vector<UsdGeomSubset> GetAllGeomSubsets(
const UsdGeomImageable &geom);
/// Returns all the GeomSubsets of the given \p elementType belonging to
/// the specified family, \p familyName on the given imageable, \p geom.
/// If \p elementType is empty, then subsets containing all element types
/// are returned.
/// If \p familyName is left empty, then all subsets of the specified
/// \p elementType will be returned.
USDGEOM_API
static std::vector<UsdGeomSubset> GetGeomSubsets(
const UsdGeomImageable &geom,
const TfToken &elementType=TfToken(),
const TfToken &familyName=TfToken());
/// Returns the names of all the families of GeomSubsets defined on the given
/// imageable, \p geom.
USDGEOM_API
static TfToken::Set GetAllGeomSubsetFamilyNames(
const UsdGeomImageable &geom);
/// This method is used to encode the type of family that the GeomSubsets
/// on the given geometric prim \p geom, with the given family name,
/// \p familyName belong to.
///
/// See \ref UsdGeomSubset::GetFamilyNameAttr for the possible values for
/// \p familyType.
///
/// When a family of GeomSubsets is tagged as a UsdGeomTokens->partition or
/// UsdGeomTokens->nonOverlapping, the validity of the data (i.e.
/// mutual exclusivity and/or wholeness) is not enforced by the authoring
/// APIs. Use ValidateFamily() to validate the data in a family of
/// GeomSubsets.
///
/// \return Returns false upon failure to create or set the appropriate
/// attribute on \p geom.
USDGEOM_API
static bool SetFamilyType(
const UsdGeomImageable &geom,
const TfToken &familyName,
const TfToken &familyType);
/// Returns the type of family that the GeomSubsets on the given geometric
/// prim \p geom, with the given family name, \p familyName belong to.
///
/// This only returns the token that's encoded on \p geom and does not perform
/// any actual validation on the family of GeomSubsets. Please use
/// ValidateFamily() for such validation.
///
/// When familyType is not set on \p geom, the fallback value
/// UsdTokens->unrestricted is returned.
USDGEOM_API
static TfToken GetFamilyType(
const UsdGeomImageable &geom,
const TfToken &familyName);
/// Utility for getting the list of indices that are not assigned to any of
/// the GeomSubsets in \p subsets at the timeCode, \p time, given the
/// element count (total number of indices in the array being subdivided),
/// \p elementCount.
USDGEOM_API
static VtIntArray GetUnassignedIndices(
const std::vector<UsdGeomSubset> &subsets,
const size_t elementCount,
const UsdTimeCode &time=UsdTimeCode::EarliestTime());
/// Validates the data in the given set of GeomSubsets, \p subsets, given
/// the total number of elements in the array being subdivided,
/// \p elementCount and the \p familyType that the subsets belong to.
///
/// For proper validation of indices in \p subsets, all of the GeomSubsets
/// must have the same 'elementType'.
///
/// If one or more subsets contain invalid data, then false is returned and
/// \p reason is populated with a string explaining the reason why it is
/// invalid.
///
/// The python version of this method returns a tuple containing
/// a (bool, string), where the bool has the validity of the subsets and
/// the string contains the reason (if they're invalid).
///
USDGEOM_API
static bool ValidateSubsets(
const std::vector<UsdGeomSubset> &subsets,
const size_t elementCount,
const TfToken &familyType,
std::string * const reason);
/// Validates whether the family of subsets identified by the given
/// \p familyName and \p elementType on the given imageable, \p geom contain
/// valid data. If the family is designated as a partition or as
/// non-overlapping using SetFamilyType(), then the validity of the data
/// is checked. If the familyType is "unrestricted", then this performs only
/// bounds checking of the values in the "indices" arrays.
///
/// If \p reason is not NULL, then it is populated with a string explaining
/// why the family is invalid, if it is invalid.
///
/// The python version of this method returns a tuple containing
/// a (bool, string), where the bool has the validity of the family and
/// the string contains the reason (if it's invalid).
///
USDGEOM_API
static bool ValidateFamily(
const UsdGeomImageable &geom,
const TfToken &elementType,
const TfToken &familyName,
std::string * const reason);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif