USD File Extensions and Saving

   5540   4   2
User Avatar
Member
4 posts
Joined: 10月 2013
Offline
Is there any option on save/output to prefer ascii vs binary when saving to the .usd extension?

I could see advantages in saving to .usd as opposed to .usda to avoid hard-linking asset path file formats, but I've been finding that Houdini hasn't exposed any options for this?

Does anyone have any alternate strategies to deal with this?

Thanks!
User Avatar
スタッフ
4588 posts
Joined: 7月 2005
Offline
You can tell the USD library to write a .usd file in ASCII format using "sdf format arguments" appended to the file name. So if you set a USD ROP to output "$HIP/foo.usd:SDF_FORMAT_ARGS:format=usda", foo.usd will be written in ASCII format. The Component Output LOP I believe uses this approach (appending the ":SDF_FORMAT_ARGS:format=usda" to the user-specified output file path).
User Avatar
Member
4 posts
Joined: 10月 2013
Offline
That works. I've gone and included it within an output processor to fit my "default" behaviour needs, and included it here if anyone else finds a need for it.

import hou
import husd.outputprocessor as base
from pxr import Sdf
import pathlib

class UsdFormatOutputProcessor(base.OutputProcessor):
    def __init__(self):
        super().__init__()

    @staticmethod
    def name():
        return 'usdformat'

    @staticmethod
    def displayName():
        return '.USD Format'

    @staticmethod
    def parameters():
        group = hou.ParmTemplateGroup()
        group.append(hou.StringParmTemplate("format", "Format", 1))
        return group.asDialogScript()

    def beginSave(self, config_node, config_overrides, lop_node, t):
        super().beginSave(config_node, config_overrides, lop_node, t)
        self.format = config_node.parm("format").evalAsString()

    def processSavePath(self, asset_path, referencing_layer_path, asset_is_layer):
        obj = pathlib.Path(asset_path)
        if asset_is_layer and obj.suffix == ".usd":
            asset_path = Sdf.Layer.CreateIdentifier(str(obj), {"format": self.format})
            print(".USD Format:", asset_path)
            return asset_path
        return asset_path

################################################################################
# In order to be considered for output processing, this python module
# implements the function that returns a processor object.
#
def usdOutputProcessor():
    return UsdFormatOutputProcessor
User Avatar
Member
2 posts
Joined: 5月 2019
Offline
Question for developers. Maybe for convenience it is worth adding a format parameter in USD ROP node when using the .usd extension?
User Avatar
Member
20 posts
Joined: 8月 2019
Offline
To set the format for all USD file paths, I've created an environment variable (Edit > Aliases and Variables > Variables tab) USD_FORMAT: usda. And added a SDF format argument to the file path path/to/usd_file.usd:SDF_FORMAT_ARGS:format=$USD_FORMAT. So now I can switch between the two formats (usda, usdc) by changing the environment variable. It would be convenient if Sidefx added an option to switch between the two formats throughout a project.
Edited by HypoSection - 2026年6月27日 04:05:24
  • Quick Links