Search - User list
Full Version: USD File Extensions and Saving
Root » Solaris and Karma » USD File Extensions and Saving
draymond
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!
mtucker
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).
draymond
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
bazhutkin
Question for developers. Maybe for convenience it is worth adding a format parameter in USD ROP node when using the .usd extension?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB