usd-validation-nvidia 1.19.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- omni/asset_validator/__init__.py +11 -0
- omni/asset_validator/__main__.py +7 -0
- omni/asset_validator/tests/__init__.py +11 -0
- omni/capabilities/__init__.py +7 -0
- usd_validation_nvidia/__init__.py +444 -0
- usd_validation_nvidia/__main__.py +14 -0
- usd_validation_nvidia/_asset_format.py +146 -0
- usd_validation_nvidia/_assets.py +78 -0
- usd_validation_nvidia/_atomic_asset_checker.py +291 -0
- usd_validation_nvidia/_base_rule_checker.py +221 -0
- usd_validation_nvidia/_base_rule_metadata.py +176 -0
- usd_validation_nvidia/_base_rules.py +1082 -0
- usd_validation_nvidia/_capabilities.py +172 -0
- usd_validation_nvidia/_categories.py +206 -0
- usd_validation_nvidia/_cli.py +917 -0
- usd_validation_nvidia/_compliance_checker.py +449 -0
- usd_validation_nvidia/_compliance_runners.py +321 -0
- usd_validation_nvidia/_context_managers.py +142 -0
- usd_validation_nvidia/_csv_reports.py +278 -0
- usd_validation_nvidia/_default_categories.py +209 -0
- usd_validation_nvidia/_default_plugin.py +167 -0
- usd_validation_nvidia/_deprecate.py +60 -0
- usd_validation_nvidia/_engine.py +873 -0
- usd_validation_nvidia/_events.py +147 -0
- usd_validation_nvidia/_examples.py +61 -0
- usd_validation_nvidia/_expression.py +281 -0
- usd_validation_nvidia/_features.py +142 -0
- usd_validation_nvidia/_fix.py +478 -0
- usd_validation_nvidia/_gaussian_splat_checker.py +222 -0
- usd_validation_nvidia/_geometry_checker.py +1130 -0
- usd_validation_nvidia/_graph_tools.py +44 -0
- usd_validation_nvidia/_hierarchy_rules.py +95 -0
- usd_validation_nvidia/_identifiers.py +676 -0
- usd_validation_nvidia/_import_utils.py +129 -0
- usd_validation_nvidia/_issues.py +959 -0
- usd_validation_nvidia/_json_reports.py +257 -0
- usd_validation_nvidia/_layer_checker.py +310 -0
- usd_validation_nvidia/_layout_checker.py +176 -0
- usd_validation_nvidia/_material_checker.py +1043 -0
- usd_validation_nvidia/_mesh_tools.py +843 -0
- usd_validation_nvidia/_misc_checker.py +204 -0
- usd_validation_nvidia/_parameters.py +154 -0
- usd_validation_nvidia/_performance_checker.py +344 -0
- usd_validation_nvidia/_physics_checker.py +469 -0
- usd_validation_nvidia/_plugins.py +361 -0
- usd_validation_nvidia/_profiles.py +169 -0
- usd_validation_nvidia/_registry.py +191 -0
- usd_validation_nvidia/_requirements.py +289 -0
- usd_validation_nvidia/_results.py +154 -0
- usd_validation_nvidia/_semver.py +102 -0
- usd_validation_nvidia/_singleton.py +33 -0
- usd_validation_nvidia/_stats.py +116 -0
- usd_validation_nvidia/_units_rules.py +61 -0
- usd_validation_nvidia/_url_utils.py +145 -0
- usd_validation_nvidia/_usd_utils.py +25 -0
- usd_validation_nvidia/_usd_validator_adapter.py +228 -0
- usd_validation_nvidia/_utf8_checker.py +99 -0
- usd_validation_nvidia/_validation_context.py +156 -0
- usd_validation_nvidia/_version.py +14 -0
- usd_validation_nvidia/capabilities/__init__.py +61 -0
- usd_validation_nvidia/capabilities/_capabilities.py +1293 -0
- usd_validation_nvidia/capabilities/_examples.py +947 -0
- usd_validation_nvidia/capabilities/_features.py +68 -0
- usd_validation_nvidia/capabilities/_parameters.py +60 -0
- usd_validation_nvidia/capabilities/_profiles.py +32 -0
- usd_validation_nvidia/capabilities/_protocols.py +88 -0
- usd_validation_nvidia/capabilities/_requirements.py +1387 -0
- usd_validation_nvidia/capabilities/resources/examples/00/45669ab9dd09.usd +12 -0
- usd_validation_nvidia/capabilities/resources/examples/00/4896a3fc137f.usd +12 -0
- usd_validation_nvidia/capabilities/resources/examples/00/533092c966dd.usd +20 -0
- usd_validation_nvidia/capabilities/resources/examples/00/9767384c2c07.usd +49 -0
- usd_validation_nvidia/capabilities/resources/examples/00/98e9917af76b.usd +21 -0
- usd_validation_nvidia/capabilities/resources/examples/00/a018f1762b78.usd +41 -0
- usd_validation_nvidia/capabilities/resources/examples/00/b376fbb51d87.usd +12 -0
- usd_validation_nvidia/capabilities/resources/examples/00/c2d5688e153e.usd +13 -0
- usd_validation_nvidia/capabilities/resources/examples/00/ca3906cd7380.usd +13 -0
- usd_validation_nvidia/capabilities/resources/examples/00/ce676dd7e665.usd +27 -0
- usd_validation_nvidia/capabilities/resources/examples/00/d1e740ab553d.usd +16 -0
- usd_validation_nvidia/capabilities/resources/examples/00/fafd55b35003.usd +21 -0
- usd_validation_nvidia/capabilities/resources/examples/00/fba14ee4cdf3.usd +9 -0
- usd_validation_nvidia/capabilities/resources/examples/01/02b23309ee4a.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/01/05b659d1f160.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/01/0a19ac9d7a5d.usd +25 -0
- usd_validation_nvidia/capabilities/resources/examples/01/61e7932c800a.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/01/73d14a824a24.usd +9 -0
- usd_validation_nvidia/capabilities/resources/examples/01/74cb537131a9.usd +9 -0
- usd_validation_nvidia/capabilities/resources/examples/01/78a1d7eb6c15.usd +9 -0
- usd_validation_nvidia/capabilities/resources/examples/01/7a4d2458d7ea.usd +21 -0
- usd_validation_nvidia/capabilities/resources/examples/01/7fcb32c2828c.usd +13 -0
- usd_validation_nvidia/capabilities/resources/examples/01/87f39d3a0ffe.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/01/c334b91c9672.usd +29 -0
- usd_validation_nvidia/capabilities/resources/examples/01/d73c83879ffe.usd +9 -0
- usd_validation_nvidia/capabilities/resources/examples/01/fc3b97f9b696.usd +43 -0
- usd_validation_nvidia/capabilities/resources/examples/02/2b61e74a3e88.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/02/3add5da75b2f.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/02/5fa8d56cc0bc.usd +12 -0
- usd_validation_nvidia/capabilities/resources/examples/02/64d05bd08943.usd +13 -0
- usd_validation_nvidia/capabilities/resources/examples/02/6b64e42eb8ea.usd +12 -0
- usd_validation_nvidia/capabilities/resources/examples/02/75539e535b9d.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/02/7dfd94ef0098.usd +26 -0
- usd_validation_nvidia/capabilities/resources/examples/02/8b27eeb796b3.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/02/8bcb6159d05d.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/02/94a45a0666bc.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/02/aeb059656113.usd +12 -0
- usd_validation_nvidia/capabilities/resources/examples/02/e151d7f67362.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/02/f624d6678ddf.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/03/02af8fef4c08.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/03/054e31dbb16e.usd +13 -0
- usd_validation_nvidia/capabilities/resources/examples/03/088c32bfae76.usd +14 -0
- usd_validation_nvidia/capabilities/resources/examples/03/120b882a9833.usd +18 -0
- usd_validation_nvidia/capabilities/resources/examples/03/3d5baf1c77b8.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/03/5479443d3f56.usd +24 -0
- usd_validation_nvidia/capabilities/resources/examples/03/59e4d07a6d7d.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/03/719a688b955c.usd +13 -0
- usd_validation_nvidia/capabilities/resources/examples/03/8254eb4eedd8.usd +17 -0
- usd_validation_nvidia/capabilities/resources/examples/03/8921a503eb51.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/03/90b35f9ae887.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/03/d9afe93fedea.usd +18 -0
- usd_validation_nvidia/capabilities/resources/examples/03/e8a658439f16.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/04/0d71981cdb5e.usd +20 -0
- usd_validation_nvidia/capabilities/resources/examples/04/187726556645.usd +20 -0
- usd_validation_nvidia/capabilities/resources/examples/04/281c37e748b9.usd +9 -0
- usd_validation_nvidia/capabilities/resources/examples/04/2ebd0d916c9b.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/04/59a6ec7a03ef.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/04/61159d4ac695.usd +17 -0
- usd_validation_nvidia/capabilities/resources/examples/04/706032040b61.usd +9 -0
- usd_validation_nvidia/capabilities/resources/examples/04/75accf7692de.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/04/7c2551dd5b8e.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/04/83b58e415ca8.usd +12 -0
- usd_validation_nvidia/capabilities/resources/examples/04/8438e5579a1a.usd +18 -0
- usd_validation_nvidia/capabilities/resources/examples/04/b08778acebc7.usd +20 -0
- usd_validation_nvidia/capabilities/resources/examples/04/b6e495b692f5.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/05/26eb65906442.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/05/38cf2e8cb400.usd +5 -0
- usd_validation_nvidia/capabilities/resources/examples/05/72fcbd86aac3.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/05/77b339f0b2b5.usd +12 -0
- usd_validation_nvidia/capabilities/resources/examples/05/792d2542acaa.usd +13 -0
- usd_validation_nvidia/capabilities/resources/examples/05/82fa6f3b3ac1.usd +13 -0
- usd_validation_nvidia/capabilities/resources/examples/05/9f506b1db128.usd +4 -0
- usd_validation_nvidia/capabilities/resources/examples/05/a80e5ec526a5.usd +3 -0
- usd_validation_nvidia/capabilities/resources/examples/05/cffa17b140ea.usd +4 -0
- usd_validation_nvidia/capabilities/resources/examples/05/d53866b4a643.usd +14 -0
- usd_validation_nvidia/capabilities/resources/examples/05/ecbadd46db8c.usd +12 -0
- usd_validation_nvidia/capabilities/resources/examples/05/f564eeaf18ff.usd +4 -0
- usd_validation_nvidia/capabilities/resources/examples/05/fdc43961451d.usd +9 -0
- usd_validation_nvidia/capabilities/resources/examples/06/068985dfa562.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/06/138f1f201473.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/06/17ffd2f1e7da.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/06/32cfaa0e3280.usd +12 -0
- usd_validation_nvidia/capabilities/resources/examples/06/4074296992d8.usd +5 -0
- usd_validation_nvidia/capabilities/resources/examples/06/4a04f5d9b830.usd +4 -0
- usd_validation_nvidia/capabilities/resources/examples/06/648eed8228b7.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/06/75c7001ad571.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/06/854e68429163.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/06/9f506b1db128.usd +4 -0
- usd_validation_nvidia/capabilities/resources/examples/06/a80e5ec526a5.usd +3 -0
- usd_validation_nvidia/capabilities/resources/examples/06/f564eeaf18ff.usd +4 -0
- usd_validation_nvidia/capabilities/resources/examples/07/015426938bd9.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/07/281148c05f7d.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/07/2f2fa557aa97.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/07/4064d5be6f9d.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/07/4c581f66ec9f.usd +29 -0
- usd_validation_nvidia/capabilities/resources/examples/07/5f9fcf60e7fa.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/07/605418b688ae.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/07/9ea9a6ab4f4b.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/07/c536337f94d6.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/07/d22af09d4d2e.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/07/d5b20f0af146.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/07/f3fae83e2685.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/07/f59a1e074f6a.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/08/3a5112836bdc.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/08/3cd3e440196a.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/08/48231d3dd720.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/08/5b5b555687aa.usd +17 -0
- usd_validation_nvidia/capabilities/resources/examples/08/7cf0027fa259.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/08/89f6053199b2.usd +16 -0
- usd_validation_nvidia/capabilities/resources/examples/08/a6615727dcbd.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/08/bea446a82e13.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/08/d359b91aa14d.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/08/d77805a3c964.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/08/eaf0928d41d1.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/08/f4fcea4fc846.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/08/fea09720eddf.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/09/194e40325329.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/09/2c583ce006e8.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/09/61999acd7ef8.usd +15 -0
- usd_validation_nvidia/capabilities/resources/examples/09/7cf0027fa259.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/09/7cf88b803519.usd +22 -0
- usd_validation_nvidia/capabilities/resources/examples/09/82e29477b866.usd +15 -0
- usd_validation_nvidia/capabilities/resources/examples/09/843069bdea5d.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/09/8661669793e5.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/09/b6cd230b3dae.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/09/edb67c6299cc.usd +15 -0
- usd_validation_nvidia/capabilities/resources/examples/0a/0663731da3b1.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/0a/327844431d93.usd +20 -0
- usd_validation_nvidia/capabilities/resources/examples/0a/3b5ccc0bccf8.usd +15 -0
- usd_validation_nvidia/capabilities/resources/examples/0a/4e3f9359fd1c.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/0a/506aa9882eff.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/0a/5aa805c2ad4a.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/0a/6a72b4df46a1.usd +13 -0
- usd_validation_nvidia/capabilities/resources/examples/0a/7221a6f87568.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/0a/79f7e607bccc.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/0a/8b7bf5824da2.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/0a/bbe44b74e0f7.usd +6 -0
- usd_validation_nvidia/capabilities/resources/examples/0a/ddd69d178f70.usd +15 -0
- usd_validation_nvidia/capabilities/resources/examples/0a/fd2b9c6f7425.usd +22 -0
- usd_validation_nvidia/capabilities/resources/examples/0b/210351a9aa2d.usd +9 -0
- usd_validation_nvidia/capabilities/resources/examples/0b/30f1cdc37598.usd +12 -0
- usd_validation_nvidia/capabilities/resources/examples/0b/3ff310969c95.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/0b/42d548491dea.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/0b/6a9646b37dd0.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/0b/82e8138d517e.usd +14 -0
- usd_validation_nvidia/capabilities/resources/examples/0b/838d5944f69c.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/0b/9ea469e25c80.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/0b/a86d845b778b.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/0b/d1e3cac25d86.usd +13 -0
- usd_validation_nvidia/capabilities/resources/examples/0b/db78319c95eb.usd +9 -0
- usd_validation_nvidia/capabilities/resources/examples/0b/e14977912bb8.usd +16 -0
- usd_validation_nvidia/capabilities/resources/examples/0c/09523f6f9331.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/0c/0b55f29c3ad4.usd +11 -0
- usd_validation_nvidia/capabilities/resources/examples/0c/1dcd01fcc830.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/0c/3476de1647c0.usd +16 -0
- usd_validation_nvidia/capabilities/resources/examples/0c/37e50e2cc5e8.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/0c/48b1c5ad267b.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/0c/67b2df583c67.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/0c/74114ce8c7f7.usd +8 -0
- usd_validation_nvidia/capabilities/resources/examples/0c/9c0ba66799b1.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/0c/9de07f8ca5ef.usd +7 -0
- usd_validation_nvidia/capabilities/resources/examples/0c/e95f1b332fea.usd +15 -0
- usd_validation_nvidia/capabilities/resources/examples/0c/ebd273a1eb51.usd +10 -0
- usd_validation_nvidia/capabilities/resources/examples/0c/edcb672a6776.usd +9 -0
- usd_validation_nvidia/capabilities/resources/examples/0d/21714600c604.usd +16 -0
- usd_validation_nvidia/capabilities/resources/examples/0d/22ca9e12942b.usd +37 -0
- usd_validation_nvidia/capabilities/resources/examples/0d/6397793faf00.usd +47 -0
- usd_validation_nvidia/capabilities/resources/examples/0d/9fba68d1fc41.usd +33 -0
- usd_validation_nvidia/capabilities/resources/examples/0d/e236731fa5b7.usd +14 -0
- usd_validation_nvidia/capabilities/resources/examples/0d/f71ef7ff2bfd.usd +14 -0
- usd_validation_nvidia/capabilities/resources/examples/0d/fceedef3aeb0.usd +19 -0
- usd_validation_nvidia/tests/__init__.py +16 -0
- usd_validation_nvidia/tests/_assertions.py +197 -0
- usd_validation_nvidia/tests/_testcases.py +465 -0
- usd_validation_nvidia-1.19.3.dist-info/METADATA +137 -0
- usd_validation_nvidia-1.19.3.dist-info/RECORD +246 -0
- usd_validation_nvidia-1.19.3.dist-info/WHEEL +4 -0
- usd_validation_nvidia-1.19.3.dist-info/entry_points.txt +5 -0
- usd_validation_nvidia-1.19.3.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,1082 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2018 Pixar
|
|
3
|
+
# Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the terms set forth in the LICENSE.txt file available at
|
|
6
|
+
# https://openusd.org/license.
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
import re
|
|
11
|
+
from collections.abc import Callable, Generator
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
from functools import partial
|
|
14
|
+
from itertools import groupby
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from pxr import Ar, Gf, Kind, Plug, Sdf, Tf, Usd, UsdGeom, UsdLux, UsdSkel, Vt
|
|
18
|
+
|
|
19
|
+
import usd_validation_nvidia.capabilities as cap
|
|
20
|
+
|
|
21
|
+
from ._base_rule_checker import BaseRuleChecker, Suggestion
|
|
22
|
+
from ._categories import register_rule
|
|
23
|
+
from ._requirements import register_requirements
|
|
24
|
+
from ._usd_validator_adapter import UsdValidatorAdapter
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"ByteAlignmentChecker",
|
|
28
|
+
"CompressionChecker",
|
|
29
|
+
"ExtentsChecker",
|
|
30
|
+
"KindChecker",
|
|
31
|
+
"MissingReferenceChecker",
|
|
32
|
+
"NormalMapTextureChecker",
|
|
33
|
+
"PortableAssetPathChecker",
|
|
34
|
+
"PrimEncapsulationChecker",
|
|
35
|
+
"StageMetadataChecker",
|
|
36
|
+
"TextureChecker",
|
|
37
|
+
"TypeChecker",
|
|
38
|
+
"UsdzPackageValidator",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class NodeTypes:
|
|
43
|
+
UsdPreviewSurface = "UsdPreviewSurface"
|
|
44
|
+
UsdUVTexture = "UsdUVTexture"
|
|
45
|
+
UsdTransform2d = "UsdTransform2d"
|
|
46
|
+
UsdPrimvarReader = "UsdPrimvarReader"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ShaderProps:
|
|
50
|
+
Bias = "bias"
|
|
51
|
+
Scale = "scale"
|
|
52
|
+
SourceColorSpace = "sourceColorSpace"
|
|
53
|
+
Normal = "normal"
|
|
54
|
+
File = "file"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@register_rule("Basic", skip="usdUtilsValidators:UsdzPackageValidator" not in UsdValidatorAdapter)
|
|
58
|
+
class UsdzPackageValidator(UsdValidatorAdapter):
|
|
59
|
+
|
|
60
|
+
@classmethod
|
|
61
|
+
def validator_name(cls) -> str:
|
|
62
|
+
return "usdUtilsValidators:UsdzPackageValidator"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@register_rule("Basic", skip=UsdzPackageValidator.is_implemented())
|
|
66
|
+
class ByteAlignmentChecker(BaseRuleChecker):
|
|
67
|
+
"""
|
|
68
|
+
Files within a usdz package must be laid out properly, i.e. they should be aligned to 64 bytes.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
def __init__(self, verbose, consumerLevelChecks, assetLevelChecks):
|
|
72
|
+
super().__init__(verbose, consumerLevelChecks, assetLevelChecks)
|
|
73
|
+
|
|
74
|
+
def CheckZipFile(self, zipFile, packagePath):
|
|
75
|
+
file_names = zipFile.GetFileNames()
|
|
76
|
+
for file_name in file_names:
|
|
77
|
+
_ = Ar.GetResolver().GetExtension(file_name)
|
|
78
|
+
file_info = zipFile.GetFileInfo(file_name)
|
|
79
|
+
offset = file_info.dataOffset
|
|
80
|
+
if offset % 64 != 0:
|
|
81
|
+
self._AddFailedCheck(f"File '{file_name}' in package '{packagePath}' has an invalid offset {offset}.")
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@register_rule("Basic", skip=UsdzPackageValidator.is_implemented())
|
|
85
|
+
class CompressionChecker(BaseRuleChecker):
|
|
86
|
+
"""
|
|
87
|
+
Files within a usdz package should not be compressed or encrypted.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
def __init__(self, verbose, consumerLevelChecks, assetLevelChecks):
|
|
91
|
+
super().__init__(verbose, consumerLevelChecks, assetLevelChecks)
|
|
92
|
+
|
|
93
|
+
def CheckZipFile(self, zipFile, packagePath):
|
|
94
|
+
file_names = zipFile.GetFileNames()
|
|
95
|
+
for file_name in file_names:
|
|
96
|
+
_ = Ar.GetResolver().GetExtension(file_name)
|
|
97
|
+
file_info = zipFile.GetFileInfo(file_name)
|
|
98
|
+
if file_info.compressionMethod != 0:
|
|
99
|
+
self._AddFailedCheck(
|
|
100
|
+
f"File '{file_name}' in package '{packagePath}' has "
|
|
101
|
+
"compression. Compression method is '{file_info.compressionMethod}', actual size "
|
|
102
|
+
"is {file_info.size}. Uncompressed size is {file_info.uncompressedSize}."
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@register_rule("Basic")
|
|
107
|
+
class MissingReferenceChecker(BaseRuleChecker):
|
|
108
|
+
"""
|
|
109
|
+
The composed USD stage should not contain any unresolvable asset dependencies (in every possible variation of the
|
|
110
|
+
asset), when using the default asset resolver.
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
# See UsdStage::_ReportErrors
|
|
114
|
+
# See PcpErrorInvalidAssetPath::ToString
|
|
115
|
+
_PATH_ASSET_PATTERN = re.compile(
|
|
116
|
+
r"In <(?P<path>.+?)>: Could not open asset @(?P<asset>.+?)@ "
|
|
117
|
+
r"(?P<message>for (reference|payload) introduced by @.+?@<.+?>\.) "
|
|
118
|
+
r"\((instantiating|recomposing) stage on stage @.+?@ <.+?>\)"
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
def __init__(self, verbose, consumerLevelChecks, assetLevelChecks):
|
|
122
|
+
super().__init__(verbose, consumerLevelChecks, assetLevelChecks)
|
|
123
|
+
self.stage: Usd.Stage | None = None
|
|
124
|
+
self.references: set[str] = set()
|
|
125
|
+
|
|
126
|
+
@classmethod
|
|
127
|
+
def _is_composition_warning(cls, diagnostic: Tf.Warning) -> bool:
|
|
128
|
+
"""
|
|
129
|
+
A diagnostic is a composition error if it is issued by the _ReportErrors function in the usd::Stage class.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
diagnostic: The diagnostic to check.
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
True if the diagnostic is a composition error, False otherwise.
|
|
136
|
+
"""
|
|
137
|
+
return (
|
|
138
|
+
"_ReportErrors" in diagnostic.sourceFunction
|
|
139
|
+
and os.path.join("usd", "stage.cpp") in diagnostic.sourceFileName
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
@classmethod
|
|
143
|
+
def _extract_from_commentary(cls, commentary: str) -> tuple[str, Sdf.Path | None, Sdf.AssetPath | None]:
|
|
144
|
+
"""
|
|
145
|
+
Args:
|
|
146
|
+
commentary: The warning found.
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
A tuple of message, path (optional) and unresolved reference (optional).
|
|
150
|
+
"""
|
|
151
|
+
if match := cls._PATH_ASSET_PATTERN.match(commentary):
|
|
152
|
+
path: Sdf.Path = Sdf.Path(match.group("path"))
|
|
153
|
+
asset: Sdf.AssetPath = Sdf.AssetPath(match.group("asset"))
|
|
154
|
+
message: str = match.group("message")
|
|
155
|
+
return (f"Could not open asset {asset} {message}", path if path else None, asset if asset else None)
|
|
156
|
+
return commentary, None, None
|
|
157
|
+
|
|
158
|
+
def CheckStage(self, stage: Usd.Stage) -> None:
|
|
159
|
+
self.stage = stage
|
|
160
|
+
|
|
161
|
+
def CheckDiagnostics(self, diagnostics) -> None:
|
|
162
|
+
composition_warnings: list[Tf.Warning] = list(filter(self._is_composition_warning, diagnostics))
|
|
163
|
+
warnings_commentaries: list[str] = list(map(lambda diagnostic: diagnostic.commentary, composition_warnings))
|
|
164
|
+
missing_references: list[tuple] = list(map(self._extract_from_commentary, warnings_commentaries))
|
|
165
|
+
missing_references.sort()
|
|
166
|
+
for (message, path, reference), _ in groupby(missing_references):
|
|
167
|
+
self._AddFailedCheck(message, at=self.stage.GetPrimAtPath(path.GetPrimPath()) if path else None)
|
|
168
|
+
if reference:
|
|
169
|
+
self.references.add(reference.path)
|
|
170
|
+
|
|
171
|
+
def CheckUnresolvedPaths(self, unresolvedPaths) -> None:
|
|
172
|
+
paths: set[str] = set(unresolvedPaths)
|
|
173
|
+
paths -= self.references
|
|
174
|
+
for unresolved_path in paths:
|
|
175
|
+
self._AddFailedCheck(f"Found unresolvable external dependency '{unresolved_path}'.")
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
@register_rule("Basic", skip=True)
|
|
179
|
+
@register_requirements(cap.Requirements.AA_003)
|
|
180
|
+
class PortableAssetPathChecker(BaseRuleChecker):
|
|
181
|
+
"""
|
|
182
|
+
Asset paths should use forward slashes for portability.
|
|
183
|
+
|
|
184
|
+
Windows-style backslashes in asset paths are not supported by USD and will cause
|
|
185
|
+
assets to fail loading on non-Windows platforms. This checker detects backslashes
|
|
186
|
+
in sublayer, reference, and payload paths and provides a fixer to convert them
|
|
187
|
+
to forward slashes.
|
|
188
|
+
"""
|
|
189
|
+
|
|
190
|
+
def CheckLayer(self, layer: Sdf.Layer) -> None:
|
|
191
|
+
for path in layer.subLayerPaths:
|
|
192
|
+
if "\\" in path:
|
|
193
|
+
self._AddFailedCheck(at=layer, fn=self._fix_sublayers)
|
|
194
|
+
|
|
195
|
+
def check_spec(spec_path: Sdf.Path) -> None:
|
|
196
|
+
spec = layer.GetObjectAtPath(spec_path)
|
|
197
|
+
|
|
198
|
+
if isinstance(spec, Sdf.PrimSpec):
|
|
199
|
+
for list_op in [
|
|
200
|
+
spec.referenceList.addedItems,
|
|
201
|
+
spec.referenceList.prependedItems,
|
|
202
|
+
spec.referenceList.appendedItems,
|
|
203
|
+
spec.referenceList.explicitItems,
|
|
204
|
+
]:
|
|
205
|
+
for ref in list_op:
|
|
206
|
+
if "\\" in ref.assetPath:
|
|
207
|
+
self._AddFailedCheck(at=spec, fn=self._fix_references)
|
|
208
|
+
for list_op in [
|
|
209
|
+
spec.payloadList.addedItems,
|
|
210
|
+
spec.payloadList.prependedItems,
|
|
211
|
+
spec.payloadList.appendedItems,
|
|
212
|
+
spec.payloadList.explicitItems,
|
|
213
|
+
]:
|
|
214
|
+
for payload in list_op:
|
|
215
|
+
if "\\" in payload.assetPath:
|
|
216
|
+
self._AddFailedCheck(at=spec, fn=self._fix_payloads)
|
|
217
|
+
|
|
218
|
+
elif isinstance(spec, Sdf.AttributeSpec):
|
|
219
|
+
if isinstance(spec.default, Sdf.AssetPath) and "\\" in spec.default.path:
|
|
220
|
+
self._AddFailedCheck(at=spec, fn=self._fix_attribute)
|
|
221
|
+
|
|
222
|
+
layer.Traverse(Sdf.Path.absoluteRootPath, check_spec)
|
|
223
|
+
|
|
224
|
+
def _AddFailedCheck(self, at: Sdf.Layer | Sdf.Spec, fn: Callable[..., None]) -> None:
|
|
225
|
+
super()._AddFailedCheck(
|
|
226
|
+
"Use forward slashes for portability",
|
|
227
|
+
requirement=cap.Requirements.AA_003,
|
|
228
|
+
at=at,
|
|
229
|
+
suggestion=Suggestion(
|
|
230
|
+
message="Replace backslashes with forward slashes",
|
|
231
|
+
callable=fn,
|
|
232
|
+
),
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
@staticmethod
|
|
236
|
+
def _fix_sublayers(_: Usd.Stage, at: Sdf.Layer) -> None:
|
|
237
|
+
at.subLayerPaths = [p.replace("\\", "/") for p in at.subLayerPaths]
|
|
238
|
+
|
|
239
|
+
@staticmethod
|
|
240
|
+
def _fix_references(_: Usd.Stage, at: Sdf.PrimSpec) -> None:
|
|
241
|
+
for list_op in [
|
|
242
|
+
at.referenceList.addedItems,
|
|
243
|
+
at.referenceList.prependedItems,
|
|
244
|
+
at.referenceList.appendedItems,
|
|
245
|
+
at.referenceList.explicitItems,
|
|
246
|
+
]:
|
|
247
|
+
list_op[:] = [
|
|
248
|
+
(
|
|
249
|
+
Sdf.Reference(
|
|
250
|
+
assetPath=ref.assetPath.replace("\\", "/"),
|
|
251
|
+
primPath=ref.primPath,
|
|
252
|
+
layerOffset=ref.layerOffset,
|
|
253
|
+
customData=ref.customData,
|
|
254
|
+
)
|
|
255
|
+
if "\\" in ref.assetPath
|
|
256
|
+
else ref
|
|
257
|
+
)
|
|
258
|
+
for ref in list_op
|
|
259
|
+
]
|
|
260
|
+
|
|
261
|
+
@staticmethod
|
|
262
|
+
def _fix_payloads(_: Usd.Stage, at: Sdf.PrimSpec) -> None:
|
|
263
|
+
for list_op in [
|
|
264
|
+
at.payloadList.addedItems,
|
|
265
|
+
at.payloadList.prependedItems,
|
|
266
|
+
at.payloadList.appendedItems,
|
|
267
|
+
at.payloadList.explicitItems,
|
|
268
|
+
]:
|
|
269
|
+
list_op[:] = [
|
|
270
|
+
(
|
|
271
|
+
Sdf.Payload(
|
|
272
|
+
assetPath=payload.assetPath.replace("\\", "/"),
|
|
273
|
+
primPath=payload.primPath,
|
|
274
|
+
layerOffset=payload.layerOffset,
|
|
275
|
+
)
|
|
276
|
+
if "\\" in payload.assetPath
|
|
277
|
+
else payload
|
|
278
|
+
)
|
|
279
|
+
for payload in list_op
|
|
280
|
+
]
|
|
281
|
+
|
|
282
|
+
@staticmethod
|
|
283
|
+
def _fix_attribute(_: Usd.Stage, at: Sdf.AttributeSpec) -> None:
|
|
284
|
+
if isinstance(at.default, Sdf.AssetPath):
|
|
285
|
+
at.default = Sdf.AssetPath(at.default.path.replace("\\", "/"))
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
@register_rule("Basic")
|
|
289
|
+
@register_requirements(cap.Requirements.UN_001, cap.Requirements.UN_002)
|
|
290
|
+
class StageMetadataChecker(BaseRuleChecker):
|
|
291
|
+
"""
|
|
292
|
+
All stages should declare their 'upAxis' and 'metersPerUnit'. Stages that can be consumed as referencable assets
|
|
293
|
+
should furthermore have a valid 'defaultPrim' declared, and stages meant for consumer-level packaging should
|
|
294
|
+
always have upAxis set to 'Y'
|
|
295
|
+
"""
|
|
296
|
+
|
|
297
|
+
def __init__(self, verbose, consumerLevelChecks, assetLevelChecks):
|
|
298
|
+
super().__init__(verbose, consumerLevelChecks, assetLevelChecks)
|
|
299
|
+
|
|
300
|
+
def CheckStage(self, usdStage):
|
|
301
|
+
from pxr import UsdGeom
|
|
302
|
+
|
|
303
|
+
if not usdStage.HasAuthoredMetadata(UsdGeom.Tokens.upAxis):
|
|
304
|
+
self._AddFailedCheck(
|
|
305
|
+
message="Stage does not specify an upAxis.",
|
|
306
|
+
requirement=cap.Requirements.UN_001,
|
|
307
|
+
)
|
|
308
|
+
elif self._consumerLevelChecks:
|
|
309
|
+
up_axis = UsdGeom.GetStageUpAxis(usdStage)
|
|
310
|
+
if up_axis != UsdGeom.Tokens.y:
|
|
311
|
+
self._AddFailedCheck(
|
|
312
|
+
f"Stage specifies upAxis '{up_axis}'. upAxis should be '{UsdGeom.Tokens.y}'.",
|
|
313
|
+
requirement=cap.Requirements.UN_001,
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
if not usdStage.HasAuthoredMetadata(UsdGeom.Tokens.metersPerUnit):
|
|
317
|
+
self._AddFailedCheck(
|
|
318
|
+
message="Stage does not specify its linear scale " "in metersPerUnit.",
|
|
319
|
+
requirement=cap.Requirements.UN_002,
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
if self._assetLevelChecks:
|
|
323
|
+
default_prim = usdStage.GetDefaultPrim()
|
|
324
|
+
if not default_prim:
|
|
325
|
+
self._AddFailedCheck("Stage has missing or invalid defaultPrim.")
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
@register_rule("Basic")
|
|
329
|
+
class TextureChecker(BaseRuleChecker):
|
|
330
|
+
"""A RuleChecker which handles locating texture files automatically.
|
|
331
|
+
|
|
332
|
+
Texture files should be readable by intended client (only .jpg or .png for consumer-level USDZ). Derived classes
|
|
333
|
+
can reimplement `TextureChecker._CheckTexture`.
|
|
334
|
+
"""
|
|
335
|
+
|
|
336
|
+
# The most basic formats are those published in the USDZ spec
|
|
337
|
+
_BASIC_USDZ_IMAGE_FORMATS = ("jpg", "png")
|
|
338
|
+
|
|
339
|
+
# In non-consumer-content mode, OIIO can allow us to
|
|
340
|
+
# additionaly read other formats from USDZ packages
|
|
341
|
+
_EXTRA_USDZ_OIIO_IMAGE_FORMATS = ".exr"
|
|
342
|
+
|
|
343
|
+
# Include a list of "unsupported" image formats to provide better error
|
|
344
|
+
# messages when we find one of these. Our builtin image decoder
|
|
345
|
+
# _can_ decode these, but they are not considered portable consumer-level
|
|
346
|
+
_UNSUPPORTED_IMAGE_FORMATS = ["bmp", "tga", "hdr", "exr", "tif", "zfile", "tx"]
|
|
347
|
+
|
|
348
|
+
def __init__(self, verbose, consumerLevelChecks, assetLevelChecks):
|
|
349
|
+
# Check if the prim has an allowed type.
|
|
350
|
+
super().__init__(verbose, consumerLevelChecks, assetLevelChecks)
|
|
351
|
+
# allow all known formats by default
|
|
352
|
+
self._allowedFormats = (
|
|
353
|
+
list(TextureChecker._BASIC_USDZ_IMAGE_FORMATS) + TextureChecker._UNSUPPORTED_IMAGE_FORMATS
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
def CheckStage(self, usdStage):
|
|
357
|
+
# This is the point at which we can determine whether we have a USDZ
|
|
358
|
+
# archive, and so have enough information to set the allowed formats.
|
|
359
|
+
root_layer = usdStage.GetRootLayer()
|
|
360
|
+
if root_layer.GetFileFormat().IsPackage() or self._consumerLevelChecks:
|
|
361
|
+
self._allowedFormats = list(TextureChecker._BASIC_USDZ_IMAGE_FORMATS)
|
|
362
|
+
if not self._consumerLevelChecks:
|
|
363
|
+
self._allowedFormats.append(TextureChecker._EXTRA_USDZ_OIIO_IMAGE_FORMATS)
|
|
364
|
+
|
|
365
|
+
def _CheckTexture(self, texAssetPath, attr):
|
|
366
|
+
"""Check the texture asset used by the shader input
|
|
367
|
+
|
|
368
|
+
Args:
|
|
369
|
+
texAssetPath: The AssetPath for the texture file
|
|
370
|
+
attr: The attribute that uses the texture
|
|
371
|
+
"""
|
|
372
|
+
text_file_ext = Ar.GetResolver().GetExtension(texAssetPath).lower()
|
|
373
|
+
|
|
374
|
+
# Lights are somewhat special in that they have a connectable shader.
|
|
375
|
+
# Their ies light distribution files are not textures, so we skip them.
|
|
376
|
+
if self._is_ies_asset(attr, text_file_ext):
|
|
377
|
+
return
|
|
378
|
+
|
|
379
|
+
if self._consumerLevelChecks and text_file_ext in TextureChecker._UNSUPPORTED_IMAGE_FORMATS:
|
|
380
|
+
self._AddFailedCheck(
|
|
381
|
+
f"Texture <{attr.GetPath()}> with asset @{texAssetPath}@ has non-portable " "file format.",
|
|
382
|
+
at=attr,
|
|
383
|
+
)
|
|
384
|
+
elif text_file_ext not in self._allowedFormats:
|
|
385
|
+
self._AddFailedCheck(
|
|
386
|
+
f"Texture <{attr.GetPath()}> with asset @{texAssetPath}@ has unknown " "file format.", at=attr
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
def CheckPrim(self, prim):
|
|
390
|
+
# Right now, we find texture referenced by looking at the asset-valued
|
|
391
|
+
# inputs on Connectable prims.
|
|
392
|
+
from pxr import Sdf, Usd, UsdShade
|
|
393
|
+
|
|
394
|
+
# Nothing to do if we are an untyped prim
|
|
395
|
+
if not prim.GetTypeName():
|
|
396
|
+
return
|
|
397
|
+
|
|
398
|
+
# Check if the prim is Connectable.
|
|
399
|
+
connectable = UsdShade.ConnectableAPI(prim)
|
|
400
|
+
if not connectable:
|
|
401
|
+
return
|
|
402
|
+
|
|
403
|
+
shader_inputs = connectable.GetInputs()
|
|
404
|
+
for ip in shader_inputs:
|
|
405
|
+
attr = ip.GetAttr()
|
|
406
|
+
if ip.GetTypeName() == Sdf.ValueTypeNames.Asset:
|
|
407
|
+
text_file_path = ip.Get(Usd.TimeCode.EarliestTime())
|
|
408
|
+
# ip may be unauthored and/or connected
|
|
409
|
+
if text_file_path:
|
|
410
|
+
self._CheckTexture(text_file_path.path, attr)
|
|
411
|
+
elif ip.GetTypeName() == Sdf.ValueTypeNames.AssetArray:
|
|
412
|
+
text_path_array = ip.Get(Usd.TimeCode.EarliestTime())
|
|
413
|
+
if text_path_array:
|
|
414
|
+
for text_path in text_path_array:
|
|
415
|
+
self._CheckTexture(text_path, attr)
|
|
416
|
+
|
|
417
|
+
@staticmethod
|
|
418
|
+
def _is_ies_asset(attr: Usd.Attribute, assetFileExt: str):
|
|
419
|
+
"""Returns true if the asset type is a light intensity distribution file applied to a light prim.
|
|
420
|
+
Args:
|
|
421
|
+
attr: The attribute that uses the asset
|
|
422
|
+
assetFileExt: The file extension of the asses
|
|
423
|
+
"""
|
|
424
|
+
if (attr_prim := attr.GetPrim()) and UsdLux.LightAPI(attr_prim):
|
|
425
|
+
return assetFileExt == "ies"
|
|
426
|
+
return False
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
@register_rule("Basic")
|
|
430
|
+
class PrimEncapsulationChecker(BaseRuleChecker):
|
|
431
|
+
"""
|
|
432
|
+
Check for basic prim encapsulation rules:
|
|
433
|
+
|
|
434
|
+
- Boundables may not be nested under Gprims
|
|
435
|
+
- Connectable prims (e.g. Shader, Material, etc) can only be nested inside other Container-like Connectable prims.
|
|
436
|
+
Container-like prims include Material, NodeGraph, Light, LightFilter, and *exclude Shader*
|
|
437
|
+
"""
|
|
438
|
+
|
|
439
|
+
def __init__(self, verbose, consumerLevelChecks, assetLevelChecks):
|
|
440
|
+
super().__init__(verbose, consumerLevelChecks, assetLevelChecks)
|
|
441
|
+
self.ResetCaches()
|
|
442
|
+
|
|
443
|
+
def _HasGprimAncestor(self, prim):
|
|
444
|
+
from pxr import Sdf, UsdGeom
|
|
445
|
+
|
|
446
|
+
path = prim.GetPath()
|
|
447
|
+
if path in self._hasGprimInPathMap:
|
|
448
|
+
return self._hasGprimInPathMap[path]
|
|
449
|
+
elif path == Sdf.Path.absoluteRootPath:
|
|
450
|
+
self._hasGprimInPathMap[path] = False
|
|
451
|
+
return False
|
|
452
|
+
else:
|
|
453
|
+
val = self._HasGprimAncestor(prim.GetParent()) or prim.IsA(UsdGeom.Gprim)
|
|
454
|
+
self._hasGprimInPathMap[path] = val
|
|
455
|
+
return val
|
|
456
|
+
|
|
457
|
+
def _FindConnectableAncestor(self, prim):
|
|
458
|
+
from pxr import Sdf, UsdShade
|
|
459
|
+
|
|
460
|
+
path = prim.GetPath()
|
|
461
|
+
if path in self._connectableAncestorMap:
|
|
462
|
+
return self._connectableAncestorMap[path]
|
|
463
|
+
elif path == Sdf.Path.absoluteRootPath:
|
|
464
|
+
self._connectableAncestorMap[path] = None
|
|
465
|
+
return None
|
|
466
|
+
else:
|
|
467
|
+
val = self._FindConnectableAncestor(prim.GetParent())
|
|
468
|
+
# The GetTypeName() check is to work around a bug in
|
|
469
|
+
# ConnectableAPIBehavior registry.
|
|
470
|
+
if prim.GetTypeName() and not val:
|
|
471
|
+
conn = UsdShade.ConnectableAPI(prim)
|
|
472
|
+
if conn:
|
|
473
|
+
val = prim
|
|
474
|
+
self._connectableAncestorMap[path] = val
|
|
475
|
+
return val
|
|
476
|
+
|
|
477
|
+
def CheckPrim(self, prim):
|
|
478
|
+
from pxr import UsdGeom, UsdShade
|
|
479
|
+
|
|
480
|
+
parent = prim.GetParent()
|
|
481
|
+
|
|
482
|
+
# Of course we must allow Boundables under other Boundables, so that
|
|
483
|
+
# schemas like UsdGeom.Pointinstancer can nest their prototypes. But
|
|
484
|
+
# we disallow a PointInstancer under a Mesh just as we disallow a Mesh
|
|
485
|
+
# under a Mesh, for the same reason: we cannot then independently
|
|
486
|
+
# adjust visibility for the two objects, nor can we reasonably compute
|
|
487
|
+
# the parent Mesh's extent.
|
|
488
|
+
if prim.IsA(UsdGeom.Boundable):
|
|
489
|
+
if parent:
|
|
490
|
+
if self._HasGprimAncestor(parent):
|
|
491
|
+
self._AddFailedCheck(
|
|
492
|
+
f"Gprim <{prim.GetPath()}> has an ancestor prim that " "is also a Gprim, which is not allowed.",
|
|
493
|
+
at=prim,
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
connectable = UsdShade.ConnectableAPI(prim)
|
|
497
|
+
# The GetTypeName() check is to work around a bug in
|
|
498
|
+
# ConnectableAPIBehavior registry.
|
|
499
|
+
if prim.GetTypeName() and connectable:
|
|
500
|
+
if parent:
|
|
501
|
+
p_connectable = UsdShade.ConnectableAPI(parent)
|
|
502
|
+
if not parent.GetTypeName():
|
|
503
|
+
p_connectable = None
|
|
504
|
+
|
|
505
|
+
if p_connectable and hasattr(p_connectable, "IsContainer") and not p_connectable.IsContainer():
|
|
506
|
+
# XXX This should be a failure as it is a violation of the
|
|
507
|
+
# UsdShade OM. But pragmatically, there are many
|
|
508
|
+
# authoring tools currently producing this structure, which
|
|
509
|
+
# does not _currently_ perturb Hydra, so we need to start
|
|
510
|
+
# with a warning
|
|
511
|
+
self._AddWarning(
|
|
512
|
+
f"Connectable {prim.GetTypeName()} <{prim.GetPath()}> cannot reside "
|
|
513
|
+
f"under a non-Container Connectable {parent.GetTypeName()}",
|
|
514
|
+
at=prim,
|
|
515
|
+
)
|
|
516
|
+
elif not p_connectable:
|
|
517
|
+
# it's only OK to have a non-connectable parent if all
|
|
518
|
+
# the rest of your ancestors are also non-connectable. The
|
|
519
|
+
# error message we give is targeted at the most common
|
|
520
|
+
# infraction, using Scope or other grouping prims inside
|
|
521
|
+
# a Container like a Material
|
|
522
|
+
conn_anstr = self._FindConnectableAncestor(parent)
|
|
523
|
+
if conn_anstr is not None:
|
|
524
|
+
self._AddFailedCheck(
|
|
525
|
+
f"Connectable {prim.GetTypeName()} <{prim.GetPath()}> can only have"
|
|
526
|
+
" Connectable Container ancestors"
|
|
527
|
+
f" up to {conn_anstr.GetTypeName()} ancestor <{conn_anstr.GetPath()}>, but its"
|
|
528
|
+
f" parent {parent.GetName()} is a {parent.GetTypeName()}.",
|
|
529
|
+
at=prim,
|
|
530
|
+
)
|
|
531
|
+
|
|
532
|
+
def ResetCaches(self):
|
|
533
|
+
self._connectableAncestorMap = dict()
|
|
534
|
+
self._hasGprimInPathMap = dict()
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
@register_rule("Basic")
|
|
538
|
+
class NormalMapTextureChecker(BaseRuleChecker):
|
|
539
|
+
"""
|
|
540
|
+
UsdUVTexture nodes that feed the `inputs:normals` of a
|
|
541
|
+
UsdPreviewSurface must ensure that the data is encoded and scaled properly.
|
|
542
|
+
Specifically:
|
|
543
|
+
|
|
544
|
+
- Since normals are expected to be in the range [(-1,-1,-1), (1,1,1)],
|
|
545
|
+
the Texture node must transform 8-bit textures from their [0..1] range by
|
|
546
|
+
setting its `inputs:scale` to [2, 2, 2, 1] and
|
|
547
|
+
`inputs:bias` to [-1, -1, -1, 0]
|
|
548
|
+
- Normal map data is commonly expected to be linearly encoded. However, many
|
|
549
|
+
image-writing tools automatically set the profile of three-channel, 8-bit
|
|
550
|
+
images to SRGB. To prevent an unwanted transformation, the UsdUVTexture's
|
|
551
|
+
`inputs:sourceColorSpace` must be set to "raw". This program cannot
|
|
552
|
+
currently read the texture metadata itself, so for now we emit warnings
|
|
553
|
+
about this potential infraction for all 8 bit image formats.
|
|
554
|
+
"""
|
|
555
|
+
|
|
556
|
+
def __init__(self, verbose, consumerLevelChecks, assetLevelChecks):
|
|
557
|
+
super().__init__(verbose, consumerLevelChecks, assetLevelChecks)
|
|
558
|
+
|
|
559
|
+
def _GetShaderId(self, shader):
|
|
560
|
+
# We might someday try harder to find an identifier...
|
|
561
|
+
return shader.GetShaderId()
|
|
562
|
+
|
|
563
|
+
def _TextureIs8Bit(self, asset):
|
|
564
|
+
# Eventually we hope to leverage HioImage through a plugin system,
|
|
565
|
+
# when Imaging is present, to answer this and other image queries
|
|
566
|
+
# more definitively
|
|
567
|
+
from pxr import Ar
|
|
568
|
+
|
|
569
|
+
ext = Ar.GetResolver().GetExtension(asset.resolvedPath)
|
|
570
|
+
# not an exhaustive list, but ones we typically can read
|
|
571
|
+
return ext in ["bmp", "tga", "jpg", "png", "tif"]
|
|
572
|
+
|
|
573
|
+
def _GetInputValue(self, shader, inputName):
|
|
574
|
+
from pxr import Usd, UsdShade
|
|
575
|
+
|
|
576
|
+
shader_input = shader.GetInput(inputName)
|
|
577
|
+
if not shader_input:
|
|
578
|
+
return None
|
|
579
|
+
# Query value producing attributes for input values.
|
|
580
|
+
# This has to be a length of 1, otherwise no attribute is producing a value.
|
|
581
|
+
# If the input is not connected the UsdAttribute for this input is returned,
|
|
582
|
+
# but only if it has an authored value.
|
|
583
|
+
value_producing_attrs = UsdShade.Utils.GetValueProducingAttributes(shader_input)
|
|
584
|
+
if not value_producing_attrs or len(value_producing_attrs) != 1:
|
|
585
|
+
return None
|
|
586
|
+
# We require an input parameter producing the value.
|
|
587
|
+
if not UsdShade.Input.IsInput(value_producing_attrs[0]):
|
|
588
|
+
return None
|
|
589
|
+
return value_producing_attrs[0].Get(Usd.TimeCode.EarliestTime())
|
|
590
|
+
|
|
591
|
+
def CheckPrim(self, prim):
|
|
592
|
+
from pxr import Gf, UsdShade
|
|
593
|
+
from pxr.UsdShade import Utils as ShadeUtils
|
|
594
|
+
|
|
595
|
+
if not prim.IsA(UsdShade.Shader):
|
|
596
|
+
return
|
|
597
|
+
|
|
598
|
+
shader = UsdShade.Shader(prim)
|
|
599
|
+
if not shader:
|
|
600
|
+
self._AddError(f"Invalid shader prim <{prim.GetPath()}>.", at=prim)
|
|
601
|
+
return
|
|
602
|
+
|
|
603
|
+
shader_id = self._GetShaderId(shader)
|
|
604
|
+
|
|
605
|
+
# We may have failed to fetch an identifier for asset/source-based
|
|
606
|
+
# nodes. We are only interested in UsdPreviewSurface nodes identified via
|
|
607
|
+
# info:id, so it's not an error
|
|
608
|
+
if not shader_id or shader_id != NodeTypes.UsdPreviewSurface:
|
|
609
|
+
return
|
|
610
|
+
|
|
611
|
+
normal_input = shader.GetInput(ShaderProps.Normal)
|
|
612
|
+
if not normal_input:
|
|
613
|
+
return
|
|
614
|
+
if not hasattr(ShadeUtils, "GetValueProducingAttributes"):
|
|
615
|
+
return
|
|
616
|
+
value_producing_attrs = ShadeUtils.GetValueProducingAttributes(normal_input)
|
|
617
|
+
if not value_producing_attrs or value_producing_attrs[0].GetPrim() == prim:
|
|
618
|
+
return
|
|
619
|
+
|
|
620
|
+
source_prim = value_producing_attrs[0].GetPrim()
|
|
621
|
+
|
|
622
|
+
source_shader = UsdShade.Shader(source_prim)
|
|
623
|
+
if not source_shader:
|
|
624
|
+
# In theory, could be connected to an interface attribute of a
|
|
625
|
+
# parent connectable... not useful, but not an error
|
|
626
|
+
if UsdShade.ConnectableAPI(source_prim):
|
|
627
|
+
return
|
|
628
|
+
self._AddFailedCheck(
|
|
629
|
+
f"{NodeTypes.UsdPreviewSurface}.{ShaderProps.Normal} on prim <{source_prim}> is connected to a"
|
|
630
|
+
" non-Shader prim.",
|
|
631
|
+
at=source_prim,
|
|
632
|
+
)
|
|
633
|
+
return
|
|
634
|
+
|
|
635
|
+
source_id = self._GetShaderId(source_shader)
|
|
636
|
+
|
|
637
|
+
# We may have failed to fetch an identifier for asset/source-based
|
|
638
|
+
# nodes. OR, we could potentially be driven by a UsdPrimvarReader,
|
|
639
|
+
# in which case we'd have nothing to validate
|
|
640
|
+
if not source_id or source_id != NodeTypes.UsdUVTexture:
|
|
641
|
+
return
|
|
642
|
+
|
|
643
|
+
text_asset = self._GetInputValue(source_shader, ShaderProps.File)
|
|
644
|
+
|
|
645
|
+
if text_asset is None:
|
|
646
|
+
# There's no attribute connected to the input of the source shader
|
|
647
|
+
# and the input has no authored value, so we can't check anything.
|
|
648
|
+
return
|
|
649
|
+
|
|
650
|
+
if not text_asset or not text_asset.resolvedPath:
|
|
651
|
+
self._AddFailedCheck(
|
|
652
|
+
f"{NodeTypes.UsdUVTexture} prim <{source_prim.GetPath()}> has invalid or unresolvable "
|
|
653
|
+
f"inputs:file of @{text_asset.path if text_asset else ''}@",
|
|
654
|
+
at=source_prim,
|
|
655
|
+
)
|
|
656
|
+
return
|
|
657
|
+
|
|
658
|
+
if not self._TextureIs8Bit(text_asset):
|
|
659
|
+
# really nothing more is required for image depths > 8 bits,
|
|
660
|
+
# which we assume FOR NOW, are floating point
|
|
661
|
+
return
|
|
662
|
+
|
|
663
|
+
if not self._GetInputValue(source_shader, ShaderProps.SourceColorSpace):
|
|
664
|
+
self._AddWarning(
|
|
665
|
+
f"{NodeTypes.UsdUVTexture} prim <{source_prim}> that reads Normal Map @{text_asset.path}@ may need "
|
|
666
|
+
"to set inputs:sourceColorSpace to 'raw' as some "
|
|
667
|
+
"8-bit image writers always indicate an SRGB "
|
|
668
|
+
"encoding.",
|
|
669
|
+
at=source_prim,
|
|
670
|
+
)
|
|
671
|
+
|
|
672
|
+
bias = self._GetInputValue(source_shader, ShaderProps.Bias)
|
|
673
|
+
|
|
674
|
+
scale = self._GetInputValue(source_shader, ShaderProps.Scale)
|
|
675
|
+
|
|
676
|
+
if not (bias and scale and isinstance(bias, Gf.Vec4f) and isinstance(scale, Gf.Vec4f)):
|
|
677
|
+
# XXX This should be a failure, as it results in broken normal
|
|
678
|
+
# maps in Storm and hdPrman, at least. But for the same reason
|
|
679
|
+
# as the shader-under-shader check, we cannot fail until at least
|
|
680
|
+
# the major authoring tools have been updated.
|
|
681
|
+
self._AddWarning(
|
|
682
|
+
f"{NodeTypes.UsdUVTexture} prim <{source_prim.GetPath()}> reads 8 bit Normal Map @{text_asset.path}@, "
|
|
683
|
+
"which requires that inputs:scale be set to "
|
|
684
|
+
"[2, 2, 2, 1] and inputs:bias be set to "
|
|
685
|
+
"[-1, -1, -1, 0] for proper interpretation.",
|
|
686
|
+
at=source_prim,
|
|
687
|
+
)
|
|
688
|
+
return
|
|
689
|
+
|
|
690
|
+
# don't really care about fourth components...
|
|
691
|
+
if bias[0] != -1 or bias[1] != -1 or bias[2] != -1 or scale[0] != 2 or scale[1] != 2 or scale[2] != 2:
|
|
692
|
+
self._AddWarning(
|
|
693
|
+
f"{NodeTypes.UsdUVTexture} prim <{source_prim.GetPath()}> reads an 8 bit Normal Map, "
|
|
694
|
+
"but has non-standard inputs:scale and "
|
|
695
|
+
f"inputs:bias values of {scale} and {bias}",
|
|
696
|
+
at=source_prim,
|
|
697
|
+
)
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
@dataclass(frozen=True)
|
|
701
|
+
class _CachedKindState:
|
|
702
|
+
all_group: bool
|
|
703
|
+
"""Self and ancestors are all group kind."""
|
|
704
|
+
|
|
705
|
+
has_empty_ancestor: bool
|
|
706
|
+
"""Self or ancestors have empty kind."""
|
|
707
|
+
|
|
708
|
+
has_component_ancestor: bool
|
|
709
|
+
"""Self or ancestors have component kind."""
|
|
710
|
+
|
|
711
|
+
def join(self, other):
|
|
712
|
+
return self.__class__(
|
|
713
|
+
self.all_group and other.all_group,
|
|
714
|
+
self.has_empty_ancestor or other.has_empty_ancestor,
|
|
715
|
+
self.has_component_ancestor or other.has_component_ancestor,
|
|
716
|
+
)
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
@register_rule("Basic")
|
|
720
|
+
class KindChecker(BaseRuleChecker):
|
|
721
|
+
"""
|
|
722
|
+
All kinds must be registered and conform to the rules specified in the `USD Glossary`_.
|
|
723
|
+
|
|
724
|
+
.. _`USD Glossary`: https://graphics.pixar.com/usd/release/glossary.html?#usdglossary-kind
|
|
725
|
+
"""
|
|
726
|
+
|
|
727
|
+
_ROOT_KINDS = tuple(
|
|
728
|
+
kind
|
|
729
|
+
for kind in Kind.Registry.GetAllKinds()
|
|
730
|
+
if Kind.Registry.IsA(kind, Kind.Tokens.assembly)
|
|
731
|
+
or Kind.Registry.IsA(kind, Kind.Tokens.component)
|
|
732
|
+
or Kind.Registry.IsA(kind, Kind.Tokens.group)
|
|
733
|
+
)
|
|
734
|
+
_GROUP_KINDS = tuple(kind for kind in Kind.Registry.GetAllKinds() if Kind.Registry.IsA(kind, Kind.Tokens.group))
|
|
735
|
+
_VALID_KINDS = tuple(kind for kind in Kind.Registry.GetAllKinds() if kind != Kind.Tokens.model)
|
|
736
|
+
|
|
737
|
+
def __init__(self, verbose, consumerLevelChecks, assetLevelChecks):
|
|
738
|
+
super().__init__(verbose, consumerLevelChecks, assetLevelChecks)
|
|
739
|
+
|
|
740
|
+
self._kind_cache: dict[Sdf.Path, _CachedKindState] = {}
|
|
741
|
+
|
|
742
|
+
@classmethod
|
|
743
|
+
def _is_root_model(cls, prim) -> bool:
|
|
744
|
+
"""Whether this is the first model in the hierarchy."""
|
|
745
|
+
model: Usd.ModelAPI = Usd.ModelAPI(prim)
|
|
746
|
+
if not model.IsModel():
|
|
747
|
+
return False
|
|
748
|
+
parent_prim: Usd.Prim = prim.GetParent()
|
|
749
|
+
if parent_prim.IsPseudoRoot():
|
|
750
|
+
return True
|
|
751
|
+
parent_model = Usd.ModelAPI(parent_prim)
|
|
752
|
+
if parent_model.IsModel():
|
|
753
|
+
return False
|
|
754
|
+
return True
|
|
755
|
+
|
|
756
|
+
def CheckPrim(self, prim):
|
|
757
|
+
model = Usd.ModelAPI(prim)
|
|
758
|
+
kind = model.GetKind()
|
|
759
|
+
if not kind:
|
|
760
|
+
return
|
|
761
|
+
elif self._is_root_model(prim):
|
|
762
|
+
if kind not in self._ROOT_KINDS:
|
|
763
|
+
self._AddFailedCheck(
|
|
764
|
+
f'Invalid Kind "{kind}". Kind "{kind}" cannot be at the root of the Model Hierarchy. The root '
|
|
765
|
+
f"prim of a model must one of {KindChecker._ROOT_KINDS}.",
|
|
766
|
+
at=prim,
|
|
767
|
+
)
|
|
768
|
+
elif kind == Kind.Tokens.model or kind not in Kind.Registry.GetAllKinds():
|
|
769
|
+
self._AddFailedCheck(
|
|
770
|
+
f'Invalid Kind "{kind}". Must be one of {KindChecker._VALID_KINDS}.',
|
|
771
|
+
at=prim,
|
|
772
|
+
)
|
|
773
|
+
elif Kind.Registry.IsA(kind, Kind.Tokens.model):
|
|
774
|
+
kind_state = self._query_ancestors_kind_state(prim)
|
|
775
|
+
if not kind_state.all_group:
|
|
776
|
+
if kind_state.has_component_ancestor:
|
|
777
|
+
suggestion = Suggestion(message="Fix", callable=self.fix_ancestors_kind_with_components)
|
|
778
|
+
elif kind_state.has_empty_ancestor:
|
|
779
|
+
suggestion = Suggestion(message="Fix", callable=self.fix_ancestors_empty_kind)
|
|
780
|
+
else:
|
|
781
|
+
suggestion = None
|
|
782
|
+
self._AddFailedCheck(
|
|
783
|
+
f'Invalid Kind "{kind}". Model prims can only be parented under "{KindChecker._GROUP_KINDS}" prims.',
|
|
784
|
+
at=prim,
|
|
785
|
+
suggestion=suggestion,
|
|
786
|
+
)
|
|
787
|
+
|
|
788
|
+
def _query_ancestors_kind_state(self, prim: Usd.Prim):
|
|
789
|
+
parent_path = prim.GetParent().GetPath()
|
|
790
|
+
if parent_path in self._kind_cache:
|
|
791
|
+
return self._kind_cache[parent_path]
|
|
792
|
+
|
|
793
|
+
prims: list[Usd.Prim] = []
|
|
794
|
+
current: Usd.Prim = prim
|
|
795
|
+
while not current.IsPseudoRoot():
|
|
796
|
+
prims.append(current)
|
|
797
|
+
current = current.GetParent()
|
|
798
|
+
|
|
799
|
+
kind_state = _CachedKindState(True, False, False)
|
|
800
|
+
for current in reversed(prims):
|
|
801
|
+
try:
|
|
802
|
+
kind_state = self._kind_cache[current.GetPath()]
|
|
803
|
+
except KeyError:
|
|
804
|
+
model: Usd.ModelAPI = Usd.ModelAPI(current)
|
|
805
|
+
prim_kind = model.GetKind()
|
|
806
|
+
is_group_kind: bool = Kind.Registry.IsA(prim_kind, Kind.Tokens.group)
|
|
807
|
+
is_empty_kind: bool = not prim_kind
|
|
808
|
+
is_component_kind: bool = not is_group_kind and Kind.Registry.IsA(prim_kind, Kind.Tokens.component)
|
|
809
|
+
prim_kind_state = _CachedKindState(is_group_kind, is_empty_kind, is_component_kind)
|
|
810
|
+
self._kind_cache[current.GetPath()] = kind_state = kind_state.join(prim_kind_state)
|
|
811
|
+
|
|
812
|
+
return self._kind_cache[parent_path]
|
|
813
|
+
|
|
814
|
+
def fix_ancestors_kind_with_components(self, _: Usd.Stage, prim: Usd.Prim):
|
|
815
|
+
model = Usd.ModelAPI(prim)
|
|
816
|
+
kind = model.GetKind()
|
|
817
|
+
if Kind.Registry.IsA(kind, Kind.Tokens.model):
|
|
818
|
+
model.SetKind(Kind.Tokens.subcomponent)
|
|
819
|
+
|
|
820
|
+
def fix_ancestors_empty_kind(self, _: Usd.Stage, prim: Usd.Prim):
|
|
821
|
+
parent = prim.GetParent()
|
|
822
|
+
while not parent.IsPseudoRoot():
|
|
823
|
+
parent_model = Usd.ModelAPI(parent)
|
|
824
|
+
parent_kind = parent_model.GetKind()
|
|
825
|
+
if not parent_kind:
|
|
826
|
+
parent_model.SetKind(Kind.Tokens.group)
|
|
827
|
+
|
|
828
|
+
parent = parent.GetParent()
|
|
829
|
+
|
|
830
|
+
def ResetCaches(self):
|
|
831
|
+
self._kind_cache = {}
|
|
832
|
+
return super().ResetCaches()
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
@register_rule("Basic")
|
|
836
|
+
@register_requirements(cap.Requirements.VG_002)
|
|
837
|
+
class ExtentsChecker(BaseRuleChecker):
|
|
838
|
+
"""
|
|
839
|
+
Boundable prims have the extent attribute. For point based prims, the value of the extent must be correct at each
|
|
840
|
+
time sample of the point attribute
|
|
841
|
+
"""
|
|
842
|
+
|
|
843
|
+
_SCHEMA_TYPE_GETTERS: list[tuple[type[Usd.SchemaBase], list[Callable[[Usd.SchemaBase], Usd.Attribute]]]] = [
|
|
844
|
+
(UsdGeom.PointBased, [lambda obj: obj.GetPointsAttr()]),
|
|
845
|
+
(UsdGeom.Curves, [lambda obj: obj.GetWidthsAttr()]),
|
|
846
|
+
(UsdGeom.Points, [lambda obj: obj.GetWidthsAttr()]),
|
|
847
|
+
(UsdSkel.Root, [lambda obj: obj.GetExtentAttr()]),
|
|
848
|
+
(UsdSkel.Skeleton, [lambda obj: obj.GetExtentAttr()]),
|
|
849
|
+
]
|
|
850
|
+
"""
|
|
851
|
+
Unfortunately, there's no universal way of knowing which attributes extent calculation depends on.
|
|
852
|
+
Hence we hardcode the attributes per schema in SCHEMA_TYPE_GETTERS
|
|
853
|
+
"""
|
|
854
|
+
_MAX_TIME_SAMPLES: int = 5
|
|
855
|
+
"""
|
|
856
|
+
int: The maximum number of samples to report.
|
|
857
|
+
"""
|
|
858
|
+
|
|
859
|
+
def __init__(self, verbose: bool, consumerLevelChecks: bool, assetLevelChecks: bool):
|
|
860
|
+
super().__init__(verbose, consumerLevelChecks, assetLevelChecks)
|
|
861
|
+
self.ResetCaches()
|
|
862
|
+
|
|
863
|
+
@staticmethod
|
|
864
|
+
def _get_attribute_time_samples(attribute: Usd.Attribute) -> Generator[Usd.TimeCode, None, None]:
|
|
865
|
+
"""
|
|
866
|
+
Args:
|
|
867
|
+
attribute: The attribute to extract the time samples.
|
|
868
|
+
Returns:
|
|
869
|
+
All time samples in an attribute.
|
|
870
|
+
"""
|
|
871
|
+
if attribute.IsValid():
|
|
872
|
+
if not attribute.ValueMightBeTimeVarying():
|
|
873
|
+
yield Usd.TimeCode.Default()
|
|
874
|
+
else:
|
|
875
|
+
for time in attribute.GetTimeSamples():
|
|
876
|
+
yield Usd.TimeCode(time)
|
|
877
|
+
|
|
878
|
+
@classmethod
|
|
879
|
+
def _get_extent_time_samples(cls, prim: Usd.Prim) -> Generator[Usd.TimeCode, None, None]:
|
|
880
|
+
"""Get the time samples for the extent attribute from the associated attributes (Points, Widths, Extent, etc..).
|
|
881
|
+
Args:
|
|
882
|
+
prim: The prim of the extent attribute to query the time samples .
|
|
883
|
+
|
|
884
|
+
Returns:
|
|
885
|
+
All time samples of the extent attribute.
|
|
886
|
+
"""
|
|
887
|
+
for schema_type, getters in cls._SCHEMA_TYPE_GETTERS:
|
|
888
|
+
instance: Usd.SchemaBase = schema_type(prim)
|
|
889
|
+
if not instance:
|
|
890
|
+
continue
|
|
891
|
+
for getter in getters:
|
|
892
|
+
attribute: Usd.Attribute = getter(instance)
|
|
893
|
+
yield from cls._get_attribute_time_samples(attribute)
|
|
894
|
+
|
|
895
|
+
@classmethod
|
|
896
|
+
def _layers_to_apply(cls, prim: Usd.Prim) -> list[Sdf.Layer]:
|
|
897
|
+
"""
|
|
898
|
+
Iterate Schemas and their respective attributes and fix those layers first.
|
|
899
|
+
"""
|
|
900
|
+
layers: list[Sdf.Layer] = []
|
|
901
|
+
for schema_type, getters in cls._SCHEMA_TYPE_GETTERS:
|
|
902
|
+
instance: Usd.SchemaBase = schema_type(prim)
|
|
903
|
+
if not instance:
|
|
904
|
+
continue
|
|
905
|
+
for getter in getters:
|
|
906
|
+
attribute: Usd.Attribute = getter(instance)
|
|
907
|
+
for spec in attribute.GetPropertyStack(time=Usd.TimeCode.Default()):
|
|
908
|
+
layers.append(spec.layer)
|
|
909
|
+
return layers
|
|
910
|
+
|
|
911
|
+
def _compute_extents(
|
|
912
|
+
self, _: Usd.Stage, prim: Usd.Prim, extent_time_samples: list[Usd.TimeCode | float] | None = None
|
|
913
|
+
) -> None:
|
|
914
|
+
"""
|
|
915
|
+
Compute the extents of a specific prim.
|
|
916
|
+
"""
|
|
917
|
+
boundable: UsdGeom.Boundable = UsdGeom.Boundable(prim)
|
|
918
|
+
|
|
919
|
+
time_code_extent: dict[Usd.TimeCode, Vt.Vec3fArray] = {}
|
|
920
|
+
if not extent_time_samples:
|
|
921
|
+
extent_time_samples = list(ExtentsChecker._get_extent_time_samples(prim))
|
|
922
|
+
for time in extent_time_samples:
|
|
923
|
+
time_code_extent[time] = boundable.ComputeExtentFromPlugins(boundable, time)
|
|
924
|
+
|
|
925
|
+
attribute: Usd.Attribute = boundable.CreateExtentAttr()
|
|
926
|
+
with Sdf.ChangeBlock():
|
|
927
|
+
for time, extent in time_code_extent.items():
|
|
928
|
+
attribute.Set(extent, time)
|
|
929
|
+
|
|
930
|
+
@staticmethod
|
|
931
|
+
def _is_close(lh: Vt.Vec3fArray, rh: Vt.Vec3fArray) -> bool:
|
|
932
|
+
# If either vector is empty don't consider them to be close
|
|
933
|
+
if len(lh) == 0 or len(rh) == 0:
|
|
934
|
+
return False
|
|
935
|
+
|
|
936
|
+
# If the vectors are of different length then they cannot be considered close
|
|
937
|
+
if len(lh) != len(rh):
|
|
938
|
+
return False
|
|
939
|
+
|
|
940
|
+
# Compare the values in the vector
|
|
941
|
+
for lh_value, rh_value in zip(lh, rh):
|
|
942
|
+
if not Gf.IsClose(lh_value, rh_value, Gf.MIN_VECTOR_LENGTH):
|
|
943
|
+
return False
|
|
944
|
+
return True
|
|
945
|
+
|
|
946
|
+
def CheckPrim(self, prim: Usd.Prim) -> None:
|
|
947
|
+
# Skip checked prims.
|
|
948
|
+
if prim in self._checked_prims:
|
|
949
|
+
return
|
|
950
|
+
|
|
951
|
+
# Check UsdSkel prims
|
|
952
|
+
if prim.IsA(UsdSkel.Root):
|
|
953
|
+
self._check_skel(prim)
|
|
954
|
+
else:
|
|
955
|
+
self._check_extent(prim)
|
|
956
|
+
|
|
957
|
+
def _check_extent(self, prim: Usd.Prim, extent_time_samples: list[Usd.TimeCode | float] | None = None) -> None:
|
|
958
|
+
boundable: UsdGeom.Boundable = UsdGeom.Boundable(prim)
|
|
959
|
+
if not boundable:
|
|
960
|
+
return
|
|
961
|
+
|
|
962
|
+
attribute: Usd.Attribute = boundable.GetExtentAttr()
|
|
963
|
+
# Has no value
|
|
964
|
+
if not attribute.HasValue():
|
|
965
|
+
prim_type: Tf.Type = prim.GetPrimTypeInfo().GetSchemaType()
|
|
966
|
+
prim_type_metadata: dict[str, Any] = (
|
|
967
|
+
Plug.Registry().GetPluginForType(prim_type).GetMetadataForType(prim_type.typeName)
|
|
968
|
+
)
|
|
969
|
+
# Boundables that implement compute extent but don't have any authored extent
|
|
970
|
+
# We can assume that the user has made the choice explicitly.
|
|
971
|
+
if prim_type_metadata.get("implementsComputeExtent"):
|
|
972
|
+
return
|
|
973
|
+
self._AddFailedCheck(
|
|
974
|
+
"Prim does not have any extent value",
|
|
975
|
+
at=prim,
|
|
976
|
+
requirement=cap.Requirements.VG_002,
|
|
977
|
+
suggestion=Suggestion(
|
|
978
|
+
message="Compute the extents",
|
|
979
|
+
callable=partial(self._compute_extents, extent_time_samples=extent_time_samples),
|
|
980
|
+
at=self._layers_to_apply(prim),
|
|
981
|
+
),
|
|
982
|
+
)
|
|
983
|
+
return # Nothing more to do
|
|
984
|
+
|
|
985
|
+
# Check extent at each time sample
|
|
986
|
+
authored_vs_computed: dict[Usd.TimeCode, bool] = {}
|
|
987
|
+
|
|
988
|
+
extent_time_samples = extent_time_samples or list(ExtentsChecker._get_extent_time_samples(prim))
|
|
989
|
+
for time in extent_time_samples:
|
|
990
|
+
authored_extent: Vt.Vec3fArray = attribute.Get(time)
|
|
991
|
+
if not authored_extent and time == Usd.TimeCode.Default():
|
|
992
|
+
# It is possible the extent time sample is authored on a time that is not at default. We try at time 0
|
|
993
|
+
time = Usd.TimeCode()
|
|
994
|
+
authored_extent = attribute.Get(time)
|
|
995
|
+
computed_extent: Vt.Vec3fArray = boundable.ComputeExtentFromPlugins(boundable, time)
|
|
996
|
+
authored_vs_computed[time] = self._is_close(authored_extent, computed_extent)
|
|
997
|
+
|
|
998
|
+
# Get all timestamps where values differ
|
|
999
|
+
time_codes: list[Usd.TimeCode] = []
|
|
1000
|
+
for time, flag in authored_vs_computed.items():
|
|
1001
|
+
if not flag:
|
|
1002
|
+
time_codes.append(time)
|
|
1003
|
+
|
|
1004
|
+
if Usd.TimeCode.Default() in time_codes:
|
|
1005
|
+
self._AddFailedCheck(
|
|
1006
|
+
"Prim has incorrect extent value",
|
|
1007
|
+
at=prim,
|
|
1008
|
+
requirement=cap.Requirements.VG_002,
|
|
1009
|
+
suggestion=Suggestion(
|
|
1010
|
+
message="Recompute the extents",
|
|
1011
|
+
callable=partial(self._compute_extents, extent_time_samples=extent_time_samples),
|
|
1012
|
+
at=self._layers_to_apply(prim),
|
|
1013
|
+
),
|
|
1014
|
+
)
|
|
1015
|
+
elif len(time_codes) == 1:
|
|
1016
|
+
self._AddFailedCheck(
|
|
1017
|
+
f"Incorrect extent value for prim at time {time_codes[0].GetValue()}",
|
|
1018
|
+
at=prim,
|
|
1019
|
+
requirement=cap.Requirements.VG_002,
|
|
1020
|
+
suggestion=Suggestion(
|
|
1021
|
+
message="Recompute the extents",
|
|
1022
|
+
callable=partial(self._compute_extents, extent_time_samples=extent_time_samples),
|
|
1023
|
+
at=self._layers_to_apply(prim),
|
|
1024
|
+
),
|
|
1025
|
+
)
|
|
1026
|
+
elif len(time_codes) > 1:
|
|
1027
|
+
values = ", ".join(map(lambda time_code: str(time_code.GetValue()), time_codes[: self._MAX_TIME_SAMPLES]))
|
|
1028
|
+
if len(time_codes) > self._MAX_TIME_SAMPLES:
|
|
1029
|
+
values = f"{values}, ..."
|
|
1030
|
+
self._AddFailedCheck(
|
|
1031
|
+
f"Incorrect extent value for prim at multiple times (i.e. {values})",
|
|
1032
|
+
at=prim,
|
|
1033
|
+
requirement=cap.Requirements.VG_002,
|
|
1034
|
+
suggestion=Suggestion(
|
|
1035
|
+
message="Recompute the extents",
|
|
1036
|
+
callable=partial(self._compute_extents, extent_time_samples=extent_time_samples),
|
|
1037
|
+
at=self._layers_to_apply(prim),
|
|
1038
|
+
),
|
|
1039
|
+
)
|
|
1040
|
+
|
|
1041
|
+
def _check_skel(self, skel_root_prim: Usd.Prim) -> None:
|
|
1042
|
+
"""Check the extent of a UsdSkel.SkelRoot and all the UsdSkel.Skeleton prims underneath it"""
|
|
1043
|
+
skel_root_cache = UsdSkel.Cache()
|
|
1044
|
+
skel_root_cache.Populate(UsdSkel.Root(skel_root_prim), Usd.PrimAllPrimsPredicate)
|
|
1045
|
+
skel_root_time_samples: list[float] = []
|
|
1046
|
+
|
|
1047
|
+
for child_prim in Usd.PrimRange(skel_root_prim):
|
|
1048
|
+
if child_prim.IsA(UsdSkel.Skeleton):
|
|
1049
|
+
# Get the extent time samples from the SkelAnimation binding
|
|
1050
|
+
skel_query = skel_root_cache.GetSkelQuery(UsdSkel.Skeleton(child_prim))
|
|
1051
|
+
anim_query = skel_query.GetAnimQuery()
|
|
1052
|
+
if anim_query:
|
|
1053
|
+
time_samples = [Usd.TimeCode(time) for time in anim_query.GetJointTransformTimeSamples()]
|
|
1054
|
+
skel_root_time_samples.extend(time_samples)
|
|
1055
|
+
self._check_extent(child_prim, extent_time_samples=time_samples)
|
|
1056
|
+
else:
|
|
1057
|
+
# No SkelAnimation binding. Get the extent time samples directly from the extent attribute.
|
|
1058
|
+
self._check_extent(child_prim)
|
|
1059
|
+
self._checked_prims.add(child_prim)
|
|
1060
|
+
|
|
1061
|
+
# The time samples of a SkelRoot are all the time samples of the Skeletons underneath it.
|
|
1062
|
+
self._check_extent(skel_root_prim, extent_time_samples=sorted(list(skel_root_time_samples)))
|
|
1063
|
+
|
|
1064
|
+
def ResetCaches(self):
|
|
1065
|
+
self._checked_prims: set[Usd.Prim] = set()
|
|
1066
|
+
|
|
1067
|
+
|
|
1068
|
+
@register_rule("Basic")
|
|
1069
|
+
class TypeChecker(BaseRuleChecker):
|
|
1070
|
+
"""
|
|
1071
|
+
All prims must have a type defined.
|
|
1072
|
+
"""
|
|
1073
|
+
|
|
1074
|
+
def CheckPrim(self, prim):
|
|
1075
|
+
# Ignore specific prim.
|
|
1076
|
+
if prim.GetPath().HasPrefix(Sdf.Path("/Render")):
|
|
1077
|
+
return
|
|
1078
|
+
if prim.IsDefined() and not prim.GetTypeName():
|
|
1079
|
+
self._AddFailedCheck(
|
|
1080
|
+
f"Missing type for Prim <{prim.GetPath()}>",
|
|
1081
|
+
at=prim,
|
|
1082
|
+
)
|