USD File Extensions and Saving

   1972   2   1
User Avatar
Member
4 posts
Joined: Oct. 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
Staff
4443 posts
Joined: July 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: Oct. 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
  • Quick Links