From b89c03270a9af519c44a5c06497698881debb188 Mon Sep 17 00:00:00 2001 From: rickrams Date: Mon, 4 May 2026 22:25:52 +0000 Subject: [PATCH] feat: add submission hook for automatic USD dependency discovery Add a pre-submission hook to the houdini_husk_usd_render job bundle that automatically discovers USD file dependencies using UsdUtils.ComputeAllDependencies and adds them as input attachments before submission. This eliminates the need to run generate_usd_job.py as a separate step. Users can now submit the bundle directly with 'deadline bundle submit'. Signed-off-by: rickrams --- job_bundles/houdini_husk_usd_render/README.md | 44 +++++++++++---- .../discover_usd_dependencies.py | 54 +++++++++++++++++++ .../houdini_husk_usd_render/hooks.yaml | 5 ++ 3 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 job_bundles/houdini_husk_usd_render/discover_usd_dependencies.py create mode 100644 job_bundles/houdini_husk_usd_render/hooks.yaml diff --git a/job_bundles/houdini_husk_usd_render/README.md b/job_bundles/houdini_husk_usd_render/README.md index 97c0548f..14ce5214 100644 --- a/job_bundles/houdini_husk_usd_render/README.md +++ b/job_bundles/houdini_husk_usd_render/README.md @@ -36,17 +36,43 @@ uses this metadata to generate its UI. Please note that if the USD file refers t these files must be made available to the job. When using a service-managed fleets you must use job attachments. When using a customer-managed fleet you may use job attachments or alternatively use [storage profiles](https://docs.aws.amazon.com/deadline-cloud/latest/userguide/storage-shared.html) to use shared storage. -These job attachments may be attached manually or by using the included `generate_usd_job.py` script. +### Automatic Dependency Discovery (Submission Hook) -This script introspects the USD file and find all files required by the USD stage to render. -To use this script you must have the usd-core and deadline python libraries available in your python installation. -`pip3 install usd-core deadline` -Then run the script to find required files -`python3 generate_usd_job.py my_scene.usd` -This script will generate a new job bundle with job attachment references for required assets and will preset the input USD file to the file you selected. -After running, this script will open the Deadline Cloud job submissions UI. You may select which queue to use and further adjust job parameters such as resolution before submitting. +This job bundle includes a **pre-submission hook** (`hooks.yaml`) that automatically discovers all USD file dependencies (textures, materials, sublayers, references, etc.) and adds them as job attachments before submission. No manual file attachment is needed. -Please note that husk will not render your scene if no camera is included. the `generate_usd_job.py` script will warn you if this is the case. +To use the hook: + +1. Install the `usd-core` Python package: + ``` + pip3 install usd-core + ``` + +2. Enable bundle hooks in your Deadline Cloud configuration: + ``` + deadline config set settings.allow_bundle_hooks true + ``` + +3. Submit the job bundle directly: + ``` + deadline bundle gui-submit job_bundles/houdini_husk_usd_render + ``` + or + ``` + deadline bundle submit job_bundles/houdini_husk_usd_render + ``` + +The hook will introspect the USD scene file specified in the `USDSceneFile` parameter, find all dependent files, and add them as input attachments automatically. It will also warn if no camera is found in the scene. + +### Legacy Script (generate_usd_job.py) + +Alternatively, you can use the included `generate_usd_job.py` script to manually generate a job bundle with pre-resolved dependencies. This requires both `usd-core` and `deadline` Python packages: +``` +pip3 install usd-core deadline +python3 generate_usd_job.py my_scene.usd +``` +This script will generate a new job bundle with job attachment references for required assets and open the submission UI. + +Please note that husk will not render your scene if no camera is included. Both the hook and the legacy script will warn you if this is the case. Only a few husk parameters are included for demonstration purpose. Please see the [husk documentation](https://www.sidefx.com/docs/houdini/ref/utils/husk.html) for reference. diff --git a/job_bundles/houdini_husk_usd_render/discover_usd_dependencies.py b/job_bundles/houdini_husk_usd_render/discover_usd_dependencies.py new file mode 100644 index 00000000..1fd8c2bf --- /dev/null +++ b/job_bundles/houdini_husk_usd_render/discover_usd_dependencies.py @@ -0,0 +1,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() diff --git a/job_bundles/houdini_husk_usd_render/hooks.yaml b/job_bundles/houdini_husk_usd_render/hooks.yaml new file mode 100644 index 00000000..b2b0407b --- /dev/null +++ b/job_bundles/houdini_husk_usd_render/hooks.yaml @@ -0,0 +1,5 @@ +version: "1.0" +preSubmission: + - command: python3 + args: [discover_usd_dependencies.py] + timeout: 120