forked from aws-deadline/deadline-cloud-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscover_usd_dependencies.py
More file actions
54 lines (42 loc) · 1.49 KB
/
Copy pathdiscover_usd_dependencies.py
File metadata and controls
54 lines (42 loc) · 1.49 KB
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
#!/usr/bin/env python3
"""
Pre-submission hook that discovers USD file dependencies and adds them
as input file attachments automatically.
Requires: pip install usd-core
"""
import json
import sys
from pxr import Usd, UsdGeom, UsdUtils
def main():
metadata = json.load(sys.stdin)
usd_file = metadata.get("parameters", {}).get("USDSceneFile")
if not usd_file:
print(
"No USDSceneFile parameter found, skipping dependency discovery",
file=sys.stderr,
)
sys.exit(0)
# Discover all dependencies
layers, assets, unresolved = UsdUtils.ComputeAllDependencies(usd_file)
input_files = [layer.realPath for layer in layers] + assets
if unresolved:
print(f"WARNING: {len(unresolved)} unresolved paths:", file=sys.stderr)
for p in unresolved:
print(f" {p}", file=sys.stderr)
# Check for cameras
stage = Usd.Stage.Open(usd_file)
cameras = [
p.GetPath().pathString for p in stage.Traverse() if p.IsA(UsdGeom.Camera)
]
if not cameras:
print(
"WARNING: No cameras found in USD stage. The scene may not render.",
file=sys.stderr,
)
# Output discovered files as additional input attachments
if input_files:
print(f"Discovered {len(input_files)} dependency file(s)", file=sys.stderr)
output = {"attachments": {"assetReferences": {"inputFilenames": input_files}}}
print(json.dumps(output))
if __name__ == "__main__":
main()