usdlib
Layer
dataclass
Source code in client/ayon_core/pipeline/usdlib.py
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 |
|
create_anonymous(path, tag='LOP', anchor=None)
classmethod
Create an anonymous layer instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | str | The layer's filepath. | required |
tag | Optional[str] | The tag to give to the anonymous layer. This defaults to 'LOP' because Houdini requires that tag for its in-memory layers that it will be able to manage. In other integrations no similar requirements have been found so it was deemed a 'safe' default for now. | 'LOP' |
anchor | Optional[Layer] | Another layer to relatively anchor to. | None |
Source code in client/ayon_core/pipeline/usdlib.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
export(path=None, args=None)
Save the layer
Source code in client/ayon_core/pipeline/usdlib.py
34 35 36 37 38 39 40 41 42 |
|
get_full_path()
Return full path relative to the anchor layer
Source code in client/ayon_core/pipeline/usdlib.py
26 27 28 29 30 31 32 |
|
add_ordered_reference(layer, prim_path, reference, order)
Add reference alongside other ordered references.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer | Layer | Layer to operate in. | required |
prim_path | Path | Prim path to reference into. This may include variant selections to reference into a prim inside the variant selection. | required |
reference | Reference | Reference to add. | required |
order | (int | Order. | required |
Returns:
Type | Description |
---|---|
Sdf.PrimSpec: The prim spec for the prim path. |
Source code in client/ayon_core/pipeline/usdlib.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 |
|
add_ordered_sublayer(layer, contribution_path, layer_id, order=None, add_sdf_arguments_metadata=True)
Add sublayer paths in the Sdf.Layer at given "orders"
USD does not provide a way to set metadata per sublayer entry, but we can 'sneak it in' by adding it as part of the file url after :SDF_FORMAT_ARGS: There they will then just be unused args that we can parse later again to access our data.
A higher order will appear earlier in the subLayerPaths as a stronger opinion. An unordered layer (order=None
) will be stronger than any ordered opinion and thus will be inserted at the start of the list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer | Layer | Layer to add sublayers in. | required |
contribution_path | str | Path/URI to add. | required |
layer_id | str | Token that if found for an existing layer it will replace that layer. | required |
order | Any[int, None] | Order to place the contribution in the sublayers. When | None |
add_sdf_arguments_metadata | bool | Add metadata into the filepath to store the | True |
Returns:
Name | Type | Description |
---|---|---|
str | The resulting contribution path (which maybe include the sdf format args metadata if enabled) |
Source code in client/ayon_core/pipeline/usdlib.py
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 |
|
add_variant_references_to_layer(variants, variantset, default_variant=None, variant_prim='/root', reference_prim=None, set_default_variant=True, as_payload=False, skip_variant_on_single_file=False, layer=None)
Add or set a prim's variants to reference specified paths in the layer.
Note
This does not clear any of the other opinions than replacing prim.referenceList.prependedItems
with the new reference. If as_payload=True
then this only does it for payloads and leaves references as they were in-tact.
Note
If skip_variant_on_single_file=True
it does not check if any other variants do exist; it only checks whether you are currently adding more than one since it'd be hard to find out whether previously this was also skipped and should now if you're adding a new one suddenly also be its original 'variant'. As such it's recommended to keep this disabled unless you know you're not updating the file later into the same variant set.
Examples:
layer = add_variant_references_to_layer("model.usd", variants=[ ("main", "main.usd"), ("damaged", "damaged.usd"), ("twisted", "twisted.usd") ], variantset="model") layer.Export("model.usd", args={"format": "usda"})
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variants | List[List[str, str] | List of two-tuples of variant name to the filepath that should be referenced in for that variant. | required |
variantset | str | Name of the variant set | required |
default_variant | str | Default variant to set. If not provided the first variant will be used. | None |
variant_prim | str | Variant prim? | '/root' |
reference_prim | str | Path to the reference prim where to add the references and variant sets. | None |
set_default_variant | bool | Whether to set the default variant. When False no default variant will be set, even if a value was provided to | True |
as_payload | bool | When enabled, instead of referencing use payloads | False |
skip_variant_on_single_file | bool | If this is enabled and only a single variant is provided then do not create the variant set but just reference that single file. | False |
layer | Optional[Layer] | When provided operate on this layer, otherwise create an anonymous layer in memory. | None |
Returns:
Type | Description |
---|---|
Sdf.Layer: The layer with the added references inside the variants. |
Source code in client/ayon_core/pipeline/usdlib.py
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 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
|
create_asset(filepath, asset_name, reference_layers=None, kind=Kind.Tokens.component, define_class=True)
Creates and saves a prepared asset stage layer.
Creates an asset file that consists of a top level asset prim, asset info and references in the provided reference_layers
.
Returns:
Name | Type | Description |
---|---|---|
list | Created layers |
Source code in client/ayon_core/pipeline/usdlib.py
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 |
|
create_shot(filepath, layers, create_layers=False)
Create a shot with separate layers for departments.
Examples:
>>> create_shot("/path/to/shot.usd",
>>> layers=["lighting.usd", "fx.usd", "animation.usd"])
"/path/to/shot.usd"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath | str | Filepath where the asset.usd file will be saved. | required |
layers | list | When provided this will be added verbatim in the subLayerPaths layers. When the provided layer paths do not exist they are generated using Sdf.Layer.CreateNew | required |
create_layers | bool | Whether to create the stub layers on disk if they do not exist yet. | False |
Returns:
Name | Type | Description |
---|---|---|
str | The saved shot file path |
Source code in client/ayon_core/pipeline/usdlib.py
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 |
|
get_or_define_prim_spec(layer, prim_path, type_name)
Get or create a PrimSpec in the layer.
Note
This creates a Sdf.PrimSpec with Sdf.SpecifierDef but if the PrimSpec already exists this will not force it to be a Sdf.SpecifierDef and it may remain what it was, e.g. Sdf.SpecifierOver
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer | Layer | The layer to create it in. | required |
prim_path | Any[str, Path] | Prim path to create. | required |
type_name | str | Type name for the PrimSpec. This will only be set if the prim does not exist in the layer yet. It does not update type for an existing prim. | required |
Returns:
Type | Description |
---|---|
Sdf.PrimSpec: The PrimSpec in the layer for the given prim path. |
Source code in client/ayon_core/pipeline/usdlib.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
|
get_sdf_format_args(path)
Return SDF_FORMAT_ARGS parsed to dict
Source code in client/ayon_core/pipeline/usdlib.py
683 684 685 686 |
|
set_layer_defaults(layer, up_axis=UsdGeom.Tokens.y, meters_per_unit=1.0, default_prim=None)
Set some default metadata for the SdfLayer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer | Layer | The layer to set default for via Sdf API. | required |
meters_per_unit | float | Meters per unit | 1.0 |
default_prim | Optional[str] | Default prim name | None |
Source code in client/ayon_core/pipeline/usdlib.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
|
set_variant_reference(sdf_layer, prim_path, variant_selections, path, as_payload=False, append=True)
Get or define variant selection at prim path and add a reference
If the Variant Prim already exists the prepended references are replaced with a reference to path
, it is overridden.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sdf_layer | Layer | Layer to operate in. | required |
prim_path | Any[str, Path] | Prim path to add variant to. | required |
variant_selections | List[List[str, str]] | A list of variant set names and variant names to get the prim spec in. | required |
path | str | Path to reference or payload | required |
as_payload | bool | When enabled it will generate a payload instead of a reference. Defaults to False. | False |
append | bool | When enabled it will append the reference of payload to prepended items, otherwise it will replace it. | True |
Returns:
Type | Description |
---|---|
Sdf.PrimSpec: The prim spec for the prim path at the given variant selection. |
Source code in client/ayon_core/pipeline/usdlib.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
|
setup_asset_layer(layer, asset_name, reference_layers=None, kind=Kind.Tokens.component, define_class=True, force_add_payload=False, set_payload_path=False)
Adds an asset prim to the layer with the reference_layers
added as references for e.g. geometry and shading.
The referenced layers will be moved into a separate ./payload.usd
file that the asset file uses to allow deferred loading of the heavier geometrical data. An example would be:
asset.usd <-- out filepath payload.usd <-- always automatically added in-between look.usd <-- reference layer 0 from reference_layers
argument model.usd <-- reference layer 1 from reference_layers
argument
If define_class
is enabled then a /__class__/{asset_name}
class definition will be created that the root asset inherits from
Examples:
>>> create_asset("/path/to/asset.usd",
>>> asset_name="test",
>>> reference_layers=["./model.usd", "./look.usd"])
Returns:
Type | Description |
---|---|
List[Tuple[Sdf.Layer, str]]: List of created layers with their preferred output save paths. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer | Layer | Layer to set up the asset structure for. | required |
asset_name | str | The name for the Asset identifier and default prim. | required |
reference_layers | list | USD Files to reference in the asset. Note that the bottom layer (first file, like a model) would be last in the list. The strongest layer will be the first index. | None |
kind | Kind | A USD Kind for the root asset. | component |
define_class | Define a | True | |
force_add_payload | bool | Generate payload layer even if no reference paths are set - thus generating an enmpty layer. | False |
set_payload_path | bool | Whether to directly set the payload asset path to | False |
Source code in client/ayon_core/pipeline/usdlib.py
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 |
|
variant_nested_prim_path(prim_path, variant_selections)
Return the Sdf.Path for a nested variant selection at prim path.
Examples:
prim_path = Sdf.Path("/asset") variant_spec = variant_nested_prim_path( prim_path, variant_selections=[["model", "main"], ["look", "main"]] ) variant_spec.path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prim_path | PrimPath | The prim path to create the spec in | required |
variant_selections | List[List[str, str]] | A list of variant set names and variant names to get the prim spec in. | required |
Returns:
Type | Description |
---|---|
Sdf.Path: The variant prim path |
Source code in client/ayon_core/pipeline/usdlib.py
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
|